コード例 #1
0
 public static void ExecuteMethod_PopulateMonitoringItems(RequestResourceUsageCollection[] resourcesToIncludeInMonitoring, UsageMonitorItem[] newMonitoringItems)
 {
     if (resourcesToIncludeInMonitoring.Length == 0 || newMonitoringItems.Length == 0)
         return;
     int currMonitoringItemIX = 0;
     var resourcesCombined = resourcesToIncludeInMonitoring.SelectMany(coll => coll.CollectionContent).ToArray();
     var currMonitoringItem = newMonitoringItems[currMonitoringItemIX];
     foreach (var resourceItem in resourcesCombined)
     {
         DateTime resourceItemTime = resourceItem.ProcessorUsage.TimeRange.EndTime;
         while (resourceItemTime >= currMonitoringItem.TimeRangeInclusiveStartExclusiveEnd.EndTime)
         {
             currMonitoringItemIX++;
             if (currMonitoringItemIX == newMonitoringItems.Length)
                 return;
             currMonitoringItem = newMonitoringItems[currMonitoringItemIX];
         }
         DateTime currMonitorStartTime = currMonitoringItem.TimeRangeInclusiveStartExclusiveEnd.StartTime;
         bool matchesTimes = currMonitorStartTime <= resourceItemTime &&
                             currMonitoringItem.TimeRangeInclusiveStartExclusiveEnd.EndTime > resourceItemTime;
         if(matchesTimes == false)
             throw new InvalidDataException("Invalid data processing to feed invalid data to populating items");
         var diffFromMonitorBegin = resourceItemTime - currMonitorStartTime;
         var completeMinutes = Math.Floor(diffFromMonitorBegin.TotalMinutes);
         int stepIndex = (int) (completeMinutes/currMonitoringItem.StepSizeInMinutes);
         // Add data to index entries
         addValuesToMonitorItem(resourceItem, currMonitoringItem, stepIndex);
     }
 }