private async Task InternalManageAppLifeCycleAsync(string jsonParam)
        {
            Logger.Log("InternalManageAppLifeCycleAsync() invoked.", LoggingLevel.Verbose);

            await Helpers.EnsureErrorsLogged(_deviceManagementClient, PropertySectionName, async() =>
            {
                StatusSection status = new StatusSection(StatusSection.StateType.Pending);
                await _deviceManagementClient.ReportStatusAsync(PropertySectionName, status);

                // Parse json parameters
                AppxLifeCycleDataContract.ManageAppLifeCycleParams parameters = AppxLifeCycleDataContract.ManageAppLifeCycleParams.FromJsonString(jsonParam);

                // Construct request
                Message.AppLifecycleInfo appLifeCycleInfo = new Message.AppLifecycleInfo();
                appLifeCycleInfo.AppId = parameters.pkgFamilyName;
                appLifeCycleInfo.Start = parameters.action == AppxLifeCycleDataContract.JsonStart;
                var request            = new Message.AppLifecycleRequest(appLifeCycleInfo);

                // Send the request
                await _systemConfiguratorProxy.SendCommandAsync(request);

                // Report to the device twin
                status.State = StatusSection.StateType.Completed;
                await _deviceManagementClient.ReportStatusAsync(PropertySectionName, status);
            });
        }
        /// <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());
        }
Example #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);
                }
            }
        }
        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);
        }