Beispiel #1
0
        public void Execute(object parameter)
        {
            IDataImporter dataImporter = new CsvImporter();

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "Document";
            dlg.DefaultExt = ".txt";
            dlg.Filter     = "CSV documents (.csv)|*.csv|Text documents (.txt)|*.txt|All Files (*.*)|*.*";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                DataTable d;
                try
                {
                    d = dataImporter.Import(dlg.FileName);
                    _ivm.FeedData(d, true);
                }
                catch
                {
                    _ivm.FeedData(null, false);
                }
            }
            else
            {
                _ivm.FeedData(null, false);
            }
        }
Beispiel #2
0
        public async Task TestRecordAsync()
        {
            Recorder <CloseChangeRecordModel> recorder = new("Test", AppDomain.CurrentDomain.BaseDirectory);
            DateTime date = DateTime.Now;

            recorder.Insert(new CloseChangeRecordModel {
                CoinBalance1 = 1, Balance = 2, Assets = 3, Date = date
            });
            recorder.Insert(new CloseChangeRecordModel {
                CoinBalance1 = 4, Balance = 5, Assets = 6, Date = date
            });
            await recorder.SaveAsync();

            IImporter importer = new CsvImporter();
            var       result   = (await importer.Import <CloseChangeRecordModel>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test.csv"))).Data.ToList();

            Assert.AreEqual(date.ToString(), result[0].Date.ToString());
            Assert.AreEqual(1, result[0].CoinBalance1);
            Assert.AreEqual(2, result[0].Balance);
            Assert.AreEqual(3, result[0].Assets);
            Assert.AreEqual(date.ToString(), result[1].Date.ToString());
            Assert.AreEqual(4, result[1].CoinBalance1);
            Assert.AreEqual(5, result[1].Balance);
            Assert.AreEqual(6, result[1].Assets);
        }
Beispiel #3
0
        //------------------------------------------------------------------------

        public ResultInfo <Object> ImportFromExcel(String pathOfExcel)
        {
            ResultInfo <Object> resultInfo = new ResultInfo <Object> ();

            ListOfModelDirectory.Clear();

            try
            {
                FactoryModelDirectory factoryModelDirectory = new FactoryModelDirectory(this);

                CsvImporter csvImport = new CsvImporter(pathOfExcel);

                List <int> listOfNumbers = csvImport.Import();

                foreach (int number in listOfNumbers)
                {
                    ListOfModelDirectory.Add(factoryModelDirectory.Construct(number));
                }

                if (listOfNumbers.Count == 0)
                {
                    resultInfo.SetResult(1, "Es konnten keine Verzeichnisse gefunden werden", null);
                }
                else
                {
                    resultInfo.SetResult(0, "", null);
                }
            }
            catch (Exception)
            {
                ListOfModelDirectory.Clear();
            }

            return(resultInfo);
        }
Beispiel #4
0
        public void TestImportThrowsExceptionOnInvalidSetup()
        {
            string input = "asdjhskhbjfdbsnfbjndklbn";
            var    sut   = new CsvImporter(GameMode.Solo, GamePerspective.FPP, 4, new Func <IMatchBuilder, string, IMatchBuilder>[]
            {
                (builder, s) => builder,
                (builder, s) => builder
            });

            Assert.Throws <ArgumentException>(() => sut.Import(input));
        }
Beispiel #5
0
        protected static async Task <KlineModel[]> LoadCSVAsync(string path)
        {
            IImporter importer = new CsvImporter();
            var       result   = await importer.Import <KlineModel>(path);

            if (result.HasError)
            {
                throw result.Exception;
            }

            return(result.Data.DistinctBy(item => item.Date).OrderBy(item => item.Date).ToArray());
        }
        private async Task <int> ImportRecords <T>(IFormFile postedFile, CsvImporter <T> importer) where T : class
        {
            using (var reader = new StreamReader(postedFile.OpenReadStream()))
            {
                IEnumerable <T> records = importer.Import(reader);
                foreach (T record in records)
                {
                    _context.Add(record);
                }
            }
            int inserted = await _context.SaveChangesAsync();

            return(inserted);
        }
Beispiel #7
0
        public Task Run()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("IMPORT DATA\n");
            Console.ResetColor();
            Console.WriteLine(
                $"Input dir: {_inputDir}\n" +
                $"Input mask: {_fileMask}\n" +
                $"DB name: {_dbName}\n");

            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddSerilog(Log.Logger);

            string      csTemplate = _config.GetConnectionString("Census");
            string      cs         = string.Format(csTemplate, _dbName);
            CsvImporter importer   = new CsvImporter(cs)
            {
                Logger = loggerFactory.CreateLogger("import")
            };

            IDbManager manager = new MySqlDbManager(csTemplate);

            if (!manager.Exists(_dbName))
            {
                manager.CreateDatabase(
                    _dbName,
                    CsvImporter.GetTargetSchema(),
                    null);
            }

            foreach (string filePath in Directory.GetFiles(
                         _inputDir, _fileMask)
                     .OrderBy(s => s))
            {
                Console.WriteLine(Path.GetFileName(filePath));

                importer.Import(filePath, CancellationToken.None,
                                new Progress <ProgressReport>(
                                    r => Console.Write(" " + r.Message)));
                Console.WriteLine(" done");
            }

            return(Task.CompletedTask);
        }
        public IEnumerable <IMatch> Import(string source)
        {
            IMatchImporter <string> importer = new CsvImporter(_mode, _perspective, -1, new Func <IMatchBuilder, string, IMatchBuilder>[] {});
            IList <IMatch>          matches  = new List <IMatch>();

            using (StreamReader fileReader = new StreamReader(source))
            {
                string line;
                while ((line = fileReader.ReadLine()) != null)
                {
                    var match = importer.Import(line);
                    if (match != null)
                    {
                        matches.Add(match);
                    }
                }
                fileReader.Close();
            }
            return(matches);
        }
Beispiel #9
0
        public void TestImportValidSquadS4Line()
        {
            string csvInput = "1,170914,,Wrensong,1,Hsarus,0,,1,20,70,,\"1,00\",\"20,00\",2,\"2,00\"";
            var    sut      = new CsvImporter(GameMode.Squad, GamePerspective.FPP, 4, new Func <IMatchBuilder, string, IMatchBuilder>[]
            {
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithId(int.Parse(s)),
                (builder, s) => builder.WithDate(s),
                (builder, s) => builder,
                (builder, s) => builder.WithPartner(0, s),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithPartnerKills(0, int.Parse(s)),
                (builder, s) => builder.WithPartner(1, s),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithPartnerKills(1, int.Parse(s)),
                (builder, s) => builder,
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithKills(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithRank(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithScore(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithRating(int.Parse(s)),
                (builder, s) => builder,
                (builder, s) => builder,
                (builder, s) => builder,
                (builder, s) => builder
            });
            IMatch m = sut.Import(csvInput);

            Assert.AreEqual(4, m.Season);
            Assert.AreEqual(new DateTime(2017, 9, 14), m.Date);
            Assert.AreEqual(GameMode.Squad, m.Mode);
            Assert.AreEqual(GamePerspective.FPP, m.Perspective);
            Assert.AreEqual(1, m.Id);
            Assert.AreEqual(2, m.Partners.Count);
            Assert.AreEqual("Wrensong", m.Partners[0].Name);
            Assert.AreEqual(1, m.Partners[0].Kills);
            Assert.AreEqual("Hsarus", m.Partners[1].Name);
            Assert.AreEqual(0, m.Partners[1].Kills);
            Assert.AreEqual(1, m.Kills);
            Assert.AreEqual(20, m.Rank);
            Assert.AreEqual(70, m.Score);
            Assert.AreEqual(null, m.Rating);
            Assert.AreEqual(null, m.DeathCause);
            Assert.AreEqual(null, m.Lesson);
        }
Beispiel #10
0
        public void TestImport()
        {
            Account account = new LiabilityAccount("Amazon Signature Credit");

            CsvImporter importer = new CsvImporter();

            CsvFile file = CsvFile.Load(File.OpenRead("Chase_TestData.CSV"));

            importer.Import(file, account);

            account.AddStatement(new Statement(new decimal(-3638.41), AddWhen.StartOfDay), DateTime.Today);

            AccountManager manager = new AccountManager();

            manager.AddAccount(account);

            using (var s = File.OpenWrite(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TestJson.json")))
            {
                manager.ToJson(s);
            }
        }
Beispiel #11
0
        public void TestImportValidSoloS4Line(string csvInput, int id, string date, int kills, int rank, int score, int?rating, string deathCause, string lesson)
        {
            var sut = new CsvImporter(GameMode.Solo, GamePerspective.FPP, 4, new Func <IMatchBuilder, string, IMatchBuilder>[]
            {
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithId(int.Parse(s)),
                (builder, s) => builder.WithDate(s),
                (builder, s) => builder,
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithKills(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithRank(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithScore(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithRating(int.Parse(s)),
                (builder, s) => builder,
                (builder, s) => builder,
                (builder, s) => builder.WithDeathCause(s),
                (builder, s) => builder
            });
            IMatch m = sut.Import(csvInput);

            if (string.IsNullOrEmpty(date))
            {
                Assert.Null(m.Date);
            }
            else
            {
                Assert.True(m.Date.HasValue);
                Assert.AreEqual(date, m.Date.Value.ToString("yyyyMMdd"));
            }
            Assert.AreEqual(GameMode.Solo, m.Mode);
            Assert.AreEqual(GamePerspective.FPP, m.Perspective);
            Assert.AreEqual(4, m.Season);
            Assert.AreEqual(id, m.Id);
            Assert.AreEqual(kills, m.Kills);
            Assert.AreEqual(rank, m.Rank);
            Assert.AreEqual(score, m.Score);
            Assert.AreEqual(rating, m.Rating);
            Assert.AreEqual(deathCause, m.DeathCause);
            Assert.AreEqual(lesson, m.Lesson);
        }
Beispiel #12
0
        public void TestImportValidDuoS4Line()
        {
            string csvInput = "1,170923,,Wrensong,2,,4,5,294,1252,\"4,00\",\"5,00\",6,\"6,00\"";
            var    sut      = new CsvImporter(GameMode.Duo, GamePerspective.FPP, 4, new Func <IMatchBuilder, string, IMatchBuilder>[]
            {
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithId(int.Parse(s)),
                (builder, s) => builder.WithDate(s),
                (builder, s) => builder,
                (builder, s) => builder.WithPartner(0, s),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithPartnerKills(0, int.Parse(s)),
                (builder, s) => builder,
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithKills(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithRank(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithScore(int.Parse(s)),
                (builder, s) => string.IsNullOrEmpty(s) ? builder : builder.WithRating(int.Parse(s)),
                (builder, s) => builder,
                (builder, s) => builder,
                (builder, s) => builder,
                (builder, s) => builder
            });
            IMatch m = sut.Import(csvInput);

            Assert.AreEqual(4, m.Season);
            Assert.AreEqual(new DateTime(2017, 9, 23), m.Date);
            Assert.AreEqual(GameMode.Duo, m.Mode);
            Assert.AreEqual(GamePerspective.FPP, m.Perspective);
            Assert.AreEqual(1, m.Id);
            Assert.AreEqual(1, m.Partners.Count);
            Assert.AreEqual("Wrensong", m.Partners[0].Name);
            Assert.AreEqual(2, m.Partners[0].Kills);
            Assert.AreEqual(4, m.Kills);
            Assert.AreEqual(5, m.Rank);
            Assert.AreEqual(294, m.Score);
            Assert.AreEqual(1252, m.Rating);
            Assert.AreEqual(null, m.DeathCause);
            Assert.AreEqual(null, m.Lesson);
        }
Beispiel #13
0
        public void OnApplicationStarted()
        {
            var importer = new CsvImporter();

            importer.Import(Configuration.GetConnectionString("DefaultConnection"));
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            string version = typeof(Program).Assembly.GetName().Version.ToString();

            Console.WriteLine($"Flight Recorder Database Management {version}");

            Operation op = new CommandParser().ParseCommandLine(args);

            if (op.Valid)
            {
                FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateDbContext(null);
                FlightRecorderFactory   factory = new FlightRecorderFactory(context);

                try
                {
                    switch (op.Type)
                    {
                    case OperationType.add:
                        factory.Users.AddUser(op.UserName, op.Password);
                        Console.WriteLine($"Added user {op.UserName}");
                        break;

                    case OperationType.setpassword:
                        factory.Users.SetPassword(op.UserName, op.Password);
                        Console.WriteLine($"Set password for user {op.UserName}");
                        break;

                    case OperationType.delete:
                        factory.Users.DeleteUser(op.UserName);
                        Console.WriteLine($"Deleted user {op.UserName}");
                        break;

                    case OperationType.import:
                        CsvImporter importer = new CsvImporter();
                        importer.Import(op.FileName, factory);
                        Console.WriteLine($"Imported data from {op.FileName}");
                        break;

                    case OperationType.export:
                        // The third parameter is an arbitrary large number intended to capture all
                        // sightings
                        IEnumerable <Sighting> sightings = factory.Sightings.List(null, 1, 99999999);
                        CsvExporter            exporter  = new CsvExporter();
                        exporter.Export(sightings, op.FileName);
                        Console.WriteLine($"Exported the database to {op.FileName}");
                        break;

                    case OperationType.update:
                        context.Database.Migrate();
                        Console.WriteLine($"Applied the latest database migrations");
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error : {ex.Message}");
                }
            }
            else
            {
                string executable = AppDomain.CurrentDomain.FriendlyName;
                Console.WriteLine("Usage:");
                Console.WriteLine($"[1] {executable} add username password");
                Console.WriteLine($"[2] {executable} setpassword username password");
                Console.WriteLine($"[3] {executable} delete username");
                Console.WriteLine($"[4] {executable} import csv_file_path");
                Console.WriteLine($"[5] {executable} export csv_file_path");
                Console.WriteLine($"[6] {executable} update");
            }
        }
        public async Task <IActionResult> Import()
        {
            await CsvImporter.Import();

            return(RedirectToAction("Index"));
        }