Exemplo n.º 1
0
        public void Run()
        {
            try
            {
                List <RouteViewModel> routesViewModel = ReadAndSerializer <RouteViewModel>(GetPathFile("trechos.txt"));
                List <OrderViewModel> ordersViewModel = ReadAndSerializer <OrderViewModel>(GetPathFile("encomendas.txt"));

                var routes = _routeService.CreateListRoutes(routesViewModel);

                var paths = ordersViewModel.Select(order =>
                {
                    var cityOrigin      = _cityService.FindByCode(order.CityOrigin);
                    var cityDestination = _cityService.FindByCode(order.CityDestination);
                    return(_shortestPathFinder.FindShortestPath(cityOrigin, cityDestination, s => GetNeighbors(s, routes)));
                });

                var textPaths = _textSerializer.SerializeList(paths);
                _fileService.WriteAllText(GetPathFile("rotas.txt"), textPaths);

                _logger.LogDebug("{paths}", textPaths);
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                _fileService.WriteAllText(GetPathFile("rotas.txt"), "Could not calculate directions. " + e.Message);
            }
        }
Exemplo n.º 2
0
        public void SerializeListOrder()
        {
            var list = new List <OrderViewModel>
            {
                new OrderViewModel {
                    CityOrigin = "LS", CityDestination = "SF"
                },
                new OrderViewModel {
                    CityOrigin = "SF", CityDestination = "LS"
                },
            };

            var textSerializer = new TextSerializer();
            var content        = textSerializer.SerializeList(list);

            Assert.Equal(list.Count - 1, Regex.Matches(content, Environment.NewLine).Count);
        }