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

Merge pull request #61 from WilliamsJason/master

Minor changes to the Xbox Test app for usability, especially from VS
parents e778aad5 cb2e57fb
Loading
Loading
Loading
Loading
+146 −135
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Tools.WindowsDevicePortal;
using System.Diagnostics;

namespace TestApp
{
@@ -17,10 +18,23 @@ namespace TestApp
    /// </summary>
    public class Program
    {
        /// <summary>
        /// String listing the available operations.
        /// </summary>
        private static readonly string AvailableOperationsText = "Supported operations are the following:\n" +
                "info\n" +
                "xbluser\n" +
                "install\n" +
                "reboot\n" +
                "processes\n" +
                "systemPerf\n" +
                "config\n" +
                "file";

        /// <summary>
        /// Usage string
        /// </summary>
        private const string GeneralUsageMessage = "Usage: /ip:<system-ip or hostname> /user:<WDP username> /pwd:<WDP password> [/op:<operation type> [operation parameters]]";
        private static readonly string GeneralUsageMessage = "Usage: /ip:<system-ip or hostname> /user:<WDP username> /pwd:<WDP password> [/op:<operation type> [operation parameters]]";

        /// <summary>
        /// Event used to indicate that the running processes on the device have been received.
@@ -48,37 +62,42 @@ namespace TestApp
        private enum OperationType
        {
            /// <summary>
            /// Info operation
            /// No operation (just connects to the console).
            /// </summary>
            None,

            /// <summary>
            /// Info operation.
            /// </summary>
            InfoOperation,

            /// <summary>
            /// User operation
            /// User operation.
            /// </summary>
            UserOperation,

            /// <summary>
            /// Install Appx Package or loose folder operation
            /// Install Appx Package or loose folder operation.
            /// </summary>
            InstallOperation,

            /// <summary>
            /// Reboot console operation
            /// Reboot console operation.
            /// </summary>
            RebootOperation,

            /// <summary>
            /// List processes operation
            /// List processes operation.
            /// </summary>
            ListProcessesOperation,

            /// <summary>
            /// Get the system performance operation
            /// Get the system performance operation.
            /// </summary>
            GetSystemPerfOperation,

            /// <summary>
            /// Get or set Xbox Settings
            /// Get or set Xbox Settings.
            /// </summary>
            XboxSettings,

@@ -100,38 +119,17 @@ namespace TestApp
            try
            {
                parameters.ParseCommandLine(args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine();
                Console.WriteLine(GeneralUsageMessage);
                return;
            }

            OperationType operation = OperationType.InfoOperation;
                OperationType operation = OperationType.None;

                if (parameters.HasParameter(ParameterHelper.Operation))
            {
                try
                {
                    operation = OperationStringToEnum(parameters.GetParameterValue("op"));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine();
                    Console.WriteLine(GeneralUsageMessage);
                    return;
                }
            }

                if (!parameters.HasParameter(ParameterHelper.IpOrHostname) || !parameters.HasParameter(ParameterHelper.WdpUser) || !parameters.HasParameter(ParameterHelper.WdpPassword))
                {
                Console.WriteLine("Missing one or more required parameter(s). Must provide ip, user, and pwd");
                Console.WriteLine();
                Console.WriteLine(GeneralUsageMessage);
                return;
                    throw new Exception("Missing one or more required parameter(s). Must provide ip, user, and pwd");
                }

                bool listen = false;
@@ -258,6 +256,27 @@ namespace TestApp
                {
                    FileOperation.HandleOperation(portal, parameters);
                }
                else
                {
                    Console.WriteLine("Successfully connected to console but no operation was specified. \n" +
                        "Use the '/op:<operation type>' parameter to run a specified operation.");
                    Console.WriteLine();
                    Console.WriteLine(AvailableOperationsText);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine();
                Console.WriteLine(GeneralUsageMessage);
            }

            // If a debugger is attached, don't close but instead loop here until
            // closed.
            while (Debugger.IsAttached)
            {
                Thread.Sleep(0);
            }
        }

        /// <summary>
@@ -300,15 +319,7 @@ namespace TestApp
                return OperationType.FileOperation;
            }

            throw new Exception("Unknown Operation Type. Supported operations are the following:\n" +
                "info\n" +
                "xbluser\n" +
                "install\n" +
                "reboot\n" +
                "processes\n" +
                "systemPerf\n" +
                "config\n" +
                "file\n");
            throw new Exception("Unknown Operation Type. " + AvailableOperationsText);
        }

        /// <summary>