RemovePackageAsync() публичный Метод

public RemovePackageAsync ( [ packageFullName ) : DeploymentProgress>.IAsyncOperationWithProgress
packageFullName [
Результат DeploymentProgress>.IAsyncOperationWithProgress
Пример #1
0
        private async static Task FindPackages() {
            PackageManager packageManager = new PackageManager();

            IEnumerable<Windows.ApplicationModel.Package> packages =
                (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackages();

            int packageCount = 0;
            foreach (var package in packages) {
                if (
                        (package.Id.Publisher.Contains("CN=Ron") || 
                        package.Id.Publisher.Contains("CN=Bob") || 
                        package.Id.FullName.StartsWith("Ron.")) 
                        && 
                        (!package.Id.FullName.StartsWith("Keep."))
                    )
                {
                    DisplayPackageInfo(package);
                    await packageManager.RemovePackageAsync(package.Id.FullName);
                    Console.WriteLine("=========================================================");
                }
                packageCount += 1;
            }

            if (packageCount < 1) {
                Console.WriteLine("No packages were found.");
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }
Пример #2
0
 public void Cleanup()
 {
     var packageManager = new PackageManager();
     var result = packageManager.RemovePackageAsync(packageFullName, RemovalOptions.PreserveApplicationData);
     var completed = new AutoResetEvent(false);
     result.Completed = (waitResult, status) => completed.Set();
     completed.WaitOne();
 }
    public static int Main(string[] args)
    {
        Console.WriteLine("Copyright (c) Microsoft Corporation. All rights reserved.");
        Console.WriteLine("RemovePackage sample");
        Console.WriteLine();

        if (args.Length < 1)
        {
            Console.WriteLine("Usage: RemovePackageSample.exe packageFullname");
            return 1;
        }

        string inputPackageFullName = args[0];
        int returnValue = 0;

        try
        {
            Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager();

            Windows.Foundation.IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation = packageManager.RemovePackageAsync(inputPackageFullName);

            ManualResetEvent opCompletedEvent = new ManualResetEvent(false); // this event will be signaled when the deployment operation has completed.

            deploymentOperation.Completed = (depProgress, status) => { opCompletedEvent.Set(); };

            Console.WriteLine("Removing package {0}", inputPackageFullName);

            Console.WriteLine("Waiting for removal to complete...");

            opCompletedEvent.WaitOne();

            if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Error)
            {
                Windows.Management.Deployment.DeploymentResult deploymentResult = deploymentOperation.GetResults();
                Console.WriteLine("Removal Error: {0}", deploymentOperation.ErrorCode);
                Console.WriteLine("Detailed Error Text: {0}", deploymentResult.ErrorText);
                returnValue = 1;
            }
            else if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Canceled)
            {
                Console.WriteLine("Removal Canceled");
            }
            else if (deploymentOperation.Status == Windows.Foundation.AsyncStatus.Completed)
            {
                Console.WriteLine("Removal succeeded!");
            }
            else
            {
                returnValue = 1;
                Console.WriteLine("Removal status unknown");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("RemovePackageSample failed, error message: {0}", ex.Message);
            Console.WriteLine("Full Stacktrace: {0}", ex.ToString());

            return 1;
        }

        return returnValue;
    }