Пример #1
0
        public static int Main(string[] args)
        {
            Parameters parameters;

            try
            {
                var arguments = Andy.Cmd.ArgumentParser.ParseArguments(args);

                if (arguments.ContainsKey(Parameter.Keys.Help))
                {
                    Parameter.PrintInstructions(Console.WriteLine);
                    return(0);
                }

                parameters = Parameter.GetParametersOrThrow(arguments);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("There's a problem with command parameters:");
                Console.Error.WriteLine(e.Message);
                Parameter.PrintInstructions(Console.Error.WriteLine);
                return(-2);
            }

            Settings settings;

            try
            {
                settings = Andy.Cmd.JasonFileParser.ParseContents <Settings>(
                    new FileInfo(settingsFileName));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("There's a problem with the settings file:");
                Console.Error.WriteLine(e.Message);
                return(-50);
            }

            try
            {
                var delimiters = GetDelimiters(settings);

                ReportingFileComparer fileComparer = ComparerBuilder.BuildFileComparer(settings, delimiters);

                fileComparer.CompareAndWriteReport(
                    parameters.Source1File,
                    parameters.Source2File,
                    parameters.ComparisonReportFile,
                    settings.OutputCsvDelimiter);
            }
            catch (ExpenseReport.Comparison.Csv.InputParsingException e)
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.InnerException?.Message);

                return(-667);
            }
            catch (CsvStreamComparisonException e)
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.ActualException?.Message);

                return(ResolveReturnCode(e));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Unexpected error:");

                Andy.Cmd.ConsoleUtils.PrintErrorDetails(e);

                return(-1);
            }

            Console.WriteLine("Done");

            return(0);
        }