Ejemplo n.º 1
0
        private void FillIHaveThermostat(ISmartDevice dev)
        {
            if (dev is IHaveThermostat)
            {
                IHaveThermostat idev = dev as IHaveThermostat;

                int max;
                int min;
                int step;

                if (!int.TryParse(Request.Params[CreateDeviceFields.temperatureMax], out max))
                {
                    max = CreateDevicePlaceholders.temperatureMax;
                }
                if (!int.TryParse(Request.Params[CreateDeviceFields.temperatureMin], out min))
                {
                    min = CreateDevicePlaceholders.temperatureMin;
                }
                if (!int.TryParse(Request.Params[CreateDeviceFields.temperatureStep], out step))
                {
                    step = CreateDevicePlaceholders.temperatureStep;
                }

                idev.TempMin  = min;
                idev.TempMax  = max;
                idev.TempStep = step;
            }
        }
Ejemplo n.º 2
0
        public ActionResult AdjustTemperature(string id, string direction)
        {
            ViewBag.Title = title;

            SmartHouseContext shContext = LoadContext();

            ISmartDevice dev = shContext.SmartHouse[id];

            if (dev is IHaveThermostat)
            {
                IHaveThermostat thermo = dev as IHaveThermostat;
                switch (direction)
                {
                case AdjustDirections.increase:
                    thermo.IncreaseTemperature();
                    break;

                case AdjustDirections.decrease:
                    thermo.DecreaseTemperature();
                    break;
                }
            }

            SmartHouseConfig shConfig = GetConfig();

            SaveSmartHouse(shContext.SmartHouse);

            return(View("Index", shContext as object));
        }
Ejemplo n.º 3
0
        protected void DisplayIHaveThermostat(Control destination)
        {
            if (Device is IHaveThermostat)
            {
                IHaveThermostat dev = Device as IHaveThermostat;
                Label           td;
                Button          b;
                Panel           tr = new Panel();

                b    = new Button();
                b.ID = "btnTemperatureDec" + Device.Name;
                b.Attributes["title"] = "Min = " + dev.TempMin;
                b.CssClass            = "btnArrow btnArrowLeft";

                b.Click += (senderCtrl, eargs) =>
                {
                    dev.DecreaseTemperature();
                    ResetSubControls(templatePath);
                    BuildControlMarkup();
                };
                tr.Controls.Add(b);

                td          = new Label();
                td.CssClass = "value";
                td.Text     = dev.Temperature.ToString();
                tr.Controls.Add(td);

                b    = new Button();
                b.ID = "btnTemperatureInc" + Device.Name;
                b.Attributes["title"] = "Max = " + dev.TempMax;
                b.CssClass            = "btnArrow btnArrowRight";

                b.Click += (senderCtrl, eargs) =>
                {
                    dev.IncreaseTemperature();
                    ResetSubControls(templatePath);
                    BuildControlMarkup();
                };
                tr.Controls.Add(b);

                td      = new Label();
                td.Text = "Температура";
                tr.Controls.Add(td);

                destination.Controls.Add(tr);
            }
            else
            {
            }
        }
Ejemplo n.º 4
0
        // POST: api/Device
        public IHttpActionResult Post([FromBody] string value)
        {
            IHttpActionResult           result = BadRequest();
            Dictionary <string, string> fields;
            DataContractJsonSerializer  js = new DataContractJsonSerializer(typeof(Dictionary <string, string>));

            using (Stream str = GenerateStreamFromString(value))
            {
                fields = (Dictionary <string, string>)js.ReadObject(str);
            }
            ISmartHouse sh = LoadSmartHouse();

            if (sh[fields[CreateDeviceFields.name]] == null)
            {
                Assembly           modelAssembly = Assembly.Load("SmartHouse");
                ISmartHouseCreator shc           = Manufacture.GetManufacture(modelAssembly);

                ISmartDevice dev = shc.CreateDevice(fields[CreateDeviceFields.devType], fields[CreateDeviceFields.name]);
                if (dev != null)
                {
                    if (dev is IBrightable)
                    {
                        IBrightable idev = dev as IBrightable;
                        idev.BrightnessMax  = int.Parse(fields[CreateDeviceFields.brightnessMax]);
                        idev.BrightnessMin  = int.Parse(fields[CreateDeviceFields.brightnessMin]);
                        idev.BrightnessStep = int.Parse(fields[CreateDeviceFields.brightnessStep]);
                    }

                    if (dev is IHaveThermostat)
                    {
                        IHaveThermostat idev = dev as IHaveThermostat;
                        idev.TempMax  = int.Parse(fields[CreateDeviceFields.temperatureMax]);
                        idev.TempMin  = int.Parse(fields[CreateDeviceFields.temperatureMin]);
                        idev.TempStep = int.Parse(fields[CreateDeviceFields.temperatureStep]);
                    }


                    sh.AddDevice(dev);
                    SaveSmartHouse(sh);
                    result = Ok();
                }
            }
            else
            {
                result = BadRequest(string.Format("Устройство {0} уже есть в системе", fields[CreateDeviceFields.name]));
            }
            return(result);
        }
Ejemplo n.º 5
0
        protected void btnAddDevice_OnClick(object sender, EventArgs e)
        {
            ISmartHouseCreator shc = Manufacture.GetManufacture(Assembly.Load("SmartHouse"));

            string name;

            name = (FindControl(idName) as TextBox).Text.ToLower();

            ISmartDevice dev = shc.CreateDevice(DevType, name);

            //TODO: Вот где-то здесь какая-то верификация должна быть. Наверное.

            if (dev is IHaveThermostat)
            {
                int             min, max, step;
                IHaveThermostat iterm = dev as IHaveThermostat;

                TextBox tbMin  = FindControl(idTempMin) as TextBox;
                TextBox tbMax  = FindControl(idTempMax) as TextBox;
                TextBox tbStep = FindControl(idTempStep) as TextBox;

                if (!int.TryParse(tbMax.Text, out max))
                {
                    int.TryParse(tbMax.Attributes["placeholder"], out max);
                }
                if (!int.TryParse(tbMin.Text, out min))
                {
                    int.TryParse(tbMin.Attributes["placeholder"], out min);
                }
                if (!int.TryParse(tbStep.Text, out step))
                {
                    int.TryParse(tbStep.Attributes["placeholder"], out step);
                }

                iterm.TempMax     = max;
                iterm.TempMin     = min;
                iterm.TempStep    = step;
                iterm.Temperature = max;
            }

            if (dev is IBrightable)
            {
                int         min, max, step;
                IBrightable ibri = dev as IBrightable;

                TextBox tbMin  = FindControl(idBrightMin) as TextBox;
                TextBox tbMax  = FindControl(idBrightMax) as TextBox;
                TextBox tbStep = FindControl(idBrightStep) as TextBox;

                if (!int.TryParse(tbMax.Text, out max))
                {
                    int.TryParse(tbMax.Attributes["placeholder"], out max);
                }
                if (!int.TryParse(tbMin.Text, out min))
                {
                    int.TryParse(tbMin.Attributes["placeholder"], out min);
                }
                if (!int.TryParse(tbStep.Text, out step))
                {
                    int.TryParse(tbStep.Attributes["placeholder"], out step);
                }

                ibri.BrightnessMax  = max;
                ibri.BrightnessMin  = min;
                ibri.BrightnessStep = step;
                ibri.Brightness     = max;
            }

            SmartHouse.AddDevice(dev);

            Session["showAddDevice"] = null;
            ParentForm.RefreshControls();
        }