static async Task RunOptionsAsync(string[] args) { Sw.Start(); var options = new Options(); if (Parser.Default.ParseArguments(args, options)) { Console.WriteLine(ApplicationInfo.HeadingInfo); Console.WriteLine(ApplicationInfo.Copyright); Console.WriteLine(ApplicationInfo.Description); Console.WriteLine("Start processing url: " + options.Url); await ProcessComandLineAsync(options); } }
static async Task ProcessComandLineAsync(Options options) { //------- PocoSetting------ if (options.Key) _PocoSetting.AddKeyAttribute = true; if (options.Table) _PocoSetting.AddTableAttribute = true; if (options.Required) _PocoSetting.AddRequiredAttribute = true; if (options.Navigation) _PocoSetting.AddNavigation = true; if (options.AddNullableDataType) _PocoSetting.AddNullableDataType = true; // if (options.Url == null) return; //O2P o2p = options.User == null // ? new O2P(new Uri(options.Url), _PocoSetting) // : new O2P(new Uri(options.Url), options.User, options.Password, _PocoSetting); O2P o2p = new O2P(_PocoSetting); string code = ""; if (options.Url.StartsWith("http")) { code = await o2p.GenerateAsync(new Uri(options.Url), options.User, options.Password); // } else { var xml = File.ReadAllText(options.Url); code = o2p.Generate(xml); } // Console.WriteLine(code); //.Generate(_PocoSetting); Console.WriteLine("Saving generated code to file : " + options.CodeFilename); SaveToFile(options.CodeFilename, code, " c# code is empty"); //---------metafile -m if (options.MetaFilename != null) { Console.WriteLine(); //SaveMetaDataTo(options.MetaFilename); Console.WriteLine("Saving Metadata to file : {0}", options.MetaFilename); var metaData = FormatXml(o2p.MetaDataAsString); SaveToFile(options.MetaFilename, metaData, " Metadata is empty"); } //------------ header -h for http media only not file-------------------- if (options.Header && options.Url.StartsWith("http")) { // MetaDataInfo meta = o2p; Console.WriteLine(); Console.WriteLine("HTTP Header"); Console.WriteLine(new string('=', 15)); // o2p.MetaData.ServiceHeader.ToList().ForEach(m => o2p.ServiceHeader.ToList().ForEach(m => { Console.WriteLine(" {0}: {1}", m.Key, m.Value); }); } //---------list -l if (options.ListPoco) { Console.WriteLine(); Console.WriteLine("POCO classes (count: {0})", o2p.ClassList.Count); Console.WriteLine(new string('=', 20)); var items = o2p.ClassList.OrderBy(m => m.Name).ToList(); items.ForEach(m => { int index = items.IndexOf(m); var remoteUrl = string.IsNullOrEmpty(m.EntitySetName) ? "" : options.Url + @"/" + m.EntitySetName; // Console.WriteLine("{0}: {1} ", index + 1, m.Name); //v1.5 Console.WriteLine("{0}: {1} {2}", index + 1, m.Name, remoteUrl); }); } //---------verbose -v if (options.Verbose) { Console.WriteLine(); Console.WriteLine(code); } Sw.Stop(); Console.WriteLine(); Console.WriteLine("Total processing time: {0} sec", Sw.ElapsedMilliseconds / 1000.0); }