private void HearbeatOnElapsed(object sender, ElapsedEventArgs e) { try { jiraTimerCollection.RemoveTimersOlderThanDays(settingsCollection.AppSettings.KeepTimersForDays); idleTimerCollection.RemoveOldTimers(); jiraConnection.UpdateCache(); var runningTimerId = jiraTimerCollection.GetRunningTimerId(); if (runningTimerId.HasValue) { var runningTimer = jiraTimerCollection.GetTimer(runningTimerId.Value); if (runningTimer.DateStarted.Date != DateTime.Now.Date) { jiraTimerCollection.StopTimer(runningTimerId.Value); jiraTimerCollection.StartTimer(runningTimerId.Value); } } if (settingsCollection.InternalSettings.LastHeartbeatTracked.Date < DateTime.UtcNow.Date) { trackUsage.TrackAppUsage(TrackingType.DailyHearbeat); settingsCollection.InternalSettings.LastHeartbeatTracked = DateTime.UtcNow; settingsCollection.SaveSettings(); } } catch { /*Surpress Errors, if this fails timers won't be removed*/ } }
private void CleanUpAndTrackingHeartbeatOnElapsed(object sender, ElapsedEventArgs e) { try { jiraTimerCollection.RemoveTimersOlderThanDays(settingsCollection.AppSettings.KeepTimersForDays); idleTimerCollection.RemoveOldTimers(); jiraConnection.UpdateCache(); var runningTimerId = jiraTimerCollection.GetRunningTimerId(); if (runningTimerId.HasValue) { var runningTimer = jiraTimerCollection.GetTimer(runningTimerId.Value); if (runningTimer.DateStarted.Date != DateTime.Now.Date) { jiraTimerCollection.StopTimer(runningTimerId.Value, true); jiraTimerCollection.StartTimer(runningTimerId.Value); } } BackendModifiedTimers?.Invoke(this, null); if (settingsCollection.InternalSettings.LastHeartbeatTracked.Date < DateTime.UtcNow.Date) { if (versionControl.IsAutomatedDeploy && jiraConnection.IsConnected) { DailyTrackingEvent?.Invoke(this, null); trackUsage.TrackAppUsage(TrackingType.DailyHeartbeat); settingsCollection.InternalSettings.SetLastHeartbeatTracked(DateTime.UtcNow); settingsCollection.SaveSettings(); } } } catch { /*Suppress Errors, if this fails timers won't be removed*/ } }
private void CheckAndConnectJira(bool useRestApi = true) { if (jira == null) { if (string.IsNullOrWhiteSpace(jiraConnectionSettings.JiraUrl) || string.IsNullOrWhiteSpace(jiraConnectionSettings.JiraUsername) || string.IsNullOrWhiteSpace(jiraConnectionSettings.JiraPassword)) { throw new MissingJiraConfigException("Required settings to create connection to jira are missing"); } try { var url = jiraConnectionSettings.JiraUrl.Replace("/secure/Dashboard.jspa", ""); if (useRestApi) { jira = new JiraRestClient(url, jiraConnectionSettings.JiraUsername, jiraConnectionSettings.JiraPassword); } else { jira = new JiraSoapClient(url, jiraConnectionSettings.JiraUsername, jiraConnectionSettings.JiraPassword); } CurrentUser = jira.GetCurrentUser(); TrackingType trackingType; if (useRestApi) { trackingType = url.Contains(".atlassian.net") ? TrackingType.JiraConnectCloudRest : TrackingType.JiraConnectSelfhostRest; } else { trackingType = url.Contains(".atlassian.net") ? TrackingType.JiraConnectCloudSoap : TrackingType.JiraConnectSelfhostSoap; } trackUsage.TrackAppUsage(trackingType); } catch (Exception ex) { jira = null; if (useRestApi) { CheckAndConnectJira(false); } else { throw new JiraConnectionException("Error creating instance of Jira", ex); } } } }
private void AddTimer(JiraTimer newTimer) { var timerSearch = timerList.FirstOrDefault(timer => timer.JiraReference == newTimer.JiraReference && timer.DateStarted.Date == newTimer.DateStarted.Date); if (timerSearch != null) { throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId); } trackUsage.TrackAppUsage(TrackingType.TimerAdded); timerList.Add(newTimer); SaveTimers(); }
private void AddTimer(JiraTimer newTimer) { var timerSearch = timerList.FirstOrDefault(timer => string.Equals(timer.JiraReference, newTimer.JiraReference, StringComparison.InvariantCultureIgnoreCase) && timer.DateStarted.Date == newTimer.DateStarted.Date); if (timerSearch != null) { throw new DuplicateTimerException("Already have a timer for this task on this day!", timerSearch.UniqueId); } trackUsage.TrackAppUsage(TrackingType.TimerAdded); timerList.Add(newTimer); SaveTimers(); }
public Task <UpdateResult> CheckForUpdates(bool manualCheck = false) { if (!IsAutomatedDeploy) { return(Task.Factory.StartNew(() => UpdateResult.NotDeployable)); } if (IsAutomatedDeploy && (manualCheck || lastUpdateCheck < DateTime.UtcNow.AddMinutes(-5))) { trackUsage.TrackAppUsage(TrackingType.UpdateCheck); lastUpdateCheck = DateTime.UtcNow; try { var updateInfo = ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate(false); if (updateInfo.UpdateAvailable && updateInfo.AvailableVersion > ApplicationDeployment.CurrentDeployment.CurrentVersion) { return(Task.Factory.StartNew(() => ApplicationDeployment.CurrentDeployment.Update()).ContinueWith(task => { SetVersionName(); UpdateInstalled = true; return UpdateResult.Updated; })); } if (manualCheck) { return(Task.Factory.StartNew(() => { Task.Delay(1500); return UpdateResult.NoUpdate; })); } } catch (TrustNotGrantedException) { if (manualCheck) { throw new ManualReinstallRequiredException(); } } catch (Exception) { } } return(Task.Factory.StartNew(() => UpdateResult.TooSoon)); }
public Backend(InstanceType instanceType) { settingsCollection = SettingsCollectionSerializer.DeSerialize(); versionControl = new VersionControl(instanceType); trackUsage = new TrackUsage(versionControl, settingsCollection, instanceType); versionControl.UpdateCheckOccured += (sender, b) => trackUsage.TrackAppUsage(b ? TrackingType.UpdateCheckManual : TrackingType.UpdateCheck); jiraTimerCollection = new JiraTimerCollection(settingsCollection, trackUsage); jiraTimerCollection.exportPrompt += OnExportPromptEvent; jiraConnection = new JiraConnection(trackUsage); idleTimerCollection = new IdleTimerCollection(); ActivityChecker = new ActivityChecker(jiraTimerCollection, settingsCollection); withThanksCreator = new WithThanksCreator(); premiumChecker = new PremiumChecker(); ActivityChecker.NoActivityEvent += OnNoActivityEvent; var cleanUpAndTrackingHeartbeat = new Timer(TimeSpan.FromMinutes(15).TotalMilliseconds); cleanUpAndTrackingHeartbeat.Elapsed += CleanUpAndTrackingHearbeatOnElapsed; cleanUpAndTrackingHeartbeat.Start(); exportedHeartbeatMutex = new Mutex(false); var jiraExportHearbeat = new Timer(TimeSpan.FromMinutes(10).TotalMilliseconds); jiraExportHearbeat.Elapsed += JiraExportHearbeatHearbeatOnElapsed; jiraExportHearbeat.Start(); if (Settings.AppSettings.TimerRunningOnShutdown.HasValue) { var timer = jiraTimerCollection.GetTimer(Settings.AppSettings.TimerRunningOnShutdown.Value); if (timer != null && timer.DateStarted.Date == DateTime.Now.Date) { JiraTimerCollection.StartTimer(Settings.AppSettings.TimerRunningOnShutdown.Value); } Settings.AppSettings.TimerRunningOnShutdown = null; SaveSettings(false, false); } }
public void LogTime(string jiraRef, DateTime exportTimeStamp, TimeSpan exportTime, WorkLogStrategy strategy, string comment = "", TimeSpan?remainingTime = null) { trackUsage.TrackAppUsage(TrackingType.ExportOccured); var jiraIssue = jira.GetIssue(jiraRef); var wasClosed = TryReopenJira(jiraIssue); if (string.IsNullOrWhiteSpace(comment)) { comment = exportSettings.EmptyExportComment; } if (!string.IsNullOrWhiteSpace(exportSettings.ExportCommentPrefix)) { comment = string.Format("{0}: {1}", exportSettings.ExportCommentPrefix, comment); } try { jira.AddWorkLog(jiraRef, strategy, comment, exportTime, DateTime.SpecifyKind(exportTimeStamp, DateTimeKind.Local), remainingTime); } catch (Exception ex) { throw new WorkLogException("Error logging work", ex); } if (wasClosed) { try { ReCloseJira(jiraRef); } catch (Exception ex) { throw new StateChangedException("Time Logged, but state is now open", ex); } } }
public Backend(InstanceType instanceType) { settingsCollection = new SettingsCollection(SettingsCollectionSerializer.DeSerialize()); versionControl = new VersionControl(instanceType); trackUsage = new TrackUsage(versionControl, settingsCollection, instanceType); jiraTimerCollection = new JiraTimerCollection(settingsCollection, trackUsage); recentJiraCollection = new RecentJiraCollection(); jiraConnection = new JiraConnection(trackUsage, recentJiraCollection); idleTimerCollection = new IdleTimerCollection(); ActivityChecker = new ActivityChecker(jiraTimerCollection, settingsCollection); withThanksCreator = new WithThanksCreator(); versionControl.UpdateCheckOccured += (sender, b) => trackUsage.TrackAppUsage(b ? TrackingType.UpdateCheckManual : TrackingType.UpdateCheck); jiraTimerCollection.ExportPrompt += OnExportPromptEvent; ActivityChecker.NoActivityEvent += OnNoActivityEvent; cleanUpAndTrackingHeartbeat = new Timer(TimeSpan.FromMinutes(15).TotalMilliseconds); cleanUpAndTrackingHeartbeat.Elapsed += CleanUpAndTrackingHeartbeatOnElapsed; exportedHeartbeatMutex = new Mutex(false); jiraExportHeartbeat = new Timer(TimeSpan.FromMinutes(10).TotalMilliseconds); jiraExportHeartbeat.Elapsed += JiraExportHeartbeatHeartbeatOnElapsed; }
private void CheckAndConnectJira() { if (jira == null) { try { jira = JiraClientFactory.BuildJiraClient(jiraConnectionSettings.JiraUrl, jiraConnectionSettings.JiraUsername, jiraConnectionSettings.JiraPassword, jiraConnectionSettings.UseTempo); CurrentUser = jira.GetCurrentUser(); LoggedIn?.Invoke(this, null); TrackingType trackingType; if (jira.GetType() == typeof(JiraRestClient) && jira.HasTempo) { trackingType = jiraConnectionSettings.JiraUrl.Contains(".atlassian.net") ? TrackingType.JiraConnectCloudRestWithTempo : TrackingType.JiraConnectSelfhostRestWithTempo; } else if (jira.GetType() == typeof(JiraRestClient)) { trackingType = jiraConnectionSettings.JiraUrl.Contains(".atlassian.net") ? TrackingType.JiraConnectCloudRest : TrackingType.JiraConnectSelfhostRest; } else { trackingType = jiraConnectionSettings.JiraUrl.Contains(".atlassian.net") ? TrackingType.JiraConnectCloudSoap : TrackingType.JiraConnectSelfhostSoap; } trackUsage.TrackAppUsage(trackingType); } catch (InvalidCredentialException) { throw new MissingJiraConfigException("Required settings to create connection to jira are missing"); } catch (Exception ex) { throw new JiraConnectionException("Error creating instance of Jira", ex); } } }