Microsoft.Iot.IotCoreAppDeployment.WebbHelper.UninstallAppAsync C# (CSharp) Method

UninstallAppAsync() public method

public UninstallAppAsync ( string packageFullName, string target, UserInfo credentials ) : Task
packageFullName string
target string
credentials UserInfo
return Task
        public async Task<HttpStatusCode> UninstallAppAsync(string packageFullName, string target, UserInfo credentials)
        {
            var url = string.Empty;
            var result = HttpStatusCode.BadRequest;

            IPAddress ipAddress = IPAddress.Parse(target);
            RestHelper restHelper = new RestHelper(ipAddress, credentials);

            CancellationToken? cts;

            EnterWebBCall(out cts);

            try
            {
                url = AppApiUrl + "package?package=" + packageFullName;

                using (var response = await restHelper.SendRequestAsync(url, HttpMethod.Delete, null, cts))
                {
                    result = response.StatusCode;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }


            return result;
        }

Usage Example

Exemplo n.º 1
0
        private HttpStatusCode DeployAppx(string outputAppx, string outputCer, ReadOnlyCollection<FileStreamInfo> dependencies, string dependencyFolder, string identityName)
        {
            OutputMessage(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentWorker_StartDeploy, targetName));

            // Create list of all APPX and CER files for deployment
            var files = new List<FileInfo>()
                    {
                        new FileInfo(outputAppx),
                        new FileInfo(outputCer),
                    };
            foreach (var dependency in dependencies)
            {
                files.Add(new FileInfo(dependencyFolder + @"\" + dependency.AppxRelativePath));
            }

            // Call WEBB Rest APIs to deploy
            var packageFullName = string.Format(CultureInfo.InvariantCulture, packageFullNameFormat, identityName, targetType.ToString());
            using (var webbHelper = new WebbHelper())
            {
                OutputMessage(Resource.DeploymentWorker_DeployAppx_starting_to_deploy_certificate_APPX_and_dependencies);
                // Attempt to uninstall existing package if found
                var uninstallTask = webbHelper.UninstallAppAsync(packageFullName, targetName, credentials);
                if (uninstallTask.Result == HttpStatusCode.OK)
                {
                    // result == OK means the package was uninstalled.
                    OutputMessage(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentWorker_PreviousDeployUninstalled, packageFullName));
                }
                else if (uninstallTask.Result == HttpStatusCode.Unauthorized)
                {
                    // result == Unauthorized means the credentials were not accepted.
                    return uninstallTask.Result;
                }
                else
                {
                    // result != OK could mean that the package wasn't already installed
                    //           or it could mean that there was a problem with the uninstall
                    //           request.
                    OutputMessage(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentWorker_PreviousDeployNotUninstalled, packageFullName));
                }
                // Deploy new APPX, cert, and dependency files
                var deployTask = webbHelper.DeployAppAsync(files, targetName, credentials);
                if (deployTask.Result == HttpStatusCode.Accepted)
                {
                    var result = webbHelper.PollInstallStateAsync(targetName, credentials).Result;
                    OutputMessage(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentWorker_DeployFinished, packageFullName));

                    OutputMessage("\r\n\r\n***");
                    OutputMessage(string.Format(CultureInfo.InvariantCulture, "*** PackageFullName = {0}", packageFullName));
                    OutputMessage("***\r\n\r\n");

                    if (!result)
                    {
                        return HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    OutputMessage(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentWorker_DeployFailed, packageFullName));
                }
                return deployTask.Result;
            }
        }
All Usage Examples Of Microsoft.Iot.IotCoreAppDeployment.WebbHelper::UninstallAppAsync