示例#1
0
        private string RealiseCommand(string[] arr)
        {
            switch (arr[0])
            {
            case "AddProduct":
                return(cm.AddProduct(arr[1], double.Parse(arr[2])));

            case "RegisterStorage":
                return(cm.RegisterStorage(arr[1], arr[2]));

            case "SelectVehicle":
                return(cm.SelectVehicle(arr[1], int.Parse(arr[2])));

            case "LoadVehicle":
                return(cm.LoadVehicle(arr.Skip(1)));

            case "SendVehicleTo":
                return(cm.SendVehicleTo(arr[1], int.Parse(arr[2]), arr[3]));

            case "UnloadVehicle":
                return(cm.UnloadVehicle(arr[1], int.Parse(arr[2])));

            case "GetStorageStatus":
                return(cm.GetStorageStatus(arr[1]));

            case "END":
                return(cm.GetSummary());

            default:
                throw new ArgumentException("Didn Realise Command");
            }
        }
示例#2
0
        public void Run()
        {
            while (true)
            {
                var input = Console.ReadLine().Split();

                string command = input[0];

                try
                {
                    switch (command)
                    {
                    case "AddProduct":
                        Console.WriteLine(storageMaster
                                          .AddProduct(input[1], double.Parse(input[2])));
                        break;

                    case "RegisterStorage":
                        Console.WriteLine(storageMaster
                                          .RegisterStorage(input[1], input[2]));
                        break;

                    case "SelectVehicle":
                        Console.WriteLine(storageMaster
                                          .SelectVehicle(input[1], int.Parse(input[2])));
                        break;

                    case "LoadVehicle":
                        Console.WriteLine(storageMaster
                                          .LoadVehicle(input.Skip(1).ToList()));
                        break;

                    case "SendVehicleTo":
                        Console.WriteLine(storageMaster
                                          .SendVehicleTo(input[1], int.Parse(input[2]), input[3]));
                        break;

                    case "UnloadVehicle":
                        Console.WriteLine(storageMaster
                                          .UnloadVehicle(input[1], int.Parse(input[2])));
                        break;

                    case "GetStorageStatus":
                        Console.WriteLine(storageMaster
                                          .GetStorageStatus(input[1]));
                        break;

                    case "END":
                        Console.WriteLine(this.storageMaster.GetSummary());
                        return;
                    }
                }

                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"Error: {ioe.Message}");
                }
            }
        }
示例#3
0
 public void Run()
 {
     string[] inputArgs;
     while ((inputArgs = Console.ReadLine().Split())[0] != "END")
     {
         string command = inputArgs[0].ToLower();
         try
         {
             if (command == "addproduct")
             {
                 string type  = inputArgs[1];
                 double price = double.Parse(inputArgs[2]);
                 Console.WriteLine(sm.AddProduct(type, price));
             }
             else if (command == "registerstorage")
             {
                 string type = inputArgs[1];
                 string name = inputArgs[2];
                 Console.WriteLine(sm.RegisterStorage(type, name));
             }
             else if (command == "selectvehicle")
             {
                 string storageName = inputArgs[1];
                 int    garageSlot  = int.Parse(inputArgs[2]);
                 Console.WriteLine(sm.SelectVehicle(storageName, garageSlot));
             }
             else if (command == "loadvehicle")
             {
                 string[] products = inputArgs.Skip(1).ToArray();
                 Console.WriteLine(sm.LoadVehicle(products));
             }
             else if (command == "sendvehicleto")
             {
                 string sourceName       = inputArgs[1];
                 int    sourceGarageSlot = int.Parse(inputArgs[2]);
                 string destinationName  = inputArgs[3];
                 Console.WriteLine(sm.SendVehicleTo(sourceName, sourceGarageSlot, destinationName));
             }
             else if (command == "unloadvehicle")
             {
                 string storageName = inputArgs[1];
                 int    garageSlot  = int.Parse(inputArgs[2]);
                 Console.WriteLine(sm.UnloadVehicle(storageName, garageSlot));
             }
             else if (command == "getstoragestatus")
             {
                 string storageName = inputArgs[1];
                 Console.WriteLine(sm.GetStorageStatus(storageName));
             }
         }
         catch (InvalidOperationException ioe)
         {
             Console.WriteLine("Error: " + ioe.Message);
         }
     }
     Console.Write(sm.GetSummary());
 }
示例#4
0
        public void Run()
        {
            StorageMaster storageMaster = new StorageMaster();

            while (true)
            {
                var    input   = Console.ReadLine().Split();
                string command = input[0];

                if (command.Equals("END"))
                {
                    break;
                }

                string result = null;

                try
                {
                    switch (command)
                    {
                    case "AddProduct":
                        result = storageMaster.AddProduct(input[1], double.Parse(input[2]));
                        break;

                    case "RegisterStorage":
                        result = storageMaster.RegisterStorage(input[1], input[2]);
                        break;

                    case "SelectVehicle":
                        result = storageMaster.SelectVehicle(input[1], int.Parse(input[2]));
                        break;

                    case "LoadVehicle":
                        result = storageMaster.LoadVehicle(input.Skip(1).ToList());
                        break;

                    case "SendVehicleTo":
                        result = storageMaster.SendVehicleTo(input[1], int.Parse(input[2]), input[3]);
                        break;

                    case "UnloadVehicle":
                        result = storageMaster.UnloadVehicle(input[1], int.Parse(input[2]));
                        break;

                    case "GetStorageStatus":
                        result = storageMaster.GetStorageStatus(input[1]);
                        break;
                    }
                }
                catch (InvalidOperationException e)
                {
                    result = "Error: " + e.Message;
                }
                Console.WriteLine(result);
            }
            Console.WriteLine(storageMaster.GetSummary());
        }
示例#5
0
        public void Run()
        {
            string        command = Console.ReadLine();
            StorageMaster master  = new StorageMaster();

            while (command != "END")
            {
                string[] arr = command.Split();

                try
                {
                    switch (arr[0])
                    {
                    case "AddProduct":
                        string type  = arr[1];
                        double price = double.Parse(arr[2]);
                        Console.WriteLine(master.AddProduct(type, price));
                        break;

                    case "RegisterStorage":
                        type = arr[1];
                        string name = arr[2];
                        Console.WriteLine(master.RegisterStorage(type, name));
                        break;

                    case "SelectVehicle":
                        Console.WriteLine(master.SelectVehicle(storageName: arr[1], garageSlot: int.Parse(arr[2])));
                        break;

                    case "LoadVehicle":
                        IEnumerable <string> productNames = arr.Skip(1).ToArray();
                        Console.WriteLine(master.LoadVehicle(productNames));
                        break;

                    case "SendVehicleTo":
                        Console.WriteLine(master.SendVehicleTo(sourceName: arr[1], sourceGarageSlot: int.Parse(arr[2]), destinationName: arr[3]));
                        break;

                    case "UnloadVehicle":
                        Console.WriteLine(master.UnloadVehicle(storageName: arr[1], garageSlot: int.Parse(arr[2])));
                        break;

                    case "GetStorageStatus":
                        Console.WriteLine(master.GetStorageStatus(storageName: arr[1]));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex.Message}");
                }
                command = Console.ReadLine();
            }
            Console.WriteLine(master.GetSummary());
        }
示例#6
0
        private string ReadCommand(string[] args)
        {
            string command     = args[0];
            string type        = string.Empty;
            string storageName = string.Empty;
            string result      = string.Empty;

            switch (command)
            {
            case "AddProduct":
                type = args[1];
                double price = double.Parse(args[2]);
                result = storageMaster.AddProduct(type, price);
                break;

            case "RegisterStorage":
                type = args[1];
                string name = args[2];
                result = storageMaster.RegisterStorage(type, name);
                break;

            case "SelectVehicle":
                storageName = args[1];
                int garageSlot = int.Parse(args[2]);
                result = storageMaster.SelectVehicle(storageName, garageSlot);
                break;

            case "LoadVehicle":
                string[] products = args.Skip(1).ToArray();
                result = storageMaster.LoadVehicle(products);
                break;

            case "SendVehicleTo":
                string sourceName       = args[1];
                int    sourceGarageSlot = int.Parse(args[2]);
                string destinationName  = args[3];
                result = storageMaster.SendVehicleTo(sourceName, sourceGarageSlot, destinationName);
                break;

            case "UnloadVehicle":
                storageName = args[1];
                int garageSlotToUnload = int.Parse(args[2]);
                result = storageMaster.UnloadVehicle(storageName, garageSlotToUnload);
                break;

            case "GetStorageStatus":
                storageName = args[1];
                result      = storageMaster.GetStorageStatus(storageName);
                break;

            default:
                break;
            }
            return(result);
        }
示例#7
0
        private string CommandParser(string[] data)
        {
            string command     = data[0];
            string type        = "";
            int    garageSlot  = 0;
            string storageName = "";
            string result      = "";

            switch (command)
            {
            case "AddProduct":
                type = data[1];
                double price = double.Parse(data[2]);
                result = storageMaster.AddProduct(type, price);
                break;

            case "RegisterStorage":
                type = data[1];
                string name = data[2];
                result = storageMaster.RegisterStorage(type, name);
                break;

            case "SelectVehicle":
                storageName = data[1];
                garageSlot  = int.Parse(data[2]);
                result      = storageMaster.SelectVehicle(storageName, garageSlot);
                break;

            case "LoadVehicle":
                IEnumerable <string> productNames = data.Skip(1);
                result = storageMaster.LoadVehicle(productNames);
                break;

            case "SendVehicleTo":
                string sourceName       = data[1];
                int    sourceGarageSlot = int.Parse(data[2]);
                string destinationName  = data[3];
                result = storageMaster.SendVehicleTo(sourceName, sourceGarageSlot, destinationName);
                break;

            case "UnloadVehicle":
                storageName = data[1];
                garageSlot  = int.Parse(data[2]);
                result      = storageMaster.UnloadVehicle(storageName, garageSlot);
                break;

            case "GetStorageStatus":
                storageName = data[1];
                result      = storageMaster.GetStorageStatus(storageName);
                break;
            }

            return(result);
        }
        public void Run()
        {
            string input;

            while ((input = Console.ReadLine()) != "END")
            {
                var command = input.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                var args    = command.Skip(1).ToArray();
                try
                {
                    switch (command[0])
                    {
                    case "AddProduct":
                        Console.WriteLine(storageMaster.AddProduct(args[0], double.Parse(args[1])));
                        break;

                    case "RegisterStorage":
                        Console.WriteLine(storageMaster.RegisterStorage(args[0], args[1]));
                        break;

                    case "SelectVehicle":
                        Console.WriteLine(storageMaster.SelectVehicle(args[0], int.Parse(args[1])));
                        break;

                    case "LoadVehicle":
                        Console.WriteLine(storageMaster.LoadVehicle(args));
                        break;

                    case "SendVehicleTo":
                        Console.WriteLine(storageMaster.SendVehicleTo(args[0], int.Parse(args[1]), args[2]));
                        break;

                    case "UnloadVehicle":
                        Console.WriteLine(storageMaster.UnloadVehicle(args[0], int.Parse(args[1])));
                        break;

                    case "GetStorageStatus":
                        Console.WriteLine(storageMaster.GetStorageStatus(args[0]));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                }
            }

            Console.WriteLine(storageMaster.GetSummary());
        }
示例#9
0
        private static void Execute(string commandLine, StorageMaster storageMaster)
        {
            var    args    = commandLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var    command = args[0];
            string result;

            switch (command)
            {
            case "AddProduct":
                result = storageMaster.AddProduct(args[1], double.Parse(args[2]));
                break;

            case "RegisterStorage":
                result = storageMaster.RegisterStorage(args[1], args[2]);
                break;

            case "SelectVehicle":
                result = storageMaster.SelectVehicle(args[1], int.Parse(args[2]));
                break;

            case "LoadVehicle":
                result = storageMaster.LoadVehicle(args.Skip(1).ToArray());
                break;

            case "SendVehicleTo":
                result = storageMaster.SendVehicleTo(args[1], int.Parse(args[2]), args[3]);
                break;

            case "UnloadVehicle":
                result = storageMaster.UnloadVehicle(args[1], int.Parse(args[2]));
                break;

            case "GetStorageStatus":
                result = storageMaster.GetStorageStatus(args[1]);
                break;

            default:
                throw new ArgumentException();
            }

            Console.WriteLine(result);
        }
示例#10
0
        private string RunCommand(string[] args)
        {
            var    command = args[0];
            string type    = args[1];
            string name    = args[1];
            int    garageSlot;

            switch (command)
            {
            case "AddProduct":
                double price = double.Parse(args[2]);
                return(storageMaster.AddProduct(type, price));

            case "RegisterStorage":
                name = args[2];
                return(storageMaster.RegisterStorage(type, name));

            case "SelectVehicle":
                garageSlot = int.Parse(args[2]);
                return(storageMaster.SelectVehicle(name, garageSlot));

            case "LoadVehicle":
                return(storageMaster.LoadVehicle(args.Skip(1)));

            case "SendVehicleTo":
                garageSlot = int.Parse(args[2]);
                string destination = args[3];
                return(storageMaster.SendVehicleTo(name, garageSlot, destination));

            case "UnloadVehicle":
                garageSlot = int.Parse(args[2]);
                return(storageMaster.UnloadVehicle(name, garageSlot));

            case "GetStorageStatus":
                return(storageMaster.GetStorageStatus(name));

            default:
                throw new InvalidOperationException("Invalid command");
            }
        }
示例#11
0
        private void Execute(string command, string[] commandArgs)
        {
            switch (command)
            {
            case "AddProduct":
                Console.WriteLine(storageMaster.AddProduct(commandArgs[0], double.Parse(commandArgs[1])));
                break;

            case "RegisterStorage":
                Console.WriteLine(storageMaster.RegisterStorage(commandArgs[0], commandArgs[1]));
                break;

            case "SelectVehicle":
                Console.WriteLine(storageMaster.SelectVehicle(commandArgs[0], int.Parse(commandArgs[1])));
                break;

            case "LoadVehicle":
                Console.WriteLine(storageMaster.LoadVehicle(commandArgs));
                break;

            case "SendVehicleTo":
                Console.WriteLine(storageMaster.SendVehicleTo(commandArgs[0], int.Parse(commandArgs[1]), commandArgs[2]));
                break;

            case "UnloadVehicle":
                Console.WriteLine(storageMaster.UnloadVehicle(commandArgs[0], int.Parse(commandArgs[1])));
                break;

            case "GetStorageStatus":
                Console.WriteLine(storageMaster.GetStorageStatus(commandArgs[0]));
                break;

            default:
                break;
            }
        }
示例#12
0
        public void MoveCommand(string inputLine, StorageMaster sm)
        {
            string[] input   = inputLine.Split();
            string   command = input[0];

            switch (command)
            {
            case "AddProduct":
                Console.WriteLine(sm.AddProduct(input[1], double.Parse(input[2]))); break;

            case "RegisterStorage":
                Console.WriteLine(sm.RegisterStorage(input[1], input[2])); break;

            case "SelectVehicle":
                Console.WriteLine(sm.SelectVehicle(input[1], int.Parse(input[2]))); break;

            case "LoadVehicle":
                List <string> collection = new List <string>();
                for (int i = 1; i < input.Length; i++)
                {
                    collection.Add(input[i]);
                }
                Console.WriteLine(sm.LoadVehicle(collection)); break;

            case "SendVehicleTo":
                Console.WriteLine(sm.SendVehicleTo(input[1], int.Parse(input[2]), input[3])); break;

            case "UnloadVehicle":
                Console.WriteLine(sm.UnloadVehicle(input[1], int.Parse(input[2]))); break;

            case "GetStorageStatus":
                Console.WriteLine(sm.GetStorageStatus(input[1])); break;

            default: break;
            }
        }
示例#13
0
        static void Main(string[] args)
        {
            string[]      command = Console.ReadLine().Split(' ').ToArray();
            StorageMaster sm      = new StorageMaster();

            while (command[0] != "END")
            {
                try
                {
                    if (command[0] == "AddProduct")
                    {
                        string type   = command[1];
                        double price  = double.Parse(command[2]);
                        var    result = sm.AddProduct(type, price);
                        Console.WriteLine(result);
                    }
                    else if (command[0] == "RegisterStorage")
                    {
                        string type   = command[1];
                        string name   = command[2];
                        var    result = sm.RegisterStorage(type, name);
                        Console.WriteLine(result);
                    }
                    else if (command[0] == "SelectVehicle")
                    {
                        string storageName = command[1];
                        int    garageSlot  = int.Parse(command[2]);
                        var    result      = sm.SelectVehicle(storageName, garageSlot);
                        Console.WriteLine(result);
                    }
                    else if (command[0] == "LoadVehicle")
                    {
                        int           lenght   = command.Length;
                        List <string> products = new List <string>();

                        for (int i = 1; i < command.Length; i++)
                        {
                            products.Add(command[i]);
                        }
                        IEnumerable <string> p = products.AsEnumerable();
                        var result             = sm.LoadVehicle(p);
                        Console.WriteLine(result);
                    }
                    else if (command[0] == "SendVehicleTo")
                    {
                        string sourceName      = command[1];
                        int    sourceSlot      = int.Parse(command[2]);
                        string destinationName = command[3];

                        var result = sm.SendVehicleTo(sourceName, sourceSlot, destinationName);
                        Console.WriteLine(result);
                    }
                    else if (command[0] == "UnloadVehicle")
                    {
                        string storageName = command[1];
                        int    sourceSlot  = int.Parse(command[2]);

                        var result = sm.UnloadVehicle(storageName, sourceSlot);
                        Console.WriteLine(result);
                    }
                    else if (command[0] == "GetStorageStatus")
                    {
                        string storageName = command[1];
                        var    result      = sm.GetStorageStatus(storageName);
                        Console.WriteLine(result);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                }
                command = Console.ReadLine().Split(' ').ToArray();
            }

            string summary = sm.GetSummary();

            Console.WriteLine(summary);
        }
        private string ParseCommand(string command, string[] parameters)
        {
            string result = "";

            switch (command)
            {
            case "AddProduct":
                string type  = parameters[0];
                double price = double.Parse(parameters[1]);

                result = storageMaster.AddProduct(type, price);
                break;

            case "RegisterStorage":
                type = parameters[0];
                string name = parameters[1];

                result = storageMaster.RegisterStorage(type, name);
                break;

            case "SelectVehicle":
                string storageName = parameters[0];
                int    garageSlot  = int.Parse(parameters[1]);

                result = storageMaster.SelectVehicle(storageName, garageSlot);
                break;

            case "LoadVehicle":

                List <string> productsLoad = new List <string>();

                for (int i = 0; i < parameters.Length; i++)
                {
                    productsLoad.Add(parameters[i]);
                }

                result = storageMaster.LoadVehicle(productsLoad);

                break;

            case "SendVehicleTo":
                string sourceName       = parameters[0];
                int    sourceGarageSlot = int.Parse(parameters[1]);
                string destinationName  = parameters[2];

                result = storageMaster.SendVehicleTo(sourceName, sourceGarageSlot, destinationName);
                break;

            case "UnloadVehicle":
                storageName = parameters[0];
                garageSlot  = int.Parse(parameters[1]);

                result = storageMaster.UnloadVehicle(storageName, garageSlot);
                break;

            case "GetStorageStatus":
                storageName = parameters[0];

                result = storageMaster.GetStorageStatus(storageName);
                break;

            default:
                throw new InvalidOperationException("Unrecognized command " + command);
            }

            return(result);
        }
示例#15
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (input != "END")
            {
                string[] tokens  = input.Split().ToArray();
                string   command = tokens[0];
                string   result  = string.Empty;

                try
                {
                    switch (command)
                    {
                    case "AddProduct":
                        //{type} {price}
                        string productTypeToAdd = tokens[1];
                        double priceToAdd       = double.Parse(tokens[2]);
                        result = storageMaster.AddProduct(productTypeToAdd, priceToAdd);
                        Console.WriteLine(result);
                        break;

                    case "RegisterStorage":
                        // {type} {name}
                        string storageTypeToAdd = tokens[1];
                        string nameToAdd        = tokens[2];
                        result = storageMaster.RegisterStorage(storageTypeToAdd, nameToAdd);
                        Console.WriteLine(result);
                        break;

                    case "SelectVehicle":
                        // {storageName} {garageSlot}
                        string storageName        = tokens[1];
                        int    garageSlotToSelect = int.Parse(tokens[2]);
                        result = storageMaster.SelectVehicle(storageName, garageSlotToSelect);
                        Console.WriteLine(result);
                        break;

                    case "LoadVehicle":
                        // {productName1} {productName2} {productNameN}
                        string[] productsToAdd = tokens.Skip(1).ToArray();
                        result = storageMaster.LoadVehicle(productsToAdd);
                        Console.WriteLine(result);
                        break;

                    case "SendVehicleTo":
                        // {sourceName} {sourceGarageSlot} {destinationName}
                        string sourceName       = tokens[1];
                        int    sourceGarageSlot = int.Parse(tokens[2]);
                        string destinationName  = tokens[2];
                        result = storageMaster.SendVehicleTo(sourceName, sourceGarageSlot, destinationName);
                        Console.WriteLine(result);
                        break;

                    case "UnloadVehicle":
                        // {storageName} {garageSlot}
                        string storageNameToUnload = tokens[1];
                        int    garageSlot          = int.Parse(tokens[2]);
                        result = storageMaster.UnloadVehicle(storageNameToUnload, garageSlot);
                        Console.WriteLine(result);
                        break;

                    case "GetStorageStatus":
                        // {storageName}
                        string storageNameStatus = tokens[1];
                        result = storageMaster.GetStorageStatus(storageNameStatus);
                        Console.WriteLine(result);
                        break;
                    }
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"Error:{ioe.Message}");
                }
            }

            string summary = storageMaster.GetSummary();

            Console.WriteLine(summary);
        }
示例#16
0
        public void Run()
        {
            string[] command = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                               .ToArray();

            StorageMaster storageMaster = new StorageMaster();

            while (command[0]?.ToLower() != "end")
            {
                try
                {
                    string type             = string.Empty;
                    double price            = 0;
                    string name             = string.Empty;
                    string storageName      = string.Empty;
                    int    garageSlot       = 0;
                    string sourceName       = string.Empty;
                    int    sourceGarageSlot = 0;
                    string destinationName  = string.Empty;

                    switch (command[0].ToLower())
                    {
                    case "addproduct":
                        type  = command[1];
                        price = double.Parse(command[2]);
                        string addedProduct = storageMaster.AddProduct(type, price);
                        Console.WriteLine(addedProduct);
                        break;

                    case "registerstorage":
                        type = command[1];
                        name = command[2];
                        string registeredStorage = storageMaster.RegisterStorage(type, name);
                        Console.WriteLine(registeredStorage);
                        break;

                    case "selectvehicle":
                        storageName = command[1];
                        garageSlot  = int.Parse(command[2]);
                        string selectedVehicle = storageMaster.SelectVehicle(storageName, garageSlot);
                        Console.WriteLine(selectedVehicle);
                        break;

                    case "loadvehicle":
                        List <string> productNames = new List <string>();
                        for (int i = 1; i < command.Length; i++)
                        {
                            productNames.Add(command[i]);
                        }
                        string loadedVehicle = storageMaster.LoadVehicle(productNames);
                        Console.WriteLine(loadedVehicle);
                        break;

                    case "sendvehicleto":
                        sourceName       = command[1];
                        sourceGarageSlot = int.Parse(command[2]);
                        destinationName  = command[3];
                        string sendVehicle = storageMaster.SendVehicleTo(sourceName, sourceGarageSlot, destinationName);
                        Console.WriteLine(sendVehicle);
                        break;

                    case "unloadvehicle":
                        storageName = command[1];
                        garageSlot  = int.Parse(command[2]);
                        string unloadedVehicle = storageMaster.UnloadVehicle(storageName, garageSlot);
                        Console.WriteLine(unloadedVehicle);
                        break;

                    case "getstoragestatus":
                        storageName = command[1];
                        string storageStatus = storageMaster.GetStorageStatus(storageName);
                        Console.WriteLine(storageStatus);
                        break;

                    default:
                        break;
                    }
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine($"Error: {e.Message}");
                }
                command = Console.ReadLine()
                          .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                          .ToArray();
            }
            Console.WriteLine(storageMaster.GetSummary());
        }
示例#17
0
        public void Run()
        {
            string[] input = Console.ReadLine().Split();

            while (input[0] != "END")
            {
                try
                {
                    string command = input[0];
                    switch (command)
                    {
                    case "AddProduct":
                        string type  = input[1];
                        double price = double.Parse(input[2]);
                        Console.WriteLine(storageMaster.AddProduct(type, price));
                        break;

                    case "RegisterStorage":
                        type = input[1];
                        string name = input[2];
                        Console.WriteLine(storageMaster.RegisterStorage(type, name));

                        break;

                    case "SelectVehicle":
                        string storageName = input[1];
                        int    garageSlot  = int.Parse(input[2]);
                        Console.WriteLine(storageMaster.SelectVehicle(storageName, garageSlot));

                        break;

                    case "LoadVehicle":

                        Console.WriteLine(storageMaster.LoadVehicle(input.Skip(1)));
                        break;

                    case "SendVehicleTo":
                        string sourceName       = input[1];
                        int    sourceGarageSlot = int.Parse(input[2]);
                        string destinationName  = input[3];
                        Console.WriteLine(storageMaster.SendVehicleTo(sourceName, sourceGarageSlot, destinationName));

                        break;

                    case "UnloadVehicle":
                        storageName = input[1];
                        garageSlot  = int.Parse(input[2]);
                        Console.WriteLine(storageMaster.UnloadVehicle(storageName, garageSlot));

                        break;

                    case "GetStorageStatus":
                        storageName = input[1];
                        Console.WriteLine(storageMaster.GetStorageStatus(storageName));
                        break;
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                }
                input = Console.ReadLine().Split();
            }
            Console.WriteLine(storageMaster.GetSummary());
        }
示例#18
0
        private string ReadCommands(string command, string[] input)
        {
            switch (command)
            {
            case "AddProduct":
            {
                string type  = input[1];
                double price = double.Parse(input[2]);

                return(storageMaster.AddProduct(type, price));
            }

            case "RegisterStorage":
            {
                string type = input[1];
                string name = input[2];

                return(storageMaster.RegisterStorage(type, name));
            }

            case "SelectVehicle":
            {
                string storageName = input[1];
                int    garageSlot  = int.Parse(input[2]);

                return(storageMaster.SelectVehicle(storageName, garageSlot));
            }

            case "LoadVehicle":
            {
                List <string> products = input.Skip(1).ToList();

                return(storageMaster.LoadVehicle(products));
            }

            case "SendVehicleTo":
            {
                string sourceName      = input[1];
                int    garageSlot      = int.Parse(input[2]);
                string destinationName = input[3];

                return(storageMaster.SendVehicleTo(sourceName, garageSlot, destinationName));
            }

            case "UnloadVehicle":
            {
                string storageName = input[1];
                int    garageSlot  = int.Parse(input[2]);

                return(storageMaster.UnloadVehicle(storageName, garageSlot));
            }

            case "GetStorageStatus":
            {
                string storageName = input[1];

                return(storageMaster.GetStorageStatus(storageName));
            }

            default:
                return(null);
            }
        }
示例#19
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (input != "END")
            {
                try
                {
                    string[] comands = input.Split();

                    string call = comands[0];

                    string output = "";
                    if (call == "AddProduct")
                    {
                        string type  = comands[1];
                        double price = double.Parse(comands[2]);

                        output = storageMaster.AddProduct(type, price);
                    }
                    else if (call == "RegisterStorage")
                    {
                        string type = comands[1];
                        string name = comands[2];

                        output = storageMaster.RegisterStorage(type, name);
                    }
                    else if (call == "SelectVehicle")
                    {
                        string storigName = comands[1];
                        int    garageSlot = int.Parse(comands[2]);

                        output = storageMaster.SelectVehicle(storigName, garageSlot);
                    }
                    else if (call == "LoadVehicle")
                    {
                        string[] hold = comands.Skip(1).ToArray();

                        output = storageMaster.LoadVehicle(hold);
                    }
                    else if (call == "SendVehicleTo")
                    {
                        string sourceName       = comands[1];
                        int    sourceGarageSlot = int.Parse(comands[2]);
                        string destinationName  = comands[3];

                        output = storageMaster.SendVehicleTo(sourceName, sourceGarageSlot, destinationName);
                    }
                    else if (call == "UnloadVehicle")
                    {
                        string storageName = comands[1];
                        int    garageSlot  = int.Parse(comands[2]);

                        output = storageMaster.UnloadVehicle(storageName, garageSlot);
                    }
                    else if (call == "GetStorageStatus")
                    {
                        string storageName = comands[1];

                        output = storageMaster.GetStorageStatus(storageName);
                    }

                    Console.WriteLine(output);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex.Message}");
                }

                input = Console.ReadLine();
            }

            Console.WriteLine(storageMaster.GetSummary());
        }
        public static void Run()
        {
            StorageMaster sm = new StorageMaster();
            string        input;

            while ((input = Console.ReadLine()) != "END")
            {
                try
                {
                    string[] commandArgs = input
                                           .Split();
                    string command = commandArgs[0];
                    string result  = string.Empty;

                    switch (command)
                    {
                    case "AddProduct":
                    {
                        string type  = commandArgs[1];
                        double price = double.Parse(commandArgs[2]);
                        result = sm.AddProduct(type, price);
                        break;
                    }

                    case "RegisterStorage":
                    {
                        string type = commandArgs[1];
                        string name = commandArgs[2];
                        result = sm.RegisterStorage(type, name);
                        break;
                    }

                    case "SelectVehicle":
                    {
                        string name       = commandArgs[1];
                        int    garageSlot = int.Parse(commandArgs[2]);
                        result = sm.SelectVehicle(name, garageSlot);
                        break;
                    }

                    case "LoadVehicle":
                    {
                        IEnumerable <string> productNames = commandArgs.Skip(1);
                        result = sm.LoadVehicle(productNames);
                        break;
                    }

                    case "SendVehicleTo":
                    {
                        string sourceName       = commandArgs[1];
                        int    sourceGarageSlot = int.Parse(commandArgs[2]);
                        string destinationName  = commandArgs[3];
                        result = sm.SendVehicleTo(sourceName, sourceGarageSlot, destinationName);
                        break;
                    }

                    case "UnloadVehicle":
                    {
                        string storageName = commandArgs[1];
                        int    garageSlot  = int.Parse(commandArgs[2]);
                        result = sm.UnloadVehicle(storageName, garageSlot);
                        break;
                    }

                    case "GetStorageStatus":
                    {
                        string storageName = commandArgs[1];
                        result = sm.GetStorageStatus(storageName);
                        break;
                    }

                    default:
                        break;
                    }

                    Console.WriteLine(result);
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.InnerException.Message);
                    }
                    else
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }

            Console.WriteLine(sm.GetSummary());
        }