private List <BulkExportModel> GetTimers(ProgressDialogController dialogController, List <JiraTimer> timers) { var timersToShow = new List <BulkExportModel>(); var issuesRetrieved = new List <Issue>(); var timersToGet = timers.Where(x => !x.TempTimer && !x.IsRunning).ToList(); for (var i = 0; i < timersToGet.Count; i++) { var timerToShow = timersToGet[i]; var requireRefresh = !timerToShow.LastJiraTimeCheck.HasValue || timerToShow.LastJiraTimeCheck < DateTime.UtcNow.AddMinutes(-15); var model = new BulkExportModel(timerToShow, modelHelpers.Gallifrey.Settings.ExportSettings); var jiraIssue = issuesRetrieved.FirstOrDefault(x => x.key == timerToShow.JiraReference); if (i == 0) { dialogController.SetMessage($"Downloading Jira Work Logs For {timerToShow.JiraReference} To Ensure Accurate Export"); } else { dialogController.SetMessage($"Downloading Jira Work Logs For {timerToShow.JiraReference} To Ensure Accurate Export\nDone {i} Of {timersToGet.Count}"); } if (jiraIssue == null) { try { jiraIssue = modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference, requireRefresh); issuesRetrieved.Add(jiraIssue); } catch (Exception) { throw new BulkExportException($"Unable To Locate Jira {timerToShow.JiraReference}!\nCannot Export Time\nPlease Verify/Correct Jira Reference"); } } if (requireRefresh) { modelHelpers.Gallifrey.JiraTimerCollection.RefreshFromJira(timerToShow.UniqueId, jiraIssue, modelHelpers.Gallifrey.JiraConnection.CurrentUser); timerToShow = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(timerToShow.UniqueId); } if (!timerToShow.FullyExported) { model.UpdateTimer(timerToShow, jiraIssue); timersToShow.Add(model); } } return(timersToShow); }
private List <BulkExportModel> GetTimers(List <JiraTimer> timers) { var timersToShow = new List <BulkExportModel>(); var issuesRetrieved = new List <Issue>(); var timersToGet = timers.Where(x => !x.LocalTimer && !x.IsRunning).ToList(); var dates = new List <DateTime>(); var references = new List <string>(); foreach (var timerToShow in timersToGet) { var jiraIssue = issuesRetrieved.FirstOrDefault(x => x.key == timerToShow.JiraReference); if (jiraIssue == null) { try { if (modelHelpers.Gallifrey.JiraConnection.DoesJiraExist(timerToShow.JiraReference)) { jiraIssue = modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference); issuesRetrieved.Add(jiraIssue); } else { throw new BulkExportException($"Unable To Locate Jira {timerToShow.JiraReference}!\nCannot Export Time\nPlease Verify/Correct Jira Reference"); } } catch (BulkExportException) { throw; } catch (Exception) { throw new BulkExportException($"Unable To Locate Jira {timerToShow.JiraReference}!\nCannot Export Time\nPlease Verify/Correct Jira Reference"); } } dates.Add(timerToShow.DateStarted.Date); references.Add(timerToShow.JiraReference); } List <StandardWorkLog> logs; try { logs = modelHelpers.Gallifrey.JiraConnection.GetWorkLoggedForDatesFilteredIssues(dates.Distinct(), references.Distinct()).ToList(); } catch (Exception ex) { ExceptionlessClient.Default.CreateEvent().SetException(ex).AddTags("Hidden").Submit(); throw new BulkExportException("Unable To Get WorkLogs!\nCannot Export Time"); } foreach (var timerToShow in timersToGet) { var jiraIssue = issuesRetrieved.FirstOrDefault(x => x.key == timerToShow.JiraReference); var time = TimeSpan.Zero; foreach (var standardWorkLog in logs.Where(x => x.JiraRef == timerToShow.JiraReference && x.LoggedDate.Date == timerToShow.DateStarted.Date)) { time = time.Add(standardWorkLog.TimeSpent); } modelHelpers.Gallifrey.JiraTimerCollection.RefreshFromJira(timerToShow.UniqueId, jiraIssue, time); var updatedTimer = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(timerToShow.UniqueId); if (!updatedTimer.FullyExported) { var model = new BulkExportModel(updatedTimer, jiraIssue, modelHelpers.Gallifrey.Settings.ExportSettings); timersToShow.Add(model); } } return(timersToShow); }
private List <BulkExportModel> GetTimers(ProgressDialogController dialogController, List <JiraTimer> timers) { var timersToShow = new List <BulkExportModel>(); var issuesRetrieved = new List <Issue>(); var timersToGet = timers.Where(x => !x.LocalTimer && !x.IsRunning).ToList(); var dates = new List <DateTime>(); var references = new List <string>(); foreach (var timerToShow in timersToGet) { var jiraIssue = issuesRetrieved.FirstOrDefault(x => x.key == timerToShow.JiraReference); if (jiraIssue == null) { try { jiraIssue = modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(timerToShow.JiraReference); issuesRetrieved.Add(jiraIssue); } catch (Exception) { throw new BulkExportException($"Unable To Locate Jira {timerToShow.JiraReference}!\nCannot Export Time\nPlease Verify/Correct Jira Reference"); } } if (!timerToShow.LastJiraTimeCheck.HasValue || timerToShow.LastJiraTimeCheck < DateTime.UtcNow.AddMinutes(-5)) { dates.Add(timerToShow.DateStarted.Date); references.Add(timerToShow.JiraReference); } } IEnumerable <StandardWorkLog> logs; try { logs = modelHelpers.Gallifrey.JiraConnection.GetWorkLoggedForDatesFilteredIssues(dates.Distinct(), references.Distinct()); } catch (Exception) { throw new BulkExportException($"Unable To Get WorkLogs!\nCannot Export Time"); } foreach (var timerToShow in timersToGet) { var jiraIssue = issuesRetrieved.FirstOrDefault(x => x.key == timerToShow.JiraReference); var time = TimeSpan.Zero; foreach (var standardWorkLog in logs.Where(x => x.JiraRef == timerToShow.JiraReference && x.LoggedDate.Date == timerToShow.DateStarted.Date)) { time = time.Add(standardWorkLog.TimeSpent); } modelHelpers.Gallifrey.JiraTimerCollection.RefreshFromJira(timerToShow.UniqueId, jiraIssue, time); var updatedTimer = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(timerToShow.UniqueId); if (!timerToShow.FullyExported) { var model = new BulkExportModel(updatedTimer, modelHelpers.Gallifrey.Settings.ExportSettings); timersToShow.Add(model); } } return(timersToShow); }