Beispiel #1
0
 /// <summary>
 /// Save all files
 /// </summary>
 public void SaveFiles()
 {
     Cursor.Current = Cursors.WaitCursor;
     SaveAnswerFile();
     // Apply all transforms
     foreach (AnswerFileTransformSet set in m_answerFileTransformSets)
     {
         string sLastSourceFile      = null;
         AnswerFileTransform lastAft = null;
         bool fTransformResult       = false;
         for (int i = 0; i < set.Count; i++)
         {
             AnswerFileTransform aft = set.GetTransform(i);
             string sSourceFile      = aft.AnswerFile;
             if (i > 0 && fTransformResult)
             {
                 sSourceFile = sLastSourceFile;
             }
             fTransformResult = aft.ApplyTransform(ConfigurationPath, sSourceFile);
             if (fTransformResult)
             {
                 if (lastAft != null)
                 {
                     lastAft.ApplyReplaceDOCTYPE();                                     // do insert DOCTYPE after transform next one (otherwise, one could just insert that DOCTYPE directly via the transform)
                 }
                 sLastSourceFile = aft.ResultFile;
                 lastAft         = aft;
             }
         }
         for (int i = 0; i < set.Count; i++)
         {
             AnswerFileTransform aft = set.GetTransform(i);
             if (!aft.SaveResult)
             {
                 File.Delete(aft.ResultFile);
             }
         }
     }
     LanguageDataChanged = false;
     SaveSettings();
     Cursor.Current = Cursors.Arrow;
 }
Beispiel #2
0
        // get all transforms and init them
        public void InitAnswerTransforms(XmlNode configurationParameters)
        {
            XmlNode versionNode    = configurationParameters.SelectSingleNode("//version");
            string  sVersionNumber = versionNode.InnerText;

            m_answerFileTransformSets.Clear();
            XmlNodeList nodeList = configurationParameters.SelectNodes("//answerFileTransformSets/answerFileTransformSet");

            foreach (XmlNode setNode in nodeList)
            {
                AnswerFileTransformSet answerFileTransforms = new AnswerFileTransformSet();
                XmlNodeList            transformNodes       = setNode.SelectNodes("transform");
                foreach (XmlNode transformNode in transformNodes)
                {
                    AnswerFileTransform aft = new AnswerFileTransform(AnswerFile, transformNode, ConfigurationPath, sVersionNumber);
                    answerFileTransforms.Add(aft);
                }
                m_answerFileTransformSets.Add(answerFileTransforms);
            }
        }
Beispiel #3
0
        public void AnswerFileTransform()
        {
            AnswerFileTransform aft;
            string      sAnswerFile        = Path.Combine(m_ksTestData, "IsthmusZapotec2.paw");
            string      sConfigurationFile = @"..\..\Configurations\PAWS\paws.xml";
            string      sConfigurationPath = @"..\..\Configurations\PAWS";
            XmlDocument doc = new XmlDocument();

            doc.Load(sConfigurationFile);
            // Grammar file
            XmlNode node = doc.SelectSingleNode("//answerFileTransformSets/answerFileTransformSet[1]/transform");

            aft = new AnswerFileTransform(sAnswerFile, node, m_ksConfigurationPath);
            Assert.AreEqual(sAnswerFile, aft.AnswerFile, "Answer file");
            Assert.AreEqual(m_ksConfigurationPath + "/Transforms/PAWSSKMasterGrammarMapper.xsl", aft.TransformFile, "Transform file");
            Assert.AreEqual(@"C:\carla\Dev\Cabhab\UserData\IZ2\IsthmusZapotec2.grm", aft.ResultFile, "result file");
            Assert.IsNull(aft.ResultPath, "result path");
            Assert.IsNull(aft.ResultFile1, "result file 1");
            Assert.IsNull(aft.ResultFile2, "result file 2");
            Assert.IsNull(aft.FileExtension, "file extension");
            Assert.IsNull(aft.ReplaceDOCTYPE, "insert DOCTYPE");
            Assert.IsTrue(aft.RemoveBOM, "remove BOM");
            Assert.IsFalse(aft.SaveResult, "save result");
            Assert.IsNull(aft.Parameters, "grammar parameters");
            Assert.IsNull(aft.ParameterSet, "parameter set");
            aft.ApplyTransform(m_ksConfigurationPath);
            string sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IsthmusZapotec2.grm"));
            string sActual   = ReadFileIntoString(aft.ResultFile);

            Assert.AreEqual(sExpected, sActual, "Grammar result file");

            // Writer first file
            node = doc.SelectSingleNode("//answerFileTransformSets/answerFileTransformSet[2]/transform[1]");
            aft  = new AnswerFileTransform(sAnswerFile, node, sConfigurationPath);
            Assert.AreEqual(sAnswerFile, aft.AnswerFile, "writer 1 Answer file");
            Assert.AreEqual(sConfigurationPath + "/Transforms/PAWSSKMasterWriterMapperUse.xsl", aft.TransformFile, "writer 1 Transform file");
            Assert.AreEqual(@"C:\carla\Dev\Cabhab\UserData\IZ2\IsthmusZapotec2.xml", aft.ResultFile, "writer 1 result file");
            Assert.IsNull(aft.ResultPath, "writer 1 result path");
            Assert.IsNull(aft.ResultFile1, "writer 1 result file 1");
            Assert.IsNull(aft.ResultFile2, "writer 1 result file 2");
            Assert.AreEqual("xml", aft.FileExtension, "writer 1 file extension");
            Assert.AreEqual("<!DOCTYPE lingPaper PUBLIC \"-//XMLmind//DTD XLingPap//EN\"\r\n\"file://%SystemDrive%/Documents and Settings/%USERNAME%/Application Data/XMLmind/XMLEditor/addon/XLingPap/XLingPap.dtd\">", aft.ReplaceDOCTYPE, "writer 1 replace DOCTYPE");
            Assert.IsFalse(aft.RemoveBOM, "writer 1 remove BOM");
            Assert.IsTrue(aft.SaveResult, "writer 1 save result");
            Assert.IsNotNull(aft.Parameters, "writer 1 parameters not null");
            Assert.AreEqual(1, aft.Parameters.Length, "writer 1 parameters count");
            CheckParameterNameValue((XMLUtilities.XSLParameter)aft.Parameters.GetValue(0), "prmSDateTime", "fake", "writer 1 first parameter");
            Assert.IsNull(aft.ParameterSet, "writer 1 parameter set");
            aft.ApplyTransform(m_ksConfigurationPath);
            sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IsthmusZapotec2.xml"));
            sActual   = ReadFileIntoString(aft.ResultFile);
            int iExpectedDateStart = sExpected.IndexOf("<date>");
            int iExpectedDateEnd   = sExpected.IndexOf("</date>");
            int iActualDateStart   = sActual.IndexOf("<date>");
            int iActualDateEnd     = sActual.IndexOf("</date>");

            Assert.AreEqual(sExpected.Substring(0, iExpectedDateStart) + sExpected.Substring(iExpectedDateEnd),
                            sActual.Substring(0, iActualDateStart) + sActual.Substring(iActualDateEnd),
                            "writer 1 result file");

            // Writer second file
            string sPass1ResultFile = aft.ResultFile;

            node = doc.SelectSingleNode("//answerFileTransformSets/answerFileTransformSet[2]/transform[2]");
            aft  = new AnswerFileTransform(sAnswerFile, node, m_ksConfigurationPath);
            Assert.AreEqual(sAnswerFile, aft.AnswerFile, "writer 2 Answer file");
            Assert.AreEqual(m_ksConfigurationPath + "/Transforms/XLingPap1.xsl", aft.TransformFile, "writer 2 Transform file");
            Assert.AreEqual(@"C:\carla\Dev\Cabhab\UserData\IZ2\IsthmusZapotec2.htm", aft.ResultFile, "writer 2 result file");
            Assert.IsNull(aft.ResultPath, "writer 2 result path");
            Assert.IsNull(aft.ResultFile1, "writer 2 result file 1");
            Assert.IsNull(aft.ResultFile2, "writer 2 result file 2");
            Assert.AreEqual("htm", aft.FileExtension, "writer 2 file extension");
            Assert.IsNull(aft.ReplaceDOCTYPE, "writer 2 insert DOCTYPE");
            Assert.IsFalse(aft.RemoveBOM, "writer 2 remove BOM");
            Assert.IsFalse(aft.SaveResult, "writer 2 save result");
            Assert.IsNull(aft.Parameters, "writer 2 parameters are null");
            Assert.IsNull(aft.ParameterSet, "writer 2 parameter set");
            aft.ApplyTransform(m_ksConfigurationPath, sPass1ResultFile);
            sExpected          = ReadFileIntoString(Path.Combine(m_ksTestData, "IsthmusZapotec2.htm"));
            sActual            = ReadFileIntoString(aft.ResultFile);
            iExpectedDateStart = sExpected.IndexOf("<center><small>");
            iExpectedDateEnd   = sExpected.IndexOf("</small></center>");
            iActualDateStart   = sActual.IndexOf("<center><small>");
            iActualDateEnd     = sActual.IndexOf("</small></center>");
            Assert.AreEqual(sExpected.Substring(0, iExpectedDateStart) + sExpected.Substring(iExpectedDateEnd),
                            sActual.Substring(0, iActualDateStart) + sActual.Substring(iActualDateEnd),
                            "writer 2 result file");

            // Example files
            node = doc.SelectSingleNode("//answerFileTransformSets/answerFileTransformSet[3]/transform");
            aft  = new AnswerFileTransform(sAnswerFile, node, m_ksConfigurationPath);
            Assert.AreEqual(sAnswerFile, aft.AnswerFile, "Answer file");
            Assert.AreEqual(m_ksConfigurationPath + "/Transforms/PAWSSKParameterizedExample.xsl", aft.TransformFile, "Transform file");
            Assert.IsNull(aft.ResultFile, "result file is null");
            Assert.AreEqual(@"C:\carla\Dev\Cabhab\UserData\IZ2", aft.ResultPath, "result path");
            Assert.AreEqual("prmIdTitle", aft.ResultFile1, "result file 1");
            Assert.AreEqual("Test", aft.ResultFile2, "result file 2");
            Assert.AreEqual("txt", aft.FileExtension, "file extension");
            Assert.IsNull(aft.ReplaceDOCTYPE, "insert DOCTYPE");
            Assert.IsTrue(aft.RemoveBOM, "remove BOM");
            Assert.IsFalse(aft.SaveResult, "save result");
            Assert.IsNull(aft.Parameters, "example parameters are null");
            Assert.IsNotNull(aft.ParameterSet, "example parameter set not null");
            Assert.AreEqual(16, aft.ParameterSet.Count, "parameter set count");
            CheckParameterNameValue(aft.ParameterSet[0][0], "prmIdTitle", "QP", "example first set, first parameter");
            CheckParameterNameValue(aft.ParameterSet[0][1], "prmTextSFM", "\\t", "example first set, second parameter");
            aft.ApplyTransform(m_ksConfigurationPath);
            sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IZ2QPTest.txt"));
            sActual   = ReadFileIntoString(Path.Combine(aft.ResultPath, "IZ2QPTest.txt"));
            Assert.AreEqual(sExpected, sActual, "IZ2QPTest result file");
            sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IZ2ExclTest.txt"));
            sActual   = ReadFileIntoString(Path.Combine(aft.ResultPath, "IZ2ExclTest.txt"));
            Assert.AreEqual(sExpected, sActual, "IZ2ExclTest result file");
        }
Beispiel #4
0
 // get all transforms and init them
 public void InitAnswerTransforms(XmlNode configurationParameters)
 {
     XmlNode versionNode = configurationParameters.SelectSingleNode("//version");
     string sVersionNumber = versionNode.InnerText;
     m_answerFileTransformSets.Clear();
     XmlNodeList nodeList = configurationParameters.SelectNodes("//answerFileTransformSets/answerFileTransformSet");
     foreach (XmlNode setNode in nodeList)
     {
         AnswerFileTransformSet answerFileTransforms = new AnswerFileTransformSet();
         XmlNodeList transformNodes = setNode.SelectNodes("transform");
         foreach (XmlNode transformNode in transformNodes)
         {
             AnswerFileTransform aft = new AnswerFileTransform(AnswerFile, transformNode, ConfigurationPath, sVersionNumber);
             answerFileTransforms.Add(aft);
         }
         m_answerFileTransformSets.Add(answerFileTransforms);
     }
 }
 public void Add(AnswerFileTransform aft)
 {
     m_transforms.Add(aft);
 }
 public void Add(AnswerFileTransform aft)
 {
     m_transforms.Add(aft);
 }
Beispiel #7
0
        public void AnswerFileTransform()
        {
            AnswerFileTransform aft;
            string sAnswerFile = Path.Combine(m_ksTestData, "IsthmusZapotec2.paw");
            string sConfigurationFile = @"..\..\Configurations\PAWS\paws.xml";
            string sConfigurationPath = @"..\..\Configurations\PAWS";
            XmlDocument doc = new XmlDocument();
            doc.Load(sConfigurationFile);
            // Grammar file
            XmlNode node = doc.SelectSingleNode("//answerFileTransformSets/answerFileTransformSet[1]/transform");
            aft = new AnswerFileTransform(sAnswerFile, node, m_ksConfigurationPath);
            Assert.AreEqual(sAnswerFile, aft.AnswerFile, "Answer file");
            Assert.AreEqual(m_ksConfigurationPath + "/Transforms/PAWSSKMasterGrammarMapper.xsl", aft.TransformFile, "Transform file");
            Assert.AreEqual(@"C:\carla\Dev\Cabhab\UserData\IZ2\IsthmusZapotec2.grm", aft.ResultFile, "result file");
            Assert.IsNull(aft.ResultPath, "result path");
            Assert.IsNull(aft.ResultFile1, "result file 1");
            Assert.IsNull(aft.ResultFile2, "result file 2");
            Assert.IsNull(aft.FileExtension, "file extension");
            Assert.IsNull(aft.ReplaceDOCTYPE, "insert DOCTYPE");
            Assert.IsTrue(aft.RemoveBOM, "remove BOM");
            Assert.IsFalse(aft.SaveResult, "save result");
            Assert.IsNull(aft.Parameters, "grammar parameters");
            Assert.IsNull(aft.ParameterSet, "parameter set");
            aft.ApplyTransform(m_ksConfigurationPath);
            string sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IsthmusZapotec2.grm"));
            string sActual = ReadFileIntoString(aft.ResultFile);
            Assert.AreEqual(sExpected, sActual, "Grammar result file");

            // Writer first file
            node = doc.SelectSingleNode("//answerFileTransformSets/answerFileTransformSet[2]/transform[1]");
            aft = new AnswerFileTransform(sAnswerFile, node, sConfigurationPath);
            Assert.AreEqual(sAnswerFile, aft.AnswerFile, "writer 1 Answer file");
            Assert.AreEqual(sConfigurationPath + "/Transforms/PAWSSKMasterWriterMapperUse.xsl", aft.TransformFile, "writer 1 Transform file");
            Assert.AreEqual(@"C:\carla\Dev\Cabhab\UserData\IZ2\IsthmusZapotec2.xml", aft.ResultFile, "writer 1 result file");
            Assert.IsNull(aft.ResultPath, "writer 1 result path");
            Assert.IsNull(aft.ResultFile1, "writer 1 result file 1");
            Assert.IsNull(aft.ResultFile2, "writer 1 result file 2");
            Assert.AreEqual("xml", aft.FileExtension, "writer 1 file extension");
            Assert.AreEqual("<!DOCTYPE lingPaper PUBLIC \"-//XMLmind//DTD XLingPap//EN\"\r\n\"file://%SystemDrive%/Documents and Settings/%USERNAME%/Application Data/XMLmind/XMLEditor/addon/XLingPap/XLingPap.dtd\">", aft.ReplaceDOCTYPE, "writer 1 replace DOCTYPE");
            Assert.IsFalse(aft.RemoveBOM, "writer 1 remove BOM");
            Assert.IsTrue(aft.SaveResult, "writer 1 save result");
            Assert.IsNotNull(aft.Parameters, "writer 1 parameters not null");
            Assert.AreEqual(1, aft.Parameters.Length, "writer 1 parameters count");
            CheckParameterNameValue((XMLUtilities.XSLParameter) aft.Parameters.GetValue(0), "prmSDateTime", "fake", "writer 1 first parameter");
            Assert.IsNull(aft.ParameterSet, "writer 1 parameter set");
            aft.ApplyTransform(m_ksConfigurationPath);
            sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IsthmusZapotec2.xml"));
            sActual = ReadFileIntoString(aft.ResultFile);
            int iExpectedDateStart = sExpected.IndexOf("<date>");
            int iExpectedDateEnd = sExpected.IndexOf("</date>");
            int iActualDateStart = sActual.IndexOf("<date>");
            int iActualDateEnd = sActual.IndexOf("</date>");
            Assert.AreEqual(sExpected.Substring(0, iExpectedDateStart) + sExpected.Substring(iExpectedDateEnd),
                            sActual.Substring(0, iActualDateStart) + sActual.Substring(iActualDateEnd),
                            "writer 1 result file");

            // Writer second file
            string sPass1ResultFile = aft.ResultFile;
            node = doc.SelectSingleNode("//answerFileTransformSets/answerFileTransformSet[2]/transform[2]");
            aft = new AnswerFileTransform(sAnswerFile, node, m_ksConfigurationPath);
            Assert.AreEqual(sAnswerFile, aft.AnswerFile, "writer 2 Answer file");
            Assert.AreEqual(m_ksConfigurationPath + "/Transforms/XLingPap1.xsl", aft.TransformFile, "writer 2 Transform file");
            Assert.AreEqual(@"C:\carla\Dev\Cabhab\UserData\IZ2\IsthmusZapotec2.htm", aft.ResultFile, "writer 2 result file");
            Assert.IsNull(aft.ResultPath, "writer 2 result path");
            Assert.IsNull(aft.ResultFile1, "writer 2 result file 1");
            Assert.IsNull(aft.ResultFile2, "writer 2 result file 2");
            Assert.AreEqual("htm", aft.FileExtension, "writer 2 file extension");
            Assert.IsNull(aft.ReplaceDOCTYPE, "writer 2 insert DOCTYPE");
            Assert.IsFalse(aft.RemoveBOM, "writer 2 remove BOM");
            Assert.IsFalse(aft.SaveResult, "writer 2 save result");
            Assert.IsNull(aft.Parameters, "writer 2 parameters are null");
            Assert.IsNull(aft.ParameterSet, "writer 2 parameter set");
            aft.ApplyTransform(m_ksConfigurationPath, sPass1ResultFile);
            sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IsthmusZapotec2.htm"));
            sActual = ReadFileIntoString(aft.ResultFile);
            iExpectedDateStart = sExpected.IndexOf("<center><small>");
            iExpectedDateEnd = sExpected.IndexOf("</small></center>");
            iActualDateStart = sActual.IndexOf("<center><small>");
            iActualDateEnd = sActual.IndexOf("</small></center>");
            Assert.AreEqual(sExpected.Substring(0, iExpectedDateStart) + sExpected.Substring(iExpectedDateEnd),
                            sActual.Substring(0, iActualDateStart) + sActual.Substring(iActualDateEnd),
                            "writer 2 result file");

            // Example files
            node = doc.SelectSingleNode("//answerFileTransformSets/answerFileTransformSet[3]/transform");
            aft = new AnswerFileTransform(sAnswerFile, node, m_ksConfigurationPath);
            Assert.AreEqual(sAnswerFile, aft.AnswerFile, "Answer file");
            Assert.AreEqual(m_ksConfigurationPath + "/Transforms/PAWSSKParameterizedExample.xsl", aft.TransformFile, "Transform file");
            Assert.IsNull(aft.ResultFile, "result file is null");
            Assert.AreEqual(@"C:\carla\Dev\Cabhab\UserData\IZ2", aft.ResultPath, "result path");
            Assert.AreEqual("prmIdTitle", aft.ResultFile1, "result file 1");
            Assert.AreEqual("Test", aft.ResultFile2, "result file 2");
            Assert.AreEqual("txt", aft.FileExtension, "file extension");
            Assert.IsNull(aft.ReplaceDOCTYPE, "insert DOCTYPE");
            Assert.IsTrue(aft.RemoveBOM, "remove BOM");
            Assert.IsFalse(aft.SaveResult, "save result");
            Assert.IsNull(aft.Parameters, "example parameters are null");
            Assert.IsNotNull(aft.ParameterSet, "example parameter set not null");
            Assert.AreEqual(16, aft.ParameterSet.Count, "parameter set count");
            CheckParameterNameValue(aft.ParameterSet[0][0], "prmIdTitle", "QP", "example first set, first parameter");
            CheckParameterNameValue(aft.ParameterSet[0][1], "prmTextSFM", "\\t", "example first set, second parameter");
            aft.ApplyTransform(m_ksConfigurationPath);
            sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IZ2QPTest.txt"));
            sActual = ReadFileIntoString(Path.Combine(aft.ResultPath, "IZ2QPTest.txt"));
            Assert.AreEqual(sExpected, sActual, "IZ2QPTest result file");
            sExpected = ReadFileIntoString(Path.Combine(m_ksTestData, "IZ2ExclTest.txt"));
            sActual = ReadFileIntoString(Path.Combine(aft.ResultPath, "IZ2ExclTest.txt"));
            Assert.AreEqual(sExpected, sActual, "IZ2ExclTest result file");
        }