/// <summary> /// Sets up and issues the <see cref="LogsharkRequest"/> to the <see cref="LogsharkRequestProcessor"/>. /// </summary> /// <returns>Exit code</returns> public ExitCode Execute(LogsharkCommandLineOptions commandLineOptions) { if (commandLineOptions.ListPlugins) { try { LogsharkRequestProcessor.PrintAvailablePlugins(); return(ExitCode.Success); } catch (Exception ex) { Log.FatalFormat($"Unable to retrieve list of available plugins: {ex.Message}"); return(ExitCode.ExecutionError); } } try { var request = BuildLogsharkRequest(commandLineOptions); var requestProcessor = new LogsharkRequestProcessor(); var outcome = requestProcessor.ProcessRequest(request); return(outcome.IsRunSuccessful.Equals(true) ? ExitCode.Success : ExitCode.ExecutionError); } catch (Exception ex) { Log.Debug(ex.GetFlattenedMessage()); Log.Debug(ex.StackTrace); return(ExitCode.ExecutionError); } }
private LogsharkRequest BuildLogsharkRequest(LogsharkCommandLineOptions commandLineArgs) { var target = commandLineArgs.Target; if (string.IsNullOrWhiteSpace(target)) { throw new ArgumentException("No logset target specified! See 'logshark --help' for usage examples."); } // If the target is a relative path, we first need to convert it to an absolute path. if (!target.IsValidMD5() && !Path.IsPathRooted(target)) { target = Path.Combine(_currentWorkingDirectory, target); } try { var request = new LogsharkRequestBuilder(target, _configuration) .WithCustomId(commandLineArgs.Id) .WithDropParsedLogset(commandLineArgs.DropParsedLogset) .WithForceParse(commandLineArgs.ForceParse) .WithLocalMongoPort(commandLineArgs.LocalMongoPort) .WithMetadata(ParseCommandLineArgToDictionary(commandLineArgs.Metadata)) .WithPluginCustomArguments(ParseCommandLineArgToDictionary(commandLineArgs.CustomArgs)) .WithPluginsToExecute(commandLineArgs.Plugins) .WithPostgresDatabaseName(commandLineArgs.DatabaseName) .WithProcessFullLogset(commandLineArgs.ParseAll) .WithProjectDescription(commandLineArgs.ProjectDescription) .WithProjectName(commandLineArgs.ProjectName) .WithPublishWorkbooks(commandLineArgs.PublishWorkbooks) .WithSiteName(commandLineArgs.SiteName) .WithSource("CLI") .WithStartLocalMongo(commandLineArgs.StartLocalMongo) .WithWorkbookTags(commandLineArgs.WorkbookTags) .GetRequest(); return(request); } catch (Exception ex) { Log.FatalFormat($"Invalid request: {ex.Message}"); throw; } }
/// <summary> /// The entry point for the application. /// </summary> /// <param name="args">Command line arguments.</param> /// <returns>Exit code indicating whether program execution was successful.</returns> private static int Main(string[] args) { // Enable TLS v1.2 for the whole application ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // Store CWD in case the executing assembly is being run from the system PATH. var currentWorkingDirectory = Environment.CurrentDirectory; // Initialize log4net settings. var assemblyLocation = Assembly.GetExecutingAssembly().Location; Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyLocation)); try { XmlConfigurator.Configure(new FileInfo(ConfigurationManager.AppSettings[Log4NetConfigKey])); } catch (Exception ex) { Log.FatalFormat($"Failed to initialize logging: {ex.Message}"); return((int)ExitCode.InitializationError); } // Parse command line args. Log.DebugFormat($"Logshark execution arguments: {string.Join(" ", args)}"); var options = new LogsharkCommandLineOptions(); if (!Parser.Default.ParseArgumentsStrict(args, options, () => Log.Fatal("Unable to parse the provided arguments. Please check your syntax and try again."))) { // Parsing failed, exit with failure code. return((int)ExitCode.ArgumentParsingError); } // Execute! try { var logsharkCli = new LogsharkCLI(currentWorkingDirectory); return((int)logsharkCli.Execute(options)); } catch (Exception) { return((int)ExitCode.ExecutionError); } }
/// <summary> /// The entry point for the application. /// </summary> /// <param name="args">Command line arguments.</param> /// <returns>0 if program execution was successful; 1 otherwise.</returns> private static int Main(string[] args) { // Store CWD in case the executing assembly is being run from the system PATH. string currentWorkingDirectory = Environment.CurrentDirectory; // Initialize log4net settings. var assemblyLocation = Assembly.GetExecutingAssembly().Location; Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyLocation)); try { XmlConfigurator.Configure(new FileInfo(ConfigurationManager.AppSettings[Log4NetConfigKey])); } catch (Exception ex) { Log.FatalFormat("Failed to initialize logging: {0}", ex.Message); return(1); } // Parse command line args. Log.DebugFormat("Logshark execution arguments: {0}", String.Join(" ", args)); LogsharkCommandLineOptions options = new LogsharkCommandLineOptions(); if (!Parser.Default.ParseArgumentsStrict(args, options)) { // Parsing failed, exit with failure code. return(1); } // Execute! try { var logsharkCli = new LogsharkCLI(options, currentWorkingDirectory); logsharkCli.Execute(); return(0); } catch (Exception) { return(1); } }
public LogsharkCLI(LogsharkCommandLineOptions commandLineOptions, string currentWorkingDirectory) { configuration = LogsharkConfigReader.LoadConfiguration(); this.commandLineOptions = commandLineOptions; this.currentWorkingDirectory = currentWorkingDirectory; }