public void WriteHelp() { int start = s_nameMidpoint; ToolConsole.WriteLine(new string(' ', _nameStart) + _name); ToolConsole.WriteLine(); if (_description != null) { s_categoryBuilder.WriteParagraph(_description); ToolConsole.WriteLine(); } if (_syntax != null) { s_categoryBuilder.WriteParagraph(_syntax); ToolConsole.WriteLine(); } if (_inputs != null) { ArgumentInfo.WriteArguments(_inputs); ToolConsole.WriteLine(); } if (_options != null) { ToolConsole.WriteLine(SR.Format(SR.HelpOptions)); ToolConsole.WriteLine(); ArgumentInfo.WriteArguments(_options); ToolConsole.WriteLine(); } }
private List <Type> CollectXmlSerializerTypes(Assembly assembly, List <XmlMapping> mappings) { List <Type> types = new List <Type>(); ExportModule.ContractLoader contractLoader = new ExportModule.ContractLoader(new Assembly[] { assembly }, _isTypeExcluded); contractLoader.ContractLoadErrorCallback = delegate(Type contractType, string errorMessage) { ToolConsole.WriteWarning(SR.Format(SR.WrnUnableToLoadContractForSGen, contractType, errorMessage)); }; foreach (ContractDescription contract in contractLoader.GetContracts()) { types.Add(contract.ContractType); foreach (OperationDescription operation in contract.Operations) { XmlSerializerOperationBehavior behavior = operation.Behaviors.Find <XmlSerializerOperationBehavior>(); if (behavior != null) { foreach (XmlMapping map in behavior.GetXmlMappings()) { mappings.Add(map); } } } } return(types); }
public void WriteParagraph(string text) { this.Reset(); this.AppendParagraph(text); ToolConsole.WriteLine(_stringBuilder.ToString()); _stringBuilder = null; }
private void CheckForBasicOptions() { _parent._noLogo = _arguments.ContainsArgument(Options.Cmd.NoLogo); #if DEBUG ToolConsole.SetOptions(_arguments.ContainsArgument(Options.Cmd.Debug)); #endif }
internal static void WriteInvalidDataContractError(InvalidDataContractException e) { WriteError(e); ToolConsole.WriteLine(); ToolConsole.WriteLine(SR.Format(SR.HintConsiderUseXmlSerializer, Options.Cmd.DataContractOnly, Options.Cmd.ImportXmlTypes)); }
internal void GenerateCode(List <Assembly> assemblies) { if (!string.IsNullOrEmpty(_outFile) && assemblies.Count > 1) { ToolConsole.WriteWarning(SR.Format(SR.WrnOptionConflictsWithInput, Options.Cmd.Out)); _outFile = null; } foreach (Assembly assembly in assemblies) { GenerateCode(assembly); } }
internal static void Assert(bool condition, string message) { if (!condition) { #if DEBUG ToolConsole.WriteError("Please file a bug or report the following issue with this tool:"); StackTrace st = new StackTrace(true); ToolConsole.WriteLine(st.ToString()); #endif ToolConsole.WriteUnexpectedError(message); Tool.FailFast(message); } }
internal static void WriteHelpText() { HelpGenerator.WriteUsage(); ToolConsole.WriteLine(); ToolConsole.WriteLine(); HelpGenerator.WriteCommonOptionsHelp(); ToolConsole.WriteLine(); ToolConsole.WriteLine(); HelpGenerator.WriteXmlSerializerTypeGenerationHelp(); ToolConsole.WriteLine(); ToolConsole.WriteLine(); HelpGenerator.WriteExamples(); ToolConsole.WriteLine(); ToolConsole.WriteLine(); }
public static void WriteArguments(ArgumentInfo[] arguments) { int maxArgumentnLength = CalculateMaxNameLength(arguments); int helpTextIndent = argHelpPrefix.Length + maxArgumentnLength + argHelpSeperator.Length; string helpPattern = argHelpPrefix + "{0, -" + maxArgumentnLength + "}" + argHelpSeperator + "{1}"; ToolStringBuilder builder = new ToolStringBuilder(helpTextIndent); foreach (ArgumentInfo argument in arguments) { if (argument.BeginGroup) { ToolConsole.WriteLine(); } string optionHelp = argument.GenerateHelp(helpPattern); builder.WriteParagraph(optionHelp); } }
public static int Main(string[] args) { try { // ValidateUICulture() makes sure that this command-line tool can run on RightToLeft systems. ValidateUICulture(); Options options = Options.ParseArguments(args); ToolRuntime runtime = new ToolRuntime(options); return((int)runtime.Run()); } catch (ToolArgumentException ae) { ToolConsole.WriteHeader(); ToolConsole.WriteToolError(ae); return((int)ae.ExitCode); } catch (ToolRuntimeException re) { ToolConsole.WriteToolError(re); return((int)re.ExitCode); } catch (DcNS.InvalidDataContractException dce) { ToolConsole.WriteInvalidDataContractError(dce); return((int)ToolExitCodes.RuntimeError); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (Tool.IsFatal(e)) { throw; } ToolConsole.WriteUnexpectedError(e); Tool.FailFast(e.ToString()); return((int)ToolExitCodes.Unknown); // unreachable code; } }
internal static void WriteError(Exception e, string prefix) { #if DEBUG if (s_debug) { ToolConsole.WriteLine(); WriteError(e.ToString(), prefix); return; } #endif WriteError(e.Message, prefix); while (e.InnerException != null) { if (e.Message != e.InnerException.Message) { WriteError(e.InnerException.Message, " "); } e = e.InnerException; } }
static public Type[] LoadTypes(Assembly assembly) { Type[] types; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException rtle) { ToolConsole.WriteWarning(SR.Format(SR.WrnCouldNotLoadTypesFromReferenceAssemblyAt, assembly.Location)); foreach (Exception e in rtle.LoaderExceptions) { ToolConsole.WriteLine(" " + e.Message, 2); } types = Array.FindAll <Type>(rtle.Types, delegate(Type t) { return(t != null); }); if (types.Length == 0) { throw new ToolInputException(SR.Format(SR.ErrCouldNotLoadTypesFromAssemblyAt, assembly.Location)); } } return(types); }
internal static void WriteToolError(ToolArgumentException ae) { WriteError(ae); ToolMexException me = ae as ToolMexException; if (me != null) { string serviceUri = me.ServiceUri.AbsoluteUri; ToolConsole.WriteLine(); ToolConsole.WriteError(SR.Format(SR.WrnWSMExFailed, serviceUri), string.Empty); ToolConsole.WriteError(me.WSMexException, " "); if (me.HttpGetException != null) { ToolConsole.WriteLine(); ToolConsole.WriteError(SR.Format(SR.WrnHttpGetFailed, serviceUri), string.Empty); ToolConsole.WriteError(me.HttpGetException, " "); } } ToolConsole.WriteLine(SR.Format(SR.MoreHelp, Options.Abbr.Help)); }
internal static void WriteHeader() { // Using CommonResStrings.WcfTrademarkForCmdLine for the trademark: the proper resource for command line tools. ToolConsole.WriteLine(SR.Format(SR.Logo, SR.WcfTrademarkForCmdLine, ThisAssembly.InformationalVersion, SR.CopyrightForCmdLine)); }
} // beforefeildInit internal static void WriteUsage() { ToolConsole.WriteLine(SR.Format(SR.HelpUsage1)); ToolConsole.WriteLine(); ToolConsole.WriteLine(SR.Format(SR.HelpUsage6)); }
private void GenerateCode(Assembly assembly) { List <XmlMapping> mappings = new List <XmlMapping>(); List <Type> types = CollectXmlSerializerTypes(assembly, mappings); if (types.Count == 0) { ToolConsole.WriteWarning(SR.Format(SR.WrnNoServiceContractTypes, assembly.GetName().CodeBase)); return; } if (mappings.Count == 0) { ToolConsole.WriteWarning(SR.Format(SR.WrnNoXmlSerializerOperationBehavior, assembly.GetName().CodeBase)); return; } bool success = false; bool toDeleteFile = true; string codePath = Path.GetTempFileName(); try { if (File.Exists(codePath)) { File.Delete(codePath); } using (FileStream fs = File.Create(codePath)) { MethodInfo method = typeof(System.Xml.Serialization.XmlSerializer).GetMethod("GenerateSerializer", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (method == null) { throw new ToolRuntimeException(SR.GenerateSerializerNotFound); } else { success = (bool)method.Invoke(null, new object[] { types.ToArray(), mappings.ToArray(), fs }); } } } finally { if (!success && toDeleteFile && File.Exists(codePath)) { File.Delete(codePath); } } string sgenSource = XmlSerializer.GetXmlSerializerAssemblyName(types[0]); // delete all temp files generated by CodeDom except source file sgenSource = BuildFilePath(sgenSource, sourceExtension, null); if (File.Exists(sgenSource)) { File.Delete(sgenSource); } string sourceName; if (_outFile != null) { sourceName = FilenameHelper.UniquifyFileName(_outFile, sourceExtension); } else { sourceName = FilenameHelper.UniquifyFileName(sgenSource, sourceExtension); } string sourceFilePath = BuildFilePath(sourceName, sourceExtension, null); CreateDirectoryIfNeeded(sourceFilePath); File.Copy(codePath, sourceFilePath, true); ToolConsole.WriteLine(sourceFilePath); return; }
private static void WriteExample(string syntax, string explanation) { ToolConsole.WriteLine(string.Format(CultureInfo.InvariantCulture, " {0}", syntax)); s_exampleBuilder.WriteParagraph(string.Format(CultureInfo.InvariantCulture, " {0}", explanation)); ToolConsole.WriteLine(); }