Commit 39ccb5ae authored by Namrata Kedia's avatar Namrata Kedia
Browse files

Merge remote-tracking branch 'Microsoft/master'

parents 81691aff da9630bc
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -376,7 +376,7 @@ namespace SampleWdpClient

                    try
                    {
                        await portal.Reboot();
                        await this.portal.Reboot();
                    }
                    catch(Exception ex)
                    {
@@ -421,7 +421,7 @@ namespace SampleWdpClient

                    try
                    {
                        await portal.Shutdown();
                        await this.portal.Shutdown();
                    }
                    catch(Exception ex)
                    {
+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);
            }
        }

Loading