public void RegisterDocument(Document document)
        {
            try
            {
                document.ContentChanged += document_ContentChanged;
                document.SegmentsConfirmationLevelChanged += document_SegmentsConfirmationLevelChanged;
                var projectInfo = document.Project.GetProjectInfo();

                foreach (var file in document.Files)
                {
                    _logger.Info(string.Format("Registered file: {0}", file.Name));

                    var trackInfo = _trackingInfos.FirstOrDefault(x => x.FileId == file.Id);
                    if (trackInfo == null)
                    {
                        trackInfo = new TrackInfo
                        {
                            FileId = file.Id,
                            FileName = file.Name,
                            ProjectId = projectInfo.Id,
                            ProjectName = projectInfo.Name,
                            Language = file.Language.CultureInfo.Name,
                            FileType = file.FileTypeId
                        };
                        _trackingInfos.Add(trackInfo);
                    }
                }
               
                ActiveDocument = document;
          
                _persistance.Save(_trackingInfos);
            }
            catch (Exception exception)
            {
                _logger.Debug(exception, @"Error appeared when RegisterDocument");
                _emailService.SendLogFile();
            }

        }
        private SegmentTrackInfo GetOrCreateSegmentTrackInfo(TrackInfo trackInfo, ISegment targetSegment)
        {
            if (trackInfo.SegmentTrackInfos == null)
            {
                var exceptionMessage =
                    string.Format("SegmentTrackInfos is null for project {0}  and segment {1}!",
                        trackInfo.ProjectName, targetSegment);
                throw new ArgumentNullException(exceptionMessage);
            }

            if (targetSegment == null)
            {
                var exceptionMessage =
                    string.Format("Segment is null for {0}!",
                        trackInfo.ProjectName);
                throw new ArgumentNullException(exceptionMessage);
            }

            if (targetSegment.Properties == null)
            {
                var exceptionMessage =
                    string.Format("Segment properties are null for {0}!",
                        trackInfo.ProjectName);
                throw new ArgumentNullException(exceptionMessage);
            }

            var segment = trackInfo.SegmentTrackInfos.Find(x => x.SegmentId == targetSegment.Properties.Id.Id);

            if (segment == null)
            {
                var segmentId = targetSegment.Properties.Id.Id;

                segment = new SegmentTrackInfo {SegmentId = segmentId};
                trackInfo.SegmentTrackInfos.Add(segment);
            }
            return segment;
        }
        private void CreateUpdateTrackInfo(TrackInfo trackInfo, ISegment targetSegment)
        {
            if (targetSegment == null) return;
            var keyStrokes = KeyboardTracking.Instance.GetCount();
            var segmentText = targetSegment.ToString();

            if (keyStrokes == 0 && segmentText.Length == 0) return;

            var segment = GetOrCreateSegmentTrackInfo(trackInfo, targetSegment);
            var translated = targetSegment.Properties.ConfirmationLevel ==
                                                  ConfirmationLevel.Translated;
            segment.SetTrackInfo(keyStrokes, targetSegment.ToString(), translated);
        }