/// <summary> /// Create a cross resource event status count summary /// </summary> /// <param name="startTime">start time</param> /// <param name="endTime">end time</param> /// <returns>the event count summary response</returns> public EventStatusCountSummaryItemCollection CreateCrossResourceEventStatusCountSummary(DateTime startTime, DateTime endTime) { int expectedNumberOfItems = (int)((endTime - startTime).Ticks / SupportedTimeGrain.Ticks) + 1; // Aggregate the summary items var listOfItems = new EventStatusCountSummaryItem[expectedNumberOfItems]; foreach (var summaryItem in this.EventStatusCountSummaryItemCollection.Value) { int position = GetPosition(startTime, SupportedTimeGrain, expectedNumberOfItems, summaryItem.EventTime); EventStatusCountSummaryItem item = listOfItems[position]; if (item == null) { item = new EventStatusCountSummaryItem { EventTime = summaryItem.EventTime, StatusCounts = new List <StatusCount>(), TimeGrain = SupportedTimeGrain, Id = null }; listOfItems[position] = item; } item.StatusCounts = MergeStatusCounts(item.StatusCounts, summaryItem.StatusCounts); } // Fill in the gaps DateTime currentTime = startTime; for (int i = expectedNumberOfItems - 1; i >= 0; i--) { if (listOfItems[i] == null) { listOfItems[i] = new EventStatusCountSummaryItem { EventTime = currentTime.ToUniversalTime(), StatusCounts = new List <StatusCount>(), TimeGrain = SupportedTimeGrain, Id = null }; } currentTime += SupportedTimeGrain; } return(new EventStatusCountSummaryItemCollection { Value = listOfItems }); }
/// <summary> /// Create a cross resource event status count summary /// </summary> /// <param name="startTime">start time</param> /// <param name="endTime">end time</param> /// <returns>the event count summary response</returns> public EventStatusCountSummaryItemCollection AggregateSummary(DateTime startTime, DateTime endTime) { int expectedNumberOfItems = (int)((endTime - startTime).Ticks / SupportedTimeGrain.Ticks) + 1; // Aggregate the summary items var listOfItems = new EventStatusCountSummaryItem[expectedNumberOfItems]; foreach (var summaryItem in this.EventStatusCountSummaryItemCollection.Value) { int position = GetPosition(startTime, SupportedTimeGrain, expectedNumberOfItems, summaryItem.EventTime); EventStatusCountSummaryItem item = listOfItems[position]; if (item == null) { item = new EventStatusCountSummaryItem { EventTime = summaryItem.EventTime, StatusCounts = new List<StatusCount>(), TimeGrain = SupportedTimeGrain, Id = null }; listOfItems[position] = item; } item.StatusCounts = MergeStatusCounts(item.StatusCounts, summaryItem.StatusCounts); } // Fill in the gaps DateTime currentTime = startTime; for (int i = expectedNumberOfItems - 1; i >= 0; i--) { if (listOfItems[i] == null) { listOfItems[i] = new EventStatusCountSummaryItem { EventTime = currentTime.ToUniversalTime(), StatusCounts = new List<StatusCount>(), TimeGrain = SupportedTimeGrain, Id = null }; } currentTime += SupportedTimeGrain; } return new EventStatusCountSummaryItemCollection { Value = listOfItems }; }
private static void AreEqual(EventStatusCountSummaryItem exp, EventStatusCountSummaryItem act) { Assert.Equal(exp.EventTime.ToUniversalTime(), act.EventTime.ToUniversalTime()); Assert.Equal(exp.Id, act.Id); Assert.Equal(exp.TimeGrain, act.TimeGrain); AreEqual(exp.StatusCounts, act.StatusCounts); }