Showing the changes to Source/Libraries/GSF.ServiceProcess (1 of 7 files). Show all
Unified · Split
| @@ -322,6 +322,27 @@ namespace GSF.ServiceProcess · 321 unmodified lines | ||
| 322 | 322 | Description("Occurs when the state of a defined ServiceProcess changes.")] |
| 323 | 323 | public event EventHandler<EventArgs<string, ServiceProcessState>> ProcessStateChanged; |
| 324 | 324 | |
| 325 | + /// <summary> | |
| 326 | + /// Provides notification of when status messages were sent to consumer(s). | |
| 327 | + /// </summary> | |
| 328 | + /// <remarks> | |
| 329 | + /// <see cref="EventArgs{T1,T2}.Argument1"/> is the status message sent to consumer(s).<br/> | |
| 330 | + /// <see cref="EventArgs{T1,T2}.Argument2"/> is the message <see cref="UpdateType"/>. | |
| 331 | + /// </remarks> | |
| 332 | + [Category("Notification"), | |
| 333 | + Description("Occurs when there are status messages sent to consumer(s).")] | |
| 334 | + public event EventHandler<EventArgs<string, UpdateType>> UpdatedStatus; | |
| 335 | + | |
| 336 | + /// <summary> | |
| 337 | + /// Provides notification of when there is an exception logged. | |
| 338 | + /// </summary> | |
| 339 | + /// <remarks> | |
| 340 | + /// <see cref="EventArgs{T}.Argument"/> is the exception that was logged. | |
| 341 | + /// </remarks> | |
| 342 | + [Category("Notification"), | |
| 343 | + Description("Occurs when there is an exception logged.")] | |
| 344 | + public event EventHandler<EventArgs<Exception>> LoggedException; | |
| 345 | + | |
| 325 | 346 | // Fields |
| 326 | 347 | private bool m_logStatusUpdates; |
| 327 | 348 | private int m_maxStatusUpdatesLength; |
| @@ -1175,7 +1196,7 @@ namespace GSF.ServiceProcess · 847 unmodified lines | ||
| 1175 | 1196 | catch (UnauthorizedAccessException ex) |
| 1176 | 1197 | { |
| 1177 | 1198 | string message = string.Format("Unable to start health monitor due to exception: {0}", ex.Message); |
| 1178 | − m_errorLogger.Log(new InvalidOperationException(message, ex)); | |
| 1199 | + LogException(new InvalidOperationException(message, ex)); | |
| 1179 | 1200 | UpdateStatus(UpdateType.Warning, "{0} Is the service account a member of the \"Performance Log Users\" group?", message); |
| 1180 | 1201 | } |
| 1181 | 1202 | } |
| @@ -1318,7 +1339,7 @@ namespace GSF.ServiceProcess · 136 unmodified lines | ||
| 1318 | 1339 | catch (Exception ex) |
| 1319 | 1340 | { |
| 1320 | 1341 | // Log the exception. |
| 1321 | − m_errorLogger.Log(ex); | |
| 1342 | + LogException(ex); | |
| 1322 | 1343 | } |
| 1323 | 1344 | } |
| 1324 | 1345 | |
| @@ -1359,6 +1380,8 @@ namespace GSF.ServiceProcess · 34 unmodified lines | ||
| 1359 | 1380 | |
| 1360 | 1381 | // Send response to service |
| 1361 | 1382 | SendResponse(requestInfo.Sender.ClientID, response); |
| 1383 | + | |
| 1384 | + OnUpdatedStatus(response.Message, success ? UpdateType.Information : UpdateType.Alarm); | |
| 1362 | 1385 | } |
| 1363 | 1386 | catch (Exception ex) |
| 1364 | 1387 | { |
| @@ -1609,6 +1632,18 @@ namespace GSF.ServiceProcess · 244 unmodified lines | ||
| 1609 | 1632 | } |
| 1610 | 1633 | } |
| 1611 | 1634 | |
| 1635 | + /// <summary> | |
| 1636 | + /// Log exception to <see cref="ErrorLogger"/>. | |
| 1637 | + /// </summary> | |
| 1638 | + /// <param name="ex">Exception to log.</param> | |
| 1639 | + public void LogException(Exception ex) | |
| 1640 | + { | |
| 1641 | + if ((object)m_errorLogger != null) | |
| 1642 | + m_errorLogger.Log(ex); | |
| 1643 | + | |
| 1644 | + OnLoggedException(ex); | |
| 1645 | + } | |
| 1646 | + | |
| 1612 | 1647 | /// <summary> |
| 1613 | 1648 | /// Raises the <see cref="ServiceStarting"/> event. |
| 1614 | 1649 | /// </summary> |
| @@ -1741,6 +1776,30 @@ namespace GSF.ServiceProcess · 126 unmodified lines | ||
| 1741 | 1776 | SendProcessStateChangedResponse(processName, processState); |
| 1742 | 1777 | } |
| 1743 | 1778 | |
| 1779 | + /// <summary> | |
| 1780 | + /// Raises the <see cref="UpdatedStatus"/> event with the updated status message. | |
| 1781 | + /// </summary> | |
| 1782 | + /// <param name="status">Updated status message.</param> | |
| 1783 | + /// <param name="type"><see cref="UpdateType"/> of status message.</param> | |
| 1784 | + /// <remarks> | |
| 1785 | + /// This overload combines string.Format and SendStatusMessage for convenience. | |
| 1786 | + /// </remarks> | |
| 1787 | + protected virtual void OnUpdatedStatus(string status, UpdateType type) | |
| 1788 | + { | |
| 1789 | + if ((object)UpdatedStatus != null) | |
| 1790 | + UpdatedStatus(this, new EventArgs<string, UpdateType>(status, type)); | |
| 1791 | + } | |
| 1792 | + | |
| 1793 | + /// <summary> | |
| 1794 | + /// Raises <see cref="LoggedException"/> event with logged exception. | |
| 1795 | + /// </summary> | |
| 1796 | + /// <param name="ex">Logged <see cref="Exception"/>.</param> | |
| 1797 | + protected virtual void OnLoggedException(Exception ex) | |
| 1798 | + { | |
| 1799 | + if ((object)LoggedException != null) | |
| 1800 | + LoggedException(this, new EventArgs<Exception>(ex)); | |
| 1801 | + } | |
| 1802 | + | |
| 1744 | 1803 | /// <summary> |
| 1745 | 1804 | /// Releases the unmanaged resources used by the <see cref="ServiceHelper"/> object and optionally releases the managed resources. |
| 1746 | 1805 | /// </summary> |
| @@ -1982,29 +2041,31 @@ namespace GSF.ServiceProcess · 235 unmodified lines | ||
| 1982 | 2041 | SendResponse(clientID, new ServiceResponse("AuthenticationFailure")); |
| 1983 | 2042 | } |
| 1984 | 2043 | |
| 1985 | − private void SendUpdateClientStatusResponse(Guid clientID, UpdateType type, string response) | |
| 2044 | + private void SendUpdateClientStatusResponse(Guid clientID, UpdateType type, string responseMessage) | |
| 1986 | 2045 | { |
| 1987 | − if (string.IsNullOrEmpty(response)) | |
| 2046 | + if (string.IsNullOrEmpty(responseMessage)) | |
| 1988 | 2047 | return; |
| 1989 | 2048 | |
| 1990 | − ServiceResponse serviceResponse = new ServiceResponse(); | |
| 1991 | − serviceResponse.Type = "UPDATECLIENTSTATUS-" + type.ToString().ToUpper(); | |
| 1992 | − serviceResponse.Message = CurtailMessageLength(response); | |
| 1993 | − SendResponse(clientID, serviceResponse); | |
| 2049 | + ServiceResponse response = new ServiceResponse(); | |
| 2050 | + response.Type = "UPDATECLIENTSTATUS-" + type.ToString().ToUpper(); | |
| 2051 | + response.Message = CurtailMessageLength(responseMessage); | |
| 2052 | + SendResponse(clientID, response); | |
| 2053 | + | |
| 2054 | + OnUpdatedStatus(response.Message, type); | |
| 1994 | 2055 | } |
| 1995 | 2056 | |
| 1996 | 2057 | private void SendServiceStateChangedResponse(ServiceState currentState) |
| 1997 | 2058 | { |
| 1998 | − ServiceResponse serviceResponse = new ServiceResponse("SERVICESTATECHANGED"); | |
| 1999 | − serviceResponse.Attachments.Add(new ObjectState<ServiceState>(Name, currentState)); | |
| 2000 | − SendResponse(serviceResponse); | |
| 2059 | + ServiceResponse response = new ServiceResponse("SERVICESTATECHANGED"); | |
| 2060 | + response.Attachments.Add(new ObjectState<ServiceState>(Name, currentState)); | |
| 2061 | + SendResponse(response); | |
| 2001 | 2062 | } |
| 2002 | 2063 | |
| 2003 | 2064 | private void SendProcessStateChangedResponse(string processName, ServiceProcessState currentState) |
| 2004 | 2065 | { |
| 2005 | − ServiceResponse serviceResponse = new ServiceResponse("PROCESSSTATECHANGED"); | |
| 2006 | − serviceResponse.Attachments.Add(new ObjectState<ServiceProcessState>(processName, currentState)); | |
| 2007 | − SendResponse(serviceResponse); | |
| 2066 | + ServiceResponse response = new ServiceResponse("PROCESSSTATECHANGED"); | |
| 2067 | + response.Attachments.Add(new ObjectState<ServiceProcessState>(processName, currentState)); | |
| 2068 | + SendResponse(response); | |
| 2008 | 2069 | } |
| 2009 | 2070 | |
| 2010 | 2071 | private void Process_StateChanged(object sender, EventArgs e) |
| @@ -2028,7 +2089,7 @@ namespace GSF.ServiceProcess · 17 unmodified lines | ||
| 2028 | 2089 | |
| 2029 | 2090 | private void StatusUpdateQueue_ProcessException(object sender, EventArgs<Exception> e) |
| 2030 | 2091 | { |
| 2031 | − m_errorLogger.Log(e.Argument); | |
| 2092 | + LogException(e.Argument); | |
| 2032 | 2093 | } |
| 2033 | 2094 | |
| 2034 | 2095 | private void StatusLog_LogException(object sender, EventArgs<Exception> e) |
| @@ -2047,7 +2108,7 @@ namespace GSF.ServiceProcess · 12 unmodified lines | ||
| 2047 | 2108 | private void RemotingServer_ClientConnectingException(object sender, EventArgs<Exception> e) |
| 2048 | 2109 | { |
| 2049 | 2110 | UpdateStatus(UpdateType.Alarm, "Error occurred while connecting client to remoting server - {0}\r\n\r\n", e.Argument.Message); |
| 2050 | − m_errorLogger.Log(e.Argument); | |
| 2111 | + LogException(e.Argument); | |
| 2051 | 2112 | } |
| 2052 | 2113 | |
| 2053 | 2114 | private void RemotingServer_ClientDisconnected(object sender, EventArgs<Guid> e) |
| @@ -2067,7 +2128,7 @@ namespace GSF.ServiceProcess · 13 unmodified lines | ||
| 2067 | 2128 | { |
| 2068 | 2129 | // We'll encounter an exception because we'll try to update the status of the client that had the |
| 2069 | 2130 | // remote command session open and this will fail since the client is disconnected. |
| 2070 | − m_errorLogger.Log(ex); | |
| 2131 | + LogException(ex); | |
| 2071 | 2132 | } |
| 2072 | 2133 | } |
| 2073 | 2134 | |
| @@ -2125,7 +2186,7 @@ namespace GSF.ServiceProcess · 51 unmodified lines | ||
| 2125 | 2186 | } |
| 2126 | 2187 | catch (Exception ex) |
| 2127 | 2188 | { |
| 2128 | − m_errorLogger.Log(ex); | |
| 2189 | + LogException(ex); | |
| 2129 | 2190 | |
| 2130 | 2191 | try |
| 2131 | 2192 | { |
| @@ -2139,7 +2200,7 @@ namespace GSF.ServiceProcess · 7 unmodified lines | ||
| 2139 | 2200 | } |
| 2140 | 2201 | catch (Exception ex2) |
| 2141 | 2202 | { |
| 2142 | − m_errorLogger.Log(ex2); | |
| 2203 | + LogException(ex2); | |
| 2143 | 2204 | } |
| 2144 | 2205 | } |
| 2145 | 2206 | } |
| @@ -2220,7 +2281,7 @@ namespace GSF.ServiceProcess · 74 unmodified lines | ||
| 2220 | 2281 | } |
| 2221 | 2282 | catch (Exception ex) |
| 2222 | 2283 | { |
| 2223 | − m_errorLogger.Log(ex); | |
| 2284 | + LogException(ex); | |
| 2224 | 2285 | |
| 2225 | 2286 | if ((object)requestInfo != null) |
| 2226 | 2287 | SendActionableResponse(requestInfo, false, null, "Failed to process request \"{0}\" - {1}\r\n\r\n", request.Command, ex.Message); |
| @@ -2747,8 +2808,8 @@ namespace GSF.ServiceProcess · 520 unmodified lines | ||
| 2747 | 2808 | { |
| 2748 | 2809 | foreach (ClientRequestHandler handler in m_clientRequestHandlers) |
| 2749 | 2810 | { |
| 2750 | − if (m_secureRemoteInteractions && | |
| 2751 | − SecurityProviderUtility.IsResourceSecurable(handler.Command) && | |
| 2811 | + if (m_secureRemoteInteractions && | |
| 2812 | + SecurityProviderUtility.IsResourceSecurable(handler.Command) && | |
| 2752 | 2813 | !SecurityProviderUtility.IsResourceAccessible(handler.Command)) |
| 2753 | 2814 | continue; |
| 2754 | 2815 | |
| @@ -2816,7 +2877,7 @@ namespace GSF.ServiceProcess · 61 unmodified lines | ||
| 2816 | 2877 | } |
| 2817 | 2878 | catch (Exception ex) |
| 2818 | 2879 | { |
| 2819 | − m_errorLogger.Log(ex); | |
| 2880 | + LogException(ex); | |
| 2820 | 2881 | message = "Failed to query system health monitor status: " + ex.Message; |
| 2821 | 2882 | UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, message + "\r\n\r\n"); |
| 2822 | 2883 | success = false; |
| @@ -2873,7 +2934,7 @@ namespace GSF.ServiceProcess · 50 unmodified lines | ||
| 2873 | 2934 | } |
| 2874 | 2935 | catch (Exception ex) |
| 2875 | 2936 | { |
| 2876 | − m_errorLogger.Log(ex); | |
| 2937 | + LogException(ex); | |
| 2877 | 2938 | UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, "Failed to reset system health monitor: {0}\r\n\r\n", ex.Message); |
| 2878 | 2939 | } |
| 2879 | 2940 | } |
| @@ -3200,7 +3261,7 @@ namespace GSF.ServiceProcess · 320 unmodified lines | ||
| 3200 | 3261 | } |
| 3201 | 3262 | catch (Exception ex) |
| 3202 | 3263 | { |
| 3203 | − m_errorLogger.Log(ex); | |
| 3264 | + LogException(ex); | |
| 3204 | 3265 | UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, "Failed to start system process \"{0}\". {1}.\r\n\r\n", processName, ex.Message); |
| 3205 | 3266 | } |
| 3206 | 3267 | } |
| @@ -3339,7 +3400,7 @@ namespace GSF.ServiceProcess · 132 unmodified lines | ||
| 3339 | 3400 | } |
| 3340 | 3401 | catch (Exception ex) |
| 3341 | 3402 | { |
| 3342 | − m_errorLogger.Log(ex); | |
| 3403 | + LogException(ex); | |
| 3343 | 3404 | UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, "Failed to abort system process \"{0}\". {1}.\r\n\r\n", processName, ex.Message); |
| 3344 | 3405 | } |
| 3345 | 3406 | } |
| @@ -3478,7 +3539,7 @@ namespace GSF.ServiceProcess · 132 unmodified lines | ||
| 3478 | 3539 | } |
| 3479 | 3540 | catch (Exception ex) |
| 3480 | 3541 | { |
| 3481 | − m_errorLogger.Log(ex); | |
| 3542 | + LogException(ex); | |
| 3482 | 3543 | UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, "Failed to schedule process \"{0}\". {1}\r\n\r\n", processName, ex.Message); |
| 3483 | 3544 | } |
| 3484 | 3545 | |