History

GSF.TimeSeries: Added support to TSF for use of a console based hosted deployment for easier use on Mono.

ritchiecarroll committed 12 years ago

Commit 36f1b791 parent de759057 files · +391 −65Browse files

Showing the changes to Source/Libraries/GSF.ServiceProcess (1 of 7 files). Show all

Unified · Split

Source/Libraries/GSF.ServiceProcess/ServiceHelper.cs+88−27
@@ -322,6 +322,27 @@ namespace GSF.ServiceProcess · 321 unmodified lines
322322 Description("Occurs when the state of a defined ServiceProcess changes.")]
323323 public event EventHandler<EventArgs<string, ServiceProcessState>> ProcessStateChanged;
324324
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+
325346 // Fields
326347 private bool m_logStatusUpdates;
327348 private int m_maxStatusUpdatesLength;
@@ -1175,7 +1196,7 @@ namespace GSF.ServiceProcess · 847 unmodified lines
11751196 catch (UnauthorizedAccessException ex)
11761197 {
11771198 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));
11791200 UpdateStatus(UpdateType.Warning, "{0} Is the service account a member of the \"Performance Log Users\" group?", message);
11801201 }
11811202 }
@@ -1318,7 +1339,7 @@ namespace GSF.ServiceProcess · 136 unmodified lines
13181339 catch (Exception ex)
13191340 {
13201341 // Log the exception.
1321− m_errorLogger.Log(ex);
1342+ LogException(ex);
13221343 }
13231344 }
13241345
@@ -1359,6 +1380,8 @@ namespace GSF.ServiceProcess · 34 unmodified lines
13591380
13601381 // Send response to service
13611382 SendResponse(requestInfo.Sender.ClientID, response);
1383+
1384+ OnUpdatedStatus(response.Message, success ? UpdateType.Information : UpdateType.Alarm);
13621385 }
13631386 catch (Exception ex)
13641387 {
@@ -1609,6 +1632,18 @@ namespace GSF.ServiceProcess · 244 unmodified lines
16091632 }
16101633 }
16111634
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+
16121647 /// <summary>
16131648 /// Raises the <see cref="ServiceStarting"/> event.
16141649 /// </summary>
@@ -1741,6 +1776,30 @@ namespace GSF.ServiceProcess · 126 unmodified lines
17411776 SendProcessStateChangedResponse(processName, processState);
17421777 }
17431778
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+
17441803 /// <summary>
17451804 /// Releases the unmanaged resources used by the <see cref="ServiceHelper"/> object and optionally releases the managed resources.
17461805 /// </summary>
@@ -1982,29 +2041,31 @@ namespace GSF.ServiceProcess · 235 unmodified lines
19822041 SendResponse(clientID, new ServiceResponse("AuthenticationFailure"));
19832042 }
19842043
1985− private void SendUpdateClientStatusResponse(Guid clientID, UpdateType type, string response)
2044+ private void SendUpdateClientStatusResponse(Guid clientID, UpdateType type, string responseMessage)
19862045 {
1987− if (string.IsNullOrEmpty(response))
2046+ if (string.IsNullOrEmpty(responseMessage))
19882047 return;
19892048
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);
19942055 }
19952056
19962057 private void SendServiceStateChangedResponse(ServiceState currentState)
19972058 {
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);
20012062 }
20022063
20032064 private void SendProcessStateChangedResponse(string processName, ServiceProcessState currentState)
20042065 {
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);
20082069 }
20092070
20102071 private void Process_StateChanged(object sender, EventArgs e)
@@ -2028,7 +2089,7 @@ namespace GSF.ServiceProcess · 17 unmodified lines
20282089
20292090 private void StatusUpdateQueue_ProcessException(object sender, EventArgs<Exception> e)
20302091 {
2031− m_errorLogger.Log(e.Argument);
2092+ LogException(e.Argument);
20322093 }
20332094
20342095 private void StatusLog_LogException(object sender, EventArgs<Exception> e)
@@ -2047,7 +2108,7 @@ namespace GSF.ServiceProcess · 12 unmodified lines
20472108 private void RemotingServer_ClientConnectingException(object sender, EventArgs<Exception> e)
20482109 {
20492110 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);
20512112 }
20522113
20532114 private void RemotingServer_ClientDisconnected(object sender, EventArgs<Guid> e)
@@ -2067,7 +2128,7 @@ namespace GSF.ServiceProcess · 13 unmodified lines
20672128 {
20682129 // We'll encounter an exception because we'll try to update the status of the client that had the
20692130 // remote command session open and this will fail since the client is disconnected.
2070− m_errorLogger.Log(ex);
2131+ LogException(ex);
20712132 }
20722133 }
20732134
@@ -2125,7 +2186,7 @@ namespace GSF.ServiceProcess · 51 unmodified lines
21252186 }
21262187 catch (Exception ex)
21272188 {
2128− m_errorLogger.Log(ex);
2189+ LogException(ex);
21292190
21302191 try
21312192 {
@@ -2139,7 +2200,7 @@ namespace GSF.ServiceProcess · 7 unmodified lines
21392200 }
21402201 catch (Exception ex2)
21412202 {
2142− m_errorLogger.Log(ex2);
2203+ LogException(ex2);
21432204 }
21442205 }
21452206 }
@@ -2220,7 +2281,7 @@ namespace GSF.ServiceProcess · 74 unmodified lines
22202281 }
22212282 catch (Exception ex)
22222283 {
2223− m_errorLogger.Log(ex);
2284+ LogException(ex);
22242285
22252286 if ((object)requestInfo != null)
22262287 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
27472808 {
27482809 foreach (ClientRequestHandler handler in m_clientRequestHandlers)
27492810 {
2750− if (m_secureRemoteInteractions &&
2751− SecurityProviderUtility.IsResourceSecurable(handler.Command) &&
2811+ if (m_secureRemoteInteractions &&
2812+ SecurityProviderUtility.IsResourceSecurable(handler.Command) &&
27522813 !SecurityProviderUtility.IsResourceAccessible(handler.Command))
27532814 continue;
27542815
@@ -2816,7 +2877,7 @@ namespace GSF.ServiceProcess · 61 unmodified lines
28162877 }
28172878 catch (Exception ex)
28182879 {
2819− m_errorLogger.Log(ex);
2880+ LogException(ex);
28202881 message = "Failed to query system health monitor status: " + ex.Message;
28212882 UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, message + "\r\n\r\n");
28222883 success = false;
@@ -2873,7 +2934,7 @@ namespace GSF.ServiceProcess · 50 unmodified lines
28732934 }
28742935 catch (Exception ex)
28752936 {
2876− m_errorLogger.Log(ex);
2937+ LogException(ex);
28772938 UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, "Failed to reset system health monitor: {0}\r\n\r\n", ex.Message);
28782939 }
28792940 }
@@ -3200,7 +3261,7 @@ namespace GSF.ServiceProcess · 320 unmodified lines
32003261 }
32013262 catch (Exception ex)
32023263 {
3203− m_errorLogger.Log(ex);
3264+ LogException(ex);
32043265 UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, "Failed to start system process \"{0}\". {1}.\r\n\r\n", processName, ex.Message);
32053266 }
32063267 }
@@ -3339,7 +3400,7 @@ namespace GSF.ServiceProcess · 132 unmodified lines
33393400 }
33403401 catch (Exception ex)
33413402 {
3342− m_errorLogger.Log(ex);
3403+ LogException(ex);
33433404 UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, "Failed to abort system process \"{0}\". {1}.\r\n\r\n", processName, ex.Message);
33443405 }
33453406 }
@@ -3478,7 +3539,7 @@ namespace GSF.ServiceProcess · 132 unmodified lines
34783539 }
34793540 catch (Exception ex)
34803541 {
3481− m_errorLogger.Log(ex);
3542+ LogException(ex);
34823543 UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Alarm, "Failed to schedule process \"{0}\". {1}\r\n\r\n", processName, ex.Message);
34833544 }
34843545

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t