Exemple #1
0
        public void GenerateCsvStub(string targetPath)
        {
            Program.Write("Generating CSV stub ...");
            using (var stream = new StreamWriter(targetPath, false, Encoding.UTF8))
            {
                var writer = new CsvWriter(stream, CsvService.GetDefaultCsvConfiguration());

                var dummyLine = new Dictionary <string, string>();
                foreach (var column in _configuration.Columns)
                {
                    dummyLine[column.Header] = "";
                }

                foreach (var field in dummyLine.Keys)
                {
                    writer.WriteField(field);
                }
                writer.NextRecord();
                foreach (var field in dummyLine.Keys)
                {
                    writer.WriteField(dummyLine[field]);
                }
            }

            Program.Write("CSV stub saved at '" + targetPath + "'.");
        }
        public static void Main(string[] args)
        {
            Write("Good Day. I hope you are doing well?");
            Write("");

            #region Command Line Arguments

            Write("Reading and verifying command line arguments ...");
            bool hasErrors;
            var commandLineArguments = new CommandLineService().ReadAndVerify(args, out hasErrors);
            if (hasErrors)
            {
                Write("Exiting ...");
                Environment.Exit(1);
            }
            Write("Command line arguments seem okay.");
            Write("");

            #endregion Command Line Arguments

            if (commandLineArguments.LogFile.HasValue())
            {
                _logFile = commandLineArguments.LogFile;
            }

            #region Configuration File

            Write("Reading and verifying configuration file ...");
            bool hasWarnings;
            var configuration = new ConfigurationService(commandLineArguments).ReadAndVerify(out hasErrors,
                out hasWarnings);
            if (hasErrors)
            {
                Write("Exiting ...");
                Environment.Exit(2);
            }
            if (hasWarnings)
            {
                ConfirmWarnings(commandLineArguments);
            }
            else
            {
                Write("Configuration file seems okay.");
            }
            Write("");

            #endregion Configuration File

            if (commandLineArguments.GenerateCsvStub)
            {
                new CsvStubService(configuration).GenerateCsvStub(commandLineArguments.CsvFile);
                Write("Exiting ...");
                Environment.Exit(0);
            }

            #region CSV file

            Write("Reading and verifying CSV file ...");
            var csv = new CsvService(commandLineArguments, configuration).ReadAndVerify(out hasErrors, out hasWarnings);
            if (hasErrors)
            {
                Write("Exiting ...");
                Environment.Exit(3);
            }
            if (hasWarnings)
            {
                ConfirmWarnings(commandLineArguments);
            }
            else
            {
                Write("CSV file seems okay.");
            }
            Write("");

            #endregion CSV file

            #region Import

            new ImportService(configuration, csv).RunImport(out hasErrors);
            if (hasErrors)
            {
                Write("Exiting ...");
                Environment.Exit(4);
            }
            Write("");

            #endregion Import

            Write("Everything done. Have a nice day.");
            Environment.Exit(0);
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            Write("Good Day. I hope you are doing well?");
            Write("");

            #region Command Line Arguments

            Write("Reading and verifying command line arguments ...");
            bool hasErrors;
            var  commandLineArguments = new CommandLineService().ReadAndVerify(args, out hasErrors);
            if (hasErrors)
            {
                Write("Exiting ...");
                Environment.Exit(1);
            }
            Write("Command line arguments seem okay.");
            Write("");

            #endregion Command Line Arguments

            if (commandLineArguments.LogFile.HasValue())
            {
                _logFile = commandLineArguments.LogFile;
            }

            #region Configuration File

            Write("Reading and verifying configuration file ...");
            bool hasWarnings;
            var  configuration = new ConfigurationService(commandLineArguments).ReadAndVerify(out hasErrors,
                                                                                              out hasWarnings);
            if (hasErrors)
            {
                Write("Exiting ...");
                Environment.Exit(2);
            }
            if (hasWarnings)
            {
                ConfirmWarnings(commandLineArguments);
            }
            else
            {
                Write("Configuration file seems okay.");
            }
            Write("");

            #endregion Configuration File

            if (commandLineArguments.GenerateCsvStub)
            {
                new CsvStubService(configuration).GenerateCsvStub(commandLineArguments.CsvFile);
                Write("Exiting ...");
                Environment.Exit(0);
            }

            #region CSV file

            Write("Reading and verifying CSV file ...");
            var csv = new CsvService(commandLineArguments, configuration).ReadAndVerify(out hasErrors, out hasWarnings);
            if (hasErrors)
            {
                Write("Exiting ...");
                Environment.Exit(3);
            }
            if (hasWarnings)
            {
                ConfirmWarnings(commandLineArguments);
            }
            else
            {
                Write("CSV file seems okay.");
            }
            Write("");

            #endregion CSV file

            #region Import

            new ImportService(configuration, csv).RunImport(out hasErrors);
            if (hasErrors)
            {
                Write("Exiting ...");
                Environment.Exit(4);
            }
            Write("");

            #endregion Import

            Write("Everything done. Have a nice day.");
            Environment.Exit(0);
        }