/// <summary> /// Checks basic parameters of translation to make sure known error are dealt with in advance. /// </summary> /// <param name="TranslationServiceUri"></param> /// <param name="user"></param> /// <param name="password"></param> /// <param name="sourceFileLanguage"></param> /// <param name="targetFileLanguage"></param> /// <param name="destination"></param> /// <param name="cts"></param> /// <returns>Return null if everythings OK. Returns an error object describing a problem /// if a pre-requisite parameter is not as required.</returns> ITranslatorError ITranslator.Check(string translationServiceUri, SecureString user, SecureString password, string sourceFileLanguage, string targetFileLanguage, ProcessDestination destination, System.Threading.CancellationTokenSource cts) { if (IsNullOrEmpty(user) == true) { return(TranslatorError.GetErrorObject(TranslateErrorCode.Missing_Login_AuthenticationParameter)); } if (IsNullOrEmpty(password) == true) { return(TranslatorError.GetErrorObject(TranslateErrorCode.Missing_Login_AuthenticationParameter)); } try { // Check if Uri appears to be formatted well and generate error if not. new Uri(translationServiceUri); } catch { return(TranslatorError.GetErrorObject(TranslateErrorCode.Missing_URI_AuthenticationParameter)); } return(null); }
public void Evaluate(int SpreadMax) { if (FProcessor == null) { FProcessor = new ProcessDestination <AsTextureDX11Instance>(FPinInImage); } bool needsInit = FProcessor.CheckInputSize(); if (needsInit) { foreach (var textureOut in FTextureOutput) { if (textureOut != null) { textureOut.Dispose(); } } FTextureOutput.SliceCount = FProcessor.SliceCount; for (int i = 0; i < FProcessor.SliceCount; i++) { var textureSlice = new DX11Resource <DX11DynamicTexture2D>(); FProcessor[i].OutputSlice = textureSlice; FTextureOutput[i] = textureSlice; } } }
/// <summary> /// Save a source or target file of the diff view. /// </summary> /// <param name="paths">file path</param> public void SaveFile(string filePath, ProcessDestination fDestin) { Action <CancellationTokenSource> processingRequest; switch (fDestin) { case ProcessDestination.Source: processingRequest = cts => { if (mProcessItems.SetIsProcessingSolution(true, mSaveFileProcessID) == false) { throw new Exception(string.Format(Local.Strings.STR_BLOCKED_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } try { DiffSource.SaveSource(filePath); } finally { if (mProcessItems.SetIsProcessingSolution(false, mSaveFileProcessID) == false) { throw new Exception(string.Format(Local.Strings.STR_FAILED_RESET_OF_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } } }; break; case ProcessDestination.Target: processingRequest = cts => { if (mProcessItems.SetIsProcessingSolution(true, mSaveFileProcessID) == false) { throw new Exception(string.Format(Local.Strings.STR_BLOCKED_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } try { DiffSource.SaveTarget(filePath); } finally { if (mProcessItems.SetIsProcessingSolution(false, mSaveFileProcessID) == false) { throw new Exception(string.Format(Local.Strings.STR_FAILED_RESET_OF_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } } }; break; default: throw new NotImplementedException(fDestin.ToString()); } mProcessAction.StartCancelableProcess(processingRequest, SaveFinishedEvent, Local.Strings.STR_CANCEL_SAVE_MESSAGE); }
/// <summary> /// Save a source or target file of the diff view. /// </summary> /// <param name="paths">file path</param> private void TranslateSelectedEntriesAsync(string sourceFileLanguage, string targetFileLanguage, ProcessDestination destination = ProcessDestination.Target) { mProcessAction.StartCancelableProcess( cts => { if (mProcessItems.SetIsProcessingSolution(true, mTranslateProcessID) == false) { throw new Exception(string.Format(Local.Strings.STR_BLOCKED_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } try { var translator = GetService <ITranslator>(); var settings = GetService <ISettingsManager>(); // Check for known errors and return problem/resolution hints if available var error = translator.Check( settings.Options.GetOptionValue <string>("Options", "MSTranslate.TranslationServiceUri"), settings.Options.GetOptionValue <SecureString>("Options", "MSTranslate.TranslationServiceUser"), settings.Options.GetOptionValue <SecureString>("Options", "MSTranslate.TranslationServicePassword"), sourceFileLanguage, targetFileLanguage, destination, cts); if (error != null) { throw new TranslationException(error); } var login = translator.CreateLoginCredentials( new Uri(settings.Options.GetOptionValue <string>("Options", "MSTranslate.TranslationServiceUri")), settings.Options.GetOptionValue <SecureString>("Options", "MSTranslate.TranslationServiceUser"), settings.Options.GetOptionValue <SecureString>("Options", "MSTranslate.TranslationServicePassword")); TranslateSelectedEntries(login, sourceFileLanguage, targetFileLanguage, destination, cts); if (cts != null) { cts.Token.ThrowIfCancellationRequested(); } } finally { if (mProcessItems.SetIsProcessingSolution(false, mTranslateProcessID) == false) { throw new Exception(string.Format(Local.Strings.STR_FAILED_RESET_OF_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } } }, TranslationFinishedEvent, LocultApp.Local.Strings.STR_CANCEL_SAVE_MESSAGE); }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FProcessor == null) FProcessor = new ProcessDestination<AsTextureInstance>(FPinInImage); bool needsInit = FProcessor.CheckInputSize(); for (int i = 0; i < FProcessor.SliceCount; i++) needsInit |= FProcessor[i].NeedsTexture; if (needsInit) Reinitialize(); SetSliceCount(FProcessor.SliceCount); Update(); }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FProcessor == null) FProcessor = new ProcessDestination<AsTextureInstance>(FPinInImage); bool needsInit = FProcessor.CheckInputSize(); for (int i = 0; i < FProcessor.SliceCount; i++) needsInit |= FProcessor[i].NeedsTexture; if (needsInit) { foreach (var processor in FProcessor) processor.Logger = this.FLogger; Reinitialize(); } SetSliceCount(FProcessor.SliceCount); Update(); }
public void Evaluate(int SpreadMax) { if (FProcessor == null) FProcessor = new ProcessDestination<AsTextureDX11Instance>(FPinInImage); bool needsInit = FProcessor.CheckInputSize(); if (needsInit) { foreach (var textureOut in FTextureOutput) { if (textureOut != null) textureOut.Dispose(); } FTextureOutput.SliceCount = FProcessor.SliceCount; for (int i = 0; i < FProcessor.SliceCount; i++) { var textureSlice = new DX11Resource<DX11DynamicTexture2D>(); FProcessor[i].OutputSlice = textureSlice; FTextureOutput[i] = textureSlice; } } }
/// <summary> /// This method translates all selected entries /// from source to target <paramref name="destination"/>=Target /// or vice versa. /// </summary> /// <param name="destination"></param> /// <param name="sourceFileLanguage"></param> /// <param name="targetFileLanguage"></param> private void TranslateSelectedEntries(ILoginCredentials login, string sourceFileLanguage, string targetFileLanguage, ProcessDestination destination = ProcessDestination.Target, CancellationTokenSource cts = null) { foreach (EntryDiffViewModel diff in DiffSource.SelectedItems) { if (cts != null) { cts.Token.ThrowIfCancellationRequested(); } List <string> l = null; var translator = GetService <ITranslator>(); switch (destination) { case ProcessDestination.Source: l = translator.GetTranslatedText(diff.TargetValue, targetFileLanguage, sourceFileLanguage, login); break; case ProcessDestination.Target: l = translator.GetTranslatedText(diff.SourceValue, sourceFileLanguage, targetFileLanguage, login); break; default: throw new NotImplementedException(destination.ToString()); } string translation = string.Empty; string newLine = string.Empty; foreach (var item in l) { translation += newLine + item; newLine = "\n"; } switch (destination) { case ProcessDestination.Source: diff.SetSourceValueComment(translation, (string.IsNullOrEmpty(diff.SourceComment) == true ? diff.TargetComment : diff.SourceComment)); break; case ProcessDestination.Target: diff.SetTargetValueComment(translation, (string.IsNullOrEmpty(diff.TargetComment) == true ? diff.SourceComment : diff.TargetComment)); break; default: throw new NotImplementedException(destination.ToString()); } } // Update deatils input view after changing selected item DiffSource.SelectedItemBuffer = null; if (cts != null) { cts.Token.ThrowIfCancellationRequested(); } if (DiffSource.SelectedItems.Count == 1) { // Update deatils input view after changing selected item DiffSource.SelectedItemBuffer = DiffSource.SelectedItems[0]; } }