private async Task <TranslatorSolution> LoadSolution(string fileLocation) { TranslatorSolution solution = null; if (mProcessItems.SetIsProcessingSolution(true, mLoadSolutionProcessID) == false) { throw new Exception(string.Format(Local.Strings.STR_BLOCKED_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } try { var solFacade = new PersistSolutionModelInXML(); solution = await solFacade.LoadSolutionAsync(fileLocation); var settings = GetService <ISettingsManager>(); settings.SessionData.SetLastActiveSolution(fileLocation); } finally { if (solution == null) { solution = new TranslatorSolution(); } if (mProcessItems.SetIsProcessingSolution(false, mLoadSolutionProcessID) == false) { ViewException.SetExceptionForDisplay(new Exception(string.Format(Local.Strings.STR_FAILED_RESET_OF_SOLUTION_TASK, mProcessItems.CurrentProcessId))); } } return(solution); }
/// <summary> /// Gets an XML formated string that persists the current state of this solution. /// </summary> /// <returns></returns> public string GetXMLString(TranslatorSolution modelSolution) { // Persist content into string var XMLStringSource = new ModelToXML(); return(XMLStringSource.ToString(modelSolution)); }
private async Task <bool> SaveSolutionAsync(string fileLocation, TranslatorSolution solution) { if (mProcessItems.SetIsProcessingSolution(true, mSaveSolutionProcessID) == false) { throw new Exception(string.Format(LocultApp.Local.Strings.STR_BLOCKED_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } try { var modelExt = new PersistSolutionModelInXML(); var result = await modelExt.SaveSolutionAsync(solution, fileLocation); var settings = GetService <ISettingsManager>(); settings.SessionData.SetLastActiveSolution(fileLocation); return(result); } finally { if (mProcessItems.SetIsProcessingSolution(false, mSaveSolutionProcessID) == false) { ViewException.SetExceptionForDisplay(new Exception(string.Format(Local.Strings.STR_FAILED_RESET_OF_SOLUTION_TASK, mProcessItems.CurrentProcessId))); } } }
public void TestXMLInternediateReadWithPoco() { var solution = new TranslatorSolution(); solution.SetName("My TestSolution"); solution.SetComment("This is test solution for testing purposes only"); var project = new Project(); project.SetSourceFile(new FileReference(@"C:\TEMP\Source.resx", "RESX", "This is a test source file comment")); project.AddTargetFile(new FileReference(@"C:\TEMP\Source_DE_DE.resx", "RESX", "This is a test target file comment")); solution.AddProject(project); // Persist content into string var modelExtension = new PersistSolutionModelInXML(); var XML = modelExtension.GetXMLString(solution); var XMLStringSource = new ModelToXML(); var XML1 = XMLStringSource.ToString(solution); Assert.AreEqual(string.Compare(XML, XML1), 0); }
public void TestXMLReadWriteWithPoco() { var solution = new TranslatorSolution(); solution.SetName("My TestSolution"); solution.SetComment("This is test solution for testing purposes only"); var project = new Project(); project.SetSourceFile(new FileReference(@"C:\TEMP\Source.resx", "RESX", "This is a test source file comment")); project.AddTargetFile(new FileReference(@"C:\TEMP\Source_DE_DE.resx", "RESX", "This is a test target file comment")); solution.AddProject(project); // Persist content into string var modelExtension = new PersistSolutionModelInXML(); var XML = modelExtension.GetXMLString(solution); var loadedSolution = new PersistSolutionModelInXML(); TranslatorSolutionLib.Models.TranslatorSolution sol = new TranslatorSolutionLib.Models.TranslatorSolution(); // Retrieve content back into object values and check if this worked as expected Assert.AreEqual(loadedSolution.SetXMLString(XML, sol), true); }
/// <summary> /// Returns a started task that saves the solution /// in the given location with the given name. /// </summary> /// <param name="solutionPathName"></param> /// <returns></returns> public Task <bool> SaveSolutionAsync(TranslatorSolution modelSolution, string solutionPathName) { return(Task.Factory.StartNew <bool>(() => { return SaveSolution(modelSolution, solutionPathName); })); }
public ApplicationRequestEvent(ApplicationRequest request, string fileLocation, TranslatorSolution solution = null) { Request = request; FileLocation = fileLocation; Solution = solution; }
/// <summary> /// Saves the current content of the solution object to disk. /// </summary> /// <param name="solution"></param> /// <param name="solutionPathName"></param> public bool SaveSolution(TranslatorSolution modelSolution, string solutionPathName) { string xml = GetXMLString(modelSolution); System.IO.File.WriteAllText(solutionPathName, xml); return(true); }
/// <summary> /// Standard constructor. /// </summary> public SolutionRootViewModel() { mChildren = new ObservableCollection <ISolutionItem>(); mSolutionModel = new TranslatorSolution(); mSolutionPath = string.Empty; ItemName = string.Empty; mIsDirty = false; }
/// <summary> /// Class constructor /// </summary> public SolutionViewModel(TranslatorSolution solutionModel, string solutionPath, string solutionName) { mChildren = new ObservableCollection <ISolutionItem>(); var modelExt = new ModelToViewModel(); ////mRoot = new SolutionRootViewModel(solutionModel, solutionPath, solutionName); mRoot = modelExt.ToViewModel(solutionModel, solutionPath, solutionName); mChildren.Add(mRoot); }
/// <summary> /// Class constructor from parameter. The given solution is expected to contain at least 1 project. /// </summary> public EditPageViewModel(TranslatorSolution solutionModel, string solutionPath, string solutionName, IProcessItems processItems, ApplicationRequestEventHandler requestedAction) : this() { RequestedAction = requestedAction; mProcessItems = processItems; mSolution = new SolutionViewModel(solutionModel, solutionPath, solutionName); mSolutionSelectedItem = null; CurrentEditPage = null; }
/// <summary> /// editPage.Solution.Root.ItemPathName /// </summary> /// <param name="filePathName"></param> /// <returns></returns> private async void SaveSolution(string filePathName, TranslatorSolution solutionModel, SolutionViewModel solutionViewModel = null) { try { // Copy solution and compute relative paths var copy = solutionModel.CopySolution(filePathName); // save data to persistence this.IsProcessing = true; if (mProcessItems.SetIsProcessingSolution(true, mSaveSolutionProcessID) == false) { throw new Exception(string.Format(Local.Strings.STR_BLOCKED_SOLUTION_TASK, mProcessItems.CurrentProcessId)); } try { var modelExt = new PersistSolutionModelInXML(); var result = await modelExt.SaveSolutionAsync(copy, filePathName); if (solutionViewModel != null) { solutionViewModel.Root.SolutionIsDirty_Reset(); } } finally { if (mProcessItems.SetIsProcessingSolution(false, mSaveSolutionProcessID) == false) { ViewException.SetExceptionForDisplay(new Exception(string.Format(Local.Strings.STR_FAILED_RESET_OF_SOLUTION_TASK, mProcessItems.CurrentProcessId))); } } } catch (System.Exception exp) { ViewException.SetExceptionForDisplay(exp); } finally { this.IsProcessing = false; } }
/// <summary> /// Converts the given parameters into a solution model and returns it. /// </summary> /// <param name="solutionPathName"></param> /// <param name="newSolutionName"></param> /// <param name="TargetFilesCollection"></param> /// <returns></returns> public static TranslatorSolution ConvertToSolutionModel(string solutionPathName, string newSolutionName, string newSourceFilePathName, string newCommment, IList <FileReferenceViewModel> TargetFilesCollection) { // Build solution model var solution = new TranslatorSolution(newSolutionName); var project = new Project(); project.SetSourceFile(new FileReference(newSourceFilePathName, UpdateNewSolutionTargetFilesViewModel.mDefaultType, newCommment)); foreach (var item in TargetFilesCollection) { project.AddTargetFile(item.GetModel()); } solution.AddProject(project); return(solution); }
public void TestXMLReadWriteIntermediateWithPoco() { var solution = new TranslatorSolution(); solution.SetName("My TestSolution"); solution.SetComment("This is test solution for testing purposes only"); var project = new Project(); project.SetSourceFile(new FileReference(@"C:\TEMP\Source.resx", "RESX", "This is a test source file comment")); project.AddTargetFile(new FileReference(@"C:\TEMP\Source_DE_DE.resx", "RESX", "This is a test target file comment")); solution.AddProject(project); // Persist content into string var XMLStringSource = new ModelToXML(); var XML = XMLStringSource.ToString(solution); var XMLSource = new XMLToModel(); TranslatorSolutionLib.Models.TranslatorSolution sol = new TranslatorSolutionLib.Models.TranslatorSolution(); // Retrieve content back into object values and check if this worked as expected Assert.AreEqual(XMLSource.SetXMLString(sol, XML), true); // Now back to XML and compare with first XML representation var XMLStringSource1 = new ModelToXML(); var XML1 = XMLStringSource1.ToString(sol); Assert.AreEqual(string.Compare(XML, XML1, false), 0); }