void ICallbackHandler.HandleChangeHighlightRequest(ChangeHighlightRequestFromMQ changeHighlighRequest, MessagePartInfo messagePartInfo) { onRequestReceived(); assembleMessageParts( ref changeHighlightMessagePartInfo, ref changeHighlightMessageParts, messagePartInfo, changeHighlighRequest, () => { List <PreviewPartWithFocusedRange> previewParts = new List <PreviewPartWithFocusedRange>(); foreach (var messagePart in changeHighlightMessageParts) { previewParts.AddRange(messagePart.ActivePreviewParts); } var request = new ChangeHighlightRequestFromMQ() { ActivePreviewParts = previewParts.ToArray() }; callbackHandler.QueueChangeHighlightRequest(request.Convert()); }); }
public void OnPreviewToolRegistrationReceivedFromWebApp(Regex regex) { lock (this) { previewPartIdRegex = regex; if (lastContentUpdateRequest != null) { var contentUpdateParams = lastContentUpdateRequest.ConvertRequestToContentUpdateParams(previewPartIdRegex); if (contentUpdateParams.PreviewParts.Length > 0) { var postMessage = new ContentUpdateMessage(contentUpdateParams).SerializeToPostMessage(); executeJavaScriptAsync(postMessage); lastContentUpdateRequest = null; } if (lastChangeHighlightRequest != null) { var changeHighlightParams = lastChangeHighlightRequest.ConvertRequestToChangeHighlightParams(previewPartIdRegex); if (changeHighlightParams.ActivePreviewParts.Length > 0) { var postMessage = new ChangeHighlightInPreviewMessage(changeHighlightParams).SerializeToPostMessage(); executeJavaScriptAsync(postMessage); lastChangeHighlightRequest = null; } } } else { requestPreviewPartIdUpdate(); } } }
public void QueueChangeHighlightRequest(ChangeHighlightRequestFromMQ request) { lock (this) { callbackActions.Enqueue(() => previewToolCallback.HandleChangeHighlightRequest(request)); callbackEnqueued.Set(); } }
public void HandleDisconnect() { lock (this) { externalToolAddress = null; previewPartIdRegex = null; lastContentUpdateRequest = null; lastChangeHighlightRequest = null; handleDisconnect(); } }
public void HandleContentUpdateRequest(ContentUpdateRequestFromMQ contentUpdateRequest) { lock (this) { if (externalToolAddress == null) { foreach (var previewPart in contentUpdateRequest.PreviewParts) { if (updateExternalToolAddress(previewPart.PreviewProperties)) { break; } } } if (previewPartIdRegex != null) { var contentUpdateParams = contentUpdateRequest.ConvertRequestToContentUpdateParams(previewPartIdRegex); if (contentUpdateParams.PreviewParts.Length > 0) { var postMessage = new ContentUpdateMessage(contentUpdateParams).SerializeToPostMessage(); executeJavaScriptAsync(postMessage); } if (lastChangeHighlightRequest != null) { var changeHighlightParams = lastChangeHighlightRequest.ConvertRequestToChangeHighlightParams(previewPartIdRegex); if (changeHighlightParams.ActivePreviewParts.Length > 0) { var postMessage = new ChangeHighlightInPreviewMessage(changeHighlightParams).SerializeToPostMessage(); executeJavaScriptAsync(postMessage); lastChangeHighlightRequest = null; } } } else { lastContentUpdateRequest = contentUpdateRequest; } } }
public void HandleChangeHighlightRequest(ChangeHighlightRequestFromMQ changeHighlighRequest) { lock (this) { updateExternalToolAddress(changeHighlighRequest.ActivePreviewParts[0].PreviewProperties); if (previewPartIdRegex != null) { var changeHighlightParams = changeHighlighRequest.ConvertRequestToChangeHighlightParams(previewPartIdRegex); if (changeHighlightParams.ActivePreviewParts.Length > 0) { var postMessage = new ChangeHighlightInPreviewMessage(changeHighlightParams).SerializeToPostMessage(); executeJavaScriptAsync(postMessage); } } else { lastChangeHighlightRequest = changeHighlighRequest; } } }
private bool updateExternalToolAddress(PreviewProperty[] previewProperties) { for (int i = 0; i < previewProperties.Length; i++) { if (previewProperties[i].Name == PropertyNames.WebPreviewBaseUrl) { if (externalToolAddress != (string)previewProperties[i].Value) { externalToolAddress = (string)previewProperties[i].Value; previewPartIdRegex = null; lastContentUpdateRequest = null; lastChangeHighlightRequest = null; handlePreviewUrlChange(externalToolAddress); return(true); } return(false); } } return(false); }
public void HandleChangeHighlightRequest(ChangeHighlightRequestFromMQ changeHighlightRequest) { if (!changeHighlightRequest.ActivePreviewParts.Any()) { return; } Log.Instance.WriteMessage($"Highlight changed in memoQ.", SeverityOption.Info); this.InvokeIfRequired(_ => { SourceDocument sourceDocument = null; if (Settings.Instance.PlayMode == PlayMode.All) { handlePlayAllMode(changeHighlightRequest.ActivePreviewParts.First().SourceDocument); return; } long minStart = 0; long maxEnd = 0; bool isFirstPreviewPart = true; foreach (var activePreviewPart in changeHighlightRequest.ActivePreviewParts) { var previewIdParts = activePreviewPart.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); } if (isFirstPreviewPart) { minStart = start; maxEnd = end; sourceDocument = activePreviewPart.SourceDocument; isFirstPreviewPart = false; } // if other document found, skip those parts, we cannot open multiple videos if (!isFirstPreviewPart && sourceDocument.DocumentGuid != activePreviewPart.SourceDocument.DocumentGuid) { continue; } minStart = Math.Min(minStart, start); maxEnd = Math.Max(maxEnd, end); } var document = addMediaToDocumentIfNeeded(sourceDocument.DocumentGuid, sourceDocument.DocumentName, sourceDocument.ImportPath); if (mainViewModel.VideoViewModel.Document.Id != sourceDocument.DocumentGuid) { mainViewModel.VideoViewModel.Document = document; // also update the document list if the highlight reached a new document if (!mainViewModel.VideoViewModel.DocumentsWithSameMedia.Any(d => d.Id == document.Id)) { mainViewModel.VideoViewModel.DocumentsWithSameMedia = new List <Document>() { document } } ; reinitVideoPlayer(); } loopVideo(minStart - Settings.Instance.TimePaddingForLoop, maxEnd + Settings.Instance.TimePaddingForLoop); }); }
public void HandleChangeHighlightRequest(ChangeHighlightRequestFromMQ changeHighlighRequest) { logRequest("Change highlight request", changeHighlighRequest); }
public static ChangeHighlightInPreviewParams ConvertRequestToChangeHighlightParams(this ChangeHighlightRequestFromMQ changeHighlighRequest, Regex previewPartIdRegex) { var activeParts = changeHighlighRequest.ActivePreviewParts.Where(p => previewPartIdRegex.IsMatch(p.PreviewPartId)).Select(part => new PreviewToolPreviewPartWithFocusedRange ( part.PreviewPartId, part.SourceLangCode, part.TargetLangCode, part.SourceContent.Content, part.TargetContent.Content, part.SourceFocusedRange, part.TargetFocusedRange )).ToArray(); return(new ChangeHighlightInPreviewParams(activeParts)); }
public HttpResponseMessage ChangeHighlight(ChangeHighlightRequestFromMQ request) { getCallbackHandler().HandleChangeHighlightRequest(request, getMessagePartInfo()); return(new HttpResponseMessage(HttpStatusCode.OK)); }