private void FillIBrightable(ISmartDevice dev) { if (dev is IBrightable) { IBrightable idev = dev as IBrightable; int max; int min; int step; if (!int.TryParse(Request.Params[CreateDeviceFields.brightnessMax], out max)) { max = CreateDevicePlaceholders.brightnessMax; } if (!int.TryParse(Request.Params[CreateDeviceFields.brightnessMin], out min)) { min = CreateDevicePlaceholders.brightnessMin; } if (!int.TryParse(Request.Params[CreateDeviceFields.brightnessStep], out step)) { step = CreateDevicePlaceholders.brightnessStep; } idev.BrightnessMin = min; idev.BrightnessMax = max; idev.BrightnessStep = step; } }
public ActionResult AdjustBrightness(string id, string direction) { ViewBag.Title = title; SmartHouseContext shContext = LoadContext(); ISmartDevice dev = shContext.SmartHouse[id]; if (dev is IBrightable) { IBrightable thermo = dev as IBrightable; switch (direction) { case AdjustDirections.increase: thermo.IncreaseBrightness(); break; case AdjustDirections.decrease: thermo.DecreaseBrightness(); break; } } SmartHouseConfig shConfig = GetConfig(); SaveSmartHouse(shContext.SmartHouse); return(View("Index", shContext as object)); }
protected void DisplayIBrightable(Control destination) { if (Device is IBrightable) { IBrightable dev = Device as IBrightable; Label td; Button b; Panel tr = new Panel(); b = new Button(); b.ID = "btnBrightnessDec" + Device.Name; b.ToolTip = "Min = " + dev.BrightnessMin; b.CssClass = "btnArrow btnArrowLeft"; b.Click += (senderCtrl, eargs) => { dev.DecreaseBrightness(); ResetSubControls(templatePath); BuildControlMarkup(); }; tr.Controls.Add(b); //================ td = new Label(); td.CssClass = "value"; td.Text = dev.Brightness.ToString(); tr.Controls.Add(td); //================ b = new Button(); b.ID = "btnBrightnessInc" + Device.Name; b.ToolTip = "Max = " + dev.BrightnessMax; b.CssClass = "btnArrow btnArrowRight"; b.Click += (senderCtrl, eargs) => { dev.IncreaseBrightness(); ResetSubControls(templatePath); BuildControlMarkup(); }; tr.Controls.Add(b); td = new Label(); td.Text = "Яркость"; tr.Controls.Add(td); destination.Controls.Add(tr); } else { } }
// 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); }
private void GoToBrightCommands() { if (command.Length > 3) { throw new ArgumentException("Wrong command"); } else if ("down" == command[2].ToLower()) { if (deviceList[command[0]] is IBrightable) { IBrightable device = (IBrightable)deviceList[command[0]]; device.BrightDown(); } else if (deviceList[command[0]] is ILampHolderBrightable) { ILampHolderBrightable device = (ILampHolderBrightable)deviceList[command[0]]; device.BrightDownLamp(); } else { throw new ArgumentException("Wrong device"); } } else if ("up" == command[2].ToLower()) { if (deviceList[command[0]] is IBrightable) { IBrightable device = (IBrightable)deviceList[command[0]]; device.BrightUp(); } else if (deviceList[command[0]] is ILampHolderBrightable) { ILampHolderBrightable device = (ILampHolderBrightable)deviceList[command[0]]; device.BrightUpLamp(); } else { throw new ArgumentException("Wrong device"); } } else { throw new ArgumentException("Wrong command"); } }
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(); }