Esempio n. 1
0
 public void Setup(TrackedController controller)
 {
     _controller = controller;
     _controller.OnTriggerDown += TryGrab;
     _controller.OnTriggerUp   += Release;
     CurrentlyActiveJoint       = ConfigurableJoint;
 }
        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);
            }
        }
Esempio n. 3
0
 // Use this for initialization
 void Start()
 {
     m_trackedController = TrackedController.GetController(m_handedness);
     m_animator          = GetComponent <Animator> ();
     m_targetFollower    = GetComponent <TargetFollower> ();
     m_networkhand       = GetComponent <NetworkHand> ();
 }
Esempio n. 4
0
        private void TryPush(TrackedController sender, float TriggerValue)
        {
            var toPush = _scanner.GetClosestInterractableObject();

            if (toPush != null)
            {
                var pushedObject = toPush.GetComponentInParent <ASwitchable>();
                if (pushedObject != null)
                {
                    pushedObject.Switch();
                    Debug.Log("Pushed " + toPush.name);
                }
            }
        }
Esempio n. 5
0
 public void SetupAutority()
 {
     isAuthority         = true;
     m_targetFollower    = GetComponent <TargetFollower> ();
     m_trackedController = TrackedController.GetController(m_handedness);
     if (m_handedness == OVRInput.Controller.LTouch)
     {
         m_targetFollower.target = PlayerObjectAccess.Instance.leftHandTarget;
     }
     else if (m_handedness == OVRInput.Controller.RTouch)
     {
         m_targetFollower.target = PlayerObjectAccess.Instance.rightHandTarget;
     }
 }
Esempio n. 6
0
        private void TryGrab(TrackedController sender, float TriggerValue)
        {
            if (IsGrabbing)
            {
                Debug.Log("Grabber is Grabbing already, something went wrong");
                return;
            }

            var toGrab = Scanner.GetClosestInterractableObject();

            if (toGrab != null)
            {
                var grabbedObject = toGrab.GetComponentInParent <GrabbableObject>();
                if (grabbedObject != null && grabbedObject.CurrentGrabber == null)
                {
                    GrabbedObject = grabbedObject;
                    IsGrabbing    = true;
                    GrabbedObject.Grab(this);
                    Debug.Log("Grabbed " + GrabbedObject.name);
                    if (!grabbedObject.UsesFakeGrab)
                    {
                        if (grabbedObject.UseSpring)
                        {
                            CurrentlyActiveJoint = SpringJoint;
                        }
                        else
                        {
                            CurrentlyActiveJoint = ConfigurableJoint;
                        }
                        CurrentlyActiveJoint.connectedBody = GrabbedObject.GetComponentInParent <Rigidbody>();
                        _grabbedMagnitude = (CurrentlyActiveJoint.transform.position - CurrentlyActiveJoint.connectedBody.transform.position).sqrMagnitude;
                    }
                    _controller.HandController.SetGrabState(true, GrabbedObject.ActivationHandState);
                }
            }
        }
Esempio n. 7
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();
            }
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
0
        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();
            }
        }
Esempio n. 10
0
 private void Start()
 {
     controller = tracker.GetComponent <TrackedController>();
     spawn      = tracker.transform.Find("Spawn");
 }
Esempio n. 11
0
 public void Setup(TrackedController controller)
 {
     _controller = controller;
 }
Esempio n. 12
0
        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();
        }
Esempio n. 13
0
        private static void WarningMessageTrackingNotRunning(object sender, string projectFileId)
        {
            if (!Convert.ToBoolean(Tracked.Settings.GetTrackingProperty(@"warningMessageActivityTrackingNotRunning").Value))
            {
                return;
            }

            var ignoreWarning = false;

            if (Tracked.WarningMessageDocumentsIgnoreActivityNotRunning.ContainsKey(projectFileId))
            {
                ignoreWarning = Tracked.WarningMessageDocumentsIgnoreActivityNotRunning[projectFileId];
            }

            if (ignoreWarning || Tracked.TrackingTimer.IsRunning && Tracked.TrackingState != Tracked.TimerState.Stopped)
            {
                return;
            }

            var dr = MessageBox.Show(PluginResources.The_activity_tracker_is_not_running_ + "\r\n\r\n"
                                     + PluginResources.Note_The_current_change_will_be_ignored, Application.ProductName, MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                Tracked.TrackingState = Tracked.TimerState.Started;

                if (!Tracked.TrackingTimer.IsRunning)
                {
                    Tracked.TrackingTimer.Start();
                }

                if (!Tracked.DictCacheDocumentItems.ContainsKey(projectFileId))
                {
                    TrackedController.TrackNewDocumentEntry(Tracked.ActiveDocument);
                }

                var trackedDocument = Tracked.DictCacheDocumentItems[projectFileId];

                if (Tracked.TrackingState == Tracked.TimerState.Started)
                {
                    trackedDocument.ActiveDocument.DocumentTimer.Start();
                }

                TrackedController.InitializeDocumentTracking(Tracked.ActiveDocument);
                ActiveSegmentChanged(sender, null);

                Tracked.TrackingIsDirtyC0 = true;
                Tracked.TrackingIsDirtyC1 = true;
                Tracked.TrackingIsDirtyC2 = true;
            }
            else
            {
                //remember the decision from the user
                if (!Tracked.WarningMessageDocumentsIgnoreActivityNotRunning.ContainsKey(projectFileId))
                {
                    Tracked.WarningMessageDocumentsIgnoreActivityNotRunning.Add(projectFileId, true);
                }
                else
                {
                    Tracked.WarningMessageDocumentsIgnoreActivityNotRunning[projectFileId] = true;
                }
            }
        }
Esempio n. 14
0
        public static void ContentChanged(object sender, DocumentContentEventArgs e)
        {
            Tracked.TrackerLastActivity = DateTime.Now;

            if (Tracked.ActiveDocument == null)
            {
                return;
            }

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

            if (projectFile == null)
            {
                return;
            }

            var projectFileId = projectFile.Id.ToString();

            // Warning message to user -> if content changes and activity tracking is turned off  |
            WarningMessageTrackingNotRunning(sender, projectFileId);

            if (!Tracked.DictCacheDocumentItems.ContainsKey(projectFileId))
            {
                return;
            }

            //grab the latest keys selected
            var keyStroke = (KeyStroke)Viewer.KsCache.Clone();

            keyStroke.Created = DateTime.Now;

            //get the cache document item
            var trackedDocument = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()];

            trackedDocument.ActiveSegment.CurrentSegmentContentHasChanged = true;
            keyStroke.Selection = trackedDocument.ActiveSegment.CurrentTargetSelection;

            //reset the class
            Viewer.KsCache = new KeyStroke();

            //get the latest version of the target content
            TrackedController.ContentProcessor.ProcessSegment(e.Segments.FirstOrDefault(), true, new List <string>());
            var trackingSegmentContentTrg = string.Empty;
            var targetSectionsCurrent     = TrackedController.GetRecordContentSections(TrackedController.ContentProcessor.SegmentSections
                                                                                       , ContentSection.LanguageType.Target
                                                                                       , ref trackingSegmentContentTrg);

            //remove the revision marker for this test
            foreach (var contentSection in targetSectionsCurrent)
            {
                if (contentSection.RevisionMarker == null || contentSection.RevisionMarker.RevType != RevisionMarker.RevisionType.Delete)
                {
                    continue;
                }

                contentSection.Content        = string.Empty;
                contentSection.RevisionMarker = null;
            }


            var comparisonUnits = ComparisonUnitDifferences(trackedDocument, targetSectionsCurrent, keyStroke);

            try
            {
                // add the key stroke data  |
                AddKeyStrokeData(keyStroke, comparisonUnits, trackedDocument);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //update the current cause selection list
                trackedDocument.ActiveSegment.CurrentTargetSections = new List <ContentSection>();
                foreach (var section in targetSectionsCurrent)
                {
                    trackedDocument.ActiveSegment.CurrentTargetSections.Add((ContentSection)section.Clone());
                }

                //remove the cach holder for current seleciton
                trackedDocument.ActiveSegment.CurrentTargetSelection = string.Empty;
            }
        }
Esempio n. 15
0
 public void Setup(TrackedController controller)
 {
     _controller = controller;
     _controller.OnTriggerDown += TryPush;
     _scanner = GetComponent <Scanner>();
 }
Esempio n. 16
0
 public static bool GetUp(AirVRCameraRig cameraRig, TrackedController.Button button)
 {
     return(GetButtonUp(cameraRig, AirVRInputDeviceName.TrackedController, TrackedController.ParseControlID(button)));
 }
Esempio n. 17
0
 public static Vector2 Get(AirVRCameraRig cameraRig, TrackedController.Axis2D axis)
 {
     return(GetAxis2D(cameraRig, AirVRInputDeviceName.TrackedController, TrackedController.ParseControlID(axis)));
 }
        public static void ContentChanged(object sender, DocumentContentEventArgs e)
        {
            Tracked.TrackerLastActivity = DateTime.Now;

            #region  |  warning message to user -> if content changes and activity tracking is turned off  |

            var firstOrDefault = Tracked.ActiveDocument.Files.FirstOrDefault();
            if (firstOrDefault != null && Convert.ToBoolean(Tracked.Settings.GetTrackingProperty(@"warningMessageActivityTrackingNotRunning").Value) && Tracked.ActiveDocument != null && Tracked.DictCacheDocumentItems.ContainsKey(firstOrDefault.Id.ToString()))
            {
                var ignoreWarning = false;
                var projectFile   = Tracked.ActiveDocument.Files.FirstOrDefault();
                if (projectFile != null && Tracked.WarningMessageDocumentsIgnoreActivityNotRunning.ContainsKey(projectFile.Id.ToString()))
                {
                    var orDefault = Tracked.ActiveDocument.Files.FirstOrDefault();
                    if (orDefault != null)
                    {
                        ignoreWarning = Tracked.WarningMessageDocumentsIgnoreActivityNotRunning[orDefault.Id.ToString()];
                    }
                }
                if (!ignoreWarning)
                {
                    var dr = MessageBox.Show(PluginResources.The_activity_tracker_is_not_running_ + "\r\n\r\n"
                                             + PluginResources.Note_The_current_change_will_be_ignored, Application.ProductName, MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Yes)
                    {
                        Tracked.TrackingState = Tracked.TimerState.Started;


                        if (!Tracked.TrackingTimer.IsRunning)
                        {
                            Tracked.TrackingTimer.Start();
                        }

                        var orDefault = Tracked.ActiveDocument.Files.FirstOrDefault();
                        if (orDefault != null && !Tracked.DictCacheDocumentItems.ContainsKey(orDefault.Id.ToString()))
                        {
                            TrackedController.TrackNewDocumentEntry(Tracked.ActiveDocument);
                        }

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

                            if (Tracked.TrackingState == Tracked.TimerState.Started)
                            {
                                trackedDocuments.ActiveDocument.DocumentTimer.Start();
                            }
                        }

                        TrackedController.InitializeDocumentTracking(Tracked.ActiveDocument);
                        ActiveSegmentChanged(sender, null);

                        Tracked.TrackingIsDirtyC0 = true;
                        Tracked.TrackingIsDirtyC1 = true;
                        Tracked.TrackingIsDirtyC2 = true;
                    }
                    else
                    {
                        //remember the decision from the user
                        var orDefault = Tracked.ActiveDocument.Files.FirstOrDefault();
                        if (orDefault != null && !Tracked.WarningMessageDocumentsIgnoreActivityNotRunning.ContainsKey(orDefault.Id.ToString()))
                        {
                            var @default = Tracked.ActiveDocument.Files.FirstOrDefault();
                            if (@default != null)
                            {
                                Tracked.WarningMessageDocumentsIgnoreActivityNotRunning.Add(@default.Id.ToString(), true);
                            }
                        }
                        else
                        {
                            var file = Tracked.ActiveDocument.Files.FirstOrDefault();
                            if (file != null)
                            {
                                Tracked.WarningMessageDocumentsIgnoreActivityNotRunning[file.Id.ToString()] = true;
                            }
                        }
                    }
                }
            }
            #endregion

            var o = Tracked.ActiveDocument.Files.FirstOrDefault();
            if (o == null || Tracked.ActiveDocument == null || !Tracked.DictCacheDocumentItems.ContainsKey(o.Id.ToString()))
            {
                return;
            }
            {
                //grab the latest keys selected
                var keyStroke = (KeyStroke)Viewer.KsCache.Clone();
                keyStroke.Created = DateTime.Now;


                //get the cache document item
                var projectFile = Tracked.ActiveDocument.Files.FirstOrDefault();
                if (projectFile == null)
                {
                    return;
                }
                var trackedDocuments = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()];
                trackedDocuments.ActiveSegment.CurrentSegmentContentHasChanged = true;
                keyStroke.Selection = trackedDocuments.ActiveSegment.CurrentTargetSelection;


                //reset the class
                Viewer.KsCache = new KeyStroke();

                //get the latest version of the target content
                TrackedController.ContentProcessor.ProcessSegment(e.Segments.FirstOrDefault(), true, new List <string>());
                var trackingSegmentContentTrg = string.Empty;
                var targetSectionsCurrent     = TrackedController.GetRecordContentSections(TrackedController.ContentProcessor.SegmentSections
                                                                                           , ContentSection.LanguageType.Target
                                                                                           , ref trackingSegmentContentTrg);


                //remove the revision marker for this test
                foreach (var t in targetSectionsCurrent)
                {
                    if (t.RevisionMarker == null ||
                        t.RevisionMarker.RevType != RevisionMarker.RevisionType.Delete)
                    {
                        continue;
                    }
                    t.Content        = string.Empty;
                    t.RevisionMarker = null;
                }

                #region  |  compare the content  |


                //compare at a character level to understand what was added or removed (no transposition)
                var textComparer = new TextComparer {
                    Type = TextComparer.ComparisonType.Characters
                };
                var comparisonUnits = textComparer.GetComparisonTextUnits(trackedDocuments.ActiveSegment.CurrentTargetSections, targetSectionsCurrent, false);


                #region  |  fix the selection removal from the cache  |

                // clean up the removed selection from the current placeholder; we are only looking for what is new from this holder
                if (trackedDocuments.ActiveSegment.CurrentTargetSelection.Length > 2)
                {
                    try
                    {
                        var indexCharDiffStart = 0;
                        foreach (var t in comparisonUnits)
                        {
                            if (t.Type == ComparisonUnit.ComparisonType.Identical)
                            {
                                indexCharDiffStart += t.Text.Length;
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (indexCharDiffStart > trackedDocuments.ActiveSegment.CurrentTargetSelection.Length)
                        {
                            indexCharDiffStart = indexCharDiffStart - trackedDocuments.ActiveSegment.CurrentTargetSelection.Length;
                        }


                        var indexCharDiffCounter = 0;
                        foreach (var t in trackedDocuments.ActiveSegment.CurrentTargetSections)
                        {
                            indexCharDiffCounter += t.Content.Length;
                            if (indexCharDiffCounter < indexCharDiffStart)
                            {
                                continue;
                            }
                            var indexStartingPointA = indexCharDiffCounter - t.Content.Length;
                            var indexStartingPointB = indexStartingPointA;
                            if (indexCharDiffStart > indexStartingPointA)
                            {
                                indexStartingPointB = indexCharDiffStart - indexStartingPointA;
                            }

                            var indexStartingPointBBefore = t.Content.Substring(0, indexStartingPointB);
                            var indexStartingPointBAfter  = t.Content.Substring(indexStartingPointB);

                            if (indexStartingPointBAfter.IndexOf(trackedDocuments.ActiveSegment.CurrentTargetSelection, StringComparison.Ordinal) <= -1)
                            {
                                continue;
                            }
                            //remove the selection
                            var indexBefore = indexStartingPointBAfter.IndexOf(keyStroke.Selection, StringComparison.Ordinal);
                            var strBefore   = indexStartingPointBAfter.Substring(0, indexBefore);
                            var strAfter    = indexStartingPointBAfter.Substring(indexBefore + trackedDocuments.ActiveSegment.CurrentTargetSelection.Length);

                            t.Content = indexStartingPointBBefore + strBefore + strAfter;

                            //redo the comparison
                            comparisonUnits = textComparer.GetComparisonTextUnits(trackedDocuments.ActiveSegment.CurrentTargetSections, targetSectionsCurrent, false);
                            break;
                        }
                    }
                    catch
                    {
                        //ignore here for now
                    }
                }


                #endregion


                #endregion

                try
                {
                    #region  |  add the key stroke data  |

                    var textDelete = string.Empty;
                    keyStroke.Text = string.Empty;

                    foreach (var comparisonUnit in comparisonUnits)
                    {
                        switch (comparisonUnit.Type)
                        {
                        case ComparisonUnit.ComparisonType.New:
                            foreach (var trgu in comparisonUnit.Section)
                            {
                                keyStroke.Text += trgu.Content;
                            }
                            break;

                        case ComparisonUnit.ComparisonType.Removed:
                            textDelete = comparisonUnit.Section.Aggregate(textDelete, (current, trgu) => current + trgu.Content);
                            break;
                        }
                    }

                    // logical deduction
                    // needs to be revised!
                    // 1. exclude translations from providers
                    // 2. exclude suggestions from termbase? no api handler here... TODO
                    // 3. if content changed is greater than 1 char in length then check the key char
                    //  - 3.a. if the char == tab or return, then we can assume that this was derived from auto-suggest; however
                    //         this does not take into account when the user has selected the auto-suggestion via mouse selection
                    if (string.Compare(keyStroke.Key, @"[Tab]", StringComparison.OrdinalIgnoreCase) == 0 && keyStroke.Text.Length > 1)
                    {
                        keyStroke.OriginType = @"auto-suggest";
                    }

                    //if the user hit the back key then attempt to get the selection from the comparison if it is not already present
                    if (string.Compare(keyStroke.Key, @"[Back]", StringComparison.OrdinalIgnoreCase) == 0 ||
                        string.Compare(keyStroke.Key, @"[Delete]", StringComparison.OrdinalIgnoreCase) == 0 &&
                        keyStroke.Text == string.Empty &&
                        keyStroke.Selection == string.Empty &&
                        textDelete != string.Empty)
                    {
                        keyStroke.Selection = textDelete;
                    }


                    if (keyStroke.Text == string.Empty && keyStroke.Selection == string.Empty)
                    {
                        return;
                    }
                    //add the key stroke object to the list
                    trackedDocuments.ActiveSegment.CurrentTranslationKeyStokeObjectId     = keyStroke.Id;
                    trackedDocuments.ActiveSegment.CurrentTranslationKeyStrokeObjectCheck = true;
                    trackedDocuments.ActiveSegment.CurrentKeyStrokes.Add(keyStroke);

                    #endregion
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    //update the current cause selection list
                    trackedDocuments.ActiveSegment.CurrentTargetSections = new List <ContentSection>();
                    foreach (var section in targetSectionsCurrent)
                    {
                        trackedDocuments.ActiveSegment.CurrentTargetSections.Add((ContentSection)section.Clone());
                    }

                    //remove the cach holder for current seleciton
                    trackedDocuments.ActiveSegment.CurrentTargetSelection = string.Empty;
                }
            }
        }
Esempio n. 19
0
 private void Release(TrackedController sender, float TriggerValue)
 {
     Release();
 }
Esempio n. 20
0
        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();
        }
Esempio n. 21
0
        public static void ContentChanged(object sender, DocumentContentEventArgs e)
        {
            Tracked.TrackerLastActivity = DateTime.Now;

            if (Tracked.ActiveDocument == null)
            {
                return;
            }

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

            if (projectFile == null)
            {
                return;
            }

            var projectFileId = projectFile.Id.ToString();

            // Warning message to user -> if content changes and activity tracking is turned off  |
            WarningMessageTrackingNotRunning(sender, projectFileId);

            if (!Tracked.DictCacheDocumentItems.ContainsKey(projectFileId))
            {
                return;
            }

            //grab the latest keys selected
            var keyStroke = (KeyStroke)Viewer.KsCache.Clone();

            keyStroke.Created = DateTime.Now;

            //get the cache document item
            var trackedDocument = Tracked.DictCacheDocumentItems[projectFile.Id.ToString()];

            trackedDocument.ActiveSegment.CurrentSegmentContentHasChanged = true;
            keyStroke.Selection = trackedDocument.ActiveSegment.CurrentTargetSelection;

            //reset the class
            Viewer.KsCache = new KeyStroke();

            //get the latest version of the target content
            TrackedController.ContentProcessor.ProcessSegment(e.Segments.FirstOrDefault(), true, new List <string>());
            var trackingSegmentContentTrg = string.Empty;
            var targetSectionsCurrent     = TrackedController.GetRecordContentSections(
                TrackedController.ContentProcessor.SegmentSections
                , ContentSection.LanguageType.Target
                , ref trackingSegmentContentTrg);

            //remove the revision marker for this test
            foreach (var contentSection in targetSectionsCurrent)
            {
                if (contentSection.RevisionMarker == null || contentSection.RevisionMarker.RevType != RevisionMarker.RevisionType.Delete)
                {
                    continue;
                }

                contentSection.Content        = string.Empty;
                contentSection.RevisionMarker = null;
            }


            try
            {
#if DEBUG
                var temp1 = new List <ContentSection>();
                var temp2 = new List <ContentSection>();
                trackedDocument.ActiveSegment.CurrentTargetSections.ForEach(x => temp1.Add(x.Clone() as ContentSection));
                targetSectionsCurrent.ForEach(x => temp2.Add(x.Clone() as ContentSection));
#endif
                // Compare the before/after text, to work out (as much as we can) what was typed/pasted/etc. and
                // what selection (if any) was replaced as a result.
                // We can assume that the change will affect a contiguous span of text, because this event fires in response
                // to whatever change, and the target segment can't have multiple selected spans.
                // Even if we have a segment with the same word repeated in different places, and we perform 'replace all'
                // in Studio, the two replacements fire separately here.
                var newSections       = TextComparer.ConcatenateComparableContentSections(trackedDocument.ActiveSegment.CurrentTargetSections);
                var previousSections  = TextComparer.ConcatenateComparableContentSections(targetSectionsCurrent);
                var newTextWithMarkup = SimpleParse(newSections, true);
                var oldTextWithMarkup = SimpleParse(previousSections, true);
                var newText           = SimpleParse(newSections, false);
                var oldText           = SimpleParse(previousSections, false);

                // Find the shared prefix and suffix to identify the affected span
                int prefixLength = CommonPrefixLength(newTextWithMarkup, oldTextWithMarkup);
                int suffixLength = 0;
                if (prefixLength < Math.Min(newTextWithMarkup.Length, oldTextWithMarkup.Length))
                {
                    suffixLength = CommonSuffixLength(newTextWithMarkup, oldTextWithMarkup, prefixLength);
                }
                // Extract typed/pasted and removed (selected) text
                string typedText   = TypedText(newTextWithMarkup, oldTextWithMarkup, prefixLength, suffixLength);
                string removedText = RemovedText(newTextWithMarkup, oldTextWithMarkup, prefixLength, suffixLength);

                // For logging, report the position in the text without tags, because that's a value that's
                // most likely to be usable when analysing
                int prefixLengthPlain = CommonPrefixLength(newText, oldText);
                Debug.WriteLine("Got typed text of <" + typedText + ">");
                Debug.WriteLine("Got removed text of <" + removedText + ">");
                Debug.WriteLine("newTextWithMarkup: " + newTextWithMarkup);
                Debug.WriteLine("c2: " + oldTextWithMarkup);

                // Try to detect case where (say) 'Parliament' was selected in the text, then the user typed 'P';
                // at this point, text comparison will have left typedText empty, and selection one character short ('P')
                if (!string.IsNullOrEmpty(keyStroke.Key) && typedText.Length == 0 && prefixLength > 0 && !keyStroke.Ctrl && !keyStroke.Alt)
                {
                    string altTypedText = TypedText(newTextWithMarkup, oldTextWithMarkup, prefixLength - 1, suffixLength);
                    if (altTypedText.Length > 0 && altTypedText.ToLower()[0] == keyStroke.Key.ToLower()[0])
                    {
                        typedText   = altTypedText;
                        removedText = RemovedText(newTextWithMarkup, oldTextWithMarkup, prefixLength - 1, suffixLength);
                        Debug.WriteLine("Detected overtype of selected text");
                        Debug.WriteLine("Got typed text of <" + typedText + ">");
                        Debug.WriteLine("Got removed text of <" + removedText + ">");
                    }
                }

                // add the key stroke data  |
                AddKeyStrokeData(keyStroke, typedText, removedText, prefixLengthPlain, trackedDocument);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //update the current cause selection list
                trackedDocument.ActiveSegment.CurrentTargetSections = new List <ContentSection>();
                foreach (var section in targetSectionsCurrent)
                {
                    trackedDocument.ActiveSegment.CurrentTargetSections.Add((ContentSection)section.Clone());
                }

                //remove the cach holder for current seleciton
                trackedDocument.ActiveSegment.CurrentTargetSelection = string.Empty;
            }
        }