private static int Main(string[] args) { SetProfile(); ArgumentParseResult arguments; var console = new ScriptConsole(); try { var parser = new ArgumentHandler(new ArgumentParser(), new ConfigFileParser(console), new FileSystem()); arguments = parser.Parse(args); } catch (Exception ex) { console.WriteLine(ex.Message); var options = new ArgUsageOptions { ShowPosition = false, ShowType = false }; var usage = ArgUsage.GetUsage <ScriptCsArgs>(options: options); console.WriteLine(usage); return(1); } finally { console.Exit(); } var scriptServicesBuilder = ScriptServicesBuilderFactory.Create(arguments.CommandArguments, arguments.ScriptArguments); var factory = new CommandFactory(scriptServicesBuilder); var command = factory.CreateCommand(arguments.CommandArguments, arguments.ScriptArguments); return((int)command.Execute()); }
static void Main(string[] args) { // Set version Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; Console.WriteLine(""); Console.WriteLine("PPD - Parse Performance Data v{0}", version); Console.WriteLine("Copyright (C) 2010-2016 Ryan Bijkerk"); Console.WriteLine("Logit Blog - www.logitblog.com"); Console.WriteLine(""); // Check for Excel 2013 or 2016 var ExcelCheck = new ReportHandler(); ExcelCheck.Version(); // Check the arguments var argumentHandler = new ArgumentHandler(); var arguments = argumentHandler.Parse(args); // Collecting the metrics var settingsMetric = new MetricsHandler(); var metrics = settingsMetric.Load(); // File parsing var file = new FileItemHandler(); var report = new ReportHandler(); // Start for the timer var startTime = DateTime.Now; foreach (var fileItem in arguments.fileLocation) { // File Check file.Check(fileItem); Console.WriteLine("{0}: Working on file: {1}", DateTime.Now, fileItem); // File Parse for the data var fileResults = file.Parse(fileItem, metrics); // File time interval data var fileTime = file.Time(fileItem); // Create Excel file var reportFile = report.Create(fileItem); Console.WriteLine("{0}: Creating Excel report on location: {1}", DateTime.Now, reportFile); // Add data to Excel file report.AddData(reportFile, fileResults, fileTime); // Add charts to Excel file report.AddCharts(reportFile); } // Done and reporting total time var stopTime = DateTime.Now; Console.WriteLine("{0}: Done in {1} sec! ", DateTime.Now, Math.Round(stopTime.Subtract(startTime).TotalSeconds)); }
private static int Main(string[] args) { ProfileOptimization.SetProfileRoot(typeof(Program).Assembly.Location); ProfileOptimization.StartProfile(typeof(Program).Assembly.GetName().Name + ".profile"); var console = new ScriptConsole(); var parser = new ArgumentHandler(new ArgumentParser(console), new ConfigFileParser(console), new FileSystem()); var arguments = parser.Parse(args); var commandArgs = arguments.CommandArguments; var scriptArgs = arguments.ScriptArguments; var configurator = new LoggerConfigurator(commandArgs.LogLevel); configurator.Configure(console); var logger = configurator.GetLogger(); var scriptServicesBuilder = new ScriptServicesBuilder(console, logger) .Cache(commandArgs.Cache) .Debug(commandArgs.Debug) .LogLevel(commandArgs.LogLevel) .ScriptName(commandArgs.ScriptName) .Repl(commandArgs.Repl); var modules = GetModuleList(commandArgs.Modules); var extension = Path.GetExtension(commandArgs.ScriptName); if (string.IsNullOrWhiteSpace(extension) && !commandArgs.Repl) { // No extension was given, i.e we might have something like // "scriptcs foo" to deal with. We activate the default extension, // to make sure it's given to the LoadModules below. extension = ".csx"; if (!string.IsNullOrWhiteSpace(commandArgs.ScriptName)) { // If the was in fact a script specified, we'll extend it // with the default extension, assuming the user giving // "scriptcs foo" actually meant "scriptcs foo.csx". We // perform no validation here thought; let it be done by // the activated command. If the file don't exist, it's // up to the command to detect and report. commandArgs.ScriptName += extension; } } scriptServicesBuilder.LoadModules(extension, modules); var scriptServiceRoot = scriptServicesBuilder.Build(); var commandFactory = new CommandFactory(scriptServiceRoot); var command = commandFactory.CreateCommand(commandArgs, scriptArgs); var result = command.Execute(); return(result == CommandResult.Success ? 0 : -1); }
private static ArgumentParseResult ParseArguments(string[] args) { var console = new ScriptConsole(); try { var parser = new ArgumentHandler(new ArgumentParser(console), new ConfigFileParser(console), new FileSystem()); return(parser.Parse(args)); } finally { console.Exit(); } }
public void ShouldUseScriptOptsIfParsingFailed() { var parser = new Mock <IArgumentParser>(); parser.Setup(x => x.Parse(It.IsAny <string[]>())).Returns <ScriptCsArgs>(null); var system = new Mock <IFileSystem>(); system.Setup(x => x.CurrentDirectory).Returns(@"C:"); var configParser = new Mock <IConfigFileParser>(); var argumentHandler = new ArgumentHandler(parser.Object, configParser.Object, system.Object); var result = argumentHandler.Parse(new string[0]); system.Verify(x => x.FileExists(@"C:\scriptcs.opts"), Times.Once()); }
private static int Main(string[] args) { var console = new ScriptConsole(); var parser = new ArgumentHandler(new ArgumentParser(console), new ConfigFileParser(console), new FileSystem()); var arguments = parser.Parse(args); var commandArgs = arguments.CommandArguments; var scriptArgs = arguments.ScriptArguments; var configurator = new LoggerConfigurator(commandArgs.LogLevel); configurator.Configure(console); var logger = configurator.GetLogger(); var scriptServicesBuilder = new ScriptServicesBuilder(console, logger) .InMemory(commandArgs.InMemory) .LogLevel(commandArgs.LogLevel) .ScriptName(commandArgs.ScriptName) .Repl(commandArgs.Repl); var modules = GetModuleList(commandArgs.Modules); var extension = Path.GetExtension(commandArgs.ScriptName); if (!string.IsNullOrWhiteSpace(extension)) { extension = extension.Substring(1); } else if (extension == string.Empty) { console.WriteLine(string.Format("{0} is not a valid script name.", commandArgs.ScriptName)); return(1); } scriptServicesBuilder.LoadModules(extension, modules); var scriptServiceRoot = scriptServicesBuilder.Build(); var commandFactory = new CommandFactory(scriptServiceRoot); var command = commandFactory.CreateCommand(commandArgs, scriptArgs); var result = command.Execute(); return(result == CommandResult.Success ? 0 : -1); }