Ejemplo n.º 1
0
        public Pc CreatePc()
        {
            Pc pc;

            var factory   = new DellFactory();
            var ram       = new Ram(8);
            var videoCard = new ColorfullVideoCard();

            pc = new Pc(new Cpu64(4, ram, videoCard), ram, new[] { new HardDriver(1000) }, videoCard);

            return(pc);
        }
Ejemplo n.º 2
0
        private static IComputerFactory CreateFactory(string manufacturer)
        {
            IComputerFactory factory;

            if (manufacturer == "HP")
            {
                factory = new HpFactory();
            }
            else if (manufacturer == "Dell")
            {
                factory = new DellFactory();
            }
            else
            {
                throw new InvalidArgumentException("Invalid manufacturer!");
            }

            return(factory);
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            var manufacturer = Console.ReadLine();

            if (manufacturer == "HP")
            {
                var hp             = new HpFactory();
                var factoryBuilder = new FactoryBuilder(hp);
                pc     = factoryBuilder.MakePersonalComputer();
                laptop = factoryBuilder.MakeLaptop();
                server = factoryBuilder.MakeServer();
            }
            else if (manufacturer == "Dell")
            {
                var dell           = new DellFactory();
                var factoryBuilder = new FactoryBuilder(dell);
                pc     = factoryBuilder.MakePersonalComputer();
                laptop = factoryBuilder.MakeLaptop();
                server = factoryBuilder.MakeServer();
            }
            else if (manufacturer == "Lenovo")
            {
                var lenovo         = new LenovoFactory();
                var factoryBuilder = new FactoryBuilder(lenovo);
                pc     = factoryBuilder.MakePersonalComputer();
                laptop = factoryBuilder.MakeLaptop();
                server = factoryBuilder.MakeServer();
            }
            else
            {
                throw new InvalidArgumentException("Invalid manufacturer!");
            }

            while (true)
            {
                var inputLine = Console.ReadLine();
                if (inputLine == null || inputLine.StartsWith("Exit"))
                {
                    break;
                }

                var commandParameters = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (commandParameters.Length != 2)
                {
                    throw new ArgumentException("Invalid command, command should consist of two parameters");
                }

                var command   = commandParameters[0];
                var parameter = int.Parse(commandParameters[1]);

                if (command == "Charge")
                {
                    laptop.Execute(parameter);
                }
                else if (command == "Process")
                {
                    server.Execute(parameter);
                }
                else if (command == "Play")
                {
                    pc.Execute(parameter);
                }
                else
                {
                    Console.WriteLine("Invalid command, there are three types of commands - Play, Charge, Process");
                }
            }
        }