Commit da9630bc authored by Jason Williams's avatar Jason Williams Committed by GitHub
Browse files

Merge pull request #149 from WilliamsJason/master

Adds a PLM operation to the XboxWdpDriver app
parents 935bd752 202ac8ae
Loading
Loading
Loading
Loading
+146 −0
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="AppOperation.cs" company="Microsoft Corporation">
//     Licensed under the MIT License. See LICENSE.TXT in the project root license information.
// </copyright>
//----------------------------------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using Microsoft.Tools.WindowsDevicePortal;
using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;

namespace XboxWdpDriver
{
    /// <summary>
    /// Helper for App related operations (List, Suspend, Resume, Launch, Terminate, Uninstall)
    /// </summary>
    public class AppOperation
    {
        /// <summary>
        /// Usage message for this operation
        /// </summary>
        private const string AppUsageMessage = "Usage:\n" +
            "  /subop:list\n" +
            "        Lists all installed packages on the console.\n" +
    // Suspend and resume are currently not supported. The endpoints are not very
    // reliable yet on Xbox One and are completely unavailable on other platforms.
    // We'll revisit these two operations in the future.
            //"  /subop:suspend /pfn:<packageFullName>\n" +
            //"        Suspends the requested application.\n" +
            //"  /subop:resume /pfn:<packageFullName>\n" +
            //"        Resumes the requested application.\n" +
            "  /subop:launch /pfn:<packageFullName> /aumid:<appId>\n" +
            "        Starts the requested application.\n" +
            "  /subop:terminate /pfn:<packageFullName>\n" +
            "        Stops the requested application.\n" +
            "  /subop:uninstall /pfn:<packageFullName>\n" +
            "        Removes or unregisters the given application from the console.\n";

        /// <summary>
        /// Main entry point for handling a Config operation
        /// </summary>
        /// <param name="portal">DevicePortal reference for communicating with the device.</param>
        /// <param name="parameters">Parsed command line parameters.</param>
        public static void HandleOperation(DevicePortal portal, ParameterHelper parameters)
        {
            if (parameters.HasFlag(ParameterHelper.HelpFlag))
            {
                Console.WriteLine(AppUsageMessage);
                return;
            }

            string operationType = parameters.GetParameterValue("subop");

            if (string.IsNullOrWhiteSpace(operationType))
            {
                Console.WriteLine("Missing subop parameter");
                Console.WriteLine();
                Console.WriteLine(AppUsageMessage);
                return;
            }

            operationType = operationType.ToLowerInvariant();

            try
            {
                if (operationType.Equals("list"))
                {
                    Task<AppPackages> packagesTask = portal.GetInstalledAppPackages();

                    packagesTask.Wait();
                    Console.WriteLine(packagesTask.Result);
                }
                else
                {
                    string packageFullName = parameters.GetParameterValue("pfn");

                    if (string.IsNullOrEmpty(packageFullName))
                    {
                        Console.WriteLine("The Package Full Name is required as the /pfn<packageFullName> parameter for this operation.");
                        Console.WriteLine();
                        Console.WriteLine(AppUsageMessage);
                        return;
                    }

                    if (operationType.Equals("suspend"))
                    {
                        Console.WriteLine("Suspend isn't currently supported, but will be in the future.");
                    }
                    else if (operationType.Equals("resume"))
                    {
                        Console.WriteLine("Resume isn't currently supported, but will be in the future.");
                    }
                    else if (operationType.Equals("launch"))
                    {
                        string aumid = parameters.GetParameterValue("aumid");
                        if (string.IsNullOrEmpty(aumid))
                        {
                            Console.WriteLine("The appId (AUMID) is required as the /aumid:<appId> parameter for the launch operation.");
                            Console.WriteLine();
                            Console.WriteLine(AppUsageMessage);
                            return;
                        }

                        Task launchTask = portal.LaunchApplication(aumid, packageFullName);
                        launchTask.Wait();

                        Console.WriteLine("Application launched.");
                    }
                    else if (operationType.Equals("terminate"))
                    {
                        Task terminateTask = portal.TerminateApplication(packageFullName);
                        terminateTask.Wait();

                        Console.WriteLine("Application terminated.");
                    }
                    else if (operationType.Equals("uninstall"))
                    {
                        Task uninstallTask = portal.UninstallApplication(packageFullName);
                        uninstallTask.Wait();

                        Console.WriteLine("Application uninstalled.");
                    }
                }
            }
            catch (AggregateException e)
            {
                if (e.InnerException is DevicePortalException)
                {
                    DevicePortalException innerException = e.InnerException as DevicePortalException;

                    Console.WriteLine(string.Format("Exception encountered: 0x{0:X} : {1}", innerException.HResult, innerException.Reason));
                }
                else if (e.InnerException is OperationCanceledException)
                {
                    Console.WriteLine("The operation was cancelled.");
                }
                else
                {
                    Console.WriteLine(string.Format("Unexpected exception encountered: {0}", e.Message));
                }

                return;
            }
        }
    }
}
 No newline at end of file
+16 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ namespace XboxWdpDriver
        /// String listing the available operations.
        /// </summary>
        private static readonly string AvailableOperationsText = "Supported operations are the following:\n" +
                                "   app\n" +
                                "   config\n" +
                                "   connect\n" +
                                "   fiddler\n" +
@@ -63,6 +64,12 @@ namespace XboxWdpDriver
            /// </summary>
            None,

            /// <summary>
            /// Perform an App operation (List, Suspend, Resume, Launch, Terminate,
            /// Uninstall)
            /// </summary>
            AppOperation,

            /// <summary>
            /// Get or set Xbox Settings.
            /// </summary>
@@ -255,6 +262,10 @@ namespace XboxWdpDriver
                    // for ease of use.
                    switch (operation)
                    {
                        case OperationType.AppOperation:
                            AppOperation.HandleOperation(portal, parameters);
                            break;

                        case OperationType.ConfigOperation:
                            ConfigOperation.HandleOperation(portal, parameters);
                            break;
@@ -354,7 +365,11 @@ namespace XboxWdpDriver
        /// <returns>enum representation of the operation type.</returns>
        private static OperationType OperationStringToEnum(string operation)
        {
            if (operation.Equals("config", StringComparison.OrdinalIgnoreCase))
            if (operation.Equals("app", StringComparison.OrdinalIgnoreCase))
            {
                return OperationType.AppOperation;
            }
            else if (operation.Equals("config", StringComparison.OrdinalIgnoreCase))
            {
                return OperationType.ConfigOperation;
            }
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@
  <ItemGroup>
    <Compile Include="DevicePortalConnection.cs" />
    <Compile Include="NetworkShare.cs" />
    <Compile Include="Operations\AppOperation.cs" />
    <Compile Include="Operations\SystemPerfOperation.cs" />
    <Compile Include="Operations\ListProcessesOperation.cs" />
    <Compile Include="Operations\FileOperation.cs" />
+15 −1
Original line number Diff line number Diff line
@@ -276,6 +276,20 @@ namespace Microsoft.Tools.WindowsDevicePortal
            /// </summary>
            [DataMember(Name = "InstalledPackages")]
            public List<PackageInfo> Packages { get; set; }

            /// <summary>
            /// Presents a user readable representation of a list of AppPackages
            /// </summary>
            /// <returns></returns>
            public override string ToString()
            {
                string output = "Packages:\n";
                foreach (PackageInfo package in this.Packages)
                {
                    output += package;
                }
                return output;
            }
        }

        /// <summary>
@@ -357,7 +371,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
            /// <returns>String representation</returns>
            public override string ToString()
            {
                return string.Format("{0} ({1})", this.Name, this.Version);
                return string.Format("\t{0}\n\t\t{1}\n", this.FullName, this.AppId);
            }
        }

+35 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ Scripts or other executables could be written to interface with XboxWdpDriver.ex

Supported operations (in alphabetical order) are the following:

  * [app](#app)
  * [config](#config)
  * [connect](#connect)
  * [fiddler](#fiddler)
@@ -32,6 +33,40 @@ Supported operations (in alphabetical order) are the following:
  * [xbluser](#xbluser)


<a name="app"/>
### The app operation

Allows getting the list of applications on the console and performing some basic lifetime management (launch, terminate, etc). Suspend and resume aren't currently supported but will be in the future.

Usage:
```shell
  /subop:list
        Lists all installed packages on the console.
  /subop:launch /pfn:<packageFullName> /aumid:<appId>
        Starts the requested application.
  /subop:terminate /pfn:<packageFullName>
        Stops the requested application.
  /subop:uninstall /pfn:<packageFullName>
        Removes or unregisters the given application from the console.
```

Examples:
```shell
XboxWdpDriver.exe /op:app /subop:list
```

```shell
XboxWdpDriver.exe /op:app /subop:launch /pfn:Microsoft.Xbox.DevHome_100.1607.22000.0_x64__8wekyb3d8bbwe /aumid:Microsoft.Xbox.DevHome_8wekyb3d8bbwe!App
```

```shell
XboxWdpDriver.exe /op:app /subop:terminate /pfn:Microsoft.Xbox.DevHome_100.1607.22000.0_x64__8wekyb3d8bbwe
```

```shell
XboxWdpDriver.exe /op:app /subop:uninstall /pfn:d15692ce-8b27-4bd3-9ceb-81652e9fea54_1.0.0.0_x64__55mw97kmv3wha
```

<a name="config"/>
### The config operation