Exemple #1
0
        async void OnAdded(FezHatWatcher sender, AllJoynServiceInfo args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                      async() =>
            {
                // Get the about data.
                var aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, _busAttachment, args.SessionPort);
                Debug.WriteLine("Found {0} on {1} from manufacturer: {2}. Connecting...", aboutData.AppName, aboutData.DeviceName, aboutData.Manufacturer);

                var joinResult = await FezHatConsumer.JoinSessionAsync(args, sender);
                if (joinResult.Status != AllJoynStatus.Ok)
                {
                    return;
                }
                FezHats.Add(new FezHatItem()
                {
                    UniqueName        = args.UniqueName,
                    DefaultAppName    = aboutData.AppName,
                    ModelNumber       = aboutData.ModelNumber,
                    DateOfManufacture = aboutData.DateOfManufacture,
                    Consumer          = joinResult.Consumer
                });
                joinResult.Consumer.SessionLost += OnFezHatLost;
                joinResult.Consumer.Signals.ButtonDio18PressedReceived += Signals_ButtonDio18PressedReceived;
            }
                                      );
        }
        private async void _watcher_Added(CurrentTemperatureWatcher sender, AllJoynServiceInfo args)
        {
            CurrentTemperatureJoinSessionResult result = await CurrentTemperatureConsumer.JoinSessionAsync(args, sender);

            _consumer = result.Consumer;
            _consumer.CurrentValueChanged += _consumer_CurrentValueChanged;
        }
        private async void channelWatcher_Added(channelWatcher watcher, AllJoynServiceInfo args)
        {
            if (_channelConsumer == null && args.ObjectPath.Contains(_expectedBusObjectPath))
            {
                var joinSessionResult = await channelConsumer.JoinSessionAsync(args, watcher);

                if (joinSessionResult.Status == AllJoynStatus.Ok)
                {
                    _channelConsumer              = joinSessionResult.Consumer;
                    _channelConsumer.SessionLost += this.Consumer_SessionLost;

                    // subscribe to value changes
                    _channelConsumer.ChannelUpDownChanged += this.channelConsumer_ChannelUpDownChanged;

                    // populate initial values
                    var channelUpDownResult = await _channelConsumer.GetChannelUpDownAsync();

                    if (channelUpDownResult.Status != AllJoynStatus.Ok)
                    {
                        return;
                    }
                    this.ChannelUpDown = channelUpDownResult.ChannelUpDown;

                    this.IsConnected = true;
                }
            }
        }
Exemple #4
0
        private async void _watcher_Added(GarageDoorWatcher sender, AllJoynServiceInfo args)
        {
            GarageDoorJoinSessionResult result = await GarageDoorConsumer.JoinSessionAsync(args, sender);

            _consumer = result.Consumer;
            _consumer.Signals.GarageDoorStateChangedReceived += Signals_GarageDoorStateChangedReceived;
        }
Exemple #5
0
        private async void Watcher_Added(OnboardingWatcher sender, AllJoynServiceInfo args)
        {
            // This demo supports a single onboarding producer, if there are multiple onboarding producers found, then they are ignored.
            // Another approach would be to create a list of all producers found and then allow the user to choose the one they want
            bool bAlreadyJoined = (Interlocked.CompareExchange(ref m_onboardSessionAlreadyJoined, 1, 0) == 1);

            if (bAlreadyJoined)
            {
                return;
            }

            UpdateStatusAsync("Joining session...", NotifyType.StatusMessage);

            OnboardingJoinSessionResult joinSessionResult = await OnboardingConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                UpdateStatusAsync("Session Joined.", NotifyType.ErrorMessage);
                DisposeConsumer();
                m_consumer              = joinSessionResult.Consumer;
                m_consumer.SessionLost += Consumer_SessionLost;

                GetOnboardeeNetworkListAsync();
            }
            else
            {
                UpdateStatusAsync(string.Format("Attempt to join session failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
Exemple #6
0
        private async void Watcher_Added(SecureInterfaceWatcher sender, AllJoynServiceInfo args)
        {
            UpdateStatus("Connecting...", NotifyType.StatusMessage);

            // Attempt to join the session when a producer is discovered.
            SecureInterfaceJoinSessionResult joinSessionResult = await SecureInterfaceConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                m_consumer  = joinSessionResult.Consumer;
                isConnected = true;

                // At the time of connection, the request credentials callback not being invoked is an
                // indication that the client and server are already authenticated from a previous session.
                if (!isCredentialsRequested)
                {
                    UpdateStatus("Connected and already authenticated from previous session.", NotifyType.StatusMessage);
                }
                else
                {
                    if (isAuthenticated)
                    {
                        UpdateStatus("Connected with authentication.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        UpdateStatus("Connected but authentication failed.", NotifyType.ErrorMessage);
                    }
                }
            }
            else
            {
                UpdateStatus(String.Format("Attempt to connect failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
Exemple #7
0
        private async void Watcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            AllJoynAboutDataView aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, busAttachment, args.SessionPort);

            if (aboutData != null && !string.IsNullOrWhiteSpace(aboutData.DeviceId))
            {
                // Join session with the producer of the LampState interface.
                LampStateJoinSessionResult joinSessionResult = await LampStateConsumer.JoinSessionAsync(args, sender);

                if (joinSessionResult.Status == AllJoynStatus.Ok)
                {
                    if (string.Equals(aboutData.DeviceId, lampDeviceId))
                    {
                        consumer = joinSessionResult.Consumer;
                        LampFound?.Invoke(this, new EventArgs());
                        consumer.Signals.LampStateChangedReceived += Signals_LampStateChangedReceived;
                    }

                    if (!arrLamp.Contains(joinSessionResult.Consumer))
                    {
                        arrLamp.Add(joinSessionResult.Consumer);
                    }
                }
            }
        }
        private async void powerSwitchWatcher_Added(binaryWatcher watcher, AllJoynServiceInfo args)
        {
            if (_powerSwitchConsumer == null && args.ObjectPath.Contains(_expectedBusObjectPath))
            {
                var joinResult = await binaryConsumer.JoinSessionAsync(args, watcher);

                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 valueResult = await _powerSwitchConsumer.GetValueAsync();

                    if (valueResult.Status != AllJoynStatus.Ok)
                    {
                        return;
                    }
                    this.IsOn = valueResult.Value;

                    this.IsConnected = true;
                }
            }
        }
        private async void _watcher_Added(CurrentTemperatureWatcher sender, AllJoynServiceInfo args)
        {
            CurrentTemperatureJoinSessionResult result = await CurrentTemperatureConsumer.JoinSessionAsync(args, sender);
            _consumer = result.Consumer;
            _consumer.CurrentValueChanged += _consumer_CurrentValueChanged;

        }
        private async void Watcher_Added(OnboardingWatcher sender, AllJoynServiceInfo args)
        {
            UpdateStatusAsync("Joining session...", NotifyType.StatusMessage);
            OnboardingJoinSessionResult joinSessionResult = await OnboardingConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                DisposeConsumer();
                m_consumer              = joinSessionResult.Consumer;
                m_consumer.SessionLost += Consumer_SessionLost;

                if (!m_isCredentialsRequested)
                {
                    GetOnboardeeNetworkListAsync();
                }
                else
                {
                    if (m_isAuthenticated)
                    {
                        GetOnboardeeNetworkListAsync();
                    }
                }
            }
            else
            {
                UpdateStatusAsync(string.Format("Attempt to join session failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
        private async void Shade_Added(ShadesWatcher sender, AllJoynServiceInfo args)
        {
            ShadesJoinSessionResult joinSessionResult = await ShadesConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                m_Shades.Add(joinSessionResult.Consumer);
                joinSessionResult.Consumer.SessionLost += Consumer_SessionLost;
            }
        }
        private async void Sensor_Added(TemperatureSensorWatcher sender, AllJoynServiceInfo args)
        {
            TemperatureSensorJoinSessionResult joinSessionResult = await TemperatureSensorConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                TemperatureSensorConsumer consumer = joinSessionResult.Consumer;
                m_Sensors.Add(consumer);
            }
        }
        private async void _watcher_Added(GarageDoorWatcher sender, AllJoynServiceInfo args)
        {
            GarageDoorJoinSessionResult result = await GarageDoorConsumer.JoinSessionAsync(args, sender);

            _consumer = result.Consumer;
            _consumer.Signals.GarageDoorStateChangedReceived += Signals_GarageDoorStateChangedReceived;
            var result2 = await _consumer.GetDoorStateAsync();

            GarageDoorState = Convert.ToInt32(result2.DoorState.Value1);
        }
        private async void Lamp_Added(LampWatcher sender, AllJoynServiceInfo args)
        {
            LampJoinSessionResult joinSessionResult = await LampConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                m_Lamps.Add(joinSessionResult.Consumer);
                joinSessionResult.Consumer.SessionLost += Consumer_SessionLost;
            }
        }
Exemple #15
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;
            }
        }
Exemple #16
0
        private async void Watcher_Added(ShadesWatcher sender, AllJoynServiceInfo args)
        {
            ShadesJoinSessionResult joinSessionResult = await ShadesConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                var shade = new Shade(System.IO.Path.GetDirectoryName(args.ObjectPath), joinSessionResult.Consumer);
                Shades.Add(shade);
                shade.SessionLost += Shade_SessionLost;
            }
        }
        private async void SensorWatcher_Added(TemperatureSensorWatcher sender, AllJoynServiceInfo args)
        {
            TemperatureSensorJoinSessionResult joinResult = await TemperatureSensorConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                // Use file system path api to extract object name from path
                var sensor = new TemperatureSensor(System.IO.Path.GetFileName(args.ObjectPath), joinResult.Consumer);
                sensor.SessionLost += Sensor_SessionLost;
                Sensors.Add(sensor);
            }
        }
        private async void Watcher_Added(SecureInterfaceWatcher sender, AllJoynServiceInfo args)
        {
            // Optional - Get the About data of the producer.
            AllJoynAboutDataView aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, m_busAttachment, args.SessionPort);

            // Check to see if device name is populated in the about data, since device name is not a mandatory field.
            if (string.IsNullOrEmpty(aboutData.DeviceName))
            {
                UpdateStatusAsync(string.Format("Found {0} from manufacturer: {1}. Connecting...", aboutData.AppName, aboutData.Manufacturer), NotifyType.StatusMessage);
            }
            else
            {
                UpdateStatusAsync(string.Format("Found {0} on {1} from manufacturer: {2}. Connecting...", aboutData.AppName, aboutData.DeviceName, aboutData.Manufacturer), NotifyType.StatusMessage);
            }

            // Attempt to join the session when a producer is discovered.
            SecureInterfaceJoinSessionResult joinSessionResult = await SecureInterfaceConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                DisposeConsumer();
                m_consumer = joinSessionResult.Consumer;
                m_consumer.IsUpperCaseEnabledChanged += Consumer_IsUpperCaseEnabledChanged;
                m_consumer.Signals.TextSentReceived  += Signals_TextSentReceived;
                m_consumer.SessionLost += Consumer_SessionLost;

                // At the time of connection, the request credentials callback not being invoked is an
                // indication that the consumer and producer are already authenticated from a previous session.
                if (!m_isCredentialsRequested)
                {
                    UpdateStatusAsync("Connected and already authenticated from previous session.", NotifyType.StatusMessage);
                    UpdateIsUpperCaseEnabledAsync();
                }
                else
                {
                    if (m_isAuthenticated)
                    {
                        UpdateStatusAsync("Connected with authentication.", NotifyType.StatusMessage);
                        UpdateIsUpperCaseEnabledAsync();
                    }
                    else
                    {
                        UpdateStatusAsync("Connected but authentication failed.", NotifyType.ErrorMessage);
                    }
                }
                ConsumerOptionsVisibility = Visibility.Visible;
            }
            else
            {
                UpdateStatusAsync(string.Format("Attempt to connect failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
        private async void Watcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status != AllJoynStatus.Ok)
            {
                return;
            }

            _consumer = joinResult.Consumer;

            await _consumer.SetOnOffAsync(false);
        }
        private async void ToasterWatcher_Added(ToasterWatcher sender, AllJoynServiceInfo args)
        {
            ToasterJoinSessionResult toasterJoinSessionResult = await ToasterConsumer.JoinSessionAsync(args, sender);

            if (toasterJoinSessionResult.Status == AllJoynStatus.Ok)
            {
                ToasterFoundEventArgs toasterFoundArgs = new ToasterFoundEventArgs(toasterJoinSessionResult.Consumer);
                OnToasterFound(toasterFoundArgs);
            }
            else
            {
            }
        }
        private async void PhoneProducer_Added(ProducerWatcher sender, AllJoynServiceInfo args)
        {
            Debug.WriteLine("Attempt to join session for phone...");

            var phoneJoin = await ProducerConsumer.JoinSessionAsync(args, sender);

            if (phoneJoin.Status == AllJoynStatus.Ok)
            {
                _phoneMessage = phoneJoin.Consumer;
                Debug.WriteLine("Consumer has been successfully initialized");
                // await _phoneMessage.Signals
            }
        }
        private async void PhoneProducer_Added(ProducerWatcher sender, AllJoynServiceInfo args)
        {
            Debug.WriteLine("Attempt to join session for phone...");

            var phoneJoin = await ProducerConsumer.JoinSessionAsync(args, sender);

            if (phoneJoin.Status == AllJoynStatus.Ok)
            {
                _phoneMessage = phoneJoin.Consumer;
                Debug.WriteLine("Consumer has been successfully initialized");
               // await _phoneMessage.Signals

            }
        }
        private async void ToasterWatcher_Added(ToasterWatcher sender, AllJoynServiceInfo args)
        {
            ToasterJoinSessionResult toasterJoinSessionResult = await ToasterConsumer.JoinSessionAsync(args, sender);

            if (toasterJoinSessionResult.Status == AllJoynStatus.Ok)
            {
                ToasterFoundEventArgs toasterFoundArgs = new ToasterFoundEventArgs(toasterJoinSessionResult.Consumer);
                OnToasterFound(toasterFoundArgs);
            }
            else
            {

            }
        }
        private async void SenseHatLedArrayWatcher_Added(SenseHatLedArrayWatcher sender,
                                                         AllJoynServiceInfo args)
        {
            var result = await SenseHatLedArrayConsumer.JoinSessionAsync(args, senseHatLedArrayWatcher);

            if (result.Status == AllJoynStatus.Ok)
            {
                isSenseHatAvailable = true;

                senseHatLedArrayConsumer = result.Consumer;

                DiagnosticInfo.Display(diagnosticData,
                                       "Successfully joined the AllJoyn session. Bus name: " + args.UniqueName);
            }
        }
        private async void LampStateWatcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status != AllJoynStatus.Ok)
            {
                return;
            }

            // success
            _lampStateConsumers.Add(joinResult.Consumer);
            await SetLampColorAsync(joinResult.Consumer);

            System.Diagnostics.Debug.WriteLine("LampStateConsumer successfully added.");
        }
        private async void Pin16Watcher_Added(pin16.interface_1Watcher sender, AllJoynServiceInfo args)
        {
            pin16.interface_1JoinSessionResult joinSessionResult = await pin16.interface_1Consumer.JoinSessionAsync(args, sender);
            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                Pin16Consumer = joinSessionResult.Consumer;

                textBlock4.Text = "Plug Connected";

                pin16.interface_1GetPinValueResult pinResult = await Pin16Consumer.GetPinValueAsync();
                if (Convert.ToInt16(pinResult.PinValue) == 0)
                    toggleSwitch1.IsOn = true;
                else if (Convert.ToInt16(pinResult.PinValue) == 1)
                    toggleSwitch1.IsOn = false;
            }
        }
Exemple #27
0
        private async void MediaPlayerWatcher_Added(MediaPlayerWatcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await MediaPlayerConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _mediaPlayerConsumer              = joinResult.Consumer;
                _mediaPlayerConsumer.SessionLost += this.Consumer_SessionLost;

                // subscribe to value changes

                // populate initial values

                this.IsConnected = true;
            }
        }
		private async void toasterWatcher_Added(toasterWatcher sender, AllJoynServiceInfo args)
		{

			toasterJoinSessionResult joinResult = await toasterConsumer.JoinSessionAsync(args, sender);

			if (joinResult.Status == AllJoynStatus.Ok)
			{
				_toasterConsumer = joinResult.Consumer;
				_toasterConsumer.Signals.ToastDoneReceived += ToastDoneReceived_Signal;
				RetrieveDarkness();
			}
			else
			{
				System.Diagnostics.Debug.WriteLine("Joining the session went wrong");
			}
		}
        private async void Watcher_Added(SecureInterfaceWatcher sender, AllJoynServiceInfo args)
        {
            // Attempt to join the session when a producer is discovered.
            SecureInterfaceJoinSessionResult joinSessionResult = await SecureInterfaceConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                m_consumer  = joinSessionResult.Consumer;
                isConnected = true;
                UpdateStatus("Connected.", NotifyType.StatusMessage);
            }
            else
            {
                UpdateStatus(String.Format("Attempt to connect failed with error: {0}", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
        private async void RoverWatcher_Added(RoverWatcher sender, AllJoynServiceInfo args)
        {
            RoverJoinSessionResult joinSessionResult = await RoverConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                roverConsumer = joinSessionResult.Consumer;

                button1.IsEnabled = true;
                StopButton.IsEnabled = true;
                LeftButton.IsEnabled = true;
                RightButton.IsEnabled = true;
                Reverse.IsEnabled = true;
                Autonomous.IsEnabled = true;
            }
        }
Exemple #31
0
        private async void relayNodeWatcher_Added(relaynodeWatcher sender, AllJoynServiceInfo args)
        {
            relaynodeJoinSessionResult joinResult = await relaynodeConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _relayNodeConsumer = joinResult.Consumer;
                _relayNodeConsumer.Signals.ButtonPressedReceived     += Signals_ButtonPressedReceived;
                _relayNodeConsumer.Signals.RelayStateChangedReceived += Signals_RelayStateChangedReceived;
                RetrieveCurrentState();
                _fReady = true;
            }
            else
            {
                Debug.WriteLine("Joining the session went wrong");
            }
        }
        private async void airflowWatcher_Added(airflowWatcher watcher, AllJoynServiceInfo args)
        {
            if (_airflowConsumer == null && args.ObjectPath.Contains(_expectedBusObjectPath))
            {
                var joinSessionResult = await airflowConsumer.JoinSessionAsync(args, watcher);

                if (joinSessionResult.Status == AllJoynStatus.Ok)
                {
                    _airflowConsumer              = joinSessionResult.Consumer;
                    _airflowConsumer.SessionLost += Consumer_SessionLost;

                    // subscribe to value changes
                    _airflowConsumer.DirectionChanged += this.airflowConsumer_DirectionChanged;
                    _airflowConsumer.RangeChanged     += this.airflowConsumer_RangeChanged;
                    _airflowConsumer.SpeedChanged     += this.airflowConsumer_SpeedChanged;

                    // populate initial values
                    var directionResult = await _airflowConsumer.GetDirectionAsync();

                    if (directionResult.Status != AllJoynStatus.Ok)
                    {
                        return;
                    }
                    this.AirflowDirection = directionResult.Direction;

                    var rangeResult = await _airflowConsumer.GetRangeAsync();

                    if (rangeResult.Status != AllJoynStatus.Ok)
                    {
                        return;
                    }
                    this.AirflowDirection = rangeResult.Range;

                    var speedResult = await _airflowConsumer.GetSpeedAsync();

                    if (speedResult.Status != AllJoynStatus.Ok)
                    {
                        return;
                    }
                    this.AirflowSpeed = speedResult.Speed;


                    this.IsConnected = true;
                }
            }
        }
        private async void relayNodeWatcher_Added(relaynodeWatcher sender, AllJoynServiceInfo args)
        {
            relaynodeJoinSessionResult joinResult = await relaynodeConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _relayNodeConsumer = joinResult.Consumer;
                _relayNodeConsumer.Signals.ButtonPressedReceived += Signals_ButtonPressedReceived;
                _relayNodeConsumer.Signals.RelayStateChangedReceived += Signals_RelayStateChangedReceived;
                RetrieveCurrentState();
                _fReady = true;
            }
            else
            {
                Debug.WriteLine("Joining the session went wrong");
            }
        }
Exemple #34
0
        private async void Lamp_Added(LampWatcher sender, AllJoynServiceInfo args)
        {
            LampJoinSessionResult joinSessionResult = await LampConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                LampConsumer lampConsumer = joinSessionResult.Consumer;

                // Create ViewModel object from LampConsumer and add to the Lamps collection
                // Using args.ObjectPath for the name of the device. One could use args.UniqueId for an
                // Id property for lamps lookup from a dictionary.
                Lamp lamp = new Lamp(args.ObjectPath, lampConsumer);
                Lamps.Add(lamp);

                lamp.SessionLost += Lamp_SessionLost;
            }
        }
Exemple #35
0
        private async void powerinterface_1Watcher_Added(interface_1Watcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await interface_1Consumer.JoinSessionAsync(args, sender);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _interface1Consumer              = joinResult.Consumer;
                _interface1Consumer.SessionLost += this.Consumer_SessionLost;

                // subscribe to value changes
                _interface1Consumer.ButtonA0Changed += this.interface1Consumer_ButtonA0Changed;
                _interface1Consumer.ButtonAIChanged += this.interface1Consumer_ButtonAIChanged;
                _interface1Consumer.ButtonB0Changed += this.interface1Consumer_ButtonB0Changed;
                _interface1Consumer.ButtonBIChanged += this.interface1Consumer_ButtonBIChanged;

                // populate initial values

                //var asyncA0 = _interface1Consumer.GetButtonA0Async();
                //var asyncAI = _interface1Consumer.GetButtonAIAsync();
                //var asyncB0 = _interface1Consumer.GetButtonB0Async();
                //var asyncBI = _interface1Consumer.GetButtonBIAsync();

                //await Task.WhenAll(asyncA0.AsTask(), asyncAI.AsTask(), asyncB0.AsTask(), asyncBI.AsTask());

                //var resultA0 = asyncA0.GetResults();
                //var resultAI = asyncAI.GetResults();
                //var resultB0 = asyncB0.GetResults();
                //var resultBI = asyncBI.GetResults();

                //if (resultA0.Status != AllJoynStatus.Ok) return;
                //if (resultAI.Status != AllJoynStatus.Ok) return;
                //if (resultB0.Status != AllJoynStatus.Ok) return;
                //if (resultBI.Status != AllJoynStatus.Ok) return;

                //using (this.CreateInternalPropertyChangeScope())
                //{
                //    this.IsButtonA0Pressed = object.Equals(resultA0.ButtonA0, "1");
                //    this.IsButtonAIPressed = object.Equals(resultAI.ButtonAI, "1");
                //    this.IsButtonB0Pressed = object.Equals(resultB0.ButtonB0, "1");
                //    this.IsButtonBIPressed = object.Equals(resultBI.ButtonBI, "1");
                //}

                this.IsConnected = true;
            }
        }
        private async void temperatureWatcher_Added(temperatureWatcher watcher, AllJoynServiceInfo args)
        {
            if (_temperatureConsumer == null && args.ObjectPath.Contains(_expectedBusObjectPath))
            {
                var joinSessionResult = await temperatureConsumer.JoinSessionAsync(args, watcher);

                if (joinSessionResult.Status == AllJoynStatus.Ok)
                {
                    _temperatureConsumer              = joinSessionResult.Consumer;
                    _temperatureConsumer.SessionLost += this.Consumer_SessionLost;

                    // subscribe to value changes
                    _temperatureConsumer.TemperatureChanged += this.temperatureConsumer_TemperatureChanged;
                    _temperatureConsumer.RangeChanged       += this.temperatureConsumer_RangeChanged;
                    _temperatureConsumer.UnitsChanged       += this.temperatureConsumer_UnitsChanged;

                    // populate initial values
                    var temperatureResult = await _temperatureConsumer.GetTemperatureAsync();

                    if (temperatureResult.Status != AllJoynStatus.Ok)
                    {
                        return;
                    }
                    this.Temperature = temperatureResult.Temperature;

                    var temperatureRangeResult = await _temperatureConsumer.GetRangeAsync();

                    if (temperatureRangeResult.Status != AllJoynStatus.Ok)
                    {
                        return;
                    }
                    this.TemperatureRange = temperatureRangeResult.Range;

                    var temperatureUnitsResult = await _temperatureConsumer.GetUnitsAsync();

                    if (temperatureUnitsResult.Status != AllJoynStatus.Ok)
                    {
                        return;
                    }
                    this.TemperatureUnits = temperatureUnitsResult.Units;

                    this.IsConnected = true;
                }
            }
        }
        private async void Watcher_Added(CharacterLCDWatcher sender, AllJoynServiceInfo args)
        {
            CharacterLCDJoinSessionResult joinSessionResult = await CharacterLCDConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;

                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Consumer = joinSessionResult.Consumer;
                    Consumer.SessionLost += Consumer_SessionLost;
                    Consumer.SessionMemberAdded += Consumer_SessionMemberAdded;
                    Consumer.SessionMemberRemoved += Consumer_SessionMemberRemoved;
                    Status = "Connected";
                });
            }
        }
        private async void Watcher_Added(CharacterLCDWatcher sender, AllJoynServiceInfo args)
        {
            CharacterLCDJoinSessionResult joinSessionResult = await CharacterLCDConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;

                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Consumer                       = joinSessionResult.Consumer;
                    Consumer.SessionLost          += Consumer_SessionLost;
                    Consumer.SessionMemberAdded   += Consumer_SessionMemberAdded;
                    Consumer.SessionMemberRemoved += Consumer_SessionMemberRemoved;
                    Status = "Connected";
                });
            }
        }
        private async void LampFound(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            Debug.WriteLine("Lamp found, attempt to join session..");

            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _lampState = joinResult.Consumer;
                Debug.WriteLine("Consumer has been susccessfully initialized");

                await _lampState.SetOnOffAsync(PowerSwitch.IsOn);
                await _lampState.SetBrightnessAsync(/* 10% */ Convert.ToUInt32(UInt32.MaxValue * 0.1));
            }
            else
            {
                Debug.WriteLine("Ubable to join session");
            }
        }
  /*      private async void ControlPanelWatcher_Added(ControlPanelWatcher sender, AllJoynServiceInfo args)
        {
            ControlPanelJoinSessionResult joinResult = await ControlPanelConsumer.JoinSessionAsync(args, sender);
            AllJoynAboutDataView view = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, 
                this.controlPanelWatcherBusAttachment, args.SessionPort);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                

            }

        }*/

        private async void PressureWatcher_Added(PressureWatcher sender, AllJoynServiceInfo args)
        {            
            PressureJoinSessionResult joinResult = await PressureConsumer.JoinSessionAsync(args, sender);
 //           AllJoynAboutDataView view = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, this.pressureBusAttachment, args.SessionPort);
 //           var device = SensorClient.Factory.AllJoynDeviceFactory.GetAllJoynDevice(view);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                PressureSensor newSensor = new PressureSensor(joinResult.Consumer, args.UniqueName);
                
                var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
  //                  if (PerssureSensorSessionStarted != null)
 //                       PerssureSensorSessionStarted.Invoke(newSensor, device);
                });

            }
            else
            {
                throw new Exception(String.Format("Joining the session went wrong for PressureSensor {0}", args.UniqueName));
            }
        }
        private async void RadioWatcher_Added(InternetRadioWatcher sender, AllJoynServiceInfo args)
        {
            Debug.WriteLine(args.UniqueName);

            var about = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, alljoynBusAttachment, args.SessionPort);

            if (null == about)
            {
                Debug.WriteLine("Unable to get AboutData for device: " + args.UniqueName);
                return;
            }

            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, (() =>
             {
                 devices.Add(new InternetRadioDeviceRegistrationInfo()
                 {
                     Name = string.Format("{0} ({1})", about.AppName, about.DeviceName),
                     sender = sender,
                     args = args
                 });
             }));
        }
        private async void LampWatcher_Added(org.allseen.LSF.ControllerService.Lamp.LampWatcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await LampConsumer.JoinSessionAsync(args, sender);
            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _lamp = joinResult.Consumer;
                var lamps = await _lamp.GetAllLampIDsAsync();
                foreach (var lamp in lamps.LampIDs)
                {
                    var lampModel = new LampStateViewModel(this);
                    var lampDetails = await _lamp.GetLampDetailsAsync(lamp);
                    lampModel.Id = lampDetails.LampID;
                    var lampState = await _lamp.GetLampStateAsync(lamp);
                    foreach (var stateItem in lampState.LampState)
                    {
                        if (stateItem.Key == "Brightness")
                            lampModel.Brightness = Convert.ToUInt32(stateItem.Value);
                        if (stateItem.Key == "ColorTemp")
                            lampModel.ColorTemp = Convert.ToUInt32(stateItem.Value);
                        if (stateItem.Key == "Hue")
                            lampModel.Hue = Convert.ToUInt32(stateItem.Value);
                        if (stateItem.Key == "OnOff")
                            lampModel.On = Convert.ToBoolean(stateItem.Value);
                        if (stateItem.Key == "Saturation")
                            lampModel.Saturation = Convert.ToUInt32(stateItem.Value);


                        Debug.WriteLine(string.Format("Lamp State Key: {0} Value: {1}", stateItem.Key, stateItem.Value));
                    }
                    var name = await _lamp.GetLampNameAsync(lamp, "en");
                    lampModel.Name = name.LampName;
                    Lamps.Add(lampModel);
                }

                _lamp.Signals.LampStateChangedReceived += LampStateChanged;
                //UpdateUI();
            }
        }
        async void OnAdded(FezHatWatcher sender, AllJoynServiceInfo args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
              async () =>
              {
                  // Get the about data.
                  var aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, _busAttachment, args.SessionPort);
                  Debug.WriteLine("Found {0} on {1} from manufacturer: {2}. Connecting...", aboutData.AppName, aboutData.DeviceName, aboutData.Manufacturer);

                  var joinResult = await FezHatConsumer.JoinSessionAsync(args, sender);                  
                  if (joinResult.Status != AllJoynStatus.Ok) return;
                  FezHats.Add(new FezHatItem()
                  {
                      UniqueName = args.UniqueName,
                      DefaultAppName = aboutData.AppName,
                      ModelNumber = aboutData.ModelNumber,
                      DateOfManufacture = aboutData.DateOfManufacture,
                      Consumer = joinResult.Consumer
                  });
                  joinResult.Consumer.SessionLost += OnFezHatLost;
                  joinResult.Consumer.Signals.ButtonDio18PressedReceived += Signals_ButtonDio18PressedReceived;
              }
            );
        }
        private async void _watcher_Added(GarageDoorWatcher sender, AllJoynServiceInfo args)
        {
            GarageDoorJoinSessionResult result = await GarageDoorConsumer.JoinSessionAsync(args, sender);
            _consumer = result.Consumer;
            _consumer.Signals.GarageDoorStateChangedReceived += Signals_GarageDoorStateChangedReceived;
            var result2 = await _consumer.GetDoorStateAsync();
            GarageDoorState = Convert.ToInt32(result2.DoorState.Value1);

        }
Exemple #45
0
        private async void OnWatcherAdded(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            LampStateJoinSessionResult joinSessionResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                Consumers.Add(args.UniqueName,joinSessionResult.Consumer);
                joinSessionResult.Consumer.SessionLost += OnConsumerSessionLost;
                if(_lastValues != null)
                {
                    await SetValuesAsync(joinSessionResult.Consumer, _lastValues);
                }
                Debug.WriteLine("New Lamp joined. ID:" + args.UniqueName + " Lamp count: " + Consumers.Count);
                if (NewEventReceived != null)
                {
                    NewEventReceived(this, "New Lamp joined. ID:" + args.UniqueName + " Lamp count: " + Consumers.Count);
                }
            }
        }
        private async void Watcher_Added(OnboardingWatcher sender, AllJoynServiceInfo args)
        {
            UpdateStatusAsync("Joining session...", NotifyType.StatusMessage);
            OnboardingJoinSessionResult joinSessionResult = await OnboardingConsumer.JoinSessionAsync(args, sender);
            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                DisposeConsumer();
                m_consumer = joinSessionResult.Consumer;
                m_consumer.SessionLost += Consumer_SessionLost;

                if (!m_isCredentialsRequested || m_isAuthenticated)
                {
                    GetOnboardeeNetworkListAsync();
                }
            }
            else
            {
                UpdateStatusAsync(string.Format("Attempt to join session failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
        private async void LampFound(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            Debug.WriteLine("Attempt to join session..");

            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            AJNetwork.Mode = BindingMode.OneTime;
            AJNetwork.Source = "Test Network";
            //Debug.WriteLine(AJnetworkData.AppId.ToString(), "AppID");
          

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _lampState = joinResult.Consumer;
                Debug.WriteLine("Consumer has been susccessfully initialized");
                await _lampState.SetOnOffAsync(true);
                PowerSwitch.IsOn = true;

            }
            else
            {
                Debug.WriteLine("Join session has failed");
            }
        }
 private async void _watcher_Added(GarageDoorWatcher sender, AllJoynServiceInfo args)
 {
     GarageDoorJoinSessionResult result = await GarageDoorConsumer.JoinSessionAsync(args, sender);
     _consumer = result.Consumer;
     _consumer.Signals.GarageDoorStateChangedReceived += Signals_GarageDoorStateChangedReceived;
 }
        private async void Watcher_Added(SecureInterfaceWatcher sender, AllJoynServiceInfo args)
        {
            UpdateStatusAsync("Connecting...", NotifyType.StatusMessage);

            // Attempt to join the session when a producer is discovered.
            SecureInterfaceJoinSessionResult joinSessionResult = await SecureInterfaceConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                DisposeConsumer();
                m_consumer = joinSessionResult.Consumer;
                m_consumer.IsUpperCaseEnabledChanged += Consumer_IsUpperCaseEnabledChanged;
                m_consumer.Signals.TextSentReceived += Signals_TextSentReceived;
                m_consumer.SessionLost += Consumer_SessionLost;

                // At the time of connection, the request credentials callback not being invoked is an
                // indication that the client and server are already authenticated from a previous session.
                if (!m_isCredentialsRequested)
                {
                    UpdateStatusAsync("Connected and already authenticated from previous session.", NotifyType.StatusMessage);
                    UpdateIsUpperCaseEnabledAsync();
                }
                else
                {
                    if (m_isAuthenticated)
                    {
                        UpdateStatusAsync("Connected with authentication.", NotifyType.StatusMessage);
                        UpdateIsUpperCaseEnabledAsync();
                    }
                    else
                    {
                        UpdateStatusAsync("Connected but authentication failed.", NotifyType.ErrorMessage);
                    }
                }
                ClientOptionsVisibility = Visibility.Visible;
            }
            else
            {
                UpdateStatusAsync(string.Format("Attempt to connect failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
        private async void Watcher_Added(SecureInterfaceWatcher sender, AllJoynServiceInfo args)
        {
            // Optional - Get the About data of the producer. 
            AllJoynAboutDataView aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, m_busAttachment, args.SessionPort);

            // Check to see if device name is populated in the about data, since device name is not a mandatory field.
            if (string.IsNullOrEmpty(aboutData.DeviceName))
            {
                UpdateStatusAsync(string.Format("Found {0} from manufacturer: {1}. Connecting...", aboutData.AppName, aboutData.Manufacturer), NotifyType.StatusMessage);
            }
            else
            {
                UpdateStatusAsync(string.Format("Found {0} on {1} from manufacturer: {2}. Connecting...", aboutData.AppName, aboutData.DeviceName, aboutData.Manufacturer), NotifyType.StatusMessage);
            }

            // Attempt to join the session when a producer is discovered.
            SecureInterfaceJoinSessionResult joinSessionResult = await SecureInterfaceConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                DisposeConsumer();
                m_consumer = joinSessionResult.Consumer;
                m_consumer.IsUpperCaseEnabledChanged += Consumer_IsUpperCaseEnabledChanged;
                m_consumer.Signals.TextSentReceived += Signals_TextSentReceived;
                m_consumer.SessionLost += Consumer_SessionLost;

                // At the time of connection, the request credentials callback not being invoked is an
                // indication that the consumer and producer are already authenticated from a previous session.
                if (!m_isCredentialsRequested)
                {
                    UpdateStatusAsync("Connected and already authenticated from previous session.", NotifyType.StatusMessage);
                    UpdateIsUpperCaseEnabledAsync();
                }
                else
                {
                    if (m_isAuthenticated)
                    {
                        UpdateStatusAsync("Connected with authentication.", NotifyType.StatusMessage);
                        UpdateIsUpperCaseEnabledAsync();
                    }
                    else
                    {
                        UpdateStatusAsync("Connected but authentication failed.", NotifyType.ErrorMessage);
                    }
                }
                ConsumerOptionsVisibility = Visibility.Visible;
            }
            else
            {
                UpdateStatusAsync(string.Format("Attempt to connect failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
        private async void Watcher_Added(OnboardingWatcher sender, AllJoynServiceInfo args)
        {
            // This demo supports a single onboarding producer, if there are multiple onboarding producers found, then they are ignored.
            // Another approach would be to create a list of all producers found and then allow the user to choose the one they want
            bool bAlreadyJoined = (Interlocked.CompareExchange(ref m_onboardSessionAlreadyJoined, 1, 0) == 1);
            if (bAlreadyJoined)
            {
                return;
            }

            UpdateStatusAsync("Joining session...", NotifyType.StatusMessage);

            OnboardingJoinSessionResult joinSessionResult = await OnboardingConsumer.JoinSessionAsync(args, sender);
            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                UpdateStatusAsync("Session Joined.", NotifyType.ErrorMessage);
                DisposeConsumer();
                m_consumer = joinSessionResult.Consumer;
                m_consumer.SessionLost += Consumer_SessionLost;

                GetOnboardeeNetworkListAsync();
            }
            else
            {
                UpdateStatusAsync(string.Format("Attempt to join session failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage);
            }
        }
 private async void Watcher_Added(org.alljoyn.Notification.NotificationWatcher sender, AllJoynServiceInfo args)
 {
     var consumer = await org.alljoyn.Notification.NotificationConsumer.JoinSessionAsync(args, sender);
     consumer.Consumer.Signals.NotifyReceived += Signals_NotifyReceived;
 }