/// <summary>
        /// Start / Stop an application via direct method.
        /// </summary>
        private void StartStopAppButton_Click(object sender, RoutedEventArgs e)
        {
            if (PackageFamilyInput1.Text.Length == 0 || StartStopCombobox.SelectedValue == null)
            {
                _mainPage.ShowDialogAsync("Invaid Input", "Please enter all fields to Start or Stop application");
                return;
            }

            AppxLifeCycleDataContract.ManageAppLifeCycleParams parameters = new AppxLifeCycleDataContract.ManageAppLifeCycleParams();
            parameters.action        = AppxLifeCycleDataContract.JsonStart;
            parameters.pkgFamilyName = PackageFamilyInput1.Text;
            if (StartStopCombobox.SelectedValue.ToString() == "start")
            {
                parameters.action = AppxLifeCycleDataContract.JsonStart;
            }
            else if (StartStopCombobox.SelectedValue.ToString() == "stop")
            {
                parameters.action = AppxLifeCycleDataContract.JsonStop;
            }
            else
            {
                _mainPage.ShowDialogAsync("Invaid Input", "Please enter all fields to Start or Stop application");
                return;
            }
            var result = _mainPage.CallDeviceMethod(AppxLifeCycleDataContract.ManageAppLifeCycleAsync, parameters.ToJsonString());
        }
        private async void OnManageAppLifeCycle(string appLifeCycleAction, string packageFamilyName)
        {
            AppxLifeCycleDataContract.ManageAppLifeCycleParams parameters = new AppxLifeCycleDataContract.ManageAppLifeCycleParams();
            parameters.action        = appLifeCycleAction;
            parameters.pkgFamilyName = packageFamilyName;

            CancellationToken       cancellationToken = new CancellationToken();
            DeviceMethodReturnValue result            = await _deviceTwin.CallDeviceMethod(AppxLifeCycleDataContract.ManageAppLifeCycleAsync, parameters.ToJsonString(), new TimeSpan(0, 0, 30), cancellationToken);

            MessageBox.Show("ManageAppLifeCycle(start) Result:\nStatus: " + result.Status + "\nReason: " + result.Payload);
        }
Exemple #3
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);
                }
            }
        }