public void GetRate_WhenInventoryBaseRateSameAsSelected_ReturnsBaseRate()
        {
            var a1 = FileImportHelper.GenerateProductNr(0);

            Assert.True(a1 == "A1");

            var b10 = FileImportHelper.GenerateProductNr(19);

            Assert.True(b10 == "B10");

            var a10 = FileImportHelper.GenerateProductNr(9);

            Assert.True(a10 == "A10");

            var b4 = FileImportHelper.GenerateProductNr(13);

            Assert.True(b4 == "B4");

            var d9 = FileImportHelper.GenerateProductNr(48);

            Assert.True(d9 == "E9");

            var b6 = FileImportHelper.GenerateProductNr(25);

            Assert.True(b6 == "C6");

            var c6 = FileImportHelper.GenerateProductNr(35);

            Assert.True(c6 == "D6");
        }
Ejemplo n.º 2
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");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// btnImportSearch click event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnImportSearch_Click(object sender, EventArgs e)
        {
            if (fileBrowserDialog != null)
            {
                fileBrowserDialog.Filter = @"xml files (*.xml)|*.xml";

                if (this.fileBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    string fileNameAndPath = fileBrowserDialog.FileName;

                    FileImportHelper helper = new FileImportHelper();
                    if (helper.DetermineIfSelectedXmlIsValid(fileNameAndPath))
                    {
                        SpotifySearchPresenter p = new SpotifySearchPresenter(this);
                        p.ImportData(XMLImportList(fileNameAndPath));
                        KeepTopMostAndBringToFront();
                    }
                    else
                    {
                        MessageBox.Show(
                            @"The selected file is not compatible for import. SpotifySearch *.xml files only. See manual for more details.", @"File Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);

                        KeepTopMostAndBringToFront();
                    }
                }
            }
        }
        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;
            }
        }
        private static List <ExchangeRateModel> GetTestRates()
        {
            var codeBaseUrl  = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            var codeBasePath = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath);
            var dirPath      = Path.GetDirectoryName(codeBasePath);
            var defaultRates = FileImportHelper.GetRates(Path.Combine(dirPath, "TestResources"));

            return(defaultRates);
        }
Ejemplo n.º 6
0
        private void AddInventories(IList <InventoryModel> inventories)
        {
            for (var index = 0; index < inventories.Count; index++)
            {
                var inventoryDto = inventories[index];
                var productNr    = FileImportHelper.GenerateProductNr(index);
                var inventory    = new Inventory()
                {
                    Name      = inventoryDto.Name,
                    Price     = inventoryDto.Price,
                    Quantity  = inventoryDto.Quantity,
                    ProductNr = productNr
                };

                _context.Inventory.Add(inventory);
                _logger.LogInformation(string.Format("Importing roduct {0}", productNr));
            }
        }