コード例 #1
0
        static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();
            var serviceProvider   = ServicesRegistry
                                    .Register(serviceCollection)
                                    .BuildServiceProvider();

            var distances = new List <string>()
            {
                { "A-B-C" },
                { "A-D" },
                { "A-D-C" },
                { "A-E-B-C-D" },
                { "A-E-D" }
            };

            Console.WriteLine("Enter the list of routes eg.(AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7):");
            string            readLine   = Console.ReadLine();
            var               routeCodes = readLine.Split(",");
            List <RouteModel> routes     = new List <RouteModel>();

            routeCodes.ToList().ForEach(x => {
                var result = RouteModelBuilder.Get()
                             .WithChainOfProperties(x)
                             .Build();

                if (result.IsSuccess)
                {
                    routes.Add(result.Value);
                }
            });

            var service = new RouteService(routes);

            List <Result <int> > outputs = new List <Result <int> >();

            for (int i = 0; i < distances.Count; i++)
            {
                var result = service.EvaluateDistance(distances[i]);

                if (result.IsSuccess)
                {
                    Console.WriteLine($"Output #{ i + 1}: { result.Value }");
                }
                else
                {
                    Console.WriteLine($"Output #{ i + 1}: { result.Message }");
                }
            }
            var C_C = service.NumberOfTrips('C', 'C').Where(x => x.NumberOfStops == 2 || x.NumberOfStops == 3).Count();
            var A_C = service.NumberOfTrips('A', 'C').Where(x => x.NumberOfStops == 4).Count();

            Console.WriteLine($"Output #6: { C_C }");
            Console.WriteLine($"Output #7: { A_C }");

            Console.WriteLine($"Output #8: { service.ShortestDistance('A', 'C') }");
            Console.WriteLine($"Output #9: { service.ShortestDistance('B', 'B') }");


            var n = service.NumberOfTrips('C', 'C');
        }
コード例 #2
0
 public QueryActions(IServiceLocator locator, ServicesRegistry registry)
 {
     _Locator  = locator;
     _Registry = registry;
 }
コード例 #3
0
 public DynamicInsert(ServicesRegistry registry)
 {
     _Registry = registry;
 }
コード例 #4
0
 public CommandActions(IServiceLocator locator, ServicesRegistry registry)
 {
     _Locator  = locator;
     _Registry = registry;
 }
コード例 #5
0
        static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();
            var serviceProvider   = ServicesRegistry
                                    .Register(serviceCollection)
                                    .BuildServiceProvider();

            var dataSource = serviceProvider.GetService <IDataSourceService>();

            dataSource.Seed();

            var productRepository = serviceProvider.GetService <IProductRepository>();
            var receiptService    = serviceProvider.GetService <IReceiptService>();
            var printerService    = serviceProvider.GetService <IPrintService>();

            List <ProductModel> products = new List <ProductModel>();

            bool requestTotal = false;

            while (!requestTotal)
            {
                Console.WriteLine("Enter the product eg.(1 Book at 12.49):");
                string productDescription = Console.ReadLine();

                var result = ProductModelBuilder
                             .Get()
                             .WithProperties(productDescription)
                             .Build();

                if (!result.IsSuccess)
                {
                    Console.WriteLine($"There was an error trying to build the product: { result.Message }");
                    continue;
                }

                ProductModel product = productRepository.GetByName(result.Value.Description);
                product.Price = result.Value.Price;

                if (product == null)
                {
                    Console.WriteLine("Product not found");
                    continue;
                }

                products.Add(product);


                Console.WriteLine("Press (Esc) to finish or <Enter> to add an other product.");
                bool waitingForUser = true;
                while (waitingForUser)
                {
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        waitingForUser = false;
                        requestTotal   = true;
                        continue;
                    }

                    if (key.Key == ConsoleKey.Enter)
                    {
                        waitingForUser = false;
                        continue;
                    }
                }
            }

            var receipt = receiptService.GenerateReceipt(products);

            printerService.Print(receipt);
        }
コード例 #6
0
 public DynamicInsert(ServicesRegistry registry)
 {
     _Registry = registry;
 }
コード例 #7
0
 public InjectMenuResultFilter(ServicesRegistry services, ISakurityOffica offica)
 {
     _Services = services;
     _Offica   = offica;
 }
コード例 #8
0
 public CommandActions(IServiceLocator locator, ServicesRegistry registry)
 {
     _Locator = locator;
     _Registry = registry;
 }
コード例 #9
0
 public InjectMenuResultFilter(ServicesRegistry services, ISakurityOffica offica)
 {
     _Services = services;
     _Offica = offica;
 }
コード例 #10
0
 public QueryActions(IServiceLocator locator, ServicesRegistry registry)
 {
     _Locator = locator;
     _Registry = registry;
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: osvaldocampos/MarsRovers
        static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();
            var serviceProvider   = ServicesRegistry
                                    .Register(serviceCollection)
                                    .BuildServiceProvider();

            Console.WriteLine("Enter the grid bounds eg.(5 5):");
            string gridBounds = Console.ReadLine();

            bool isCommandComplete = false;
            List <NavigationCommandModel> commandModels = new List <NavigationCommandModel>();

            while (!isCommandComplete)
            {
                Console.WriteLine("Enter the rover's coordinates eg.(1 1 N):");
                string coordinates = Console.ReadLine();
                Console.WriteLine("Enter the rover's instructions eg.(LMLMLMMM):");
                string instructions = Console.ReadLine();
                var    result       = NavigationCommandBuilder.Get()
                                      .WithGridBounds(gridBounds)
                                      .WithCurrentPosition(coordinates)
                                      .WithCommands(instructions)
                                      .Build();

                if (!result.IsSuccess)
                {
                    Console.WriteLine($"There was an error trying to build the command: { result.Message }");
                    continue;
                }

                commandModels.Add(result.Value);

                Console.WriteLine("Press (Esc) to finish or <Enter> to add an other command.");
                bool waitingForUser = true;
                while (waitingForUser)
                {
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        waitingForUser    = false;
                        isCommandComplete = true;
                        continue;
                    }

                    if (key.Key == ConsoleKey.Enter)
                    {
                        waitingForUser = false;
                        continue;
                    }
                }
            }

            List <Task> commandTasks = new List <Task>();

            foreach (var command in commandModels)
            {
                var rover = serviceProvider.GetService <IRoverService>();
                commandTasks.Add(rover.ExecuteCommand(command));
            }

            var task = Task.WhenAll(commandTasks);

            task.Wait();
        }