119 lines · 4.7 KB · C#
RawDownload
//******************************************************************************************************//  ServiceMonitors.cs - Gbtc////  Copyright © 2014, Grid Protection Alliance.  All Rights Reserved.////  Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See//  the NOTICE file distributed with this work for additional information regarding copyright ownership.//  The GPA licenses this file to you under the MIT License (MIT), the "License"; you may//  not use this file except in compliance with the License. You may obtain a copy of the License at:////      http://www.opensource.org/licenses/MIT////  Unless agreed to in writing, the subject software distributed under the License is distributed on an//  "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the//  License for the specific language governing permissions and limitations.////  Code Modification History://  ----------------------------------------------------------------------------------------------------//  04/29/2014 - Stephen C. Wills//       Generated original version of source code.////****************************************************************************************************** using System;using GSF.Adapters; namespace GSF.ServiceProcess{    /// <summary>    /// A special exception thrown by error handlers.    /// </summary>    public class ErrorHandlerException : Exception    {        /// <summary>        /// Creates a new instance of the <see cref="ErrorHandlerException"/> class.        /// </summary>        public ErrorHandlerException()        {        }         /// <summary>        /// Creates a new instance of the <see cref="ErrorHandlerException"/> class.        /// </summary>        /// <param name="message">The message that describes the error.</param>        public ErrorHandlerException(string message)            : base(message)        {        }         /// <summary>        /// Creates a new instance of the <see cref="ErrorHandlerException"/> class.        /// </summary>        /// <param name="message">The message that describes the error.</param>        /// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>        public ErrorHandlerException(string message, Exception innerException)            : base(message, innerException)        {        }    }     /// <summary>    /// Adapter loader that loads implementations of <see cref="IServiceMonitor"/>    /// and delegates messages to the enabled monitors.    /// </summary>    public class ServiceMonitors : AdapterLoader<IServiceMonitor>    {        /// <summary>        /// Handles notifications from the service that occur        /// on an interval to indicate that the service is        /// still running.        /// </summary>        public void HandleServiceHeartbeat()        {            OperationQueue.Enqueue(new Action<IServiceMonitor>(serviceMonitor => serviceMonitor.HandleServiceHeartbeat()));        }         /// <summary>        /// Handles messages received by the service        /// whenever the service encounters an error.        /// </summary>        /// <param name="ex">The exception received from the service.</param>        public void HandleServiceError(Exception ex)        {            OperationQueue.Enqueue(new Action<IServiceMonitor>(serviceMonitor =>            {                try                {                    serviceMonitor.HandleServiceError(ex);                }                catch (Exception errorHandlerException)                {                    throw new ErrorHandlerException(errorHandlerException.Message, errorHandlerException);                }            }));        }         /// <summary>        /// Handles messages sent by a client.        /// </summary>        /// <param name="args">Arguments provided by the client.</param>        public void HandleClientMessage(string[] args)        {            OperationQueue.Enqueue(new Action<IServiceMonitor>(serviceMonitor => serviceMonitor.HandleClientMessage(args)));        }         /// <summary>        /// Executes an operation on the <paramref name="adapter"/> with the given <paramref name="data"/>.        /// </summary>        /// <param name="adapter">Adapter on which an operation is to be executed.</param>        /// <param name="data">The operation to be executed.</param>        protected override void ExecuteAdapterOperation(IServiceMonitor adapter, object data)        {            Action<IServiceMonitor> operation = data as Action<IServiceMonitor>;             if ((object)operation != null)                operation(adapter);        }    }}

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