//****************************************************************************************************** // GatewayStatistics.cs - Gbtc // // Copyright © 2012, 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: // ---------------------------------------------------------------------------------------------------- // 03/09/2012 - Stephen C. Wills // Generated original version of source code. // 12/20/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** using System; using System.Reflection; using GSF.TimeSeries.Transport; using GSF.Units; // ReSharper disable UnusedParameter.Local namespace GSF.TimeSeries.Statistics { internal static class GatewayStatistics { private static T GetPropertyValue(object source, string name) { PropertyInfo property = source.GetType().GetProperty(name); return property != null ? (T)property.GetValue(source) : default(T); } private static T GetFunctionValue(object source, string name, params object[] parameters) { MethodInfo method = source.GetType().GetMethod(name); return method != null ? (T)method.Invoke(source, parameters) : default(T); } #region [ Subscriber Statistics ] private static double GetSubscriberStatistic_Connected(object source, string arguments) { return (source is DataSubscriber subscriber ? subscriber.IsConnected : GetPropertyValue(source, "IsConnected")) ? 1.0D : 0.0D; } private static double GetSubscriberStatistic_Authenticated(object source, string arguments) { return (source is DataSubscriber subscriber ? subscriber.Authenticated : GetPropertyValue(source, "Authenticated")) ? 1.0D : 0.0D; } private static double GetSubscriberStatistic_ProcessedMeasurements(object source, string arguments) { double statistic = source is DataSubscriber subscriber ? subscriber.ProcessedMeasurements : GetPropertyValue(source, "ProcessedMeasurements"); return s_statisticValueCache.GetDifference(source, statistic, "ProcessedMeasurements"); } private static double GetSubscriberStatistic_TotalBytesReceived(object source, string arguments) { double statistic = source is DataSubscriber subscriber ? subscriber.TotalBytesReceived : GetPropertyValue(source, "TotalBytesReceived"); double difference = s_statisticValueCache.GetDifference(source, statistic, "TotalBytesReceived"); return difference < 0.0D ? statistic : difference; } private static double GetSubscriberStatistic_AuthorizedCount(object source, string arguments) { Guid[] authorizedSignalIDs = source is DataSubscriber subscriber ? subscriber.GetAuthorizedSignalIDs() : GetFunctionValue(source, "GetAuthorizedSignalIDs"); return authorizedSignalIDs?.Length ?? 0; } private static double GetSubscriberStatistic_UnauthorizedCount(object source, string arguments) { Guid[] unauthorizedSignalIDs = source is DataSubscriber subscriber ? subscriber.GetUnauthorizedSignalIDs() : GetFunctionValue(source, "GetUnauthorizedSignalIDs"); return unauthorizedSignalIDs?.Length ?? 0; } private static double GetSubscriberStatistic_LifetimeMeasurements(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.LifetimeMeasurements : GetPropertyValue(source, "LifetimeMeasurements"); } private static double GetSubscriberStatistic_MinimumMeasurementsPerSecond(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.MinimumMeasurementsPerSecond : GetPropertyValue(source, "MinimumMeasurementsPerSecond"); } private static double GetSubscriberStatistic_MaximumMeasurementsPerSecond(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.MaximumMeasurementsPerSecond : GetPropertyValue(source, "MaximumMeasurementsPerSecond"); } private static double GetSubscriberStatistic_AverageMeasurementsPerSecond(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.AverageMeasurementsPerSecond : GetPropertyValue(source, "AverageMeasurementsPerSecond"); } private static double GetSubscriberStatistic_LifetimeBytesReceived(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.TotalBytesReceived : GetPropertyValue(source, "TotalBytesReceived"); } private static double GetSubscriberStatistic_LifetimeMinimumLatency(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.LifetimeMinimumLatency : GetPropertyValue(source, "LifetimeMinimumLatency"); } private static double GetSubscriberStatistic_LifetimeMaximumLatency(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.LifetimeMaximumLatency : GetPropertyValue(source, "LifetimeMaximumLatency"); } private static double GetSubscriberStatistic_LifetimeAverageLatency(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.LifetimeAverageLatency : GetPropertyValue(source, "LifetimeAverageLatency"); } private static double GetSubscriberStatistic_UpTime(object source, string arguments) { return source is DataSubscriber subscriber ? subscriber.RunTime : GetPropertyValue