Exemple #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="options"></param>
 public FileContentUpdater(UpdaterOptions options)
 {
     Options = options;
 }
Exemple #2
0
        static int Main(string[] args)
        {
            mLastProgressTime = DateTime.UtcNow;

            var asmName = typeof(Program).GetTypeInfo().Assembly.GetName();
            var exeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);       // Alternatively: System.AppDomain.CurrentDomain.FriendlyName
            var version = UpdaterOptions.GetAppVersion();

            var parser = new CommandLineParser <UpdaterOptions>(asmName.Name, version)
            {
                ProgramInfo = "This program searches for files in a directory that match the specified name, " +
                              "then updates the files to find and replace text in the files.",

                ContactInfo = "Program written by Matthew Monroe for the Department of Energy" + Environment.NewLine +
                              "(PNNL, Richland, WA) in 2019" +
                              Environment.NewLine + Environment.NewLine +
                              "E-mail: [email protected] or [email protected]" + Environment.NewLine +
                              "Website: https://panomics.pnnl.gov/ or https://omics.pnl.gov",

                UsageExamples =
                {
                    exeName + @" C:\WorkDir /F:runstart.txt /T:SearchReplace.txt /Preview",
                    exeName + @" C:\WorkDir /F:runstart.txt /T:SearchReplace.txt /S /Preview",
                    exeName + @" C:\WorkDir /F:runstart.txt;tic_front.csv /T:SearchReplace.txt /S",
                }
            };

            var parseResults = parser.ParseArgs(args);
            var options      = parseResults.ParsedResults;

            try
            {
                if (!parseResults.Success)
                {
                    Thread.Sleep(1500);
                    return(-1);
                }

                if (!options.ValidateArgs(out var errorMessage))
                {
                    parser.PrintHelp();

                    Console.WriteLine();
                    ConsoleMsgUtils.ShowWarning("Validation error:");
                    ConsoleMsgUtils.ShowWarning(errorMessage);

                    Thread.Sleep(1500);
                    return(-1);
                }

                options.OutputSetOptions();
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.Write($"Error running {exeName}");
                Console.WriteLine(e.Message);
                Console.WriteLine($"See help with {exeName} --help");
                return(-1);
            }

            try
            {
                var processor = new FileContentUpdater(options);

                processor.ErrorEvent   += Processor_ErrorEvent;
                processor.StatusEvent  += Processor_StatusEvent;
                processor.WarningEvent += Processor_WarningEvent;

                var success = processor.ReplaceTextInFiles();

                if (success)
                {
                    Console.WriteLine();
                    Console.WriteLine("Search complete");
                    Thread.Sleep(1500);
                    return(0);
                }

                ConsoleMsgUtils.ShowWarning("Processing error");
                Thread.Sleep(2000);
                return(-1);
            }
            catch (Exception ex)
            {
                ConsoleMsgUtils.ShowError("Error occurred in Program->Main", ex);
                Thread.Sleep(2000);
                return(-1);
            }
        }