private static void EditorController_ActiveDocumentChanged(object sender, DocumentEventArgs e) { try { Tracked.TrackerLastActivity = DateTime.Now; //Timer4ProjectArea.Stop(); #region | stop the timer from the previous document | if (Tracked.ActiveDocument != null) { var projectFile = Tracked.ActiveDocument.Files.FirstOrDefault(); if (projectFile != null) { if (Tracked.DictCacheDocumentItems.ContainsKey(projectFile.Id.ToString())) { var trackedDocuments = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()]; trackedDocuments.ActiveDocument.DocumentTimer.Stop(); if (trackedDocuments.ActiveSegment.CurrentSegmentSelected != null) { trackedDocuments.ActiveSegment.CurrentSegmentTimer.Stop(); } TrackedController.TrackActiveChanges(trackedDocuments); } } } #endregion Tracked.ActiveDocument = null; if (e?.Document?.ActiveFile == null) { return; } { Tracked.ActiveDocument = e.Document; var projectFile = Tracked.ActiveDocument.Files.FirstOrDefault(); if (Tracked.TrackingState == Tracked.TimerState.Started || Tracked.TrackingState == Tracked.TimerState.Paused) { if (projectFile != null) { if (!Tracked.DictCacheDocumentItems.ContainsKey(projectFile.Id.ToString())) { TrackedController.TrackNewDocumentEntry(Tracked.ActiveDocument); } var trackedDocuments = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()]; if (Tracked.TrackingState == Tracked.TimerState.Started) { trackedDocuments.ActiveDocument.DocumentTimer.Start(); } TrackedController.InitializeDocumentTracking(Tracked.ActiveDocument); TrackedDocumentEvents.ActiveSegmentChanged(sender, null); Application.DoEvents(); //************************************** //initialize the quality metrics container #region | set the default current metric group what is specified for the company | var project = Helper.GetProjectFromId(trackedDocuments.ProjectId); if (project.CompanyProfileId > -1) { var ci = Helper.GetClientFromId(project.CompanyProfileId); if (ci != null && ci.Id > -1) { if (ci.MetricGroup.Id > -1) { Tracked.Settings.QualityMetricGroup = ci.MetricGroup; } } } #endregion QualitivityRevisionController.InitializeQualityMetricsData(trackedDocuments.QualityMetrics, false); } //************************************** Tracked.TrackingIsDirtyC0 = true; Tracked.TrackingIsDirtyC1 = true; Tracked.TrackingIsDirtyC2 = true; } else { if (projectFile != null && Tracked.DictCacheDocumentItems.ContainsKey(projectFile.Id.ToString())) { TrackedController.InitializeDocumentTracking(Tracked.ActiveDocument); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); Console.WriteLine(ex.Message); } finally { //Timer4ProjectArea.Start(); } }
public static void start_tracking(EditorController editorController, Timer timer, bool reset) { Tracked.TrackerLastActivity = DateTime.Now; timer.Stop(); if (reset) { Tracked.Reset(); Tracked.TrackingState = Tracked.TimerState.Started; Tracked.TrackingTimer = new Stopwatch(); Tracked.TrackingTimer.Stop(); Tracked.TrackingStart = null; Tracked.TrackingEnd = null; Tracked.TrackingPaused = new Stopwatch(); } Tracked.ActiveDocument = null; try { if (editorController != null && editorController.ActiveDocument != null) { if (editorController.ActiveDocument.ActiveFile != null) { Tracked.ActiveDocument = editorController.ActiveDocument; #region | initialize the global timer | Tracked.TrackingState = Tracked.TimerState.Started; Tracked.TrackingTimer = new Stopwatch(); Tracked.TrackingTimer.Start(); Tracked.TrackingStart = DateTime.Now; Tracked.TrackingEnd = null; Tracked.TrackingPaused = new Stopwatch(); #endregion var firstOrDefault = Tracked.ActiveDocument.Files.FirstOrDefault(); if (firstOrDefault != null && !Tracked.DictCacheDocumentItems.ContainsKey(firstOrDefault.Id.ToString())) { TrackedController.TrackNewDocumentEntry(Tracked.ActiveDocument); } var projectFile = Tracked.ActiveDocument.Files.FirstOrDefault(); if (projectFile != null) { var trackedDocuments = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()]; if (Tracked.TrackingState == Tracked.TimerState.Started) { trackedDocuments.ActiveDocument.DocumentTimer.Start(); trackedDocuments.ActiveDocument.DatetimeOpened = Tracked.TrackingStart; trackedDocuments.ActiveDocument.DatetimeClosed = null; } TrackedController.InitializeDocumentTracking(Tracked.ActiveDocument); Application.DoEvents(); //_qualityMetrics.Value. //************************************** //initialize the quality metrics container #region | set the default current metric group what is specified for the company | var project = Helper.GetProjectFromId(trackedDocuments.ProjectId); if (project.CompanyProfileId > -1) { var ci = Helper.GetClientFromId(project.CompanyProfileId); if (ci != null && ci.Id > -1) { if (ci.MetricGroup.Id > -1) { Tracked.Settings.QualityMetricGroup = ci.MetricGroup; } } } #endregion QualitivityRevisionController.InitializeQualityMetricsData(trackedDocuments.QualityMetrics, true); //************************************** TrackedController.InitializeActiveSegment(trackedDocuments); } } else { #region | set the tracking timer | Tracked.TrackingState = Tracked.TimerState.Stopped; Tracked.TrackingTimer.Stop(); Tracked.TrackingEnd = DateTime.Now; Tracked.TrackingPaused.Stop(); Tracked.TrackingTimer = new Stopwatch(); #endregion MessageBox.Show(PluginResources.Unable_To_Initialize_Timer, PluginResources.Title_Qualitivity, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Tracked.TrackingIsDirtyC0 = true; Tracked.TrackingIsDirtyC1 = true; Tracked.TrackingIsDirtyC2 = true; } timer.Start(); }
private static void EditorController_Opened(object sender, DocumentEventArgs e) { try { Tracked.TrackerLastActivity = DateTime.Now; //Timer4ProjectArea.Stop(); Tracked.ActiveDocument = null; if (e?.Document?.ActiveFile == null) { return; } Tracked.ActiveDocument = e.Document; //automatically start tracking if the setting active if (Convert.ToBoolean(Tracked.Settings.GetTrackingProperty("autoStartTrackingOnDocumentOpenEvent").Value)) { if (Tracked.TrackingState != Tracked.TimerState.Started && Tracked.TrackingState != Tracked.TimerState.Paused) { Tracked.TrackingState = Tracked.TimerState.Started; } } if (Tracked.TrackingState != Tracked.TimerState.Started && Tracked.TrackingState != Tracked.TimerState.Paused || Tracked.ActiveDocument == null) { return; } //TO CHECK THIS SHOULD NOT BE INITIALIZED UNLESS IT IS NECCESSARY if (Tracked.TrackingState == Tracked.TimerState.Started && !Tracked.TrackingTimer.IsRunning) { Tracked.TrackingState = Tracked.TimerState.Started; Tracked.TrackingTimer = new Stopwatch(); Tracked.TrackingTimer.Start(); Tracked.TrackingStart = DateTime.Now; Tracked.TrackingEnd = null; Tracked.TrackingPaused = new Stopwatch(); } var projectFile = Tracked.ActiveDocument.Files.FirstOrDefault(); if (projectFile == null) { return; } if (!Tracked.DictCacheDocumentItems.ContainsKey(projectFile.Id.ToString())) { TrackedController.TrackNewDocumentEntry(Tracked.ActiveDocument); } var trackedDocuments = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()]; if (Tracked.TrackingState == Tracked.TimerState.Started) { trackedDocuments.ActiveDocument.DocumentTimer.Start(); trackedDocuments.ActiveDocument.DatetimeOpened = DateTime.Now; trackedDocuments.ActiveDocument.DatetimeClosed = null; } TrackedController.InitializeDocumentTracking(Tracked.ActiveDocument); Application.DoEvents(); //_qualityMetrics.Value. //************************************** //initialize the quality metrics container #region | set the default current metric group what is specified for the company | var project = Helper.GetProjectFromId(trackedDocuments.ProjectId); if (project.CompanyProfileId > -1) { var ci = Helper.GetClientFromId(project.CompanyProfileId); if (ci != null && ci.Id > -1) { if (ci.MetricGroup.Id > -1) { Tracked.Settings.QualityMetricGroup = ci.MetricGroup; } } } #endregion QualitivityRevisionController.InitializeQualityMetricsData(trackedDocuments.QualityMetrics, true); try { TrackedController.InitializeActiveSegment(trackedDocuments); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Tracked.TrackingIsDirtyC0 = true; Tracked.TrackingIsDirtyC1 = true; Tracked.TrackingIsDirtyC2 = true; } //ensure that the segment id is set from the QM area trackedDocuments.ActiveSegment.CurrentDocumentId = trackedDocuments.ActiveDocument.Id; trackedDocuments.ActiveSegment.CurrentSegmentId = Tracked.ActiveDocument.GetActiveSegmentPair().Properties.Id.Id; trackedDocuments.ActiveSegment.CurrentParagraphId = Tracked.ActiveDocument.GetActiveSegmentPair().GetParagraphUnitProperties().ParagraphUnitId.Id; trackedDocuments.ActiveSegment.CurrentSegmentUniqueId = trackedDocuments.ActiveSegment.CurrentParagraphId + "." + trackedDocuments.ActiveSegment.CurrentSegmentId; QualitivityRevisionController.SetCurrentSelectedSegmentId(trackedDocuments.ActiveSegment.CurrentParagraphId, trackedDocuments.ActiveSegment.CurrentSegmentId); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //Timer4ProjectArea.Start(); } }