Unified · Split
| @@ -23,183 +23,108 @@ · 22 unmodified lines | ||
| 23 | 23 | // |
| 24 | 24 | //****************************************************************************************************** |
| 25 | 25 | |
| 26 | +using System; | |
| 27 | +using System.Reflection; | |
| 26 | 28 | using GSF.TimeSeries.Transport; |
| 29 | +using GSF.Units; | |
| 27 | 30 | |
| 28 | 31 | // ReSharper disable UnusedParameter.Local |
| 29 | 32 | namespace GSF.TimeSeries.Statistics |
| 30 | 33 | { |
| 31 | 34 | internal static class GatewayStatistics |
| 32 | 35 | { |
| 33 | − #region [ Subscriber Statistics ] | |
| 36 | + private static T GetPropertyValue<T>(object source, string name) | |
| 37 | + { | |
| 38 | + PropertyInfo property = source.GetType().GetProperty(name); | |
| 39 | + return property != null ? (T)property.GetValue(source) : default(T); | |
| 40 | + } | |
| 34 | 41 | |
| 35 | − private static double GetSubscriberStatistic_Connected(object source, string arguments) | |
| 42 | + private static T GetFunctionValue<T>(object source, string name, params object[] parameters) | |
| 36 | 43 | { |
| 37 | − double statistic = 0.0D; | |
| 38 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 44 | + MethodInfo method = source.GetType().GetMethod(name); | |
| 45 | + return method != null ? (T)method.Invoke(source, parameters) : default(T); | |
| 46 | + } | |
| 39 | 47 | |
| 40 | − if ((object)subscriber != null) | |
| 41 | − statistic = subscriber.IsConnected ? 1.0D : 0.0D; | |
| 48 | + #region [ Subscriber Statistics ] | |
| 42 | 49 | |
| 43 | − return statistic; | |
| 50 | + private static double GetSubscriberStatistic_Connected(object source, string arguments) | |
| 51 | + { | |
| 52 | + return (source is DataSubscriber subscriber ? subscriber.IsConnected : GetPropertyValue<bool>(source, "IsConnected")) ? 1.0D : 0.0D; | |
| 44 | 53 | } |
| 45 | 54 | |
| 46 | 55 | private static double GetSubscriberStatistic_Authenticated(object source, string arguments) |
| 47 | 56 | { |
| 48 | − double statistic = 0.0D; | |
| 49 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 50 | − | |
| 51 | − if ((object)subscriber != null) | |
| 52 | − statistic = subscriber.Authenticated ? 1.0D : 0.0D; | |
| 53 | − | |
| 54 | − return statistic; | |
| 57 | + return (source is DataSubscriber subscriber ? subscriber.Authenticated : GetPropertyValue<bool>(source, "Authenticated")) ? 1.0D : 0.0D; | |
| 55 | 58 | } |
| 56 | 59 | |
| 57 | 60 | private static double GetSubscriberStatistic_ProcessedMeasurements(object source, string arguments) |
| 58 | 61 | { |
| 59 | − double statistic = 0.0D; | |
| 60 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 61 | − | |
| 62 | − if ((object)subscriber != null) | |
| 63 | − statistic = s_statisticValueCache.GetDifference(subscriber, subscriber.ProcessedMeasurements, "ProcessedMeasurements"); | |
| 64 | − | |
| 65 | − return statistic; | |
| 62 | + double statistic = source is DataSubscriber subscriber ? subscriber.ProcessedMeasurements : GetPropertyValue<long>(source, "ProcessedMeasurements"); | |
| 63 | + return s_statisticValueCache.GetDifference(source, statistic, "ProcessedMeasurements"); | |
| 66 | 64 | } |
| 67 | 65 | |
| 68 | 66 | private static double GetSubscriberStatistic_TotalBytesReceived(object source, string arguments) |
| 69 | 67 | { |
| 70 | − double statistic = 0.0D; | |
| 71 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 72 | − | |
| 73 | − if ((object)subscriber != null) | |
| 74 | − { | |
| 75 | − statistic = s_statisticValueCache.GetDifference(subscriber, subscriber.TotalBytesReceived, "TotalBytesReceived"); | |
| 76 | − | |
| 77 | − if (statistic < 0.0D) | |
| 78 | − statistic = subscriber.TotalBytesReceived; | |
| 79 | − } | |
| 80 | − | |
| 81 | − return statistic; | |
| 68 | + double statistic = source is DataSubscriber subscriber ? subscriber.TotalBytesReceived : GetPropertyValue<long>(source, "TotalBytesReceived"); | |
| 69 | + double difference = s_statisticValueCache.GetDifference(source, statistic, "TotalBytesReceived"); | |
| 70 | + return difference < 0.0D ? statistic : difference; | |
| 82 | 71 | } |
| 83 | 72 | |
| 84 | 73 | private static double GetSubscriberStatistic_AuthorizedCount(object source, string arguments) |
| 85 | 74 | { |
| 86 | − double statistic = 0.0D; | |
| 87 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 88 | − | |
| 89 | − if ((object)subscriber != null) | |
| 90 | − statistic = subscriber.GetAuthorizedSignalIDs().Length; | |
| 91 | − | |
| 92 | − return statistic; | |
| 75 | + Guid[] authorizedSignalIDs = source is DataSubscriber subscriber ? subscriber.GetAuthorizedSignalIDs() : GetFunctionValue<Guid[]>(source, "GetAuthorizedSignalIDs"); | |
| 76 | + return authorizedSignalIDs?.Length ?? 0; | |
| 93 | 77 | } |
| 94 | 78 | |
| 95 | 79 | private static double GetSubscriberStatistic_UnauthorizedCount(object source, string arguments) |
| 96 | 80 | { |
| 97 | − double statistic = 0.0D; | |
| 98 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 99 | − | |
| 100 | − if ((object)subscriber != null) | |
| 101 | − statistic = subscriber.GetUnauthorizedSignalIDs().Length; | |
| 102 | − | |
| 103 | − return statistic; | |
| 81 | + Guid[] unauthorizedSignalIDs = source is DataSubscriber subscriber ? subscriber.GetUnauthorizedSignalIDs() : GetFunctionValue<Guid[]>(source, "GetUnauthorizedSignalIDs"); | |
| 82 | + return unauthorizedSignalIDs?.Length ?? 0; | |
| 104 | 83 | } |
| 105 | 84 | |
| 106 | 85 | private static double GetSubscriberStatistic_LifetimeMeasurements(object source, string arguments) |
| 107 | 86 | { |
| 108 | − double statistic = 0.0D; | |
| 109 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 110 | − | |
| 111 | − if ((object)subscriber != null) | |
| 112 | − statistic = subscriber.LifetimeMeasurements; | |
| 113 | − | |
| 114 | − return statistic; | |
| 87 | + return source is DataSubscriber subscriber ? subscriber.LifetimeMeasurements : GetPropertyValue<long>(source, "LifetimeMeasurements"); | |
| 115 | 88 | } |
| 116 | 89 | |
| 117 | 90 | private static double GetSubscriberStatistic_MinimumMeasurementsPerSecond(object source, string arguments) |
| 118 | 91 | { |
| 119 | − double statistic = 0.0D; | |
| 120 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 121 | − | |
| 122 | − if ((object)subscriber != null) | |
| 123 | − statistic = subscriber.MinimumMeasurementsPerSecond; | |
| 124 | − | |
| 125 | − return statistic; | |
| 92 | + return source is DataSubscriber subscriber ? subscriber.MinimumMeasurementsPerSecond : GetPropertyValue<long>(source, "MinimumMeasurementsPerSecond"); | |
| 126 | 93 | } |
| 127 | 94 | |
| 128 | 95 | private static double GetSubscriberStatistic_MaximumMeasurementsPerSecond(object source, string arguments) |
| 129 | 96 | { |
| 130 | − double statistic = 0.0D; | |
| 131 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 132 | − | |
| 133 | − if ((object)subscriber != null) | |
| 134 | − statistic = subscriber.MaximumMeasurementsPerSecond; | |
| 135 | − | |
| 136 | − return statistic; | |
| 97 | + return source is DataSubscriber subscriber ? subscriber.MaximumMeasurementsPerSecond : GetPropertyValue<long>(source, "MaximumMeasurementsPerSecond"); | |
| 137 | 98 | } |
| 138 | 99 | |
| 139 | 100 | private static double GetSubscriberStatistic_AverageMeasurementsPerSecond(object source, string arguments) |
| 140 | 101 | { |
| 141 | − double statistic = 0.0D; | |
| 142 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 143 | − | |
| 144 | − if ((object)subscriber != null) | |
| 145 | − statistic = subscriber.AverageMeasurementsPerSecond; | |
| 146 | − | |
| 147 | − return statistic; | |
| 102 | + return source is DataSubscriber subscriber ? subscriber.AverageMeasurementsPerSecond : GetPropertyValue<long>(source, "AverageMeasurementsPerSecond"); | |
| 148 | 103 | } |
| 149 | 104 | |
| 150 | 105 | private static double GetSubscriberStatistic_LifetimeBytesReceived(object source, string arguments) |
| 151 | 106 | { |
| 152 | − double statistic = 0.0D; | |
| 153 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 154 | − | |
| 155 | − if ((object)subscriber != null) | |
| 156 | − statistic = subscriber.TotalBytesReceived; | |
| 157 | − | |
| 158 | − return statistic; | |
| 107 | + return source is DataSubscriber subscriber ? subscriber.TotalBytesReceived : GetPropertyValue<long>(source, "TotalBytesReceived"); | |
| 159 | 108 | } |
| 160 | 109 | |
| 161 | 110 | private static double GetSubscriberStatistic_LifetimeMinimumLatency(object source, string arguments) |
| 162 | 111 | { |
| 163 | − double statistic = 0.0D; | |
| 164 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 165 | − | |
| 166 | − if ((object)subscriber != null) | |
| 167 | − statistic = subscriber.LifetimeMinimumLatency; | |
| 168 | − | |
| 169 | − return statistic; | |
| 112 | + return source is DataSubscriber subscriber ? subscriber.LifetimeMinimumLatency : GetPropertyValue<int>(source, "LifetimeMinimumLatency"); | |
| 170 | 113 | } |
| 171 | 114 | |
| 172 | 115 | private static double GetSubscriberStatistic_LifetimeMaximumLatency(object source, string arguments) |
| 173 | 116 | { |
| 174 | − double statistic = 0.0D; | |
| 175 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 176 | − | |
| 177 | − if ((object)subscriber != null) | |
| 178 | − statistic = subscriber.LifetimeMaximumLatency; | |
| 179 | − | |
| 180 | − return statistic; | |
| 117 | + return source is DataSubscriber subscriber ? subscriber.LifetimeMaximumLatency : GetPropertyValue<int>(source, "LifetimeMaximumLatency"); | |
| 181 | 118 | } |
| 182 | 119 | |
| 183 | 120 | private static double GetSubscriberStatistic_LifetimeAverageLatency(object source, string arguments) |
| 184 | 121 | { |
| 185 | − double statistic = 0.0D; | |
| 186 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 187 | − | |
| 188 | − if ((object)subscriber != null) | |
| 189 | − statistic = subscriber.LifetimeAverageLatency; | |
| 190 | − | |
| 191 | − return statistic; | |
| 122 | + return source is DataSubscriber subscriber ? subscriber.LifetimeAverageLatency : GetPropertyValue<int>(source, "LifetimeAverageLatency"); | |
| 192 | 123 | } |
| 193 | 124 | |
| 194 | 125 | private static double GetSubscriberStatistic_UpTime(object source, string arguments) |
| 195 | 126 | { |
| 196 | − double statistic = 0.0D; | |
| 197 | − DataSubscriber subscriber = source as DataSubscriber; | |
| 198 | − | |
| 199 | − if ((object)subscriber != null) | |
| 200 | − statistic = subscriber.RunTime; | |
| 201 | − | |
| 202 | − return statistic; | |
| 127 | + return source is DataSubscriber subscriber ? subscriber.RunTime : GetPropertyValue<Time>(source, "RunTime"); | |
| 203 | 128 | } |
| 204 | 129 | |
| 205 | 130 | #endregion |
| @@ -208,161 +133,76 @@ namespace GSF.TimeSeries.Statistics · 2 unmodified lines | ||
| 208 | 133 | |
| 209 | 134 | private static double GetPublisherStatistic_Connected(object source, string arguments) |
| 210 | 135 | { |
| 211 | − double statistic = 0.0D; | |
| 212 | − DataPublisher publisher = source as DataPublisher; | |
| 213 | − | |
| 214 | − if ((object)publisher != null) | |
| 215 | − statistic = publisher.IsConnected ? 1.0D : 0.0D; | |
| 216 | − | |
| 217 | − return statistic; | |
| 136 | + return (source is DataPublisher publisher ? publisher.IsConnected : GetPropertyValue<bool>(source, "IsConnected")) ? 1.0D : 0.0D; | |
| 218 | 137 | } |
| 219 | 138 | |
| 220 | 139 | private static double GetPublisherStatistic_ConnectedClientCount(object source, string arguments) |
| 221 | 140 | { |
| 222 | − double statistic = 0.0D; | |
| 223 | − DataPublisher publisher = source as DataPublisher; | |
| 224 | − | |
| 225 | − if ((object)publisher != null) | |
| 226 | − statistic = publisher.Count; | |
| 227 | − | |
| 228 | − return statistic; | |
| 141 | + return source is DataPublisher publisher ? publisher.Count : GetPropertyValue<int>(source, "Count"); | |
| 229 | 142 | } |
| 230 | 143 | |
| 231 | 144 | private static double GetPublisherStatistic_ProcessedMeasurements(object source, string arguments) |
| 232 | 145 | { |
| 233 | − double statistic = 0.0D; | |
| 234 | − DataPublisher publisher = source as DataPublisher; | |
| 235 | − | |
| 236 | − if ((object)publisher != null) | |
| 237 | − statistic = s_statisticValueCache.GetDifference(publisher, publisher.ProcessedMeasurements, "ProcessedMeasurements"); | |
| 238 | − | |
| 239 | − return statistic; | |
| 146 | + double statistic = source is DataPublisher publisher ? publisher.ProcessedMeasurements : GetPropertyValue<long>(source, "ProcessedMeasurements"); | |
| 147 | + return s_statisticValueCache.GetDifference(source, statistic, "ProcessedMeasurements"); | |
| 240 | 148 | } |
| 241 | 149 | |
| 242 | 150 | private static double GetPublisherStatistic_TotalBytesSent(object source, string arguments) |
| 243 | 151 | { |
| 244 | − double statistic = 0.0D; | |
| 245 | − DataPublisher publisher = source as DataPublisher; | |
| 246 | − | |
| 247 | − if ((object)publisher != null) | |
| 248 | − { | |
| 249 | − statistic = s_statisticValueCache.GetDifference(publisher, publisher.TotalBytesSent, "TotalBytesSent"); | |
| 250 | − | |
| 251 | − if (statistic < 0.0D) | |
| 252 | − statistic = publisher.TotalBytesSent; | |
| 253 | − } | |
| 254 | − | |
| 255 | − return statistic; | |
| 152 | + double statistic = source is DataPublisher publisher ? publisher.TotalBytesSent : GetPropertyValue<long>(source, "TotalBytesSent"); | |
| 153 | + double difference = s_statisticValueCache.GetDifference(source, statistic, "TotalBytesSent"); | |
| 154 | + return difference < 0.0D ? statistic : difference; | |
| 256 | 155 | } |
| 257 | 156 | |
| 258 | 157 | private static double GetPublisherStatistic_LifetimeMeasurements(object source, string arguments) |
| 259 | 158 | { |
| 260 | − double statistic = 0.0D; | |
| 261 | − DataPublisher publisher = source as DataPublisher; | |
| 262 | − | |
| 263 | − if ((object)publisher != null) | |
| 264 | − statistic = publisher.LifetimeMeasurements; | |
| 265 | − | |
| 266 | − return statistic; | |
| 159 | + return source is DataPublisher publisher ? publisher.LifetimeMeasurements : GetPropertyValue<long>(source, "LifetimeMeasurements"); | |
| 267 | 160 | } |
| 268 | 161 | |
| 269 | 162 | private static double GetPublisherStatistic_MinimumMeasurementsPerSecond(object source, string arguments) |
| 270 | 163 | { |
| 271 | − double statistic = 0.0D; | |
| 272 | − DataPublisher publisher = source as DataPublisher; | |
| 273 | − | |
| 274 | − if ((object)publisher != null) | |
| 275 | − statistic = publisher.MinimumMeasurementsPerSecond; | |
| 276 | − | |
| 277 | − return statistic; | |
| 164 | + return source is DataPublisher publisher ? publisher.MinimumMeasurementsPerSecond : GetPropertyValue<long>(source, "MinimumMeasurementsPerSecond"); | |
| 278 | 165 | } |
| 279 | 166 | |
| 280 | 167 | private static double GetPublisherStatistic_MaximumMeasurementsPerSecond(object source, string arguments) |
| 281 | 168 | { |
| 282 | − double statistic = 0.0D; | |
| 283 | − DataPublisher publisher = source as DataPublisher; | |
| 284 | − | |
| 285 | − if ((object)publisher != null) | |
| 286 | − statistic = publisher.MaximumMeasurementsPerSecond; | |
| 287 | − | |
| 288 | − return statistic; | |
| 169 | + return source is DataPublisher publisher ? publisher.MaximumMeasurementsPerSecond : GetPropertyValue<long>(source, "MaximumMeasurementsPerSecond"); | |
| 289 | 170 | } |
| 290 | 171 | |
| 291 | 172 | private static double GetPublisherStatistic_AverageMeasurementsPerSecond(object source, string arguments) |
| 292 | 173 | { |
| 293 | − double statistic = 0.0D; | |
| 294 | − DataPublisher publisher = source as DataPublisher; | |
| 295 | − | |
| 296 | − if ((object)publisher != null) | |
| 297 | − statistic = publisher.AverageMeasurementsPerSecond; | |
| 298 | − | |
| 299 | − return statistic; | |
| 174 | + return source is DataPublisher publisher ? publisher.AverageMeasurementsPerSecond : GetPropertyValue<long>(source, "AverageMeasurementsPerSecond"); | |
| 300 | 175 | } |
| 301 | 176 | |
| 302 | 177 | private static double GetPublisherStatistic_LifetimeBytesSent(object source, string arguments) |
| 303 | 178 | { |
| 304 | − double statistic = 0.0D; | |
| 305 | − DataPublisher publisher = source as DataPublisher; | |
| 306 | − | |
| 307 | − if ((object)publisher != null) | |
| 308 | − statistic = publisher.TotalBytesSent; | |
| 309 | − | |
| 310 | − return statistic; | |
| 179 | + return source is DataPublisher publisher ? publisher.TotalBytesSent : GetPropertyValue<long>(source, "TotalBytesSent"); | |
| 311 | 180 | } |
| 312 | 181 | |
| 313 | 182 | private static double GetPublisherStatistic_LifetimeMinimumLatency(object source, string arguments) |
| 314 | 183 | { |
| 315 | − double statistic = 0.0D; | |
| 316 | − DataPublisher publisher = source as DataPublisher; | |
| 317 | − | |
| 318 | − if ((object)publisher != null) | |
| 319 | − statistic = publisher.LifetimeMinimumLatency; | |
| 320 | − | |
| 321 | − return statistic; | |
| 184 | + return source is DataPublisher publisher ? publisher.LifetimeMinimumLatency : GetPropertyValue<int>(source, "LifetimeMinimumLatency"); | |
| 322 | 185 | } |
| 323 | 186 | |
| 324 | 187 | private static double GetPublisherStatistic_LifetimeMaximumLatency(object source, string arguments) |
| 325 | 188 | { |
| 326 | − double statistic = 0.0D; | |
| 327 | − DataPublisher publisher = source as DataPublisher; | |
| 328 | − | |
| 329 | − if ((object)publisher != null) | |
| 330 | − statistic = publisher.LifetimeMaximumLatency; | |
| 331 | − | |
| 332 | − return statistic; | |
| 189 | + return source is DataPublisher publisher ? publisher.LifetimeMaximumLatency : GetPropertyValue<int>(source, "LifetimeMaximumLatency"); | |
| 333 | 190 | } |
| 334 | 191 | |
| 335 | 192 | private static double GetPublisherStatistic_LifetimeAverageLatency(object source, string arguments) |
| 336 | 193 | { |
| 337 | − double statistic = 0.0D; | |
| 338 | − DataPublisher publisher = source as DataPublisher; | |
| 339 | − | |
| 340 | − if ((object)publisher != null) | |
| 341 | − statistic = publisher.LifetimeAverageLatency; | |
| 342 | − | |
| 343 | − return statistic; | |
| 194 | + return source is DataPublisher publisher ? publisher.LifetimeAverageLatency : GetPropertyValue<int>(source, "LifetimeAverageLatency"); | |
| 344 | 195 | } |
| 345 | 196 | |
| 346 | 197 | private static double GetPublisherStatistic_BufferBlockRetransmissions(object source, string arguments) |
| 347 | 198 | { |
| 348 | − double statistic = 0.0D; | |
| 349 | − DataPublisher publisher = source as DataPublisher; | |
| 350 | − | |
| 351 | − if ((object)publisher != null) | |
| 352 | − statistic = s_statisticValueCache.GetDifference(publisher, publisher.BufferBlockRetransmissions, "BufferBlockRetransmissions"); | |
| 353 | − | |
| 354 | − return statistic; | |
| 199 | + double statistic = source is DataPublisher publisher ? publisher.BufferBlockRetransmissions : GetPropertyValue<long>(source, "BufferBlockRetransmissions"); | |
| 200 | + return s_statisticValueCache.GetDifference(source, statistic, "BufferBlockRetransmissions"); | |
| 355 | 201 | } |
| 356 | 202 | |
| 357 | 203 | private static double GetPublisherStatistic_UpTime(object source, string arguments) |
| 358 | 204 | { |
| 359 | − double statistic = 0.0D; | |
| 360 | − DataPublisher publisher = source as DataPublisher; | |
| 361 | − | |
| 362 | − if ((object)publisher != null) | |
| 363 | − statistic = publisher.RunTime; | |
| 364 | − | |
| 365 | − return statistic; | |
| 205 | + return source is DataPublisher publisher ? publisher.RunTime : GetPropertyValue<Time>(source, "RunTime"); | |
| 366 | 206 | } |
| 367 | 207 | |
| 368 | 208 | #endregion |