static void Main(string[] args) { Task.Run(async () => { try { var arguments = new Docopt().Apply(Usage, args, version: "Seq Query 0.1", exit: true); var server = arguments["<server>"].ToString(); var query = Normalize(arguments["<query>"]); var apiKey = Normalize(arguments["--apikey"]); var @from = Normalize(arguments["--from"]); var to = Normalize(arguments["--to"]); await Run(server, apiKey, query, from, to); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("seq-query: {0}", ex); Console.ResetColor(); Environment.Exit(-1); } }).Wait(); }
private void GetCommandLineConfiguration(string[] args) { var docopt = new Docopt(); IDictionary<string, ValueObject> res = docopt.Apply(Usage, args, help: true, exit: true); _ocdmModelExportPath = res["--modelExport"] == null ? _ocdmModelExportPath : res["--modelExport"].ToString(); _readerName = res["--reader"] == null ? _readerName : res["--reader"].ToString(); _writerName = res["--writer"] == null ? _writerName : res["--writer"].ToString(); if (res["--outputPath"] == null) { // do nothing, rely on default } else if (res["--outputPath"].ToString() == String.Empty) { _outputPath = @".\"; // current working directory } else { _outputPath = res["--outputPath"].ToString(); } _metadataPath = res["<inputFile>"] == null ? _metadataPath : res["<inputFile>"].ToString(); }
public static string Docopt(string doc, string[] cmdLine) { try { var arguments = new Docopt().Apply(doc, cmdLine); var dict = new Dictionary<string, object>(); foreach (var argument in arguments) { if (argument.Value == null) dict[argument.Key] = null; else if (argument.Value.IsList) { var l = new ArrayList(); foreach (var v in argument.Value.AsList) { if (v is ValueObject) l.Add(((v) as ValueObject).Value); else l.Add(v); } dict[argument.Key] = l; } else dict[argument.Key] = argument.Value.Value; } return JsonConvert.SerializeObject(dict); } catch (Exception) { return "\"user-error\""; } }
static void Main(string[] args) { var cts = new CancellationTokenSource(); // ReSharper disable once MethodSupportsCancellation var tail = Task.Run(async () => { try { var arguments = new Docopt().Apply(Usage, args, version: "Seq Tail 0.2", exit: true); var server = arguments["<server>"].ToString(); var apiKey = Normalize(arguments["--apikey"]); var filter = Normalize(arguments["--filter"]); var window = arguments["--window"].AsInt; await Run(server, apiKey, filter, window, cts.Token); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("seq-tail: {0}", ex); Console.ResetColor(); Environment.Exit(-1); } }); Console.ReadKey(true); cts.Cancel(); // ReSharper disable once MethodSupportsCancellation tail.Wait(); }
/// <summary> /// Service main entry point /// </summary> /// <param name="args"> /// Startup parameters /// </param> public static void Main(string[] args) { // preset logger var loggerConfig = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.ColoredConsole(); var logger = loggerConfig.CreateLogger(); Log.Logger = logger; var arguments = new Docopt().Apply(CommandUsage, args, exit: true); var configurations = new List<string>(); ValueObject config; if (arguments.TryGetValue("--config", out config) && config != null) { configurations.Add(config.ToString()); } Container = new WindsorContainer(); AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { Log.Logger.Error( eventArgs.ExceptionObject as Exception, "{Type}: Unhandled domain exception from {SenderType}, terminating: {IsTerminating}\n{StackTrace}", "System", sender?.GetType().Name ?? "unknown", eventArgs.IsTerminating, (eventArgs.ExceptionObject as Exception)?.StackTrace); }; var system = Bootstrapper.ConfigureAndStart(Container, configurations.ToArray()); Log.Logger.Warning("{Type}: Started", "System"); Console.CancelKeyPress += (sender, eventArgs) => { Log.Logger.Warning("{Type}: Shutdown sequence initiated", "System"); var cluster = Akka.Cluster.Cluster.Get(system); var timeout = TimeSpan.FromSeconds(10); if (cluster.IsTerminated || cluster.State.Members.Count == 0) { system.Terminate().Wait(timeout); } else { cluster.LeaveAsync().Wait(timeout); system.Terminate().Wait(timeout); } Log.Logger.Warning("{Type}: Hard stopped", "System"); eventArgs.Cancel = true; }; system.StartNameSpaceActorsFromConfiguration(); BaseInstaller.RunPostStart(Container); var waitedTask = new System.Threading.Tasks.TaskCompletionSource<bool>(); system.WhenTerminated.ContinueWith(task => waitedTask.SetResult(true)); waitedTask.Task.Wait(); Log.Logger.Warning("{Type}: Stopped", "System"); }
private static void Main(string[] args) { var arguments = new Docopt().Apply(usage, args, version: "Naval Fate 2.0"); foreach (var argument in arguments) { Console.WriteLine("{0} = {1}", argument.Key, argument.Value); } }
static void Main(string[] args) { const string usage = @"Fluent Migrator Schema Dumper Usage: SchemaDumper.exe --connection CONNECTION [--file FILE] [--verbose] [--show] [--open] SchemaDumper.exe --version SchemaDumper.exe --help Options: --connection CONNECTION -c CONNECTION The connection string. Required. --file FILE -f FILE File to output. Optional. [default: schemaDump.cs] --show -s Show output. Optional. --open -o Open file. Optional. --verbose Verbose. Optional. --help -h Show this screen. --version -v Show version. "; var arguments = new Docopt().Apply(usage, args, version: Assembly.GetExecutingAssembly().GetName().Version, exit: true); var file = arguments["--file"].ToString(); var verbose = arguments["--verbose"].IsTrue; var open = arguments["--open"].IsTrue; var show = arguments["--show"].IsTrue; if (!Path.IsPathRooted(file)) file = Path.Combine(Environment.CurrentDirectory, file); var connectionString = arguments["--connection"].ToString(); if (verbose) WriteLine($"Saving to {file}."); try { var builder = new SqlConnectionStringBuilder(connectionString); } catch (ArgumentException) { WriteLine("Connection string is in incorrect format."); return; } using (var connection = new SqlConnection(connectionString)) { try { connection.Open(); } catch (SqlException ex) { WriteLine($"Connection couldn't be established:\n{ex.Message}"); return; } var consoleAnnouncer = new ConsoleAnnouncer(); var dumper = new SqlServerSchemaDumper(new SqlServerProcessor(connection, new SqlServer2000Generator(), consoleAnnouncer, new ProcessorOptions(), new SqlServerDbFactory()), consoleAnnouncer); var tables = dumper.ReadDbSchema(); var writer = new RCDumpWriter(); writer.WriteToFile(tables, file); } if (show) WriteLine(File.ReadAllText(file)); if (open) try { Process.Start(file); } catch { } if (verbose) WriteLine("Done."); }
private static void Main(string[] args) { try { var arguments = new Docopt().Apply(usage, args, version: "Naval Fate 2.0", exit: true); foreach (var argument in arguments) { Console.WriteLine("{0} = {1}", argument.Key, argument.Value); } } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { string templateHtml = null; var verbose = false; try { var arguments = new Docopt().Apply(Usage, args); verbose = arguments["--verbose"].IsTrue; if (arguments["--version"].IsTrue) { Console.WriteLine(Assembly.GetExecutingAssembly().GetName().Version); return; } if (arguments["--template"] != null) { var templateFilename = arguments["--template"].ToString(); var templatePath = Path.GetFullPath(templateFilename); templateHtml = File.ReadAllText(templatePath); if (verbose) Console.WriteLine("Using template " + templatePath); } var md = new Markdown(); var paths = arguments["FILES"].AsList.ToArray(); var files = paths.SelectMany(x => GlobFiles(x.ToString())); foreach (var fileName in files) { if(verbose) Console.WriteLine("Processing " + fileName); var markdown = File.ReadAllText(fileName); var html = md.Transform(markdown); var outPath = GetOutputPath(fileName); if (templateHtml != null) { html = templateHtml.Replace("{{ MarkItHere }}", html); } File.WriteAllText(outPath, html); } } catch (Exception ex) { Console.WriteLine(verbose ? ex.ToString() : ex.Message); } }
protected CommandLineArgsBase(ICollection<string> argv, bool help = true, object version = null, bool optionsFirst = false, bool exit = false) { Args = new Docopt().Apply(UsageText, argv, help, version, optionsFirst, exit); }
public void Main(string[] args) { const string usage = @"Fluent Migrator DNX Runner Usage: dnx . run --provider PROVIDER --connectionString CONNECTION [--assembly ASSEMBLY] [--output FILE] [--task TASK] [--migrateToVersion VERSION] [--profile PROFILE] [--tag TAG] [--verbose] dnx . run --version dnx . run --help Options: --provider PROVIDER -p PROVIDER Database type. Possible values: * sqlserver2000 * sqlserver2005 * sqlserver2008 * sqlserver2012 * sqlserverce * sqlserver * mysql * postgres * oracle * sqlite * jet --connectionString CONNECTION -c CONNECTION The connection string. Required. --assembly ASSEMBLY -a ASSEMBLY Optional. The project or assembly which contains the migrations You may use a dll path or a path do DNX project. It will default to the current path. --output FILE -o FILE File to output the script. If specified will write to a file instead of running the migration. [default: migration.sql] --task TASK -t TASK The task to run. [default: migrate] --migrateToVersion VERSION The specific version to migrate. Default is 0, which will run all migrations. [default: 0] --profile PROFILE The profile to run after executing migrations. --tag TAG Filters the migrations to be run by tag. --verbose Verbose. Optional. --help -h Show this screen. --version -v Show version. "; var argsWithRun = new[] { ".", "run" }.Union(args).ToArray(); var arguments = new Docopt().Apply(usage, argsWithRun, version: Assembly.GetExecutingAssembly().GetName().Version, exit: true); verbose = arguments["--verbose"].IsTrue; provider = arguments["--provider"].ToString(); connection = arguments["--connectionString"].ToString(); assembly = (arguments["--assembly"] != null) ? assembly = arguments["--assembly"].ToString() : appEnvironment.ApplicationBasePath; if (!Path.IsPathRooted(assembly)) assembly = Path.GetFullPath(Path.Combine(appEnvironment.ApplicationBasePath, assembly)); if (string.Compare(Path.GetExtension(assembly), ".dll", StringComparison.OrdinalIgnoreCase) == 0) { if (!File.Exists(assembly)) { WriteLine($"File {assembly} does not exist."); return; } } else { if (assembly.Substring(assembly.Length - 1)[0] == Path.DirectorySeparatorChar) assembly = assembly.Substring(0, assembly.Length - 1); if (!Directory.Exists(assembly)) { WriteLine($"Directory {assembly} does not exist."); return; } assembly = DnuBuild(); if (assembly == null) return; } if (arguments["--task"] != null) task = arguments["--task"].ToString(); if (arguments["--migrateToVersion"] != null) migrateToVersion = arguments["--migrateToVersion"].AsLong(); if (arguments["--profile"] != null) profile = arguments["--profile"].ToString(); if (arguments["--tag"] != null) tags = arguments["--tag"].AsList.Cast<string>(); if (arguments["--output"].ToString() == "migration.sql") ExecuteMigrations(); else ExecuteMigrations(arguments["--output"].ToString()); }
public int Execute(string [] args) { TextReader input = Console.In; TextWriter output = Console.Out; var sc = new ServiceContainer(); var rekoCfg = RekoConfigurationService.Load(); sc.AddService<IConfigurationService>(rekoCfg); var docopt = new Docopt(); IDictionary<string, ValueObject> options; try { options = docopt.Apply(usage, args); } catch (Exception ex) { Console.Error.WriteLine(ex); return 1; } var arch = rekoCfg.GetArchitecture(options["-a"].ToString()); if (arch == null) { Console.WriteLine( "c2xml: unknown architecture '{0}'. Check the c2xml config file for supported architectures.", options["-a"]); return -1; } var envElem = rekoCfg.GetEnvironment(options["-e"].ToString()); if (envElem == null) { Console.WriteLine( "c2xml: unknown environment '{0}'. Check the c2xml config file for supported architectures.", options["-e"]); return -1; } var platform = envElem.Load(sc, arch); try { input = new StreamReader(options["<inputfile>"].ToString()); } catch (Exception ex) { Console.Error.WriteLine("c2xml: unable to open file {0} for reading. {1}", options["<inputfile>"], ex.Message); return 1; } if (options.ContainsKey("<outputfile>") && options["<outputfile>"] != null) { try { output = new StreamWriter(options["<outputfile>"].ToString()); } catch (Exception ex) { Console.Error.WriteLine("c2xml: unable to open file {0} for writing. {1}", options["<outputfile>"], ex.Message); return 1; } } var xWriter = new XmlTextWriter(output) { Formatting = Formatting.Indented }; XmlConverter c = new XmlConverter(input, xWriter, platform); c.Convert(); output.Flush(); return 0; }
public static int Main(string[] args) { // call scanner and process all files with selected command var cmd_map = new Dictionary<string, Type> { { "validate", typeof(Validator) }, { "info", typeof(Info) }, { "elfinfo", typeof(ElfInfo) }, { "relocate", typeof(Relocate) }, { "signatures", typeof(SignatureGenerator) } }; var docopt = new Docopt(); var options = docopt.Apply(Program.options, args); var cmd = options["<command>"].Value.ToString(); if (!cmd_map.ContainsKey(cmd)) { Console.WriteLine("INVALID COMMAND:", cmd); Console.WriteLine("valid commands are:"); foreach (var a in cmd_map) { Console.WriteLine(" ", a); } return 1; } var cmd_cls = cmd_map[cmd]; // execute command var cmdInst = (HunkCommand)Activator.CreateInstance(cmd_cls, options); cmdInst.Output = System.Console.Out; var res = cmdInst.run(); return res ? 0 : 1; }
public static void Main(string[] args) { var traceOutput = new DvnrTraceListener("ContrastDvnr.log", "tracelog"); Trace.Listeners.Add(traceOutput); Trace.AutoFlush = true; var arguments = new Docopt().Apply(usage, args, version: "ContrastDvnr 1.0", exit: true); Trace.TraceInformation("ContrastDvnr executed with arguments [{0}]", string.Join(" ", args)); // ensure IIS is installed and we can use ServerManager if (!Reporting.PreFlightCheck()) { return; } bool isXml = arguments["xml"].IsTrue; bool isJson = arguments["json"].IsTrue; bool isText = arguments["text"].IsTrue; // default to xml if no format is specified if (!isXml && !isJson && !isText) isXml = true; string fileName = "report.xml"; string inFilename = arguments["--file"].ToString(); if(inFilename != "report.xml") { fileName = inFilename; } else { // set default report file names if (isXml) fileName = "report.xml"; else if (isJson) fileName = "report.json"; else if (isText) fileName = "report.txt"; } Console.Out.WriteLine("Gathering machine information"); var machineInformation = Reporting.GetMachineInformation(); Console.Out.WriteLine("Gathering site information"); var sites = Reporting.GetSites(); Console.Out.WriteLine("Gathering app pool information"); var appPools = Reporting.GetAppPools(); // set number of apps using each pool and remove ones that aren't used foreach (var appPool in appPools) { appPool.NumApplications = sites.SelectMany(s => s.Applications).Select(s => s.AppPoolName).Count(name => name == appPool.Name); } appPools.RemoveAll(pool => pool.NumApplications == 0); Console.Out.WriteLine("Gathering GAC library information"); var gacLibraries = Reporting.GetGACLibraries(); var report = new DvnrReport { MachineInformation = machineInformation, Sites = sites, AppPools = appPools, GacLibraries = gacLibraries }; if (arguments["--screen"].IsTrue) // write to screen instead of file { if (isXml) PrintReportXml(report, Console.Out); if (isJson) PrintReportJson(report, Console.Out); if (isText) PrintReportText(report, Console.Out); } else { // write to file try { string filePath = Path.Combine(Environment.CurrentDirectory, fileName); File.Delete(filePath); using (var file = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(file)) { if (isXml) PrintReportXml(report, sw); if (isJson) PrintReportJson(report, sw); if (isText) PrintReportText(report, sw); Console.WriteLine("Report was written to: {0}", filePath); } } } catch (Exception ex) { Trace.TraceError("Could not save report file. Error: {0}", ex.ToString()); Console.WriteLine("Could not save report file"); } } Trace.TraceInformation("ContrastDvnr exited"); Trace.Flush(); }
static void Main(string[] args) { var arguments = new Docopt().Apply(Usage, args, exit: true); var kernel = CreateConfiguretedDIContainer(arguments); try { kernel.Get<Program>(); } catch (Exception ex) { Console.WriteLine(ex); } }