Example #1
0
        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*/ }
        }
Example #2
0
        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*/ }
        }
Example #3
0
        public Backend(InstanceType instanceType, AppType appType)
        {
            settingsCollection  = SettingsCollectionSerializer.DeSerialize();
            trackUsage          = new TrackUsage(settingsCollection.AppSettings, settingsCollection.InternalSettings, instanceType, appType);
            versionControl      = new VersionControl(instanceType, appType, trackUsage);
            jiraTimerCollection = new JiraTimerCollection(settingsCollection.ExportSettings);
            jiraTimerCollection.exportPrompt += OnExportPromptEvent;
            jiraConnection                   = new JiraConnection(trackUsage);
            idleTimerCollection              = new IdleTimerCollection();
            ActivityChecker                  = new ActivityChecker(jiraTimerCollection, settingsCollection.AppSettings);
            ActivityChecker.NoActivityEvent += OnNoActivityEvent;
            hearbeat          = new Timer(1800000);
            hearbeat.Elapsed += HearbeatOnElapsed;
            hearbeat.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);
            }

            HearbeatOnElapsed(this, null);
        }
Example #4
0
        public void Initialise()
        {
            settingsCollection.Initialise();
            idleTimerCollection.Initialise();
            jiraTimerCollection.Initialise();
            recentJiraCollection.Initialise();

            if (settingsCollection.InternalSettings.LastChangeLogVersion == new Version(0, 0, 0, 0) && settingsCollection.InternalSettings.NewUser)
            {
                throw new MissingConfigException("New User");
            }

            jiraConnection.ReConnect(settingsCollection.JiraConnectionSettings, settingsCollection.ExportSettings);
            cleanUpAndTrackingHeartbeat.Start();
            jiraExportHeartbeat.Start();
            BackendModifiedTimers?.Invoke(this, null);

            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);
            }

            if (Settings.AppSettings.NoTimerRunningOnShutdown.HasValue)
            {
                ActivityChecker.SetValue(Settings.AppSettings.NoTimerRunningOnShutdown.Value);

                Settings.AppSettings.NoTimerRunningOnShutdown = null;
                SaveSettings(false, false);
            }

            CleanUpAndTrackingHeartbeatOnElapsed(this, null);

            IsInitialised = true;

            Task.Run(() => { JiraExportHeartbeatHeartbeatOnElapsed(this, null); });
        }
Example #5
0
        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);
            }
        }
Example #6
0
        public Backend(InstanceType instanceType, AppType appType)
        {
            settingsCollection  = SettingsCollectionSerializer.DeSerialize();
            trackUsage          = new TrackUsage(settingsCollection.AppSettings, settingsCollection.InternalSettings, instanceType, appType);
            versionControl      = new VersionControl(instanceType, appType, trackUsage);
            jiraTimerCollection = new JiraTimerCollection(settingsCollection.ExportSettings, trackUsage);
            jiraTimerCollection.exportPrompt += OnExportPromptEvent;
            jiraConnection      = new JiraConnection(trackUsage);
            idleTimerCollection = new IdleTimerCollection();
            ActivityChecker     = new ActivityChecker(jiraTimerCollection, settingsCollection.AppSettings);
            withThanksCreator   = new WithThanksCreator();

            ActivityChecker.NoActivityEvent += OnNoActivityEvent;
            var cleanUpAndTrackingHearbeat = new Timer(1800000); // 30 minutes

            cleanUpAndTrackingHearbeat.Elapsed += CleanUpAndTrackingHearbeatOnElapsed;
            cleanUpAndTrackingHearbeat.Start();

            exportedHeartbeatMutex = new Mutex(false);
            var jiraExportHearbeat = new Timer(600000); //10 minutes

            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);
            }
        }