public RandomCashBoxSimulator(ILogger <RandomCashBoxSimulator> logger,
                                      IHubContext <OrdersHub, IOrdersHub> ordersHub)
        {
            _logger = logger;
            _logger.LogInformation("Beginning dish population....");

            var scraperDataKFCFileNames = Directory.GetFiles($"{Directory.GetCurrentDirectory()}\\ScrapersData\\KFC\\");

            foreach (string scrapedFileName in scraperDataKFCFileNames)
            {
                Dish[] deserializedDishes = DishDeserializer.DeserializeDishFile(scrapedFileName);

                foreach (var deserializedDish in deserializedDishes)
                {
                    //Generating random estimated cooking time
                    //Can't generated random decimal so using tricks
                    deserializedDish.EstimatedCookingTime =
                        _random.Next(
                            Decimal.ToInt32(MIN_ESTIMATED_COOKING_TIME) * 100,
                            Decimal.ToInt32(MAX_ESTIMATED_COOKING_TIME) * 100 + 1
                            ) / 100;
                }

                _dishesPool.AddDishes(deserializedDishes);
            }

            _logger.LogInformation("Populated Dishes...");

            _ordersHub = ordersHub;
        }
Exemple #2
0
        public void MyScrape(string scrapeDataFolder, string newScrapeDataFolder = null,
                             bool clearOldDataFolder = false)
        {
            if (newScrapeDataFolder == null)
            {
                DishDeserializer.DeleteFilesFromFolder(scrapeDataFolder);
                menuFilesPath += scrapeDataFolder;
            }
            else
            {
                if (clearOldDataFolder)
                {
                    DishDeserializer.DeleteFilesFromFolder(scrapeDataFolder);
                }

                menuFilesPath += newScrapeDataFolder;
            }

            var scraper     = new KFCScraper();
            var scraperTask = scraper.StartAsync();

            while (true)
            {
                if (scraperTask.IsCompleted)
                {
                    break;
                }
            }

            foreach (var menuName in menu.Keys)
            {
                Scrape(menu[menuName].products, this.menuFilesPath + menuName + ".json");
            }
        }