public async void RequestHighlightChange(SegmentPart segmentPart) { Log.Instance.WriteMessage($"Requesting highlight from memoQ.", SeverityOption.Info); var sourceFocusedRange = new FocusedRange(0, segmentPart.SourceContent.Length); var targetFocusedRange = new FocusedRange(0, segmentPart.TargetContent.Length); var request = new ChangeHighlightRequestFromPreviewTool(segmentPart.PreviewPartId, segmentPart.SourceLangCode, segmentPart.TargetLangCode, segmentPart.SourceContent, segmentPart.TargetContent, sourceFocusedRange, targetFocusedRange); var requestStatus = await ConnectViewModel.CallProxyMethod(new Func <RequestStatus>(() => previewServiceProxy?.RequestHighlightChange(request))); if (requestStatus == null || !requestStatus.RequestAccepted) { ConnectViewModel.IsConnected = false; } }
private void updateLabels(SegmentPart segmentPart, long videoTime) { // Time frame mainViewModel.VideoViewModel.TimeFrame = $"{new DateTime(videoTime * TimeSpan.TicksPerMillisecond).ToString("H:mm:ss", CultureInfo.InvariantCulture)} /" + $" {new DateTime(myVlcControl.MediaPlayer.Length * TimeSpan.TicksPerMillisecond).ToString("H:mm:ss", CultureInfo.InvariantCulture)}"; if (segmentPart == null || segmentPart.PreviewProperties == null) { return; } // WPM, CPS, Line length long?wordPerMinute = null; long?charPerSecond = null; long?lineLengthLimit = null; int wordCount = 0; int charCount = 0; int currentLineLength = 0; foreach (var previewProperty in segmentPart.PreviewProperties) { long value; if (previewProperty.Name == PropertyNames.Wpm && long.TryParse((string)previewProperty.Value, out value)) { wordPerMinute = value; } else if (previewProperty.Name == PropertyNames.Cps && long.TryParse((string)previewProperty.Value, out value)) { charPerSecond = value; } else if (previewProperty.Name == PropertyNames.LineLengthLimit && long.TryParse((string)previewProperty.Value, out value)) { lineLengthLimit = value; } else if (previewProperty.Name == PropertyNames.WordCount) { wordCount = Convert.ToInt32(previewProperty.Value); } else if (previewProperty.Name == PropertyNames.CharCount) { charCount = Convert.ToInt32(previewProperty.Value); } } string[] plainTextLines = segmentPart.Subtitle.PlainText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); foreach (var line in plainTextLines) { currentLineLength = Math.Max(currentLineLength, line.Length); } var frameLength = segmentPart.Subtitle.End - segmentPart.Subtitle.Start; var currentWordPerMinute = Math.Ceiling((double)(wordCount * TimeSpan.TicksPerMinute / TimeSpan.TicksPerMillisecond) / frameLength); var currentCharPerSecond = Math.Ceiling((double)(charCount * TimeSpan.TicksPerSecond / TimeSpan.TicksPerMillisecond) / frameLength); txtWpm.Text = $"Words per minute: {currentWordPerMinute.ToString()}" + (wordPerMinute != null ? $"/{wordPerMinute.ToString()}" : ""); txtWpm.Foreground = (wordPerMinute == null || currentWordPerMinute <= wordPerMinute) ? brushUnderLimit : brushAboveLimit; txtCps.Text = $"Characters per second: {currentCharPerSecond.ToString()}" + (charPerSecond != null ? $"/{charPerSecond.ToString()}" : ""); txtCps.Foreground = (charPerSecond == null || currentCharPerSecond <= charPerSecond) ? brushUnderLimit : brushAboveLimit; txtLineLength.Text = $"Line length: {currentLineLength.ToString()}" + (lineLengthLimit != null ? $"/{lineLengthLimit.ToString()}" : ""); txtLineLength.Foreground = (lineLengthLimit == null || currentLineLength <= lineLengthLimit) ? brushUnderLimit : brushAboveLimit; }
public void HandleContentUpdateRequest(ContentUpdateRequestFromMQ contentUpdateRequest) { if (!contentUpdateRequest.PreviewParts.Any()) { return; } Log.Instance.WriteMessage($"Content updated in memoQ.", SeverityOption.Info); this.InvokeIfRequired(_ => { bool isFirstPreviewPart = true; bool docWasEmpty = mainViewModel.VideoViewModel.Document.Id == Guid.Empty; var newDocuments = new List <Document>(); foreach (var previewPart in contentUpdateRequest.PreviewParts) { var previewIdParts = previewPart.PreviewPartId.Split('|'); long start = 0; long end = 0; if (!string.IsNullOrEmpty(previewIdParts[1])) { start = TimeSpan.Parse(previewIdParts[1], CultureInfo.InvariantCulture).Ticks / TimeSpan.TicksPerMillisecond; } else { Log.Instance.WriteMessage("Start time was given probably not in the right format (hh:mm:ss.fff).", SeverityOption.Warning); } if (!string.IsNullOrEmpty(previewIdParts[1])) { end = TimeSpan.Parse(previewIdParts[2], CultureInfo.InvariantCulture).Ticks / TimeSpan.TicksPerMillisecond; } else { Log.Instance.WriteMessage("End time was given probably not in the right format (hh:mm:ss.fff).", SeverityOption.Warning); } var docGuid = previewPart.SourceDocument.DocumentGuid; var sourceContent = previewPart.SourceContent.Content; var targetContent = previewPart.TargetContent.Content; var content = string.IsNullOrEmpty(targetContent) ? sourceContent : targetContent; var segmentPart = new SegmentPart(previewPart.PreviewPartId, previewPart.PreviewProperties, previewPart.SourceLangCode, previewPart.TargetLangCode, sourceContent, targetContent, new Subtitle(start, end, content)); var segmentKey = Tuple.Create(docGuid, start, end); segmentParts[segmentKey] = segmentPart; var sourceDocument = previewPart.SourceDocument; var document = addMediaToDocumentIfNeeded(sourceDocument.DocumentGuid, sourceDocument.DocumentName, sourceDocument.ImportPath); if (isFirstPreviewPart) { if (!segmentPartsToLoop.Any()) { segmentPartsToLoop.Add(segmentPart); } if (mainViewModel.VideoViewModel.Document.Id == Guid.Empty) { mainViewModel.VideoViewModel.Document = document; } isFirstPreviewPart = false; } if (!mainViewModel.VideoViewModel.DocumentsWithSameMedia.Any(d => d.Id == document.Id)) { // collect unique documents that have the same media (e.g. a view could contain multiple documents) if (!newDocuments.Any() || (!newDocuments.Any(d => d.Id == document.Id) && newDocuments.Any(d => d.Media == document.Media))) { newDocuments.Add(document); } } } if (newDocuments.Any()) { mainViewModel.VideoViewModel.DocumentsWithSameMedia = newDocuments; } if (Settings.Instance.PlayMode == PlayMode.All) { // open video file if it wasn't if (docWasEmpty) { var firstDoc = contentUpdateRequest.PreviewParts.First().SourceDocument; var firstDocument = addMediaToDocumentIfNeeded(firstDoc.DocumentGuid, firstDoc.DocumentName, firstDoc.ImportPath); mainViewModel.VideoViewModel.Document = firstDocument; reinitVideoPlayer(); startVideo(); } } else { reinitVideoPlayer(); loopVideo(segmentPartsToLoop.First().Subtitle.Start - Settings.Instance.TimePaddingForLoop, segmentPartsToLoop.Last().Subtitle.End + Settings.Instance.TimePaddingForLoop); } }); }