/// <summary> /// if one period file is downloaded failed in configured times, /// the time duration will be split to 1 hr and the day’s data will be in 24 parts /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> public static void SplitDownloadPeriod(string startDate, string endDate) { string newEndDate = string.Empty; var isoDateTimeFormat = CultureInfo.InvariantCulture.DateTimeFormat; DateTime newstartdate = Convert.ToDateTime(startDate); TimeSpan diff = Convert.ToDateTime(endDate).AddSeconds(1) - Convert.ToDateTime(startDate); if (diff.Minutes == 5) { return; } else if (diff.Hours != 1) { using (YETIDBEntities yeticontext = new YETIDBEntities()) { yeticontext.Yammer_Download_DeleteExportDetails(startDate, endDate); for (int i = 0; i < Convert.ToInt32(DurationInHrs); i++) { DateTime tempEndDate = Convert.ToDateTime(newstartdate).AddHours(1).AddMilliseconds(-1); newEndDate = tempEndDate.ToString(isoDateTimeFormat.SortableDateTimePattern); yeticontext.Yammer_Download_NewExportDetails(newstartdate.ToString(), newEndDate, "Stopped", Environment.MachineName); newstartdate = Convert.ToDateTime(newstartdate).AddHours(1); } } } else if (diff.Hours == 1) { using (YETIDBEntities yeticontext = new YETIDBEntities()) { yeticontext.Yammer_Download_DeleteExportDetails(startDate, endDate); for (int i = 0; i < 12; i++) //splitting 1 hr data for 5 min so 12 parts { DateTime tempEndDate = Convert.ToDateTime(newstartdate).AddMinutes(5).AddMilliseconds(-1); newEndDate = tempEndDate.ToString(isoDateTimeFormat.SortableDateTimePattern); yeticontext.Yammer_Download_NewExportDetails(newstartdate.ToString(), newEndDate, "Stopped", Environment.MachineName); newstartdate = Convert.ToDateTime(newstartdate).AddMinutes(5); } } } }
private static async Task SetDuration() { string startDate = string.Empty; string endDate = string.Empty; int inProgressCount = 0; int countDownCount = 0; try { var isoDateTimeFormat = CultureInfo.InvariantCulture.DateTimeFormat; string newStartDate = string.Empty; using (YETIDBEntities yeticontext = new YETIDBEntities()) { newStartDate = yeticontext.Yammer_Download_GetLastEnddate(Year).ToString(); inProgressCount = Convert.ToInt32(yeticontext.Yammer_Download_GetInProgressCount(Year, Environment.MachineName)); countDownCount = 5 - inProgressCount; if (inProgressCount >= 5) { return; } if (!string.IsNullOrEmpty(newStartDate)) { DateTime startdate = Convert.ToDateTime(newStartDate); if (startdate.Year.ToString() == Year) { newStartDate = startdate.ToString(isoDateTimeFormat.SortableDateTimePattern); } else { UpdateYearStatus(Year); return; } } else { newStartDate = Year + "-01-01T00:00:00"; } } var countdownEvent = new CountdownEvent(countDownCount); for (int i = 0; i < countDownCount; i++) { startDate = newStartDate; DateTime tempEndDate = Convert.ToDateTime(startDate).AddHours(Convert.ToInt32(DurationInHrs)).AddMilliseconds(-1); endDate = tempEndDate.ToString(isoDateTimeFormat.SortableDateTimePattern); //if (tempEndDate < DateTime.Now.AddHours(-DateTime.Now.Hour).AddMinutes(-DateTime.Now.Minute).AddSeconds(-DateTime.Now.Second)) if (tempEndDate < DateTime.Now) { using (YETIDBEntities yeticontext = new YETIDBEntities()) { yeticontext.Yammer_Download_NewExportDetails(startDate, endDate, "Not Started", Environment.MachineName); } DateTime startDateD = Convert.ToDateTime(endDate).AddSeconds(1); if (startDateD.Year.ToString() == Year) { newStartDate = startDateD.ToString(isoDateTimeFormat.SortableDateTimePattern); } else { i = countDownCount; } //new Thread(delegate () { await ExportAPICall(startDate, endDate); countdownEvent.Signal(); }//).Start(); Thread.Sleep(10000); //Giving 10 sec gap to start the download for the assigned start & end date } else { return; } } countdownEvent.Wait(); countdownEvent.Dispose(); } catch (Exception ex) when(ex is WebException) { LogEvents("export - " + endDate.Replace(':', '-') + ".zip", ex.ToString()); } }