public void CreateClinic(string[] parameters)
 {
     try
     {
         Clinic clinic = clinicFactory.CreateClinic(parameters);
         clinics.Add(clinic);
     }
     catch (InvalidOperationException ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
示例#2
0
        public void Create(string[] args)
        {
            var name          = args[1];
            var ageOrCapacity = int.Parse(args[2]);

            if (args.Length == 4)
            {
                var  kind = args[3];
                IPet pet  = petFactory.CreatePet(name, ageOrCapacity, kind);
                this.pets.Add(pet);
            }
            else
            {
                IClinic clinic = clinicFactory.CreateClinic(name, ageOrCapacity);
                this.clinics.Add(clinic);
            }
        }
        public void Run()
        {
            int numberOfCommands = int.Parse(Console.ReadLine());

            string[] inputArgs;

            for (int curr = 0; curr < numberOfCommands; curr++)
            {
                inputArgs = Console.ReadLine().Split();

                string command = inputArgs[0];

                switch (command)
                {
                case "Create":
                    string type = inputArgs[1];

                    string[] createArgs = inputArgs.Skip(2).ToArray();

                    if (type == "Pet")
                    {
                        Pet pet = PetFactory.CreatePet(createArgs);
                        pets.Add(pet);
                    }
                    else if (type == "Clinic")
                    {
                        try
                        {
                            Clinic clinic = ClinicFactory.CreateClinic(createArgs);
                            clinics.Add(clinic);
                        }
                        catch (ArgumentException ae)
                        {
                            Console.WriteLine(ae.Message);
                        }
                    }

                    break;

                case "Add":
                    string addPetName    = inputArgs[1];
                    string addClinicName = inputArgs[2];

                    Pet    addPet    = pets.First(p => p.Name == addPetName);
                    Clinic addClinic = clinics.First(c => c.Name == addClinicName);

                    Console.WriteLine(addClinic.Add(addPet));
                    break;

                case "Release":
                    string releaseClinicName = inputArgs[1];

                    Clinic releaseClinic = clinics.First(c => c.Name == releaseClinicName);

                    Console.WriteLine(releaseClinic.Release());
                    break;

                case "HasEmptyRooms":
                    string hasEmptyRoomsClinicName = inputArgs[1];

                    Clinic hasEmptyRoomsClinic = clinics.First(c => c.Name == hasEmptyRoomsClinicName);

                    Console.WriteLine(hasEmptyRoomsClinic.HasEmptyRooms());
                    break;

                case "Print":
                    string printClinicName = inputArgs[1];

                    Clinic printClinic = clinics.First(c => c.Name == printClinicName);

                    if (inputArgs.Length == 2)
                    {
                        printClinic.Print();
                    }
                    else if (inputArgs.Length > 2)
                    {
                        int room = int.Parse(inputArgs[2]);

                        printClinic.Print(room - 1);
                    }
                    break;
                }
            }
        }