int Run(string[] args) { try { // parse command line arguments foreach (string argument in args) { ImportArgument(argument); } if (noLogo == false) { Console.WriteLine(ProductId); } if (help || urls.Count == 0) { Console.WriteLine(UsageMessage); return(0); } CodeCompileUnit codeUnit = new CodeCompileUnit(); CodeNamespace proxyCode = GetCodeNamespace(); codeUnit.Namespaces.Add(proxyCode); WebReferenceCollection references = new WebReferenceCollection(); DiscoveryClientProtocol dcc = CreateClient(); foreach (string murl in urls) { string url = murl; if (!url.StartsWith("http://") && !url.StartsWith("https://") && !url.StartsWith("file://")) { url = new Uri(Path.GetFullPath(url)).ToString(); } dcc.DiscoverAny(url); dcc.ResolveAll(); } WebReference reference = new WebReference(dcc.Documents, proxyCode, protocol, appSettingURLKey, appSettingBaseURL); references.Add(reference); if (sampleSoap != null) { ConsoleSampleGenerator.Generate(descriptions, schemas, sampleSoap, protocol); } if (sampleSoap != null) { return(0); } // generate the code GenerateCode(references, codeUnit); return(0); } catch (Exception exception) { Console.WriteLine("Error: {0}", exception.Message); // Supress this except for when debug is enabled Console.WriteLine("Stack:\n {0}", exception.StackTrace); return(2); } }
/// /// <summary> /// Driver's main control flow: /// - parse arguments /// - report required messages /// - terminate if no input /// - report errors /// </summary> /// int Run(string[] args) { try { // parse command line arguments foreach (string argument in args) { ImportArgument(argument); } if (noLogo == false) { Console.WriteLine(ProductId); } if (help || (!hasURL && className == null)) { Console.WriteLine(UsageMessage); return(0); } if (className == null) { DiscoveryClientProtocol dcc = CreateClient(); foreach (string urlEntry in urls) { string url = urlEntry; dcc.AllowAutoRedirect = true; if (!url.StartsWith("http://") && !url.StartsWith("https://") && !url.StartsWith("file://")) { url = new Uri(Path.GetFullPath(url)).ToString(); } dcc.DiscoverAny(url); dcc.ResolveAll(); } foreach (object doc in dcc.Documents.Values) { if (doc is ServiceDescription) { descriptions.Add((ServiceDescription)doc); } else if (doc is XmlSchema) { schemas.Add((XmlSchema)doc); } } if (descriptions.Count == 0) { Console.WriteLine("Warning: no classes were generated."); return(0); } } else { string[] names = className.Split(','); if (names.Length != 2) { throw new Exception("Invalid parameter value for 'type'"); } string cls = names[0].Trim(); string assembly = names[1].Trim(); Assembly asm = Assembly.LoadFrom(assembly); Type t = asm.GetType(cls); if (t == null) { throw new Exception("Type '" + cls + "' not found in assembly " + assembly); } ServiceDescriptionReflector reflector = new ServiceDescriptionReflector(); foreach (string url in urls) { reflector.Reflect(t, url); } foreach (XmlSchema s in reflector.Schemas) { schemas.Add(s); } foreach (ServiceDescription sd in reflector.ServiceDescriptions) { descriptions.Add(sd); } } if (sampleSoap != null) { ConsoleSampleGenerator.Generate(descriptions, schemas, sampleSoap, generator.Protocol); return(0); } // generate the code generator.GenerateCode(descriptions, schemas); return(0); } catch (NullReferenceException e) { Console.WriteLine(e); return(2); } catch (InvalidCastException e) { Console.WriteLine(e); return(2); } catch (Exception exception) { Console.WriteLine("Error: {0}", exception.Message); // FIXME: surpress this except for when debug is enabled //Console.WriteLine("Stack:\n {0}", exception.StackTrace); return(2); } }