public static void ActiveSegmentChanged(object sender, EventArgs e)
        {
            try
            {
                Tracked.TrackerLastActivity = DateTime.Now;
                var firstOrDefault = Tracked.ActiveDocument.Files.FirstOrDefault();
                if (firstOrDefault == null || Tracked.ActiveDocument == null || !Tracked.DictCacheDocumentItems.ContainsKey(firstOrDefault.Id.ToString()))
                {
                    return;
                }
                if (Tracked.TrackingState != Tracked.TimerState.Started &&
                    Tracked.TrackingState != Tracked.TimerState.Paused)
                {
                    return;
                }
                var projectFile = Tracked.ActiveDocument.Files.FirstOrDefault();
                if (projectFile == null)
                {
                    return;
                }
                var trackedDocuments = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()];

                if (trackedDocuments.ActiveSegment.CurrentSegmentSelected != null)
                {
                    TrackedController.TrackActiveChanges(trackedDocuments);
                }

                TrackedController.InitializeActiveSegment(trackedDocuments);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public static void stop_tracking(EditorController editorController, Timer timer)
        {
            try
            {
                Tracked.TrackerLastActivity = DateTime.Now;

                timer.Stop();


                Tracked.TrackingState = Tracked.TimerState.Stopped;
                Tracked.TrackingTimer.Stop();
                Tracked.TrackingEnd = DateTime.Now;
                Tracked.TrackingPaused.Stop();
                Tracked.TrackingTimer = new Stopwatch();


                try
                {
                    if (Tracked.ActiveDocument != null)
                    {
                        var endTime = DateTime.Now;
                        foreach (var trackedDocument in Tracked.DictCacheDocumentItems.Values)
                        {
                            foreach (var document in trackedDocument.Documents)
                            {
                                document.DatetimeClosed = endTime;
                                document.DocumentTimer.Stop();
                            }
                        }

                        var firstOrDefault = Tracked.ActiveDocument.Files.FirstOrDefault();
                        if (firstOrDefault != null)
                        {
                            var trackedDocuments = Tracked.DictCacheDocumentItems[firstOrDefault.Id.ToString()];

                            TrackedController.TrackActiveChanges(trackedDocuments);
                        }

                        foreach (var trackedDocument in Tracked.DictCacheDocumentItems.Values)
                        {
                            TrackedController.NewProjectActivity(trackedDocument);
                        }

                        Tracked.DictCacheDocumentItems = new Dictionary <string, TrackedDocuments>();
                        QualitivityRevisionController.CleanQualityMetricsDataContainer();
                    }
                }
                finally
                {
                    #region  |  null tracker cache  |

                    if (Tracked.DictCacheDocumentItems.Count == 0)
                    {
                        Tracked.Reset();
                        Tracked.TrackingState = Tracked.TimerState.Stopped;
                    }

                    Tracked.TrackingIsDirtyC0 = true;
                    Tracked.TrackingIsDirtyC1 = true;
                    Tracked.TrackingIsDirtyC2 = true;


                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            timer.Start();
        }
Exemple #3
0
        private static void EditorController_Closing(object sender, CancelDocumentEventArgs e)
        {
            try
            {
                #region  |  remove handlers  |

                if (e.Document != null)
                {
                    e.Document.SegmentsConfirmationLevelChanged -= TrackedDocumentEvents.ConfirmationLevelChanged;
                    e.Document.SegmentsTranslationOriginChanged -= TrackedDocumentEvents.TranslationOriginChanged;
                    e.Document.ActiveSegmentChanged             -= TrackedDocumentEvents.ActiveSegmentChanged;
                    e.Document.ContentChanged           -= TrackedDocumentEvents.ContentChanged;
                    e.Document.Selection.Changed        -= TrackedDocumentEvents.SelectionChanged;
                    e.Document.Selection.Source.Changed -= TrackedDocumentEvents.SourceChanged;
                    e.Document.Selection.Target.Changed -= TrackedDocumentEvents.TargetChanged;
                }

                #endregion

                Tracked.TrackerLastActivity = DateTime.Now;

                //Timer4ProjectArea.Stop();

                if (Tracked.TrackingState != Tracked.TimerState.Started &&
                    Tracked.TrackingState != Tracked.TimerState.Paused || Tracked.ActiveDocument == null)
                {
                    return;
                }

                try
                {
                    var projectFile = Tracked.ActiveDocument.Files.FirstOrDefault();

                    if (projectFile != null && Tracked.DictCacheDocumentItems.ContainsKey(projectFile.Id.ToString()))
                    {
                        var trackedDocuments = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()];

                        foreach (var document in trackedDocuments.Documents)
                        {
                            document.DatetimeClosed = DateTime.Now;
                            document.DocumentTimer.Stop();
                        }

                        TrackedController.TrackActiveChanges(trackedDocuments);
                        TrackedController.NewProjectActivity(trackedDocuments);

                        Tracked.TarckerCheckNewActivityAdded = false;

                        //FilterViewerControl(Tracked.TarckerCheckNewActivityId);
                        if (Tracked.DictCacheDocumentItems.ContainsKey(projectFile.Id.ToString()))
                        {
                            Tracked.DictCacheDocumentItems.Remove(projectFile.Id.ToString());
                        }
                    }

                    OnEditorControllerClosing();
                }
                finally
                {
                    #region  |  null tracker cache  |

                    if (Tracked.DictCacheDocumentItems.Count == 0)
                    {
                        Tracked.Reset();
                        Tracked.TrackingState = Tracked.TimerState.Stopped;
                    }

                    Tracked.TrackingIsDirtyC0 = true;
                    Tracked.TrackingIsDirtyC1 = true;
                    Tracked.TrackingIsDirtyC2 = true;

                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //Timer4ProjectArea.Start();
            }
        }
Exemple #4
0
        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();
            }
        }