static void Main(string[] args) { var cmdLineModel = new CommandLineModel(); var commandLineWithoutBinaryReference = new List <string>(); commandLineWithoutBinaryReference.AddRange(Environment.GetCommandLineArgs()); commandLineWithoutBinaryReference.RemoveAt(0); var parseCmdLine = cmdLineModel.ConstructCommandLineModel(commandLineWithoutBinaryReference.ToArray()); if (parseCmdLine == CommandLineModel.ParseCommandLineStatus.DisplayHelp) { foreach (var line in cmdLineModel.HelpInfo) { Console.WriteLine(line); } } else { foreach (var line in cmdLineModel.ErrorInfo) { Console.WriteLine(line); } if (parseCmdLine == CommandLineModel.ParseCommandLineStatus.DisplayError) { Environment.Exit(1); } Console.WriteLine(""); indexify.Execute(cmdLineModel); } }
public static void Execute(CommandLineModel cmdLineModel) { try { SetupClassProperties(cmdLineModel); ProcessIndexes(); } catch (RestCallException ex) { VerboseLogLine($"ERROR: RESTFul Call Failed calling '{_currentResourceCall}'\n"); VerboseLogLine($"Http Status Code: {ex.StatusCode}\n"); VerboseLogLine($"Http Status Description: {ex.StatusDescription}\n"); if (ex.InnerException != null) { VerboseLogLine($"Exception: {ex.InnerException.Message}\n"); } VerboseLogLine(" : ("); } catch (Exception ex) { VerboseLogLine("ERROR: Unexpected Exception\n"); VerboseLogLine($"{ex.Message}\n"); VerboseLogLine(" : ("); } try { LogResults(); } catch { } VerboseLogLine("Operation Complete."); }
static void Run(CommandLineModel commandLine) { var defaultDirectory = commandLine.DefaultDirectory ?? Environment.CurrentDirectory; var fileNames = commandLine.GetFileNames(); var files = fileNames.Select(pair => new RootTraversable(pair.stem, new EpubRoot(Path.Combine(defaultDirectory, pair.path)))); var executor = new SafeConsoleQueryExecutor(commandLine.Query, files); foreach (var result in executor.Execute()) { PrintResult(result); } }
private static void SetupClassProperties(CommandLineModel cmdLineModel) { _commandLineModel = cmdLineModel; if (cmdLineModel.UseBasicAuth) { _IAuth = new HttpBasicAuthenticator(cmdLineModel.UserName, cmdLineModel.Password); } // See README.MD for more information //SimpleJson.CurrentJsonSerializerStrategy = new PocoJsonSerializerStrategy(); if (cmdLineModel.Verbose) { VerboseLogLine("Executing INDEXIFY with the following parameters:\n"); VerboseLogLine($"Source URL: {cmdLineModel.Url} "); VerboseLogLine($"Source Index Pattern: {cmdLineModel.SourceIndexPattern}"); if (!cmdLineModel.LogFile.FullName.IsNullOrEmpty()) { VerboseLogLine($"Log File: {cmdLineModel.LogFile}"); } if (cmdLineModel.UseBasicAuth) { VerboseLogLine($"Base Auth User: {cmdLineModel.UserName}"); } if (_commandLineModel.NoDestinationJustDelete) { VerboseLogLine($"WARNING: Source Indexes will be deleted with NO DATA COPY!"); } else { if (!_commandLineModel.DestinationIndex.IsNullOrEmpty()) { VerboseLogLine($"Destination Index Name: {cmdLineModel.DestinationIndex}"); } else { if (_commandLineModel.SourceMinusNumChars > 0) { VerboseLogLine( $"Destination Index will be source index name minus {_commandLineModel.SourceMinusNumChars} characters."); } if (!_commandLineModel.SourcePlusString.IsNullOrEmpty()) { VerboseLogLine( $"Destination Index will be source index name plus '{_commandLineModel.SourcePlusString}' appended to index name."); } } if (_commandLineModel.CopyOnly) { VerboseLogLine("Source index WILL NOT be deleted upon completely successful reindexing."); } } if (_commandLineModel.DryRun) { VerboseLogLine("Dry Run only."); } if (_commandLineModel.ScrollCount > 0) { VerboseLogLine($"Scroll Count: {_commandLineModel.ScrollCount}"); } VerboseLogLine(""); } }
private static void OutputModelInfo(CommandLineModel.ParseCommandLineStatus status, CommandLineModel model) { // Always display errors. if (status == CommandLineModel.ParseCommandLineStatus.DisplayError && model.ErrorInfo.Count > 0) { foreach (var error in model.ErrorInfo) { Logger.PushError(error); } Logger.LogError($"{CommandLineModel.AppBinaryName} Command Line Errors:"); } // Display help if asked. else if (status == CommandLineModel.ParseCommandLineStatus.DisplayHelp) { foreach (var info in model.HelpInfo) { Logger.PushInfo(info); } Logger.LogInfo($"{CommandLineModel.AppBinaryName} Help:"); } // Otherwise display the parameters that will be used for this execution run. else { if (model.ParameterInfo.Count > 0) { Logger.PushHeaderInfo($"{CommandLineModel.AppBinaryName} Execution Parameters"); foreach (var info in model.ParameterInfo) { Logger.PushInfo(info); } } if (model.ConsoleMode) { Logger.LogInfo($"{CommandLineModel.AppBinaryName} Started on {DateTime.Now} in Console Mode."); } else { Logger.LogInfo($"{CommandLineModel.AppBinaryName} Started on {DateTime.Now} in Service Mode."); } } }
static void Main(string[] args) { var model = new CommandLineModel(); var status = model.LoadParameterInfo(args); try { if (model.ConsoleMode) { var appTitle = $"{CommandLineModel.AppBinaryName} Service"; Console.Title = appTitle; Console.WriteLine(appTitle); Console.WriteLine(new string('=', appTitle.Length)); OutputModelInfo(status, model); if (status != CommandLineModel.ParseCommandLineStatus.ExecuteProgram) { Environment.ExitCode = 1; Thread.Sleep(500); // Allow NLog Console Logging. return; } var reliabilityService = new GDService(model); reliabilityService.OnStartConsoleMode(); Console.WriteLine("Hit any key to stop"); Console.ReadKey(); Console.WriteLine("Key Registered, Stopping ...."); reliabilityService.OnStopConsoleMode(); Thread.Sleep(500); // Allow NLog Console Logging. } else { if (status == CommandLineModel.ParseCommandLineStatus.DisplayError) { var sb = new StringBuilder(); foreach (var error in model.ErrorInfo) { sb.AppendLine(error); } throw new Exception(sb.ToString()); } // Set all defaults when runnning as a service if a command line wasn't set when installing the service. model.SetForServiceRun(); OutputModelInfo(CommandLineModel.ParseCommandLineStatus.ExecuteProgram, model); var service = new ServiceBase[] { new GDService(model), }; ServiceBase.Run(service); } } catch (Exception ex) { Logger.LogFatal($"{CommandLineModel.AppBinaryName} Startup Exception", ex); Thread.Sleep(500); // Allow NLog Console Logging. } }
public GDService(CommandLineModel model) { _commandLineModel = model; ServiceName = "NetworkJSON Guaranteed Delivery Service"; InitializeComponent(); }
public ActionResult CommandLine(CommandLineModel model) { return(View(model)); }