Пример #1
0
        private void ImportCommand(string command)
        {
            var folder = GetCommandParam(command, "-import");

            if (Directory.Exists(folder))
            {
                try
                {
                    var config = FileImportHelper.GetConfig(folder);
                    _console.WriteLine("\n Reading config.json ok");
                    var inventories = FileImportHelper.GetInventory(folder);
                    _console.WriteLine("\n Reading inventory.json ok");
                    var exchangeRates = FileImportHelper.GetRates(folder);
                    _console.WriteLine("\n Reading exchange_rates.json ok");
                    _configService.ImportData(inventories, config, exchangeRates);
                    _console.WriteLine("\n Saving new config to db completed");
                }
                catch (Exception ex)
                {
                    _console.WriteLine("\n Error during file importing: " + ex.Message);
                }
            }
            else
            {
                _console.WriteLine("\n Error. Folder don't exists. Please provide folder path with config files");
            }
        }
        public async Task Run(string defaultFilesFolderPath)
        {
            try
            {
                _logger.LogInformation("Starting db. Checking connection to SQL server");

                await _context.Database.MigrateAsync().ConfigureAwait(false);

                if (!await _context.Inventory.AnyAsync())
                {
                    _logger.LogInformation("Empty database. Importing default config");
                    var config        = FileImportHelper.GetConfig(defaultFilesFolderPath);
                    var inventories   = FileImportHelper.GetInventory(defaultFilesFolderPath);
                    var exchangeRates = FileImportHelper.GetRates(defaultFilesFolderPath);

                    _configService.ImportData(inventories, config, exchangeRates);

                    _logger.LogInformation("Default setup completed");
                }

                _configService.UpdateCoins(0, true);
                _logger.LogInformation("Db started succesfully");
            }
            catch (Exception ex)
            {
                _logger.LogCritical("Init db failed", ex);
                System.Console.WriteLine("\nInit db failed. Please check log for more details.");
                throw;
            }
        }