/// <summary> /// Starts the process of /// </summary> /// <param name="args"></param> public void Run(string[] args) { var converted = 0; _args = FixArgs(args); ParseSwitches(); ShowWelcomeMessage(); var assemblies = DiscoverAssemblies(); var coord = new ConfigurationSectionFinderCoOrdinator(assemblies); var types = coord.GetConfigSectionTypes(_className); foreach (Type configType in types) { if (_verbose) { Console.WriteLine(configType.FullName); } // generate the schema var generator = new XsdGenerator(configType); var rootElement = string.IsNullOrEmpty(_rootElementName) ? configType.ToString() : _rootElementName; generator.GenerateXsd(rootElement); // work out what we're going to call the xsd var fInfo = new FileInfo(configType.Assembly.Location); var directoryName = _outputPath ?? fInfo.DirectoryName; var fileName = string.Format("{0}\\{1}.xsd", directoryName, configType); // warn about the file replacement if (!_silent && File.Exists(fileName)) { Console.WriteLine(); Console.Write("{0} exists, replace (y/n)?", fileName); if (Console.ReadKey().Key != ConsoleKey.Y) { continue; } } else { Console.WriteLine("Writing: {0}", fileName); } using (var memoryStream = new MemoryStream()) { converted++; generator.Schema.Write(memoryStream); using (var commentedMemoryStream = AddXsdComment(memoryStream, configType)) { using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { fs.Write(commentedMemoryStream.ToArray(), 0, (int)commentedMemoryStream.Length); } } } } // write out what we did Console.WriteLine(); Console.WriteLine("# of assemblies inspected : {0}", assemblies.Length); Console.WriteLine("# of types inspected : {0}", types.Length); Console.WriteLine("# of Xsd's created : {0}", converted); }
/// <summary> /// Starts the process of /// </summary> /// <param name="args"></param> public void Run(string[] args) { var converted = 0; _args = FixArgs(args); ParseSwitches(); ShowWelcomeMessage(); var assemblies = DiscoverAssemblies(); var coord = new ConfigurationSectionFinderCoOrdinator(assemblies); var types = coord.GetConfigSectionTypes(_className); foreach (Type configType in types) { if (_verbose) { Console.WriteLine(configType.FullName); } // generate the schema var generator = new XsdGenerator(configType); var rootElement = string.IsNullOrEmpty(_rootElementName) ? configType.ToString() : _rootElementName; generator.GenerateXsd(rootElement); // work out what we're going to call the xsd var fInfo = new FileInfo(configType.Assembly.Location); var directoryName = _outputPath ?? fInfo.DirectoryName; var fileName = string.Format("{0}\\{1}.xsd", directoryName, configType); // warn about the file replacement if (!_silent && File.Exists(fileName)) { Console.WriteLine(); Console.Write("{0} exists, replace (y/n)?", fileName); if (Console.ReadKey().Key != ConsoleKey.Y) continue; } else { Console.WriteLine("Writing: {0}", fileName); } using (var memoryStream = new MemoryStream()) { converted++; generator.Schema.Write(memoryStream); using (var commentedMemoryStream = AddXsdComment(memoryStream, configType)) { using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { fs.Write(commentedMemoryStream.ToArray(), 0, (int) commentedMemoryStream.Length); } } } } // write out what we did Console.WriteLine(); Console.WriteLine("# of assemblies inspected : {0}", assemblies.Length); Console.WriteLine("# of types inspected : {0}", types.Length); Console.WriteLine("# of Xsd's created : {0}", converted); }