| @@ -21,10 +21,43 @@ · 20 unmodified lines |
| 21 | // | 21 | // |
| 22 | //****************************************************************************************************** | 22 | //****************************************************************************************************** |
| 23 | | 23 | |
| | 24 | using System; |
| 24 | using GSF.Adapters; | 25 | using GSF.Adapters; |
| 25 | | 26 | |
| 26 | namespace GSF.ServiceProcess | 27 | namespace GSF.ServiceProcess |
| 27 | { | 28 | { |
| | 29 | /// <summary> |
| | 30 | /// A special exception thrown by error handlers. |
| | 31 | /// </summary> |
| | 32 | public class ErrorHandlerException : Exception |
| | 33 | { |
| | 34 | /// <summary> |
| | 35 | /// Creates a new instance of the <see cref="ErrorHandlerException"/> class. |
| | 36 | /// </summary> |
| | 37 | public ErrorHandlerException() |
| | 38 | { |
| | 39 | } |
| | 40 | |
| | 41 | /// <summary> |
| | 42 | /// Creates a new instance of the <see cref="ErrorHandlerException"/> class. |
| | 43 | /// </summary> |
| | 44 | /// <param name="message">The message that describes the error.</param> |
| | 45 | public ErrorHandlerException(string message) |
| | 46 | : base(message) |
| | 47 | { |
| | 48 | } |
| | 49 | |
| | 50 | /// <summary> |
| | 51 | /// Creates a new instance of the <see cref="ErrorHandlerException"/> class. |
| | 52 | /// </summary> |
| | 53 | /// <param name="message">The message that describes the error.</param> |
| | 54 | /// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param> |
| | 55 | public ErrorHandlerException(string message, Exception innerException) |
| | 56 | : base(message, innerException) |
| | 57 | { |
| | 58 | } |
| | 59 | } |
| | 60 | |
| 28 | /// <summary> | 61 | /// <summary> |
| 29 | /// Adapter loader that loads implementations of <see cref="IServiceMonitor"/> | 62 | /// Adapter loader that loads implementations of <see cref="IServiceMonitor"/> |
| 30 | /// and delegates messages to the enabled monitors. | 63 | /// and delegates messages to the enabled monitors. |
| @@ -38,25 +71,27 @@ namespace GSF.ServiceProcess · 7 unmodified lines |
| 38 | /// </summary> | 71 | /// </summary> |
| 39 | public void HandleServiceHeartbeat() | 72 | public void HandleServiceHeartbeat() |
| 40 | { | 73 | { |
| 41 | foreach (IServiceMonitor serviceMonitor in Adapters) | 74 | OperationQueue.Enqueue(new Action<IServiceMonitor>(serviceMonitor => serviceMonitor.HandleServiceHeartbeat())); |
| 42 | { | | |
| 43 | if (serviceMonitor.Enabled) | | |
| 44 | serviceMonitor.HandleServiceHeartbeat(); | | |
| 45 | } | | |
| 46 | } | 75 | } |
| 47 | | 76 | |
| 48 | /// <summary> | 77 | /// <summary> |
| 49 | /// Handles messages received by the service | 78 | /// Handles messages received by the service |
| 50 | /// whenever the service encounters an error. | 79 | /// whenever the service encounters an error. |
| 51 | /// </summary> | 80 | /// </summary> |
| 52 | /// <param name="message">The error message received from the service.</param> | 81 | /// <param name="ex">The exception received from the service.</param> |
| 53 | public void HandleServiceErrorMessage(string message) | 82 | public void HandleServiceError(Exception ex) |
| 54 | { | 83 | { |
| 55 | foreach (IServiceMonitor serviceMonitor in Adapters) | 84 | OperationQueue.Enqueue(new Action<IServiceMonitor>(serviceMonitor => |
| 56 | { | 85 | { |
| 57 | if (serviceMonitor.Enabled) | 86 | try |
| 58 | serviceMonitor.HandleServiceErrorMessage(message); | 87 | { |
| 59 | } | 88 | serviceMonitor.HandleServiceError(ex); |
| | 89 | } |
| | 90 | catch (Exception errorHandlerException) |
| | 91 | { |
| | 92 | throw new ErrorHandlerException(errorHandlerException.Message, errorHandlerException); |
| | 93 | } |
| | 94 | })); |
| 60 | } | 95 | } |
| 61 | | 96 | |
| 62 | /// <summary> | 97 | /// <summary> |
| @@ -65,11 +100,20 @@ namespace GSF.ServiceProcess · 2 unmodified lines |
| 65 | /// <param name="args">Arguments provided by the client.</param> | 100 | /// <param name="args">Arguments provided by the client.</param> |
| 66 | public void HandleClientMessage(string[] args) | 101 | public void HandleClientMessage(string[] args) |
| 67 | { | 102 | { |
| 68 | foreach (IServiceMonitor serviceMonitor in Adapters) | 103 | OperationQueue.Enqueue(new Action<IServiceMonitor>(serviceMonitor => serviceMonitor.HandleClientMessage(args))); |
| 69 | { | 104 | } |
| 70 | if (serviceMonitor.Enabled) | 105 | |
| 71 | serviceMonitor.HandleClientMessage(args); | 106 | /// <summary> |
| 72 | } | 107 | /// Executes an operation on the <paramref name="adapter"/> with the given <paramref name="data"/>. |
| | 108 | /// </summary> |
| | 109 | /// <param name="adapter">Adapter on which an operation is to be executed.</param> |
| | 110 | /// <param name="data">The operation to be executed.</param> |
| | 111 | protected override void ExecuteAdapterOperation(IServiceMonitor adapter, object data) |
| | 112 | { |
| | 113 | Action<IServiceMonitor> operation = data as Action<IServiceMonitor>; |
| | 114 | |
| | 115 | if ((object)operation != null) |
| | 116 | operation(adapter); |
| 73 | } | 117 | } |
| 74 | } | 118 | } |
| 75 | } | 119 | } |