Example #1
0
        /// <summary>
        /// Test Function: Send start / stop application direct method to all connected devices.
        /// </summary>
        /// <param name="packageFamily">Package Family of the UWP to start / stop.</param>
        /// <param name="isStart">"true" to start, "false" to stop/> instance containing the event data.</param>
        private async void CallDeviceMethodStartStopAll(string packageFamily, bool isStart)
        {
            DeviceTwinAndMethod tempDeviceTwin;

            AppxLifeCycleDataContract.ManageAppLifeCycleParams parameters = new AppxLifeCycleDataContract.ManageAppLifeCycleParams();
            parameters.pkgFamilyName = packageFamily;
            if (isStart)
            {
                parameters.action = AppxLifeCycleDataContract.JsonStart;
            }
            else
            {
                parameters.action = AppxLifeCycleDataContract.JsonStop;
            }

            foreach (var device in _deviceList)
            {
                if (device.ConnectionState != DeviceConnectionState.Connected)
                {
                    continue; //skip devices that are not connected to IoT Hub
                }
                tempDeviceTwin = new DeviceTwinAndMethod(App.IOTHUBCONNSTRING, device.Id);
                if (tempDeviceTwin != null)
                {
                    CancellationToken       cancellationToken = new CancellationToken();
                    DeviceMethodReturnValue result            = await tempDeviceTwin.CallDeviceMethod(AppxLifeCycleDataContract.ManageAppLifeCycleAsync, parameters.ToJsonString(), new TimeSpan(0, 0, 30), cancellationToken);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Change current selected Device.
        /// </summary>
        private void DeviceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string deviceIdString = (string)DeviceCombobox.SelectedItem;

            if (!String.IsNullOrEmpty(deviceIdString))
            {
                // Update _deviceTwin to selected device
                _deviceTwin = new DeviceTwinAndMethod(App.IOTHUBCONNSTRING, deviceIdString);
                if (_deviceTwin != null)
                {
                    // Update Device Info to selected device
                    DeviceInfo.SetCurrentDevice(deviceIdString);
                }

                Device device = _deviceList.FirstOrDefault(d => d.Id == deviceIdString);
                if (device != null)
                {
                    DeviceConnectionStatus.Text  = device.ConnectionState.ToString();
                    DeleteDeviceButton.IsEnabled = true;
                }
            }
        }