Beispiel #1
0
        /// <summary>
        /// Returns the event-weighted count of a <see cref="PIPoint"/> over the requested <see cref="AFTimeRange"/>.
        /// </summary>
        /// <param name="tag">A PIPoint</param>
        /// <param name="timeRange">An AFTimeRange</param>
        /// <returns>A scalar int of the events within the time range.</returns>
        public static async Task <int> GetEventCountAsync(this PIPoint tag, AFTimeRange timeRange, CancellationToken cancellationToken = default(CancellationToken))
        {
            var summaries = await tag.SummaryAsync(timeRange,
                                                   AFSummaryTypes.Count,
                                                   AFCalculationBasis.EventWeighted,
                                                   AFTimestampCalculation.Auto,
                                                   cancellationToken).ConfigureAwait(continueOnCapturedContext: false);

            cancellationToken.ThrowIfCancellationRequested();
            AFValue summary;

            if (summaries.TryGetValue(AFSummaryTypes.Count, out summary))
            {
                if (summary.IsGood)
                {
                    // One day this may have to be an Int64 or long
                    return(Convert.ToInt32(summary.Value));
                }
            }
            return(0);
        }