public MsgGenMain(string[] args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } this.showLogo = true; this.showHelp = false; this.sourceFile = null; this.destClassFile = null; this.destResourcesFile = null; // parse the command line this.ParseCommandLine(args); if (this.sourceFile == null || this.destClassFile == null) { this.showHelp = true; } if (this.destResourcesFile == null && this.destClassFile != null) { this.destResourcesFile = Path.ChangeExtension(this.destClassFile, ".resources"); } // get the assemblies var msgGenAssembly = Assembly.GetExecutingAssembly(); if (this.showLogo) { Console.WriteLine("Microsoft (R) Message Generation Tool version {0}", msgGenAssembly.GetName().Version !.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2004. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: MsgGen.exe [-?] [-nologo] sourceFile destClassFile [destResourcesFile]"); Console.WriteLine(); Console.WriteLine(" -? this help information"); Console.WriteLine(); Console.WriteLine("For more information see: http://wix.sourceforge.net"); return; // exit } // load the schema var schemaCollection = new XmlSchemaSet(); using (var reader = XmlReader.Create(msgGenAssembly.GetManifestResourceStream("WixBuildTools.MsgGen.Xsd.messages.xsd"))) { schemaCollection.Add("http://schemas.microsoft.com/genmsgs/2004/07/messages", reader); } // load the source file and process it var readerSettings = new XmlReaderSettings(); readerSettings.Schemas = schemaCollection; #pragma warning disable CS8604 // Possible null reference argument (false positive) using (var sr = new StreamReader(this.sourceFile)) using (var validatingReader = XmlReader.Create(sr, readerSettings)) { var errorsDoc = new XmlDocument(); errorsDoc.Load(validatingReader); var codeCompileUnit = new CodeCompileUnit(); using (var resourceWriter = new ResourceWriter(this.destResourcesFile)) { GenerateMessageFiles.Generate(errorsDoc, codeCompileUnit, resourceWriter); } GenerateCSharpCode(codeCompileUnit, this.destClassFile); } #pragma warning restore CS8604 }
/// <summary> /// Main method for the MsgGen application within the MsgGenMain class. /// </summary> /// <param name="args">Commandline arguments to the application.</param> public MsgGenMain(string[] args) { this.showLogo = true; this.showHelp = false; this.sourceFile = null; this.destClassFile = null; this.destResourcesFile = null; // parse the command line this.ParseCommandLine(args); if (null == this.sourceFile || null == this.destClassFile) { this.showHelp = true; } if (null == this.destResourcesFile) { this.destResourcesFile = Path.ChangeExtension(this.destClassFile, ".resources"); } // get the assemblies Assembly msgGenAssembly = Assembly.GetExecutingAssembly(); if (this.showLogo) { Console.WriteLine("Microsoft (R) Message Generation Tool version {0}", msgGenAssembly.GetName().Version.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2004. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: MsgGen.exe [-?] [-nologo] sourceFile destClassFile [destResourcesFile]"); Console.WriteLine(); Console.WriteLine(" -? this help information"); Console.WriteLine(); Console.WriteLine("For more information see: http://wix.sourceforge.net"); return; // exit } // load the schema XmlReader reader = null; XmlSchemaCollection schemaCollection = null; try { reader = new XmlTextReader(msgGenAssembly.GetManifestResourceStream("WixBuildTools.MsgGen.Xsd.messages.xsd")); schemaCollection = new XmlSchemaCollection(); schemaCollection.Add("http://schemas.microsoft.com/genmsgs/2004/07/messages", reader); } finally { reader.Close(); } // load the source file and process it using (StreamReader sr = new StreamReader(this.sourceFile)) { XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.None); XmlValidatingReader validatingReader = new XmlValidatingReader(sr.BaseStream, XmlNodeType.Document, context); validatingReader.Schemas.Add(schemaCollection); XmlDocument errorsDoc = new XmlDocument(); errorsDoc.Load(validatingReader); CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); using (ResourceWriter resourceWriter = new ResourceWriter(this.destResourcesFile)) { GenerateMessageFiles.Generate(errorsDoc, codeCompileUnit, resourceWriter); GenerateCSharpCode(codeCompileUnit, this.destClassFile); } } }