IConnectable.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Date Sign TaskId Description
  3. * ---------- ---- ------- -----------
  4. * 2006-07-31 RMa Added Debug ToString methods.
  5. * 2006-03-02 RMa Supply DeviceConnectionState in ConnectionChangedEventArgs instead of bool connected.
  6. * 2006-02-13 MLa This header added
  7. */
  8. using System;
  9. namespace Wayne.Lib
  10. {
  11. /// <summary>
  12. /// Event arguments for a connection changed event from a Wayne Device.
  13. /// </summary>
  14. public sealed class ConnectionChangedEventArgs : EventArgs
  15. {
  16. #region Fields
  17. private DeviceConnectionState connectionState;
  18. #endregion
  19. #region Construction
  20. /// <summary>
  21. /// Constructor
  22. /// </summary>
  23. /// <param name="connectionState">The new state of the connection</param>
  24. public ConnectionChangedEventArgs(DeviceConnectionState connectionState)
  25. {
  26. this.connectionState = connectionState;
  27. }
  28. #endregion
  29. #region Properties
  30. /// <summary>
  31. /// True if the device was connected.
  32. /// </summary>
  33. public DeviceConnectionState ConnectionState
  34. {
  35. get { return connectionState; }
  36. }
  37. #endregion
  38. #region Debug methods
  39. /// <summary>
  40. /// Presents the class as a string.
  41. /// </summary>
  42. /// <returns></returns>
  43. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "format")]
  44. public string ToString(string format, IFormatProvider provider)
  45. {
  46. return string.Format(provider, "ConnectionChange ({0})", connectionState);
  47. }
  48. /// <summary>
  49. /// Presents the class as a string using the specified culture-specific format information.
  50. /// </summary>
  51. /// <returns></returns>
  52. public string ToString(IFormatProvider provider)
  53. {
  54. return ToString("", provider);
  55. }
  56. /// <summary>
  57. /// Presents the class as a string using a format string.
  58. /// </summary>
  59. /// <returns></returns>
  60. public string ToString(string format)
  61. {
  62. return ToString(format, System.Globalization.CultureInfo.InvariantCulture);
  63. }
  64. /// <summary>
  65. /// Presents the class as a string using a format string and the specified culture-specific format information.
  66. /// </summary>
  67. /// <returns></returns>
  68. public override string ToString()
  69. {
  70. return ToString("", System.Globalization.CultureInfo.InvariantCulture);
  71. }
  72. #endregion
  73. }
  74. /// <summary>
  75. /// The state of the connection to a device.
  76. /// </summary>
  77. public enum DeviceConnectionState
  78. {
  79. #region Fields
  80. /// <summary>
  81. /// Unknown state of the connection.
  82. /// </summary>
  83. Unknown,
  84. /// <summary>
  85. /// Device is not connected.
  86. /// </summary>
  87. Disconnected,
  88. /// <summary>
  89. /// Trying to connect to device.
  90. /// </summary>
  91. Connecting,
  92. /// <summary>
  93. /// Connected to device.
  94. /// </summary>
  95. Connected,
  96. /// <summary>
  97. /// Disconnecting from device
  98. /// </summary>
  99. Disconnecting
  100. #endregion
  101. }
  102. /// <summary>
  103. /// The IConnectable defines a standard set of methods and properties for
  104. /// classes that represents devices that theoretically can have a connected/disconnected state.
  105. /// </summary>
  106. public interface IConnectable
  107. {
  108. #region Properties
  109. /// <summary>
  110. /// Indicates the state of the connection.
  111. /// </summary>
  112. DeviceConnectionState ConnectionState { get; }
  113. #endregion
  114. #region Methods
  115. /// <summary>
  116. /// Connect to the device.
  117. /// </summary>
  118. /// <param name="connectionString">A string that contains the connection parameters.
  119. /// The format is provided by the implementation.</param>
  120. void Connect(string connectionString);
  121. /// <summary>
  122. /// Disconnects from the device.
  123. /// </summary>
  124. void Disconnect();
  125. #endregion
  126. #region Events
  127. /// <summary>
  128. /// An event that is fired when the ConnectionState changes for to device.
  129. /// </summary>
  130. event EventHandler<ConnectionChangedEventArgs> OnConnectionStateChange;
  131. #endregion
  132. }
  133. }