Esempio n. 1
0
        private void SetModeHeatingButtonClick(object sender, EventArgs e)
        {
            HttpContext.Current.Session["Heating"] = modeHeating.SelectedIndex;
            IModeHeating h = (IModeHeating)DevicesDictionary[id];

            switch (modeHeating.SelectedIndex)
            {
            default:
                h.SetMaxMode();
                break;

            case 1:
                h.SetMinMode();
                break;
            }
            Controls.Clear();
            Initializer();
        }
Esempio n. 2
0
        public ActionResult SetModeHeating(int id, string h)
        {
            IDictionary <int, Device> devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"];
            IModeHeating heating = (IModeHeating)devicesDictionary[id];

            Session["ModeHeating"] = h;
            switch (h)
            {
            default:
                heating.SetMaxMode();
                break;

            case "MinMode":
                heating.SetMinMode();
                break;
            }

            Session["Devices"] = devicesDictionary;
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public void Show()
        {
            CO = new CreateObject();

            DevicesDictionary.Add("TV1", CO.CreateTv());
            DevicesDictionary.Add("Ref1", CO.CreateRef());
            DevicesDictionary.Add("Shut1", CO.CreateShut());
            DevicesDictionary.Add("Boiler1", CO.CreateBoiler());
            DevicesDictionary.Add("WS1", CO.CreateWs());

            while (true)
            {
                Console.Clear();
                foreach (var dev in DevicesDictionary)
                {
                    Console.WriteLine("Название: " + dev.Key + ", " + dev.Value.ToString());
                }
                Console.WriteLine();
                Console.Write("Введите команду: ");

                string[] commands = Console.ReadLine().Split(' ');
                if (commands[0].ToLower() == "exit" & commands.Length == 3)
                {
                    return;
                }
                if (commands.Length != 3)
                {
                    Help();
                    continue;
                }
                if (commands[0].ToLower() == "add" && !DevicesDictionary.ContainsKey(commands[2]))
                {
                    if (commands[1] == "TV")
                    {
                        DevicesDictionary.Add(commands[2], CO.CreateTv());
                        continue;
                    }
                    if (commands[1] == "ref")
                    {
                        DevicesDictionary.Add(commands[2], CO.CreateRef());
                        continue;
                    }
                    if (commands[1] == "shut")
                    {
                        DevicesDictionary.Add(commands[2], CO.CreateShut());
                        continue;
                    }
                    if (commands[1] == "boiler")
                    {
                        DevicesDictionary.Add(commands[2], CO.CreateBoiler());
                        continue;
                    }
                    if (commands[1] == "WS")
                    {
                        DevicesDictionary.Add(commands[2], CO.CreateWs());
                        continue;
                    }
                }

                if (commands[0].ToLower() == "add" && DevicesDictionary.ContainsKey(commands[2]))
                {
                    Console.WriteLine("Устройство с таким именем уже существует");
                    Console.WriteLine("Нажмите любую клавишу для продолжения");
                    Console.ReadLine();
                    continue;
                }

                if (commands[0].ToLower() == "del" && !DevicesDictionary.ContainsKey(commands[2]))
                {
                    Console.WriteLine("Выполнение команды невозможно, т.к. устройство с таким именем не существует");
                    Console.WriteLine("Нажмите любую клавишу для продолжения");
                    Console.ReadLine();
                    continue;
                }

                if (!DevicesDictionary.ContainsKey(commands[2]))
                {
                    Help();
                    continue;
                }

                if (commands[0].ToLower() == "del" && DevicesDictionary.ContainsKey(commands[2]))
                {
                    DevicesDictionary.Remove(commands[2]);
                    continue;
                }

                switch (commands[0].ToLower())
                {
                case "on":
                    DevicesDictionary[commands[2]].On();
                    break;

                case "off":
                    DevicesDictionary[commands[2]].Off();
                    break;
                }

                if (DevicesDictionary[commands[2]] is IChannelSetup)
                {
                    IChannelSetup t = (IChannelSetup)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "scan":
                        Console.Clear();
                        Console.WriteLine(t.ChannelScan());
                        Console.ReadKey();
                        break;

                    case "list_chan":
                        Console.WriteLine(t.ListChannel());
                        Console.ReadKey();
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is ISetChannel)
                {
                    ISetChannel ch = (ISetChannel)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "next":
                        ch.NextChannel();
                        break;

                    case "early":
                        ch.EarlyChannel();
                        break;

                    case "go_to":
                        Console.WriteLine("Введите номер канала: ");
                        Input = Console.ReadLine();
                        if (Int32.TryParse(Input, out temp))
                        {
                            if (temp < 0 || temp > ch.MAXchannel)
                            {
                                Console.WriteLine("Ошибка. Такого канала не существует!");
                                Console.ReadKey();
                            }
                            else
                            {
                                ch.GoToChannel(temp);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Ошибка! Некорректный ввод номера канала.");
                            Console.ReadKey();
                        }
                        break;

                    case "prev_chan":
                        ch.PreviousChannel();
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is ISetVolume)
                {
                    ISetVolume v = (ISetVolume)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "mute":
                        v.SetMute();
                        break;

                    case "max_vol":
                        v.MaxVolume();
                        break;

                    case "min_vol":
                        v.MinVolume();
                        break;

                    case "set_vol":
                        Console.WriteLine("Введите уровень громкости в пределах 0...100: ");
                        Input = Console.ReadLine();
                        if (Int32.TryParse(Input, out temp))
                        {
                            if (temp < 0 || temp > 100)
                            {
                                Console.WriteLine("Ошибка! Недопустимое значение громкости.");
                                Console.ReadKey();
                            }
                            else
                            {
                                v.SetVolume(temp);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Ошибка! Некорректный ввод громкости.");
                            Console.ReadKey();
                        }
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is IRateOfOpening)
                {
                    IRateOfOpening r = (IRateOfOpening)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "open":
                        r.Open();
                        break;

                    case "close":
                        r.Close();
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is ISetFreezeMode)
                {
                    ISetFreezeMode r = (ISetFreezeMode)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "low":
                        r.SetLowFreeze();
                        break;

                    case "colder":
                        r.SetColderFreezing();
                        break;

                    case "deep":
                        r.SetDeepFreeze();
                        break;

                    case "defrost":
                        r.SetDefrost();
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is ISetTemperature)
                {
                    ISetTemperature r = (ISetTemperature)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "level_t":
                        Console.WriteLine("Введите желаемую температуру в диапазоне 2...15: ");
                        Input = Console.ReadLine();
                        if (Double.TryParse(Input, out t))
                        {
                            if (t < 2 || t > 15)
                            {
                                Console.WriteLine("Ошибка! Недопустимое значение температуры.");
                                Console.ReadKey();
                            }
                            else
                            {
                                r.SetLevelTemperature(t);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Ошибка! Некорректный ввод температуры.");
                            Console.ReadKey();
                        }
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is ICustomMode)
                {
                    ICustomMode w = (ICustomMode)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "custom":
                        Console.WriteLine("Введите желаемый уровень температуры в диапазоне 30...90: ");
                        Input = Console.ReadLine();
                        if (Double.TryParse(Input, out t))
                        {
                            if (t < 30 || t > 90)
                            {
                                Console.WriteLine("Ошибка! Недопустимое значение температуры.");
                                Console.ReadKey();
                            }
                            else
                            {
                                w.SetCustomMode(t);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Ошибка! Некорректный ввод температуры.");
                            Console.ReadKey();
                        }
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is ITimeOfDayMode)
                {
                    ITimeOfDayMode w = (ITimeOfDayMode)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "morning":
                        w.SetMorningMode();
                        break;

                    case "evening":
                        w.SetEveningMode();
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is IModeHeating)
                {
                    IModeHeating b = (IModeHeating)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "min_mode":
                        b.SetMinMode();
                        break;

                    case "max_mode":
                        b.SetMaxMode();
                        break;
                    }
                }

                if (DevicesDictionary[commands[2]] is IEnterLevel)
                {
                    IEnterLevel e = (IEnterLevel)DevicesDictionary[commands[2]];
                    switch (commands[0].ToLower())
                    {
                    case "ent_l":
                        Console.WriteLine("Введите уровень влажности почвы: ");
                        Input = Console.ReadLine();
                        if (Int32.TryParse(Input, out temp))
                        {
                            if (temp < 0 || temp > 100)
                            {
                                Console.WriteLine("Ошибка! Недопустимое значение уровня влажности почвы.");
                                Console.ReadKey();
                            }
                            else
                            {
                                e.EnterLevel(temp);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Ошибка! Некорректный ввод уровня влажности почвы.");
                            Console.ReadKey();
                        }
                        break;
                    }
                }
            }
        }