public override void Awake(NSObject context) { base.Awake (context); // Configure interface objects here. Console.WriteLine ("{0} awake with context", this); _light = ((NSObjectWrapper<Light>)context).Context; this.lightNameLabel.SetText (_light.Description); _onOffSwitch = _light.On; this.onOffSwitch.SetOn (_onOffSwitch); this.brightnessSlider.SetValue (_light.Brightness); }
private void SendCommand(Light light, string requestData) { ASCIIEncoding encoding = new ASCIIEncoding (); byte[] data = encoding.GetBytes (requestData); HttpWebRequest request = new HttpWebRequest (new Uri (string.Format("{0}/lights/{1}/state", _baseUrl, light.Id))); request.ContentType = "application/json"; request.Method = "PUT"; // Set the content length of the string being posted. request.ContentLength = data.Length; Stream newStream = request.GetRequestStream (); newStream.Write (data, 0, data.Length); }
public void FlipSwitch(Light light, bool turnOn) { string requestData = string.Format("{{\"on\" : {0}}}", turnOn.ToString().ToLower()); this.SendCommand (light, requestData); }
public void AdjustBrightness(Light light, int brightnessLevel) { string requestData = string.Format("{{\"bri\" : {0}}}", brightnessLevel.ToString()); this.SendCommand (light, requestData); }