private async void LoadSearch() { Func <SearchModel> getSearchModel = () => { var recent = new List <RecentJira>(); var filters = new List <string>(); var issues = new List <Issue>(); try { recent = modelHelpers.Gallifrey.JiraTimerCollection.GetJiraReferencesForLastDays(50).ToList(); } catch (Exception) { //Ignore } try { filters = modelHelpers.Gallifrey.JiraConnection.GetJiraFilters().ToList(); } catch (Exception) { //Ignore } try { issues = modelHelpers.Gallifrey.JiraConnection.GetJiraCurrentUserOpenIssues().ToList(); } catch (Exception) { //Ignore } return(new SearchModel(filters, recent, issues, openFromEdit)); }; var result = await progressDialogHelper.Do(getSearchModel, "Loading Search Information", true, false); switch (result.Status) { case ProgressResult.JiraHelperStatus.Cancelled: modelHelpers.CloseFlyout(this); break; case ProgressResult.JiraHelperStatus.Errored: await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Error", "There Was An Error Loading Default Search Results"); modelHelpers.CloseFlyout(this); break; case ProgressResult.JiraHelperStatus.Success: DataContext = result.RetVal; break; } }
private async void AddTimer(object sender, RoutedEventArgs e) { if (DataModel.SelectedSearchResult == null) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "No Selected Item", "You Need To Select An Item To Add A Timer For It"); Focus(); return; } modelHelpers.CloseFlyout(this); if (openFromAdd) { SelectedJira = DataModel.SelectedSearchResult; } else { var addFlyout = new AddTimer(modelHelpers, DataModel.SelectedSearchResult.Reference, selectedDateTab); await modelHelpers.OpenFlyout(addFlyout); if (addFlyout.AddedTimer) { modelHelpers.SetSelectedTimer(addFlyout.NewTimerId); } else { modelHelpers.OpenFlyout(this); } } }
private async void SaveSettings(object sender, RoutedEventArgs e) { var successfulSave = true; DataModel.UpdateSettings(modelHelpers.Gallifrey.Settings, modelHelpers.Gallifrey.VersionControl); try { if (DataModel.JiraSettingsChanged) { var trackingOptOut = DataModel.TrackingOptOut; await progressDialogHelper.Do(() => modelHelpers.Gallifrey.SaveSettings(true, trackingOptOut), "Checking Jira Credentials", false, true); } else { modelHelpers.Gallifrey.SaveSettings(false, DataModel.TrackingOptOut); } } catch (MissingJiraConfigException) { successfulSave = false; } catch (JiraConnectionException) { successfulSave = false; } if (successfulSave) { if (modelHelpers.Gallifrey.Settings.JiraConnectionSettings.UseTempo && !modelHelpers.Gallifrey.JiraConnection.HasTempo) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Missing Tempo", "We Were Unable To Locate A Tempo Endpoint\nGallifrey Will Fall Back To Standard Jira Endpoints"); modelHelpers.Gallifrey.Settings.JiraConnectionSettings.UseTempo = false; //Even though we have changed jira settings, we are changing because tempo is not in use, so don't reconnect modelHelpers.Gallifrey.SaveSettings(false, false); } modelHelpers.CloseFlyout(this); var themeChanged = ThemeHelper.ChangeTheme(DataModel.Theme.Name, DataModel.Accent.Name); if (themeChanged == ThemeChangeDetail.Theme || themeChanged == ThemeChangeDetail.Both) { //This is a really ugly solution!! //The overides of system colours do not update automatically which is not good. //This message will hopefully make people restart... await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Restart Needed", "When Changing Theme, Some Colours Will Not Change Automatically\nIt Is Recommended To Restart The App"); } } else { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Jira Configuration", "You Cannot Save With Invalid Jira Configuration.\nTo Save You Have To Have A Valid Connection To Jira"); Focus(); } }
private async void SendReport(object sender, RoutedEventArgs e) { DataModel.SetUserDetailsInEvent(); ExceptionlessClient.Default.SubmitEvent(DataModel.ExceptionlessEvent); await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Thank You", "You're Helping Make Gallifrey Better!"); modelHelpers.CloseFlyout(this); }
private async void ExportButton(object sender, RoutedEventArgs e) { if (DataModel.Timer.TimeToExport < DataModel.ToExport) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Export", $"You Cannot Export More Than The Timer States Un-Exported\nThis Value Is {DataModel.ToExport.ToString(@"hh\:mm")}!"); return; } Task <MessageDialogResult> dialog = null; try { var jiraRef = DataModel.JiraRef; var date = DataModel.ExportDate; var toExport = DataModel.ToExport; var strategy = DataModel.WorkLogStrategy; var comment = DataModel.Comment; var remaining = DataModel.Remaining; var standardComment = DataModel.StandardComment; var result = await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.LogTime(jiraRef, date, toExport, strategy, standardComment, comment, remaining), "Exporting Time To Jira", false, true); if (result.Status == ProgressResult.JiraHelperStatus.Success) { modelHelpers.Gallifrey.JiraTimerCollection.AddJiraExportedTime(DataModel.Timer.UniqueId, DataModel.ToExportHours, DataModel.ToExportMinutes); modelHelpers.CloseFlyout(this); } else { throw new WorkLogException("Did not export"); } } catch (WorkLogException) { dialog = DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Error Exporting", "Unable To Log Work!"); } catch (StateChangedException) { dialog = DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Error Exporting", "Unable To Re-Close A The Jira, Manually Check!!"); } catch (CommentException) { dialog = DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Error Adding Comment", "The Comment Was Not Added"); } if (dialog != null) { await dialog; Focus(); } }
private async void SaveSettings(object sender, RoutedEventArgs e) { var successfulSave = true; DataModel.UpdateSettings(modelHelpers.Gallifrey.Settings, modelHelpers.Gallifrey.VersionControl); try { if (DataModel.JiraSettingsChanged) { var trackingOptOut = DataModel.TrackingOptOut; await progressDialogHelper.Do(() => modelHelpers.Gallifrey.SaveSettings(true, trackingOptOut), "Checking Jira Credentials", false, true); } else { modelHelpers.Gallifrey.SaveSettings(false, DataModel.TrackingOptOut); } } catch (MissingJiraConfigException) { successfulSave = false; } catch (JiraConnectionException) { successfulSave = false; } catch (TempoConnectionException) { successfulSave = false; } if (successfulSave) { modelHelpers.CloseFlyout(this); ThemeHelper.ChangeTheme(DataModel.Theme.Name); } else { if (DataModel.UseTempo) { await modelHelpers.ShowMessageAsync("Invalid Jira Or Tempo Configuration", "You Cannot Save With Invalid Jira Or Tempo Configuration.\nTo Save You Have To Have A Valid Connection To Jira And Tempo"); } else { await modelHelpers.ShowMessageAsync("Invalid Jira Configuration", "You Cannot Save With Invalid Jira Configuration.\nTo Save You Have To Have A Valid Connection To Jira"); } Focus(); } }
private async void LockedTimer_OnLoaded(object sender, RoutedEventArgs e) { if (!DataModel.LockedTimers.Any()) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "No Timers To Show", "You Have No Locked Timers\nThere is Nothing To Show Here!"); modelHelpers.CloseFlyout(this); } }
private async void ChangeLogButton(object sender, RoutedEventArgs e) { modelHelpers.CloseFlyout(this); var changeLog = modelHelpers.Gallifrey.GetChangeLog(XDocument.Parse(Properties.Resources.ChangeLog)).ToList(); if (changeLog.Any()) { await modelHelpers.OpenFlyout(new ChangeLog(changeLog)); } else { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "No Change Log", "There Is No Change Log To Show"); } modelHelpers.OpenFlyout(this); }
private async void SaveSettings(object sender, RoutedEventArgs e) { var successfulSave = true; DataModel.UpdateSettings(modelHelpers.Gallifrey.Settings, modelHelpers.Gallifrey.VersionControl); try { modelHelpers.Gallifrey.SaveSettings(DataModel.JiraSettingsChanged); } catch (MissingJiraConfigException) { successfulSave = false; } catch (JiraConnectionException) { successfulSave = false; } if (successfulSave) { modelHelpers.CloseFlyout(this); var themeChanged = ThemeHelper.ChangeTheme(DataModel.Theme.Name, DataModel.Accent.Name); if (themeChanged == ThemeChangeDetail.Theme || themeChanged == ThemeChangeDetail.Both) { //This is a really ugly solution!! //The overides of system colours do not update automatically which is not good. //This message will hopefully make people restart... await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Restart Needed", "When Changing Theme, Some Colours Will Not Change Automatically\nIt Is Recommended To Restart The App"); } } else { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Jira Configuration", "You Cannot Save With Invalid Jira Configuration.\nTo Save You Have To Have A Valid Connection To Jira"); Focus(); } }
private async void SaveButton(object sender, RoutedEventArgs e) { if (DataModel.HasModifiedRunDate) { if (!DataModel.RunDate.HasValue) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Missing Date", "You Must Enter A Start Date"); Focus(); return; } if (DataModel.RunDate.Value < DataModel.MinDate || DataModel.RunDate.Value > DataModel.MaxDate) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Date", $"You Must Enter A Start Date Between {DataModel.MinDate.ToShortDateString()} And {DataModel.MaxDate.ToShortDateString()}"); Focus(); return; } try { EditedTimerId = modelHelpers.Gallifrey.JiraTimerCollection.ChangeTimerDate(EditedTimerId, DataModel.RunDate.Value); } catch (DuplicateTimerException ex) { var handlerd = await MergeTimers(ex); if (!handlerd) { Focus(); return; } } } else if (DataModel.HasModifiedJiraReference) { if (DataModel.TempTimer) { modelHelpers.Gallifrey.JiraTimerCollection.ChangeTempTimerDescription(EditedTimerId, DataModel.TempTimerDescription); } else { Issue jiraIssue; try { jiraIssue = modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(DataModel.JiraReference); } catch (NoResultsFoundException) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Jira", "Unable To Locate The Jira"); Focus(); return; } var result = await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Correct Jira?", $"Jira found!\n\nRef: {jiraIssue.key}\nName: {jiraIssue.fields.summary}\n\nIs that correct?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative }); if (result == MessageDialogResult.Negative) { return; } try { EditedTimerId = modelHelpers.Gallifrey.JiraTimerCollection.RenameTimer(EditedTimerId, jiraIssue); } catch (DuplicateTimerException ex) { var handlerd = await MergeTimers(ex); if (!handlerd) { Focus(); return; } } } } if (DataModel.HasModifiedTime) { var originalTime = new TimeSpan(DataModel.OriginalHours, DataModel.OriginalMinutes, 0); var newTime = new TimeSpan(DataModel.Hours, DataModel.Minutes, 0); var difference = newTime.Subtract(originalTime); var addTime = difference.TotalSeconds > 0; modelHelpers.Gallifrey.JiraTimerCollection.AdjustTime(EditedTimerId, Math.Abs(difference.Hours), Math.Abs(difference.Minutes), addTime); } modelHelpers.RefreshModel(); modelHelpers.SetSelectedTimer(EditedTimerId); modelHelpers.CloseFlyout(this); }
private async void SetupContext(List <JiraTimer> timers, List <BulkExportModel> oldModels = null) { await Task.Delay(50); modelHelpers.HideFlyout(this); var timersToShow = new List <BulkExportModel>(); try { var jiraDownloadResult = await progressDialogHelper.Do(controller => GetTimers(timers), "Downloading Jira Work Logs To Ensure Accurate Export", true, true); switch (jiraDownloadResult.Status) { case ProgressResult.JiraHelperStatus.Cancelled: modelHelpers.CloseFlyout(this); return; case ProgressResult.JiraHelperStatus.Success: timersToShow = jiraDownloadResult.RetVal; break; } } catch (BulkExportException ex) { await modelHelpers.ShowMessageAsync("Unable To Locate Jira", ex.Message); modelHelpers.CloseFlyout(this); return; } if (!timersToShow.Any()) { await modelHelpers.ShowMessageAsync("Nothing To Export", "There Is No Time To Export"); modelHelpers.CloseFlyout(this); } else if (timersToShow.Count == 1) { modelHelpers.CloseFlyout(this); await modelHelpers.OpenFlyout(new Export(modelHelpers, timersToShow.First().Timer.UniqueId, null, true)); } else { var jiraComparer = new JiraReferenceComparer(); timersToShow.Sort((a, b) => { int cmp = b.ExportDate.Date.CompareTo(a.ExportDate.Date); if (cmp == 0) { cmp = jiraComparer.Compare(a.JiraRef, b.JiraRef); } return(cmp); }); timersToShow.ForEach(x => DataModel.BulkExports.Add(x)); if (oldModels != null) { foreach (var oldModel in oldModels) { foreach (var newModel in DataModel.BulkExports) { if (oldModel.JiraRef == newModel.JiraRef && oldModel.ExportDate.Date == newModel.ExportDate.Date) { newModel.ShouldExport = oldModel.ShouldExport; newModel.ToExportHours = oldModel.ToExportHours; newModel.ToExportMinutes = oldModel.ToExportMinutes; newModel.WorkLogStrategy = oldModel.WorkLogStrategy; newModel.RemainingHours = oldModel.RemainingHours; newModel.RemainingMinutes = oldModel.RemainingMinutes; newModel.Comment = oldModel.Comment; newModel.StandardComment = oldModel.StandardComment; newModel.ChangeStatus = oldModel.ChangeStatus; } } } } await modelHelpers.OpenFlyout(this); } }
private async void SaveButton(object sender, RoutedEventArgs e) { if (DataModel.HasModifiedRunDate) { if (!DataModel.RunDate.HasValue) { await modelHelpers.ShowMessageAsync("Missing Date", "You Must Enter A Start Date"); Focus(); return; } if (DataModel.RunDate.Value.Date < DataModel.MinDate.Date || DataModel.RunDate.Value.Date > DataModel.MaxDate.Date) { await modelHelpers.ShowMessageAsync("Invalid Date", $"You Must Enter A Start Date Between {DataModel.MinDate.ToShortDateString()} And {DataModel.MaxDate.ToShortDateString()}"); Focus(); return; } try { EditedTimerId = modelHelpers.Gallifrey.JiraTimerCollection.ChangeTimerDate(EditedTimerId, DataModel.RunDate.Value); } catch (DuplicateTimerException ex) { var handled = await MergeTimers(ex); if (!handled) { Focus(); return; } } } else if (DataModel.HasModifiedJiraReference) { if (DataModel.LocalTimer) { try { EditedTimerId = modelHelpers.Gallifrey.JiraTimerCollection.ChangeLocalTimerDescription(EditedTimerId, DataModel.LocalTimerDescription); } catch (DuplicateTimerException) { await modelHelpers.ShowMessageAsync("Something Went Wrong", "An Error Occured Trying To Edit That Timer, Please Try Again"); Focus(); return; } } else { Issue jiraIssue = null; var jiraRef = DataModel.JiraReference; void GetIssue() { if (modelHelpers.Gallifrey.JiraConnection.DoesJiraExist(jiraRef)) { jiraIssue = modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(jiraRef); } } var jiraDownloadResult = await progressDialogHelper.Do(GetIssue, "Searching For Jira Issue", true, false); if (jiraDownloadResult.Status == ProgressResult.JiraHelperStatus.Cancelled) { Focus(); return; } if (jiraIssue == null) { await modelHelpers.ShowMessageAsync("Invalid Jira", $"Unable To Locate The Jira '{jiraRef}'"); Focus(); return; } var result = await modelHelpers.ShowMessageAsync("Correct Jira?", $"Jira found!\n\nRef: {jiraIssue.key}\nName: {jiraIssue.fields.summary}\n\nIs that correct?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative }); if (result == MessageDialogResult.Negative) { return; } try { EditedTimerId = modelHelpers.Gallifrey.JiraTimerCollection.RenameTimer(EditedTimerId, jiraIssue); } catch (DuplicateTimerException ex) { var handled = await MergeTimers(ex); if (!handled) { Focus(); return; } } } } if (DataModel.HasModifiedTime) { var originalTime = new TimeSpan(DataModel.OriginalHours, DataModel.OriginalMinutes, 0); var newTime = new TimeSpan(DataModel.Hours ?? 0, DataModel.Minutes ?? 0, 0); var difference = newTime.Subtract(originalTime); var addTime = difference.TotalSeconds > 0; modelHelpers.Gallifrey.JiraTimerCollection.AdjustTime(EditedTimerId, Math.Abs(difference.Hours), Math.Abs(difference.Minutes), addTime); } modelHelpers.RefreshModel(); modelHelpers.SetSelectedTimer(EditedTimerId); modelHelpers.CloseFlyout(this); }
private async void LoadSearch() { SearchModel GetSearchModel() { var recent = new List <RecentJira>(); var filters = new List <string>(); var issues = new List <Issue>(); try { recent = modelHelpers.Gallifrey.JiraTimerCollection.GetJiraReferencesForLastDays(50).ToList(); } catch (NoResultsFoundException) { //Do Nothing } catch (Exception ex) { ExceptionlessClient.Default.CreateEvent().SetException(ex).AddTags("Hidden").Submit(); } try { filters = modelHelpers.Gallifrey.JiraConnection.GetJiraFilters().ToList(); } catch (NoResultsFoundException) { //Do Nothing } catch (Exception ex) { ExceptionlessClient.Default.CreateEvent().SetException(ex).AddTags("Hidden").Submit(); } try { issues = modelHelpers.Gallifrey.JiraConnection.GetJiraCurrentUserOpenIssues().ToList(); } catch (NoResultsFoundException) { //Do Nothing } catch (Exception ex) { ExceptionlessClient.Default.CreateEvent().SetException(ex).AddTags("Hidden").Submit(); } return(new SearchModel(filters, recent, issues, openFromEdit)); } var result = await progressDialogHelper.Do(GetSearchModel, "Loading Search Information", true, false); switch (result.Status) { case ProgressResult.JiraHelperStatus.Cancelled: modelHelpers.CloseFlyout(this); break; case ProgressResult.JiraHelperStatus.Errored: await modelHelpers.ShowMessageAsync("Error", "There Was An Error Loading Default Search Results"); modelHelpers.CloseFlyout(this); break; case ProgressResult.JiraHelperStatus.Success: DataContext = result.RetVal; break; } }
private async void AddButton(object sender, RoutedEventArgs e) { if (!modelHelpers.Gallifrey.Settings.InternalSettings.IsPremium) { if (DataModel.LocalTimer) { if (modelHelpers.Gallifrey.JiraTimerCollection.GetAllLocalTimers().Count() >= 2) { modelHelpers.ShowGetPremiumMessage("Without Gallifrey Premium You Are Limited To A Maximum Of 2 Local Timers"); Focus(); return; } } } if (!DataModel.StartDate.HasValue) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Missing Date", "You Must Enter A Start Date"); Focus(); return; } if (DataModel.StartDate.Value.Date < DataModel.MinDate.Date || DataModel.StartDate.Value.Date > DataModel.MaxDate.Date) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Date", $"You Must Enter A Start Date Between {DataModel.MinDate.ToShortDateString()} And {DataModel.MaxDate.ToShortDateString()}"); Focus(); return; } TimeSpan seedTime; if (DataModel.TimeEditable) { seedTime = new TimeSpan(DataModel.StartHours ?? 0, DataModel.StartMinutes ?? 0, 0); } else { seedTime = new TimeSpan(); } Issue jiraIssue = null; var jiraRef = string.Empty; if (!DataModel.LocalTimer) { try { jiraRef = DataModel.JiraReference; var jiraDownloadResult = await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(jiraRef), "Searching For Jira Issue", true, true); if (jiraDownloadResult.Status == ProgressResult.JiraHelperStatus.Success) { jiraIssue = jiraDownloadResult.RetVal; } else { Focus(); return; } } catch (NoResultsFoundException) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Jira", $"Unable To Locate The Jira '{jiraRef}'"); Focus(); return; } if (DataModel.JiraReferenceEditable) { var result = await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Correct Jira?", $"Jira found!\n\nRef: {jiraIssue.key}\nName: {jiraIssue.fields.summary}\n\nIs that correct?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative }); if (result == MessageDialogResult.Negative) { Focus(); return; } } } if (DataModel.DatePeriod) { AddedTimer = await AddPeriodTimer(jiraIssue, seedTime); } else { AddedTimer = await AddSingleTimer(jiraIssue, seedTime, DataModel.StartDate.Value); } if (!AddedTimer) { Focus(); return; } var stillDoingThings = false; if (!DataModel.LocalTimer) { if (DataModel.AssignToMe) { try { await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.AssignToCurrentUser(jiraRef), "Assigning Issue", false, true); } catch (JiraConnectionException) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Assign Jira Error", "Unable To Locate Assign Jira To Current User"); } } if (DataModel.ChangeStatus) { try { var transitionResult = await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.GetTransitions(jiraRef), "Getting Transitions To Change Status", false, true); if (transitionResult.Status == ProgressResult.JiraHelperStatus.Success) { var transitionsAvaliable = transitionResult.RetVal; var timeSelectorDialog = (BaseMetroDialog)this.Resources["TransitionSelector"]; await DialogCoordinator.Instance.ShowMetroDialogAsync(modelHelpers.DialogContext, timeSelectorDialog); var comboBox = timeSelectorDialog.FindChild <ComboBox>("Items"); comboBox.ItemsSource = transitionsAvaliable.Select(x => x.name).ToList(); var messageBox = timeSelectorDialog.FindChild <TextBlock>("Message"); messageBox.Text = $"Please Select The Status Update You Would Like To Perform To {DataModel.JiraReference}"; stillDoingThings = true; } } catch (Exception) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Status Update Error", "Unable To Change The Status Of This Issue"); } } } if (!stillDoingThings) { modelHelpers.CloseFlyout(this); modelHelpers.RefreshModel(); } }
private async void SaveButton(object sender, RoutedEventArgs e) { if (DataModel.HasModifiedRunDate) { if (!DataModel.RunDate.HasValue) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Missing Date", "You Must Enter A Start Date"); Focus(); return; } if (DataModel.RunDate.Value.Date < DataModel.MinDate.Date || DataModel.RunDate.Value.Date > DataModel.MaxDate.Date) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Date", $"You Must Enter A Start Date Between {DataModel.MinDate.ToShortDateString()} And {DataModel.MaxDate.ToShortDateString()}"); Focus(); return; } try { EditedTimerId = modelHelpers.Gallifrey.JiraTimerCollection.ChangeTimerDate(EditedTimerId, DataModel.RunDate.Value); } catch (DuplicateTimerException ex) { var handlerd = await MergeTimers(ex); if (!handlerd) { Focus(); return; } } } else if (DataModel.HasModifiedJiraReference) { if (DataModel.LocalTimer) { var currentTimer = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(EditedTimerId); if (!currentTimer.LocalTimer) { if (!modelHelpers.Gallifrey.Settings.InternalSettings.IsPremium) { var localTimersCount = modelHelpers.Gallifrey.JiraTimerCollection.GetAllLocalTimers().Count(); if (localTimersCount >= 2) { modelHelpers.ShowGetPremiumMessage("Without Gallifrey Premium You Are Limited To A Maximum Of 2 Local Timers"); Focus(); return; } } } try { EditedTimerId = modelHelpers.Gallifrey.JiraTimerCollection.ChangeLocalTimerDescription(EditedTimerId, DataModel.LocalTimerDescription); } catch (DuplicateTimerException) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Something Went Wrong", "An Error Occured Trying To Edit That Timer, Please Try Again"); Focus(); return; } } else { Issue jiraIssue; var jiraRef = string.Empty; try { jiraRef = DataModel.JiraReference; var jiraDownloadResult = await progressDialogHelper.Do(() => modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(jiraRef), "Searching For Jira Issue", true, true); if (jiraDownloadResult.Status == ProgressResult.JiraHelperStatus.Success) { jiraIssue = jiraDownloadResult.RetVal; } else { Focus(); return; } } catch (NoResultsFoundException) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Jira", $"Unable To Locate The Jira '{jiraRef}'"); Focus(); return; } var result = await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Correct Jira?", $"Jira found!\n\nRef: {jiraIssue.key}\nName: {jiraIssue.fields.summary}\n\nIs that correct?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative }); if (result == MessageDialogResult.Negative) { return; } try { EditedTimerId = modelHelpers.Gallifrey.JiraTimerCollection.RenameTimer(EditedTimerId, jiraIssue); } catch (DuplicateTimerException ex) { var handlerd = await MergeTimers(ex); if (!handlerd) { Focus(); return; } } } } if (DataModel.HasModifiedTime) { var originalTime = new TimeSpan(DataModel.OriginalHours, DataModel.OriginalMinutes, 0); var newTime = new TimeSpan(DataModel.Hours ?? 0, DataModel.Minutes ?? 0, 0); var difference = newTime.Subtract(originalTime); var addTime = difference.TotalSeconds > 0; modelHelpers.Gallifrey.JiraTimerCollection.AdjustTime(EditedTimerId, Math.Abs(difference.Hours), Math.Abs(difference.Minutes), addTime); } modelHelpers.RefreshModel(); modelHelpers.SetSelectedTimer(EditedTimerId); modelHelpers.CloseFlyout(this); }
private async void AddButton(object sender, RoutedEventArgs e) { if (!DataModel.StartDate.HasValue) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Missing Date", "You Must Enter A Start Date"); Focus(); return; } if (DataModel.StartDate.Value < DataModel.MinDate || DataModel.StartDate.Value > DataModel.MaxDate) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Date", $"You Must Enter A Start Date Between {DataModel.MinDate.ToShortDateString()} And {DataModel.MaxDate.ToShortDateString()}"); Focus(); return; } TimeSpan seedTime; if (DataModel.TimeEditable) { seedTime = new TimeSpan(DataModel.StartHours, DataModel.StartMinutes, 0); } else { seedTime = new TimeSpan(); } Issue jiraIssue = null; if (!DataModel.TempTimer) { try { jiraIssue = modelHelpers.Gallifrey.JiraConnection.GetJiraIssue(DataModel.JiraReference); } catch (NoResultsFoundException) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Jira", "Unable To Locate The Jira"); Focus(); return; } if (DataModel.JiraReferenceEditable) { var result = await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Correct Jira?", $"Jira found!\n\nRef: {jiraIssue.key}\nName: {jiraIssue.fields.summary}\n\nIs that correct?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative }); if (result == MessageDialogResult.Negative) { Focus(); return; } } } try { if (DataModel.TempTimer) { NewTimerId = modelHelpers.Gallifrey.JiraTimerCollection.AddTempTimer(DataModel.TempTimerDescription, DataModel.StartDate.Value, seedTime, DataModel.StartNow); } else { NewTimerId = modelHelpers.Gallifrey.JiraTimerCollection.AddTimer(jiraIssue, DataModel.StartDate.Value, seedTime, DataModel.StartNow); } AddedTimer = true; if (!DataModel.TimeEditable) { modelHelpers.Gallifrey.JiraTimerCollection.AddIdleTimer(NewTimerId, DataModel.IdleTimers); } } catch (DuplicateTimerException ex) { var doneSomething = false; if (seedTime.TotalMinutes > 0 || !DataModel.TimeEditable) { var result = await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Duplicate Timer", "The Timer Already Exists, Would You Like To Add The Time?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative }); if (result == MessageDialogResult.Affirmative) { if (DataModel.TimeEditable) { modelHelpers.Gallifrey.JiraTimerCollection.AdjustTime(ex.TimerId, seedTime.Hours, seedTime.Minutes, true); } else { modelHelpers.Gallifrey.JiraTimerCollection.AddIdleTimer(ex.TimerId, DataModel.IdleTimers); } doneSomething = true; } else { Focus(); return; } } if (DataModel.StartNow) { modelHelpers.Gallifrey.JiraTimerCollection.StartTimer(ex.TimerId); doneSomething = true; } if (!doneSomething) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Duplicate Timer", "This Timer Already Exists!"); Focus(); return; } NewTimerId = ex.TimerId; } if (!DataModel.TempTimer) { if (DataModel.AssignToMe) { try { modelHelpers.Gallifrey.JiraConnection.AssignToCurrentUser(DataModel.JiraReference); } catch (JiraConnectionException) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Assign Jira Error", "Unable To Locate Assign Jira To Current User"); } } if (DataModel.InProgress) { try { modelHelpers.Gallifrey.JiraConnection.SetInProgress(DataModel.JiraReference); } catch (StateChangedException) { await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Error Changing Status", "Unable To Set Issue As In Progress"); } } } AddedTimer = true; modelHelpers.CloseFlyout(this); modelHelpers.RefreshModel(); }