static void writePackage(XmlWriter xw, RMArgs xtargs) { xw.WriteStartDocument(); xw.WriteStartElement("package"); xw.WriteStartElement("metadata"); if (string.IsNullOrEmpty(xtargs.product)) { throw new ApplicationException("missing ID (AssemblyProduct)"); } else { xw.WriteElementString("id", xtargs.product); } xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteEndDocument(); }
public static void Main(string[] args) { int exitCode = 0; bool errorFound = false; //RMArgs xtargs = new RMArgs(args); RMArgs xtargs; XmlWriter xw = null; TextWriterTraceListener twtl = null; StringBuilder sb; #if TRACE Trace.AutoFlush = true; twtl = new TextWriterTraceListener(Console.Out, LISTENER_NAME); Trace.Listeners.Add(twtl); #endif xtargs = new RMArgs(args); if (args.Length < 1) { Console.Error.WriteLine("no args"); showUsage(Console.Out); exitCode = 3; } else { if (xtargs.showHelp) { Console.Error.WriteLine("help requested"); showUsage(Console.Out); } else { if (string.IsNullOrEmpty(xtargs.inputFile)) { errorFound |= true; Console.Error.WriteLine("input-file not specified."); exitCode = 3; } if (errorFound) { showUsage(Console.Error); } else { sb = new StringBuilder(); xw = XmlWriter.Create(sb, settings); //xw=XmlWriter.Create() if (string.IsNullOrEmpty(xtargs.outputFile)) { settings.CloseOutput = false; //xw = XmlWriter.Create(Console.Out, settings); } //else { // ////settings.CloseOutput = true; // //xw = XmlWriter.Create(xtargs.outputFile, settings); //} try { writePackage(xw, xtargs); xw.Flush(); if (!string.IsNullOrEmpty(xtargs.outputFile)) { File.WriteAllText(xtargs.outputFile, sb.ToString()); } else { Console.Out.WriteLine(sb.ToString()); } if (xtargs.verbose) { Trace.WriteLine("[VERBOSE] " + "wrote output to " + (string.IsNullOrEmpty(xtargs.outputFile) ? "<stdout>" : xtargs.outputFile)); } ; } catch (Exception ex) { MiniLogger.log(MethodBase.GetCurrentMethod(), ex); exitCode = 1; } finally { if (xw != null) { xw.Close(); xw.Dispose(); xw = null; } } } } //KC Trace.WriteLine("here"); } #if TRACE if (twtl != null) { Trace.Flush(); Trace.Listeners.Remove(LISTENER_NAME); } #endif Environment.Exit(exitCode); }