Exemple #1
0
        public void Run()
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                var input = reader.ReadLine().Split();

                if (input[0] == "Exit")
                {
                    //Environment.Exit(0);
                    writer.Write(sb.ToString().ToString().TrimEnd());
                }
                try
                {
                    if (input[0] == "AddAstronaut")
                    {
                        string type = input[1];
                        string name = input[2];
                        sb.AppendLine(controller.AddAstronaut(type, name));
                    }
                    else if (input[0] == "AddPlanet")
                    {
                        string   planetName = input[1];
                        string[] items      = new string[input.Length - 2];

                        for (int i = 2; i < input.Length; i++)
                        {
                            items[i - 2] = input[i];
                        }

                        sb.AppendLine(controller.AddPlanet(planetName, items));
                    }
                    else if (input[0] == "RetireAstronaut")
                    {
                        string nameToRetire = input[1];
                        sb.AppendLine(controller.RetireAstronaut(nameToRetire));
                    }
                    else if (input[0] == "ExplorePlanet")
                    {
                        string planetName = input[1];
                        sb.AppendLine(controller.ExplorePlanet(planetName));
                    }
                    else if (input[0] == "Report")
                    {
                        sb.AppendLine(controller.Report());
                    }
                }
                catch (Exception ex)
                {
                    sb.AppendLine(ex.Message);
                }
            }
        }
Exemple #2
0
        public void Run()
        {
            while (true)
            {
                string result = string.Empty;

                var input = reader.ReadLine().Split();
                if (input[0] == "Exit")
                {
                    Environment.Exit(0);
                }
                try
                {
                    if (input[0] == "AddAstronaut")
                    {
                        string type          = input[1];
                        string astronautName = input[2];

                        result = controller.AddAstronaut(type, astronautName);
                    }
                    else if (input[0] == "AddPlanet")
                    {
                        string   planetName = input[1];
                        string[] items      = input.Skip(2).ToArray();

                        result = controller.AddPlanet(input[1], items);
                    }
                    else if (input[0] == "RetireAstronaut")
                    {
                        string astronautName = input[1];

                        result = controller.RetireAstronaut(astronautName);
                    }
                    else if (input[0] == "ExplorePlanet")
                    {
                        string planetName = input[1];

                        result = controller.ExplorePlanet(planetName);
                    }
                    else if (input[0] == "Report")
                    {
                        result = controller.Report();
                    }

                    writer.WriteLine(result);
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.Message);
                }
            }
        }
Exemple #3
0
        public void Run()
        {
            while (true)
            {
                var input = reader.ReadLine().Split();
                if (input[0] == "Exit")
                {
                    Environment.Exit(0);
                }
                try
                {
                    if (input[0] == "AddAstronaut")
                    {
                        //•	AddAstronaut {astronautType} {astronautName}
                        string astronautType = input[1];
                        string astronautName = input[2];

                        writer.WriteLine(controller.AddAstronaut(astronautType, astronautName));
                    }
                    else if (input[0] == "AddPlanet")
                    {
                        //•	AddPlanet {planetName} {item1} {item2}… {itemN}
                        string   planetName = input[1];
                        string[] items      = input.Skip(2).ToArray();

                        writer.WriteLine(controller.AddPlanet(planetName, items));
                    }
                    else if (input[0] == "RetireAstronaut")
                    {
                        //•	RetireAstronaut {astronautName}
                        string astronautName = input[1];

                        writer.WriteLine(this.controller.RetireAstronaut(astronautName));
                    }
                    else if (input[0] == "ExplorePlanet")
                    {
                        //•	ExplorePlanet {planetName}
                        string planetName = input[1];

                        writer.WriteLine(this.controller.ExplorePlanet(planetName));
                    }
                    else if (input[0] == "Report")
                    {
                        writer.WriteLine(this.controller.Report().ToString());
                    }
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.Message);
                }
            }
        }
 public void Run()
 {
     while (true)
     {
         string result = string.Empty;
         var    input  = reader.ReadLine().Split();
         if (input[0] == "Exit")
         {
             Environment.Exit(0);
         }
         try
         {
             if (input[0] == "AddAstronaut")
             {
                 string type = input[1];
                 string name = input[2];
                 result = controller.AddAstronaut(type, name);
             }
             else if (input[0] == "AddPlanet")
             {
                 string name = input[1];
                 ICollection <string> collection = new List <string>();
                 for (int i = 2; i < input.Length; i++)
                 {
                     collection.Add(input[i]);
                 }
                 string[] arr = collection.ToArray();
                 result = controller.AddPlanet(name, arr);
             }
             else if (input[0] == "RetireAstronaut")
             {
                 string name = input[1];
                 result = controller.RetireAstronaut(name);
             }
             else if (input[0] == "ExplorePlanet")
             {
                 string name = input[1];
                 result = controller.ExplorePlanet(name);
             }
             else if (input[0] == "Report")
             {
                 result = controller.Report();
             }
             this.writer.WriteLine(result);
         }
         catch (Exception ex)
         {
             writer.WriteLine(ex.Message);
         }
     }
 }
        public void Run()
        {
            while (true)
            {
                var    input  = reader.ReadLine().Split();
                string output = string.Empty;

                if (input[0] == "Exit")
                {
                    Environment.Exit(0);
                }
                try
                {
                    if (input[0] == "AddAstronaut")
                    {
                        output = controller.AddAstronaut(input[1], input[2]);
                    }
                    else if (input[0] == "AddPlanet")
                    {
                        string[] parameters = input.Skip(2).ToArray();
                        output = controller.AddPlanet(input[1], parameters);
                    }
                    else if (input[0] == "RetireAstronaut")
                    {
                        output = controller.RetireAstronaut(input[1]);
                    }
                    else if (input[0] == "ExplorePlanet")
                    {
                        output = controller.ExplorePlanet(input[1]);
                    }
                    else if (input[0] == "Report")
                    {
                        output = controller.Report();
                    }
                }

                catch (Exception ex)
                {
                    writer.WriteLine(ex.Message);
                }

                if (output != string.Empty)
                {
                    Console.WriteLine(output);
                }
            }
        }
Exemple #6
0
        public void Run()
        {
            while (true)
            {
                var input  = reader.ReadLine().Split();
                var result = string.Empty;
                if (input[0] == "Exit")
                {
                    Environment.Exit(0);
                }
                try
                {
                    if (input[0] == "AddAstronaut")
                    {
                        result = controller.AddAstronaut(input[1], input[2]);
                    }
                    else if (input[0] == "AddPlanet")
                    {
                        var items = input.Skip(2).Take(input.Length - 2).ToArray();

                        result = controller.AddPlanet(input[1], items);
                    }
                    else if (input[0] == "RetireAstronaut")
                    {
                        result = controller.RetireAstronaut(input[1]);
                    }
                    else if (input[0] == "ExplorePlanet")
                    {
                        result = controller.ExplorePlanet(input[1]);
                    }
                    else if (input[0] == "Report")
                    {
                        result = controller.Report();
                    }
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.Message);
                }

                writer.WriteLine(result);
            }
        }
 public void Run()
 {
     while (true)
     {
         var input = reader.ReadLine().Split();
         if (input[0] == "Exit")
         {
             Environment.Exit(0);
         }
         try
         {
             if (input[0] == "AddAstronaut")
             {
                 writer.WriteLine(controller.AddAstronaut(input[1], input[2]));
             }
             else if (input[0] == "AddPlanet")
             {
                 writer.WriteLine(controller.AddPlanet(input[1], input.Skip(2).ToArray()));
             }
             else if (input[0] == "RetireAstronaut")
             {
                 writer.WriteLine(controller.RetireAstronaut(input[1]));
             }
             else if (input[0] == "ExplorePlanet")
             {
                 writer.WriteLine(controller.ExplorePlanet(input[1]));
             }
             else if (input[0] == "Report")
             {
                 writer.WriteLine(controller.Report());
             }
         }
         catch (Exception ex)
         {
             writer.WriteLine(ex.Message);
         }
     }
 }