internal async Task <IEnumerable <LoadMetric> > SumMetricsAsync(CancellationToken token) { IReliableDictionary <string, List <LoadMetric> > metricDictionary = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, List <LoadMetric> > >(this.metricStoreName); Dictionary <string, int> totals = new Dictionary <string, int>(); using (ITransaction tx = this.stateManager.CreateTransaction()) { await metricDictionary.ForeachAsync( tx, token, item => { foreach (LoadMetric metric in item.Value) { if (totals.ContainsKey(metric.Name)) { totals[metric.Name] += metric.Value; } else { totals[metric.Name] = metric.Value; } } }); } return(totals.Select(x => new LoadMetric(x.Key, x.Value))); }