private void Button_Click(object sender, RoutedEventArgs e) { try { this.HueUserName.Text = HueHelper.GetHueUser(this.HueBridgeIP.Text); } catch (Exception e1) { MessageBox.Show(e1.Message); } }
protected override CustomListExecuteReturnContext ExecuteFunctionOverride(CustomListData data, CustomListExecuteParameterContext context) { var bridgeIP = data.Parameter.Split(';')[0]; var userName = data.Parameter.Split(';')[1]; this.Log?.Info(string.Format("The function {0} has been called with {1} parameters", context.FunctionName, context.Values.Count)); var returnContext = default(CustomListExecuteReturnContext); if (context.FunctionName.Equals("switchlighton", StringComparison.InvariantCultureIgnoreCase)) { string lightname = context.Values[0].StringValue; this.Log?.Info(string.Format("Lightname: {0} -> switchlighton", lightname)); HueHelper.SwitchLight(bridgeIP, userName, lightname, true); } else if (context.FunctionName.Equals("switchlightoff", StringComparison.InvariantCultureIgnoreCase)) { string lightname = context.Values[0].StringValue; this.Log?.Info(string.Format("Lightname: {0} -> switchlightoff", lightname)); HueHelper.SwitchLight(bridgeIP, userName, lightname, false); } else if (context.FunctionName.Equals("setlightbrightness", StringComparison.InvariantCultureIgnoreCase)) { string lightname = context.Values[0].StringValue; int brightness = Convert.ToInt32(context.Values[1].GetValue()); this.Log?.Info(string.Format("Lightname: {0} -> setlightbrightness -> {1}", lightname, brightness)); HueHelper.SetLightBrightness(bridgeIP, userName, lightname, brightness); } else if (context.FunctionName.Equals("setlightcolor", StringComparison.InvariantCultureIgnoreCase)) { string lightname = context.Values[0].StringValue; int color = Convert.ToInt32(context.Values[1].GetValue()); this.Log?.Info(string.Format("Lightname: {0} -> setlightcolor -> {1}", lightname, color)); HueHelper.SetLightColor(bridgeIP, userName, lightname, color); } else if (context.FunctionName.Equals("alert", StringComparison.InvariantCultureIgnoreCase)) { string lightname = context.Values[0].StringValue; this.Log?.Info(string.Format("Lightname: {0} -> alert", lightname)); HueHelper.Alert(bridgeIP, userName, lightname); } else { throw new DataErrorException("Function is not supported in this version."); } return(returnContext); }