Beispiel #1
0
        //Treatment of the order depending on the order Type : Create / Add/Temperature
        public string TreatInputOrder(InputOrder newOrder)
        {
            string final;

            //Treating the order depending on the command type
            switch (newOrder.Command.ToLower())
            {
            case "create":
            {
                Machine machine = new Machine()
                {
                    MachineName = newOrder.Param1,
                    MachineId   = newOrder.Param2
                };
                bool result = machineManager.CreateMachine(machine);
                if (result == false)
                {
                    final = "A machine with the same Identifier already exists ! Please Consider using a different Identifier";
                }
                else
                {
                    final = "success";
                }
                break;
            }

            case "add":
            {
                string machineId = newOrder.Param1;
                try
                {
                    int  units = Convert.ToInt32(newOrder.Param2);
                    bool val   = machineManager.AddUnits(units, machineId);
                    if (!val)
                    {
                        final = "Machine not found , please check the machine identifier used";
                    }
                    else
                    {
                        final = "success";
                    }
                }
                catch (Exception ex)
                {
                    final = "please check the add operations parameters ! The last parameter should be integer";
                }

                break;
            }

            case "temperature":
            {
                string machineId = newOrder.Param1;
                try
                {
                    int  temperature = Convert.ToInt32(newOrder.Param2);
                    bool val         = machineManager.SetTemperature(temperature, machineId);
                    if (!val)
                    {
                        final = "Machine not found , please check the machine identifier used";
                    }
                    else
                    {
                        final = "success";
                    }
                }
                catch (Exception ex)
                {
                    final = "please check the add operations parameters ! The last parameter should be integer";
                }
                break;
            }

            default:
            {
                final = "please check the  operations parameters ! Order not recognized";
                break;
            }
            }
            return(final);
        }