public FordCar Construct(ICarSpecificationMessage carSpecification)
        {
            this.VehicleBuilder.VehicleManufacturerName = "Ford";

            this.VehicleBuilder.BuildEngine(carSpecification.EngineType);
            this.VehicleBuilder.BuildWheels(carSpecification.WheelType);
            this.VehicleBuilder.BuildDoors(carSpecification.NumberOfDoors);

            this.VehicleBuilder.Paint(carSpecification.PaintType, carSpecification.PaintColour);

            return(this.VehicleBuilder.Result);
        }
Example #2
0
        public static void Main()
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "watership_down", durable: true, exclusive: false, autoDelete: false, arguments: null);
                    channel.BasicQos(0, 20, false);

                    var basicProperties = channel.CreateBasicProperties();
                    basicProperties.Persistent = true;

                    Console.WriteLine("Select Car: [H]onda or [F]ord?");
                    var key = Console.ReadKey();

                    while (key.Key != ConsoleKey.Escape)
                    {
                        ICarSpecificationMessage carSupplierMessage = null;
                        switch (key.Key)
                        {
                        case ConsoleKey.H:
                            carSupplierMessage = new HondaCarSpecificationMessage();
                            break;

                        case ConsoleKey.F:
                            carSupplierMessage = new FordCarSpecificationMessage();
                            break;

                        default:
                            throw new NotSupportedException($"unexpected input received {key.Key} is an invalid option");
                        }

                        Console.WriteLine("How many doors?");
                        key = Console.ReadKey();
                        carSupplierMessage.NumberOfDoors = getFromKeyPress(key.Key);

                        Console.WriteLine("Engine type?");
                        carSupplierMessage.EngineType = Console.ReadLine();

                        Console.WriteLine("Wheel type?");
                        carSupplierMessage.WheelType = Console.ReadLine();

                        Console.WriteLine("Tyre type?");
                        carSupplierMessage.TyreType = Console.ReadLine();

                        Console.WriteLine("Paint type?");
                        carSupplierMessage.PaintType = Console.ReadLine();

                        Console.WriteLine("Colour?");
                        carSupplierMessage.PaintColour = Console.ReadLine();


                        var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(carSupplierMessage));

                        channel.BasicPublish(exchange: "", routingKey: "watership_down", basicProperties: basicProperties, body: body);

                        Console.WriteLine("[x] Sent {0}", carSupplierMessage.GetType().Name);

                        Console.WriteLine("Select Car: [H]onda or [F]ord?");
                        key = Console.ReadKey();
                    }
                }
            }

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }