/// <summary> /// Transpile the given input file in the given output file /// </summary> /// <param name="input">The input file</param> /// <param name="output">The output file</param> /// <param name="output">The output file</param> /// <param name=className">The defautl class name to use</param> /// <returns></returns> public static bool Transpile(string input, string output, string className = null) { string currentDir = System.IO.Directory.GetCurrentDirectory(); string xsdFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "Skeleton.xsd"); System.IO.FileInfo fi = new System.IO.FileInfo(xsdFile); SkeletonSaxParser parser = fi.Exists ? new SkeletonSaxParser(input, xsdFile) : new SkeletonSaxParser(input); try { parser.Parse(); bool bValidate = parser.ValidationErrorCount == 0 && parser.ValidationWarningCount == 0; if (!bValidate) { System.Console.Error.WriteLine(parser.ValidationMessage.ToString()); return(false); } } catch (Exception e) { System.Console.Error.WriteLine(e.Message); return(false); } SkeletonsController controller = new SkeletonsController(parser.Skeletons); controller.InputFile = input; if (className != null) { controller.SkeletonClassName = className; } string code = controller.TranspiledCode; try { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(new FileStream(output, FileMode.Create), Encoding.UTF8)) { sw.Write(code); sw.Flush(); } } catch (Exception e) { System.Console.Error.WriteLine(e.Message); return(false); } return(true); }
public void SkeletonFileXmlSaxParsingWithoutValidationTest() { string currentDir = System.IO.Directory.GetCurrentDirectory(); string xmlFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "TestSkeletons.xml"); SkeletonSaxParser parser = new SkeletonSaxParser(xmlFile); try { parser.Parse(); } catch (SaxParser.SaxParser.ParsingException e) { throw e; } }
public void SkeletonFileXmlSaxParsingWithValidationTest() { string currentDir = System.IO.Directory.GetCurrentDirectory(); string xmlFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "TestSkeletons.xml"); string xsdFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "Skeleton.xsd"); SkeletonSaxParser parser = new SkeletonSaxParser(xmlFile, xsdFile); try { parser.Parse(); bool bValidate = parser.ValidationErrorCount == 0 && parser.ValidationWarningCount == 0; Assert.IsTrue(bValidate, bValidate ? "" : parser.ValidationMessage.ToString()); } catch (SaxParser.SaxParser.ParsingException e) { throw e; } }
public void SkeletonsFileTranspilationTest0() { string currentDir = System.IO.Directory.GetCurrentDirectory(); string xmlFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "TestSkeletons.xml"); string xsdFile = System.IO.Path.Combine(System.IO.Path.Combine(currentDir, "Xml"), "Skeleton.xsd"); SkeletonSaxParser parser = new SkeletonSaxParser(xmlFile, xsdFile); try { parser.Parse(); bool bValidate = parser.ValidationErrorCount == 0 && parser.ValidationWarningCount == 0; Assert.IsTrue(bValidate, bValidate ? "" : parser.ValidationMessage.ToString()); SkeletonsController controller = new SkeletonsController(parser.Skeletons); string code = controller.TranspiledCode; controller.CreateNodesModel(); System.Diagnostics.Debug.Write(code); } catch (SaxParser.SaxParser.ParsingException e) { throw e; } }