/// <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> /// 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]; } }