Пример #1
0
        /// <summary>
        /// Enable stats collection for the given <see cref="IView"/>.
        /// </summary>
        /// <param name="view">The view.</param>
        internal void RegisterView(IView view)
        {
            this.exportedViews = null;
            this.registeredViews.TryGetValue(view.Name, out var existing);
            if (existing != null)
            {
                if (existing.Equals(view))
                {
                    // Ignore views that are already registered.
                    return;
                }
                else
                {
                    throw new ArgumentException("A different view with the same name is already registered: " + existing);
                }
            }

            var measure = view.Measure;

            this.registeredMeasures.TryGetValue(measure.Name, out var registeredMeasure);
            if (registeredMeasure != null && !registeredMeasure.Equals(measure))
            {
                throw new ArgumentException("A different measure with the same name is already registered: " + registeredMeasure);
            }

            this.registeredViews.Add(view.Name, view);
            if (registeredMeasure == null)
            {
                this.registeredMeasures.Add(measure.Name, measure);
            }

            this.AddMutableViewData(view.Measure.Name, MutableViewData.Create(view, DateTimeOffset.Now));
        }
 internal IViewData GetView(IViewName viewName, StatsCollectionState state)
 {
     lock (this.lck)
     {
         MutableViewData view = this.GetMutableViewData(viewName);
         return(view?.ToViewData(DateTimeOffset.Now, state));
     }
 }
Пример #3
0
        public static IAggregationData Sum(this IDictionary <TagValues, IAggregationData> aggMap, IView view)
        {
            var sum = MutableViewData.CreateMutableAggregation(view.Aggregation);

            foreach (var agData in aggMap.Values)
            {
                Sum(sum, agData);
            }

            return(MutableViewData.CreateAggregationData(sum, view.Measure));
        }
Пример #4
0
 private void AddMutableViewData(string name, MutableViewData mutableViewData)
 {
     if (this.mutableMap.ContainsKey(name))
     {
         this.mutableMap[name].Add(mutableViewData);
     }
     else
     {
         this.mutableMap.Add(name, new List <MutableViewData>()
         {
             mutableViewData
         });
     }
 }