Пример #1
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);
        }
Пример #2
0
        /// <summary>
        /// Attempt to parse the given XML and set correxponding values in this object.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public bool SetXMLString(TranslatorSolutionLib.Models.TranslatorSolution sol,
                                 string xml,
                                 string solutionPathName = null)
        {
            if (string.IsNullOrEmpty(xml) == true)
            {
                return(false);
            }

            string path = solutionPathName;

            try
            {
                path = System.IO.Path.GetDirectoryName(solutionPathName);
            }
            catch
            {
            }

            var param = new XMLParams(xml, path);

            (sol as IModelPart).Accept(this, param);

            return(true);
        }
        /// <summary>
        /// Convert XML string into solution model domain model object representation.
        /// </summary>
        /// <param name="xmlString"></param>
        /// <param name="modelSolution"></param>
        /// <returns></returns>
        public bool SetXMLString(string xmlString,
                                 TranslatorSolutionLib.Models.TranslatorSolution modelSolution,
                                 string solutionPathName = null)
        {
            var XMLSource = new XMLToModel();

            // Retrieve content back into object value
            return(XMLSource.SetXMLString(modelSolution, xmlString, solutionPathName));
        }
Пример #4
0
        /// <summary>
        /// Sets all paths relative to the given path if both paths are based on the same device.
        /// </summary>
        /// <param name="solutionPathName"></param>
        internal void SetRelativePath(string solutionPathName)
        {
            SourceFile.SetPath(TranslatorSolution.GetRelativePath(SourceFile.Path, solutionPathName));

            if (TargetFiles != null)
            {
                foreach (var item in TargetFiles)
                {
                    item.SetPath(TranslatorSolution.GetRelativePath(item.Path, solutionPathName));
                }
            }
        }
        /// <summary>
        /// Load the xml from the given location.
        /// </summary>
        /// <param name="solutionPathName"></param>
        /// <returns></returns>
        public TranslatorSolution LoadSolution(string solutionPathName)
        {
            var xmlString = System.IO.File.ReadAllText(solutionPathName);

            TranslatorSolutionLib.Models.TranslatorSolution sol = new TranslatorSolutionLib.Models.TranslatorSolution();

            // Retrieve content back into object value
            if (SetXMLString(xmlString, sol, solutionPathName) == true)
            {
                return(sol);
            }

            return(null);
        }
Пример #6
0
        /// <summary>
        /// Copies all solution items into a new object and computes a relative
        /// path to <paramref name="solutionPathName"/> if this is supplied.
        /// </summary>
        /// <param name="solutionPathName"></param>
        /// <returns>new solution object that is a copy of this object.</returns>
        public TranslatorSolution CopySolution(string solutionPathName = null)
        {
            var solution = new TranslatorSolution(this);

            // Make all paths relative to location of solution if supplied parameter is available
            if (solution.Projects.Count > 0 && string.IsNullOrEmpty(solutionPathName) == false)
            {
                foreach (var item in solution._Projects.Values)
                {
                    item.SetRelativePath(solutionPathName);
                }
            }

            return(solution);
        }
Пример #7
0
        /// <summary>
        /// Visit a solotion model object with the given cursor in <paramref name="cursorParams"/>.
        /// </summary>
        /// <param name="modelSolution"></param>
        /// <param name="cursorParams"></param>
        void IVisitor.Visit(TranslatorSolutionLib.Models.TranslatorSolution modelSolution, object cursorParams)
        {
            var sol = cursorParams as TranslatorSolutionLib.XMLModels.TranslatorSolution;

            sol.Version = modelSolution.Version;
            sol.Comment = modelSolution.Comment;
            sol.Name    = modelSolution.Name;
            sol.Project = new PROJECT_TAG[modelSolution.Projects.Count];

            for (int i = 0; i < modelSolution.Projects.Count; i++)
            {
                sol.Project[i] = new PROJECT_TAG();
                (modelSolution.Projects[i] as IModelPart).Accept(this, sol.Project[i]);
            }
        }
Пример #8
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="copyThis"></param>
        public TranslatorSolution(TranslatorSolution copyThis)
            : this()
        {
            if (copyThis == null)
            {
                return;
            }

            SetName(copyThis.Name);
            SetComment(copyThis.Comment);

            foreach (var item in copyThis.Projects)
            {
                AddProject(new Project(item));
            }
        }
Пример #9
0
        /// <summary>
        /// Visit a solotion model object with the given cursor in <paramref name="cursorParams"/>.
        /// </summary>
        /// <param name="modelSolution"></param>
        /// <param name="cursorParams"></param>
        void IVisitor.Visit(TranslatorSolutionLib.Models.TranslatorSolution modelSolution,
                            object cursorParams)
        {
            var par = cursorParams as XMLParams;

            var solution = XmlConverter <TranslatorSolutionLib.XMLModels.TranslatorSolution> .ToObject
                               (par.XML, "TranslatorSolutionXML.Resources.TranslatorSolution.xsd");

            if (solution == null)
            {
                return;
            }

            // This should be analyzed for backward compatibility when there are more than 1 versions around...
            //// this.Version = solution.Version;

            modelSolution.SetComment(solution.Comment);
            modelSolution.SetName(solution.Name);

            // Combine and normalize source file path to make it human readable and rooted
            string solutionPath = null;

            if (par.SolutionPathName != null)
            {
                solutionPath = System.IO.Path.GetDirectoryName(par.SolutionPathName);
            }

            foreach (var item in solution.Project)
            {
                var project = new Project();

                par.CurrentItem = item;
                (project as IModelPart).Accept(this, par);

                // This does not work here since setting absolute or relative path does not reset the key item!
                ////if (string.IsNullOrEmpty(solutionPathName) == false)
                ////  project.SetAbsolutePath(solutionPathName);

                modelSolution.AddProject(project);
            }
        }
Пример #10
0
        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);
        }