Example #1
0
        /// <summary>
        /// Do main logic e.g. command line swiches were ok
        /// </summary>
        /// <param name="opts">Options</param>
        private static void RunOptionsAndReturnExitCode(Models.CmdOptions opts, ILogger logger)
        {
            if (opts is null)
            {
                throw new ArgumentNullException(nameof(opts));
            }

            if (string.IsNullOrWhiteSpace(opts.ExportFileName) && string.IsNullOrWhiteSpace(opts.ImportFilename))
            {
                throw new ArgumentException("Either -i or -o must be specified");
            }

            var csv = new CsvUtility(new CsvOptions(), logger);

            if (!string.IsNullOrWhiteSpace(opts.ExportFileName))
            {
                dt = CreateData(opts);
                csv.WriteCsv(opts.ExportFileName, HandleCsvLineWrite);
            }

            if (!string.IsNullOrWhiteSpace(opts.ImportFilename))
            {
                csv.ReadCsv(opts.ImportFilename, HandleCsvLineRead);
            }

            logger.LogInformation("Exiting...");
        }
Example #2
0
        private static System.Data.DataTable CreateData(Models.CmdOptions opts)
        {
            var dice = new BlitzkriegSoftware.SecureRandomLibrary.SecureRandom();

            var d = new System.Data.DataTable();

            d.Columns.Add(new System.Data.DataColumn()
            {
                AllowDBNull = true, ColumnName = "Id", DataType = typeof(long), Unique = true
            });

            d.Columns.Add(new System.Data.DataColumn()
            {
                AllowDBNull = true, ColumnName = "IsDeleted", DataType = typeof(bool)
            });

            d.Columns.Add(new System.Data.DataColumn()
            {
                AllowDBNull = true, ColumnName = "Cash", DataType = typeof(decimal)
            });

            d.Columns.Add(new System.Data.DataColumn()
            {
                AllowDBNull = true, ColumnName = "Company", DataType = typeof(string), MaxLength = 512
            });

            d.Columns.Add(new System.Data.DataColumn()
            {
                AllowDBNull = true, ColumnName = "Multiplex", DataType = typeof(Double)
            });

            for (int i = 0; i < opts.MaxRows; i++)
            {
                var ia = new Object[]
                {
                    (long)i,
                    (i % 2 == 0),
                    (decimal)((double)dice.Next(1, 99) / 100) + dice.Next(1, 99),
                    Faker.Lorem.Word(),
                    (double)((double)dice.Next(1, 99) / 100) + dice.Next(100, 999)
                };
                d.Rows.Add(ia);
            }

            return(d);
        }