private bool Test(int index) { bool result = false; string inputFileName = string.Format(@"..\..\InputFiles\soal\Wsdl{0:00}.soal", index); string expectedXsdFileName = string.Format(@"..\..\ExpectedFiles\xsd\Wsdl{0:00}.Hello.xsd", index); string outputXsdFileName = string.Format(@"..\..\OutputFiles\xsd\Wsdl{0:00}.Hello.xsd", index); string expectedWsdlFileName = string.Format(@"..\..\ExpectedFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index); string outputWsdlFileName = string.Format(@"..\..\OutputFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index); string outputDirectory = string.Format(@"..\..\OutputFiles"); string inputSoal = null; using (StreamReader reader = new StreamReader(inputFileName)) { inputSoal = reader.ReadToEnd(); } SoalSyntaxTree syntaxTree = SoalSyntaxTree.ParseText(inputSoal); MetadataReference soalReference = MetadataReference.CreateFromModel(SoalInstance.Model); SoalCompilation compilation = SoalCompilation.Create("SoalTest").AddReferences(soalReference).AddSyntaxTrees(syntaxTree); ImmutableModel model = compilation.Model; Assert.IsFalse(compilation.GetDiagnostics().Any(d => d.Severity == Compiler.Diagnostics.DiagnosticSeverity.Error)); DiagnosticBag generatorDiagnostics = new DiagnosticBag(); SoalGenerator generator = new SoalGenerator(model, outputDirectory, generatorDiagnostics, inputFileName); generator.SeparateXsdWsdl = true; generator.SingleFileWsdl = false; generator.Generate(); string expectedXsd = null; using (StreamReader reader = new StreamReader(expectedXsdFileName)) { expectedXsd = reader.ReadToEnd(); } string outputXsd = null; using (StreamReader reader = new StreamReader(outputXsdFileName)) { outputXsd = reader.ReadToEnd(); } Assert.AreEqual(expectedXsd, outputXsd); string expectedWsdl = null; using (StreamReader reader = new StreamReader(expectedWsdlFileName)) { expectedWsdl = reader.ReadToEnd(); } string outputWsdl = null; using (StreamReader reader = new StreamReader(outputWsdlFileName)) { outputWsdl = reader.ReadToEnd(); } Assert.AreEqual(expectedWsdl, outputWsdl); return(result); }
private bool Test(int index) { bool result = false; string inputFileName = string.Format(@"..\..\InputFiles\soal\Xsd{0:00}.soal", index); string expectedFileName = string.Format(@"..\..\ExpectedFiles\xsd\Xsd{0:00}.Hello.xsd", index); string outputFileName = string.Format(@"..\..\OutputFiles\xsd\Xsd{0:00}.Hello.xsd", index); string outputDirectory = string.Format(@"..\..\OutputFiles"); string inputSoal = null; using (StreamReader reader = new StreamReader(inputFileName)) { inputSoal = reader.ReadToEnd(); } SoalSyntaxTree syntaxTree = SoalSyntaxTree.ParseText(inputSoal); ModelReference soalReference = ModelReference.CreateFromModel(SoalInstance.Model); BinderFlags binderFlags = BinderFlags.IgnoreAccessibility; SoalCompilationOptions options = new SoalCompilationOptions(SoalLanguage.Instance, OutputKind.NetModule, topLevelBinderFlags: binderFlags); SoalCompilation compilation = SoalCompilation.Create("SoalTest").AddReferences(soalReference).AddSyntaxTrees(syntaxTree).WithOptions(options); compilation.ForceComplete(); ImmutableModel model = compilation.Model; Assert.IsFalse(compilation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error)); DiagnosticBag generatorDiagnostics = new DiagnosticBag(); SoalGenerator generator = new SoalGenerator(model, compilation.BuildModelObjectToSymbolMap(), outputDirectory, generatorDiagnostics, inputFileName); generator.SeparateXsdWsdl = true; generator.SingleFileWsdl = false; generator.Generate(); Assert.IsFalse(generatorDiagnostics.AsEnumerable().Any(d => d.Severity == DiagnosticSeverity.Error)); string expectedXsd = null; using (StreamReader reader = new StreamReader(expectedFileName)) { expectedXsd = reader.ReadToEnd(); } string outputXsd = null; using (StreamReader reader = new StreamReader(outputFileName)) { outputXsd = reader.ReadToEnd(); } Assert.AreEqual(expectedXsd, outputXsd); return(result); }
private bool Test(int index) { bool result = false; string inputFileName = string.Format(@"..\..\InputFiles\soal\Wsdl{0:00}.soal", index); string expectedXsdFileName = string.Format(@"..\..\ExpectedFiles\xsd\Wsdl{0:00}.Hello.xsd", index); string outputXsdFileName = string.Format(@"..\..\OutputFiles\xsd\Wsdl{0:00}.Hello.xsd", index); string expectedWsdlFileName = string.Format(@"..\..\ExpectedFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index); string outputWsdlFileName = string.Format(@"..\..\OutputFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index); string outputDirectory = string.Format(@"..\..\OutputFiles"); string inputSoal = null; using (StreamReader reader = new StreamReader(inputFileName)) { inputSoal = reader.ReadToEnd(); } SoalCompiler compiler = new SoalCompiler(inputSoal, inputFileName); compiler.Compile(); Assert.IsFalse(compiler.Diagnostics.HasErrors()); SoalGenerator generator = new SoalGenerator(compiler.Model, outputDirectory, compiler.Diagnostics, compiler.FileName); generator.SeparateXsdWsdl = true; generator.SingleFileWsdl = false; generator.Generate(); string expectedXsd = null; using (StreamReader reader = new StreamReader(expectedXsdFileName)) { expectedXsd = reader.ReadToEnd(); } string outputXsd = null; using (StreamReader reader = new StreamReader(outputXsdFileName)) { outputXsd = reader.ReadToEnd(); } Assert.AreEqual(expectedXsd, outputXsd); string expectedWsdl = null; using (StreamReader reader = new StreamReader(expectedWsdlFileName)) { expectedWsdl = reader.ReadToEnd(); } string outputWsdl = null; using (StreamReader reader = new StreamReader(outputWsdlFileName)) { outputWsdl = reader.ReadToEnd(); } Assert.AreEqual(expectedWsdl, outputWsdl); return result; }
static void Main(string[] args) { string fileName = null; string outputDirectory = null; bool separateXsdWsdl = false; bool singleFileWsdl = false; for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("-")) { if (args[i] == "-separateXsdWsdl") { separateXsdWsdl = true; } else if (args[i] == "-singleFileWsdl") { singleFileWsdl = true; } else if (i + 1 < args.Length) { if (args[i] == "-o") { outputDirectory = args[++i]; } else { Console.WriteLine("Unknown option: '" + args[i] + "'"); } } else { Console.WriteLine("Unknown option: '" + args[i] + "'"); } } else { fileName = args[i]; } } if (fileName == null) { Console.WriteLine("Usage:"); Console.WriteLine(" Soal.exe [options] [input.soal]"); Console.WriteLine("Options:"); Console.WriteLine(" -o [dir]: output directory"); Console.WriteLine(" -separateXsdWsdl: separate XSD and WSDL files into different directories"); Console.WriteLine(" -singleFileWsdl: include XSD code into the WSDL"); return; } if (outputDirectory == null) { outputDirectory = Directory.GetCurrentDirectory(); } if (!File.Exists(fileName)) { Console.WriteLine("Could not find file: " + fileName); return; } if (singleFileWsdl && separateXsdWsdl) { Console.WriteLine("Warning: conflicting options '-separateXsdWsdl' and '-singleFileWsdl'. '-singleFileWsdl' will be used."); } string source; using (StreamReader reader = new StreamReader(fileName)) { source = reader.ReadToEnd(); } SoalSyntaxTree syntaxTree = SoalSyntaxTree.ParseText(source); ModelReference soalReference = ModelReference.CreateFromModel(SoalInstance.Model); BinderFlags binderFlags = BinderFlags.IgnoreAccessibility; SoalCompilationOptions options = new SoalCompilationOptions(SoalLanguage.Instance, OutputKind.NetModule, topLevelBinderFlags: binderFlags, concurrentBuild: false); SoalCompilation compilation = SoalCompilation.Create("SoalTest").AddReferences(soalReference).AddSyntaxTrees(syntaxTree).WithOptions(options); compilation.ForceComplete(); ImmutableModel model = compilation.Model; DiagnosticBag generatorDiagnostics = new DiagnosticBag(); if (!compilation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error)) { SoalGenerator generator = new SoalGenerator(model, compilation.BuildModelObjectToSymbolMap(), outputDirectory, generatorDiagnostics, fileName); generator.SeparateXsdWsdl = separateXsdWsdl; generator.SingleFileWsdl = singleFileWsdl; generator.Generate(); SoalPrinter printer = new SoalPrinter(model.Symbols); using (StreamWriter writer = new StreamWriter(fileName + "0")) { writer.WriteLine(printer.Generate()); } } DiagnosticFormatter formatter = new DiagnosticFormatter(); foreach (var diagnostic in compilation.GetDiagnostics()) { string msg = formatter.Format(diagnostic); Console.WriteLine(msg); } foreach (var diagnostic in generatorDiagnostics.AsEnumerable()) { string msg = formatter.Format(diagnostic); Console.WriteLine(msg); } }