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

Merge pull request #117 from WilliamsJason/master

Adds Sandbox Id API

This is the final Xbox specific API (though this one is on other devices).

Also adds unittests, the XboxWDPDriver operation, and associated documentation.

Also does some cleanup of the XboxWDPDriver docs by alphabetizing things.
parents 1698687b 62ecdae9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ namespace MockDataGenerator
            new Endpoint(HttpMethods.Get, DevicePortal.RunningProcessApi),
            new Endpoint(HttpMethods.WebSocket, DevicePortal.SystemPerfApi),
            new Endpoint(HttpMethods.WebSocket, DevicePortal.RunningProcessApi),
            new Endpoint(HttpMethods.Get, DevicePortal.XboxLiveSandboxApi),
        };

        /// <summary>
+6 −6
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="SettingOperation.cs" company="Microsoft Corporation">
// <copyright file="ConfigOperation.cs" company="Microsoft Corporation">
//     Licensed under the MIT License. See LICENSE.TXT in the project root license information.
// </copyright>
//----------------------------------------------------------------------------------------------
@@ -12,14 +12,14 @@ using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;
namespace XboxWdpDriver
{
    /// <summary>
    /// Helper for Setting related operations
    /// Helper for Config related operations
    /// </summary>
    public class SettingOperation
    public class ConfigOperation
    {
        /// <summary>
        /// Usage message for this operation
        /// </summary>
        private const string XblSettingUsageMessage = "Usage:\n" +
        private const string ConfigUsageMessage = "Usage:\n" +
            "  [/setting:<setting name> [/value:<setting value>]]\n" +
            "        Gets current settings and their values. If\n" +
            "        /setting is specified, only returns that value.\n" +
@@ -28,7 +28,7 @@ namespace XboxWdpDriver
            "        value.\n";

        /// <summary>
        /// Main entry point for handling a Setting operation
        /// 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>
@@ -36,7 +36,7 @@ namespace XboxWdpDriver
        {
            if (parameters.HasFlag(ParameterHelper.HelpFlag))
            {
                Console.WriteLine(XblSettingUsageMessage);
                Console.WriteLine(ConfigUsageMessage);
                return;
            }

+7 −5
Original line number Diff line number Diff line
@@ -50,8 +50,6 @@ namespace XboxWdpDriver
                return;
            }

            bool shouldReboot = parameters.HasFlag("reboot");

            try
            {
                if (string.Equals(state, "on", StringComparison.OrdinalIgnoreCase))
@@ -69,13 +67,13 @@ namespace XboxWdpDriver

                    Task fiddlerEnableTask = portal.EnableFiddlerTracing(proxyAddress, proxyPort, parameters.GetParameterValue("certpath"));
                    fiddlerEnableTask.Wait();
                    Console.WriteLine("Fiddler enabled. This will take effect on the next reboot.");
                    Console.WriteLine("Fiddler enabled.");
                }
                else if (string.Equals(state, "off", StringComparison.OrdinalIgnoreCase))
                {
                    Task fiddlerDisableTask = portal.DisableFiddlerTracing();
                    fiddlerDisableTask.Wait();
                    Console.WriteLine("Fiddler disabled. This will take effect on the next reboot.");
                    Console.WriteLine("Fiddler disabled.");
                }
                else
                {
@@ -85,12 +83,16 @@ namespace XboxWdpDriver
                    return;
                }

                if (shouldReboot)
                if (parameters.HasFlag("reboot"))
                {
                    Task rebootTask = portal.Reboot();
                    rebootTask.Wait();
                    Console.WriteLine("Console rebooting...");
                }
                else
                {
                    Console.WriteLine("A reboot is required before this takes effect.");
                }
            }
            catch (AggregateException e)
            {
+69 −0
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="ListProcessesOperation.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;
using System.Threading;

namespace XboxWdpDriver
{
    /// <summary>
    /// Helper for Listing processes
    /// </summary>
    public class ListProcessesOperation
    {
        /// <summary>
        /// Main entry point for handling listing processes
        /// </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)
        {
            RunningProcesses runningProcesses = null;
            if (parameters.HasFlag(ParameterHelper.Listen))
            {
                ManualResetEvent runningProcessesReceived = new ManualResetEvent(false);

                WebSocketMessageReceivedEventHandler<RunningProcesses> runningProcessesReceivedHandler =
                    delegate (DevicePortal sender, WebSocketMessageReceivedEventArgs<RunningProcesses> runningProccesesArgs)
                    {
                        if (runningProccesesArgs.Message != null)
                        {
                            runningProcesses = runningProccesesArgs.Message;
                            runningProcessesReceived.Set();
                        }
                    };

                portal.RunningProcessesMessageReceived += runningProcessesReceivedHandler;

                Task startListeningForProcessesTask = portal.StartListeningForRunningProcesses();
                startListeningForProcessesTask.Wait();

                runningProcessesReceived.WaitOne();

                Task stopListeningForProcessesTask = portal.StopListeningForRunningProcesses();
                stopListeningForProcessesTask.Wait();

                portal.RunningProcessesMessageReceived -= runningProcessesReceivedHandler;
            }
            else
            {
                Task<DevicePortal.RunningProcesses> getRunningProcessesTask = portal.GetRunningProcesses();
                runningProcesses = getRunningProcessesTask.Result;
            }

            foreach (DeviceProcessInfo process in runningProcesses.Processes)
            {
                if (!string.IsNullOrEmpty(process.Name))
                {
                    Console.WriteLine(process.Name);
                }
            }
        }
    }
}
 No newline at end of file
+70 −0
Original line number Diff line number Diff line
//----------------------------------------------------------------------------------------------
// <copyright file="SandboxOperation.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 Sandbox related operations
    /// </summary>
    public class SandboxOperation
    {
        /// <summary>
        /// Usage message for this operation
        /// </summary>
        private const string SandboxUsageMessage = "Usage:\n" +
            "  [/value:<desired value> [/reboot]]\n" +
            "        Gets or sets the current Xbox Live sandbox value. Changing the current\n" +
            "        sandbox requires a reboot, which can be done automatically be specifying\n" +
            "        the /reboot flag.";

        /// <summary>
        /// Main entry point for handling a Sandbox 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(SandboxUsageMessage);
                return;
            }

            string desiredValue = parameters.GetParameterValue("value");

            if (string.IsNullOrEmpty(desiredValue))
            {
                Task<Sandbox> getSandboxTask = portal.GetXboxLiveSandbox();
                getSandboxTask.Wait();

                Console.WriteLine(getSandboxTask.Result);
            }
            else
            {
                Task<Sandbox> setSandboxTask = portal.SetXboxLiveSandbox(desiredValue);
                setSandboxTask.Wait();

                Console.WriteLine("{0} -> {1}", setSandboxTask.Result, desiredValue);

                if (parameters.HasFlag("reboot"))
                {
                    Task rebootTask = portal.Reboot();
                    rebootTask.Wait();
                    Console.WriteLine("Console rebooting...");
                }
                else
                {
                    Console.WriteLine("A reboot is required before this setting takes effect.");
                }
            }
        }
    }
}
 No newline at end of file
Loading