예제 #1
0
 public MasterController(
     ModelStore store,
     IController booksController, IController shoppingCartController,
     IMasterViewFactory masterViewFactory,
     IMenuViewFactory menuViewFactory
     )
 {
     this.store                  = store;
     this.booksController        = booksController;
     this.shoppingCartController = shoppingCartController;
     this.masterViewFactory      = masterViewFactory;
     this.menuViewFactory        = menuViewFactory;
 }
예제 #2
0
        private static void Main(string[] args)
        {
            var reader = Console.In;

            var store = ModelStore.LoadFrom(reader);

            if (store == null)
            {
                Console.WriteLine("Data error.");
                return;
            }

            var masterController = new MasterController(
                store,
                new BooksController(
                    store,
                    new BooksViewFactory(),
                    new BooksDetailViewFactory()
                    ),
                new ShoppingCartController(
                    store,
                    new ShoppingCartViewFactory()
                    ),
                new MasterViewFactory(),
                new MenuViewFactory()
                );

            var writer = Console.Out;

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                masterController.ExecuteRequest(line, writer);
                writer.WriteLine("====");
            }
        }
예제 #3
0
        public static ModelStore LoadFrom(TextReader reader)
        {
            var store = new ModelStore();

            try {
                if (reader.ReadLine() != "DATA-BEGIN")
                {
                    return(null);
                }
                while (true)
                {
                    string line = reader.ReadLine();
                    if (line == null)
                    {
                        return(null);
                    }
                    else if (line == "DATA-END")
                    {
                        break;
                    }

                    string[] tokens = line.Split(';');
                    switch (tokens[0])
                    {
                    case "BOOK":
                        store.books.Add(new Book {
                            Id = int.Parse(tokens[1]), Title = tokens[2], Author = tokens[3], Price = decimal.Parse(tokens[4])
                        });
                        break;

                    case "CUSTOMER": {
                        var customer = new Customer {
                            Id = int.Parse(tokens[1]), FirstName = tokens[2], LastName = tokens[3], DateJoined = null
                        };
                        if (tokens.Length >= 6)
                        {
                            customer.DateJoined = new DateTime(int.Parse(tokens[4]), int.Parse(tokens[5]), int.Parse(tokens[6]));
                        }
                        store.customers.Add(customer);
                        break;
                    }

                    case "CART-ITEM": {
                        var customer = store.GetCustomer(int.Parse(tokens[1]));
                        if (customer == null)
                        {
                            return(null);
                        }
                        customer.ShoppingCart.Items.Add(new ShoppingCartItem {
                                BookId = int.Parse(tokens[2]), Count = int.Parse(tokens[3])
                            });
                        break;
                    }

                    default:
                        return(null);
                    }
                }
            } catch (Exception ex) {
                if (ex is FormatException || ex is IndexOutOfRangeException)
                {
                    return(null);
                }
                throw;
            }

            return(store);
        }
예제 #4
0
 public BooksController(ModelStore store, IBooksViewFactory booksViewFactory, IBooksDetailViewFactory booksDetailViewFactory)
 {
     this.store                  = store;
     this.booksViewFactory       = booksViewFactory;
     this.booksDetailViewFactory = booksDetailViewFactory;
 }
예제 #5
0
 public BooksView(ModelStore store)
 {
     this.store = store;
 }
예제 #6
0
 public IView CreateView(ModelStore store)
 {
     return(new BooksView(store));
 }
 public ShoppingCartView(ShoppingCart cart, ModelStore store)
 {
     this.cart  = cart;
     this.store = store;
 }
 public IView CreateView(ShoppingCart cart, ModelStore store)
 {
     return(new ShoppingCartView(cart, store));
 }
 public ShoppingCartController(ModelStore store, IShoppingCartViewFactory shoppingCartViewFactory)
 {
     this.store = store;
     this.shoppingCartViewFactory = shoppingCartViewFactory;
 }