private void powerSwitchConsumer_ValueChanged(SwitchConsumer consumer, object value) { if (value is bool) { this.IsOn = (bool)value; } }
private async void SwitchWatcher_Added(SwitchWatcher sender, AllJoynServiceInfo args) { SwitchJoinSessionResult joinSessionResult = await SwitchConsumer.JoinSessionAsync(args, sender); if (joinSessionResult.Status == AllJoynStatus.Ok) { switchConsumer = joinSessionResult.Consumer; btnLightSwitch.IsEnabled = true; } }
// searches for the class, initiates it (calls factory method) and returns the instance // TODO: add a lot of error handling! //IIntent CreateCachableIIntent(string className) //{ // if (!InstanceCreateCache.ContainsKey(className)) // { // try // { // // get the type (several ways exist, this is an eays one) // Type type = Type.GetType(className); // // NOTE: this can be tempting, but do NOT use the following, because you cannot // // create a delegate from a ctor and will loose many performance benefits // //ConstructorInfo constructorInfo = type.GetConstructor(Type.EmptyTypes); // // works with public instance/static methods // MethodInfo mi = type.GetMethod("Create"); // // the "magic", turn it into a delegate // var createInstanceDelegate = (Func<IIntent>)mi.CreateDelegate(typeof(Func<IIntent>),mi); // // store for future reference // InstanceCreateCache.Add(className, createInstanceDelegate); // } // catch (Exception e) // { // ShowDeadEyes(); // Debug.WriteLine(e.Message); // } // } // return InstanceCreateCache[className].Invoke(); //} private async void SwitchWatcher_Added(SwitchWatcher sender, AllJoynServiceInfo args) { SwitchJoinSessionResult joinSessionResult = await SwitchConsumer.JoinSessionAsync(args, sender); if (joinSessionResult.Status == AllJoynStatus.Ok) { context.switchConsumer = joinSessionResult.Consumer; context.lightsAvailable = true; SwitchGetValueResult x = await context.switchConsumer.GetValueAsync(); context.lightStatus = (bool)x.Value; Speak("Things network online"); // Wink Left WinkLeft.Begin(); } }
private async void powerSwitchWatcher_Added(SwitchWatcher sender, AllJoynServiceInfo args) { var joinResult = await SwitchConsumer.JoinSessionAsync(args, sender); if (joinResult.Status == AllJoynStatus.Ok) { _powerSwitchConsumer = joinResult.Consumer; _powerSwitchConsumer.SessionLost += this.Consumer_SessionLost; // subscribe to value changes _powerSwitchConsumer.ValueChanged += this.powerSwitchConsumer_ValueChanged; // populate initial values var result = await _powerSwitchConsumer.GetValueAsync(); if (result.Status != AllJoynStatus.Ok) { return; } this.IsOn = result.Value; this.IsConnected = true; } }