示例#1
0
        /// <summary>
        /// The entry point of program.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            try
            {
                Shop            shop            = new Shop();
                RequestHandler  handler         = new RequestHandler();
                JsonFileHandler jsonFileHandler = new JsonFileHandler(shop);
                Dictionary <string, ICommand> commandsDictionary = new Dictionary <string, ICommand>
                {
                    ["product"]      = new ProductCommand(shop),
                    ["address"]      = new AddressCommand(shop),
                    ["delivery"]     = new DeliveryCommand(shop),
                    ["manufacturer"] = new ManufacturerCommand(shop),
                    ["warehouse"]    = new WareHouseCommand(shop),
                };

                foreach (var command in commandsDictionary.Values)
                {
                    command.UpdateData += jsonFileHandler.UpdateJsonFile;
                }
                handler.ReadData += jsonFileHandler.ReadAndWriteFromJson;
                handler.HandleRequests(commandsDictionary);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
        }
示例#2
0
        /// <summary>
        /// Constructor for RequestHandler
        /// </summary>
        /// <param name="shop"></param>
        public RequestHandler(Shop shop)
        {
            var jsonFileHandler = new JsonFileHandler(shop);

            this.CommandsDictionary = new Dictionary <string, ICommand>
            {
                ["product"]      = new ProductCommand(shop),
                ["address"]      = new AddressCommand(shop),
                ["delivery"]     = new DeliveryCommand(shop),
                ["manufacturer"] = new ManufacturerCommand(shop),
                ["warehouse"]    = new WareHouseCommand(shop),
            };

            foreach (var command in this.CommandsDictionary.Values)
            {
                command.UpdateData += jsonFileHandler.UpdateJsonFile;
            }
            this.ReadData += jsonFileHandler.ReadAndWriteFromJson;
        }