Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        // 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();
            }
        }