private static void BeginProcessingUserAggregates(DateTime fromForAggregates, IPlugin loadedPlugin) { Log.Debug($"BeginProcessingUserAggregates(), {nameof(fromForAggregates)}:{fromForAggregates.ToString("O")}, {nameof(To)}:{To.ToString("O")}"); try { if (fromForAggregates.Equals(DateTime.MinValue)) { throw new ArgumentException("Equals(DateTime.MinValue)", nameof(fromForAggregates)); } // a legacy condition, not sure is it necessary at all // <calculating intervals> if (ToForAggregates.Subtract(fromForAggregates).TotalMinutes < 30) { return; // minimum time frame is 30 minutes (a duration of one grnuality interval) } var intervalList = new List <Interval>(); var tempFrom = fromForAggregates; // <issue API-2719 - orginal code - 7 days query intervals> //while (ToForAggregates.Subtract(tempFrom).TotalDays >= MaxIntervalDuration) //{ // var tempTo = tempFrom.AddDays(MaxIntervalDuration).Date; // intervalList.Add(new Interval(tempFrom, tempTo)); // tempFrom = tempTo.Date; //} //intervalList.Add(new Interval(tempFrom, ToForAggregates)); // </issue API-2719 - orginal code - 7 days query intervals> // <issue API-2719 - workaround - 12 hrs query intervals> const int maxIntervalDurationHours = 12; while (ToForAggregates.Subtract(tempFrom).TotalHours > maxIntervalDurationHours) { var tempTo = tempFrom.AddHours(maxIntervalDurationHours); intervalList.Add(new Interval(tempFrom, tempTo)); tempFrom = tempTo; } intervalList.Add(new Interval(tempFrom, ToForAggregates)); // </issue API-2719 - workaround - 12 hrs query intervals> // </calculating intervals> // <getting the data> foreach (var interval in intervalList) { var page = 0; var userAggregates = PureCloudObj.GetUserAggregates(interval, page); while (userAggregates != null && userAggregates.Results.Any()) { var userAggregatesJson = "{\"userdata\":" + JsonConvert.SerializeObject(userAggregates.Results) + "}"; loadedPlugin.PushData(userAggregatesJson); page++; userAggregates = PureCloudObj.GetUserAggregates(interval, page); } } // </getting the data> } catch (Exception ex) { Log.Error("BeginProcessingUserAggregates()", ex); } }