예제 #1
0
        private static void SortData()
        {
            _logger.Info("Write down number of sorters");
            var readLine = Console.ReadLine();
            var isParsed = int.TryParse(readLine, out var sortersCount);

            if (!isParsed)
            {
                _logger.Info($"Expected number of sorters but got:{readLine}");
                return;
            }

            var sw = Stopwatch.StartNew();
            List <PenPallet> pallets;

            try
            {
                pallets = _generator.GetPallets();
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return;
            }
            _logger.Info($"Got pallets data in {sw.Elapsed.TotalMilliseconds}ms");
            sw.Restart();
            var sortingTable = new SortingTable(sortersCount, SORTING_TABLE_CAPACITY, _logger);

            _logger.Info($"Found {pallets.Count} pallets");
            _logger.Info($"Total pens: {pallets.Sum(t=>t.PensColorCodes.Count)}");
            try
            {
                sortingTable.Sort(pallets, PEN_PACK_SIZE).ContinueWith(t =>
                {
                    _logger.Info($"Formed {t.Result.Count} packs.");
                    _logger.Info($"Total cost of packs: {t.Result.Count * PEN_PACK_COST}$.");
                    return(Task.CompletedTask);
                }).ContinueWith(t =>
                {
                    sw.Stop();
                    _logger.Info($"Sorted pallets data in {sw.Elapsed.TotalMilliseconds}ms");
                }).Wait();
            }
            catch (AggregateException ex)
            {
                _logger.Error(ex);
            }
            finally
            {
                sw.Stop();
            }
            _logger.Info($"Sorting ended");
        }
예제 #2
0
        private static void SortData()
        {
            _logger.Info("Write down number of sorters");
            var readLine = Console.ReadLine();
            var isParsed = int.TryParse(readLine, out var sortersCount);

            if (!isParsed)
            {
                _logger.Info($"Expected number of sorters but got:{readLine}");
                return;
            }

            var sw      = Stopwatch.StartNew();
            var pallets = _generator.GetPallets();

            _logger.Info($"Got pallets data in {sw.Elapsed.TotalMilliseconds}ms");
            sw.Restart();
            var sortingTable = new SortingTable(sortersCount, 2000, _logger);

            _logger.Info($"Found {pallets.Count} pallets");
            _logger.Info($"Total pens: {pallets.Sum(t=>t.PensColorCodes.Count)}");
            sortingTable.Sort(pallets, 4).ContinueWith(t =>
            {
                _logger.Info($"Formed {t.Result.Count} packs.");
                var costInUsd = t.Result.Count * 10;
                _logger.Info($"Total cost of packs: {costInUsd}$.");
                var costInRubles = _costCalculator.CalculateCost(costInUsd, "USD", "RUB");
                _logger.Info($"Converted cost of packs: {costInRubles:F2}Rub.");

                return(Task.CompletedTask);
            }).ContinueWith(t =>
            {
                sw.Stop();
                _logger.Info($"Sorted pallets data in {sw.Elapsed.TotalMilliseconds}ms");
            }).Wait();
            _logger.Info($"Sorting ended");
        }