Commit 9f2f5349 authored by David Kline's avatar David Kline
Browse files

add HoloLens specific API implementations

parent 206e4328
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests
            Assert.AreEqual(TaskStatus.RanToCompletion, getTask.Status);

            // Check some known things about this response.
            ProcessStatus processStatus = getTask.Result.Status;
            MrcProcessStatus processStatus = getTask.Result.Status;
            Assert.AreEqual("Running", processStatus.MrcProcess);
        }

+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,11 @@ namespace Microsoft.Tools.WindowsDevicePortal
    /// </content>
    public partial class DevicePortal
    {
        /// <summary>
        /// API for running a Perception client.
        /// </summary>
        public static readonly string HolographicPerceptionClient = "api/holographic/perception/client";

        /// <summary>
        /// API for getting or setting the Holographic Perception Simulation control mode.
        /// </summary>
+2 −2
Original line number Diff line number Diff line
@@ -317,14 +317,14 @@ namespace Microsoft.Tools.WindowsDevicePortal
            /// Gets the recording status
            /// </summary>
            [DataMember(Name = "ProcessStatus")]
            public ProcessStatus Status { get; private set; }
            public MrcProcessStatus Status { get; private set; }
        }

        /// <summary>
        /// Object representation of the recording process status
        /// </summary>
        [DataContract]
        public class ProcessStatus
        public class MrcProcessStatus
        {
            /// <summary>
            /// Gets the process status
+179 −5
Original line number Diff line number Diff line
@@ -4,6 +4,12 @@
// </copyright>
//----------------------------------------------------------------------------------------------

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;

namespace Microsoft.Tools.WindowsDevicePortal
{
    /// <content>
@@ -14,12 +20,12 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// <summary>
        /// API for loading or unloading a Holographic Perception Simulation recording.
        /// </summary>
        public static readonly string HolographicSimulationLoadUnloadRecordingApi = "api/holographic/simulation/playback/session/file";
        public static readonly string HolographicSimulationPlaybackSessionFileApi = "api/holographic/simulation/playback/session/file";

        /// <summary>
        /// API for pausing a Holographic Perception Simulation recording.
        /// </summary>
        public static readonly string HolographicSimulationPauseApi = "api/holographic/simulation/playback/session/pause";
        public static readonly string HolographicSimulationPlaybackPauseApi = "api/holographic/simulation/playback/session/pause";

        /// <summary>
        /// API for uploading or deleting a Holographic Perception Simulation recording file.
@@ -34,7 +40,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// <summary>
        /// API for starting playback of a Holographic Perception Simulation recording.
        /// </summary>
        public static readonly string HolographicSimulationPlayApi = "api/holographic/simulation/playback/session/play";
        public static readonly string HolographicSimulationPlaybackPlayApi = "api/holographic/simulation/playback/session/play";

        /// <summary>
        /// API for loading or unloading a Holographic Perception Simulation recording.
@@ -49,15 +55,183 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// <summary>
        /// API for starting playback of a Holographic Perception Simulation recording.
        /// </summary>
        public static readonly string HolographicSimulationStopApi = "api/holographic/simulation/playback/session/stop";
        public static readonly string HolographicSimulationPlaybackStopApi = "api/holographic/simulation/playback/session/stop";

        /// <summary>
        /// API for retrieving the types of data in a Holographic Perception Simulation recording.
        /// </summary>
        public static readonly string HolographicSimulationTypesApi = "api/holographic/simulation/playback/session/types";
        public static readonly string HolographicSimulationPlaybackDataTypesApi = "api/holographic/simulation/playback/session/types";

        /// <summary>
        /// Deletes the specified Holographic Simulation recording.
        /// </summary>
        /// <param name="name">The name of the recording to delete (ex: testsession.xef).</param>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task DeleteHolographicSimulationRecording(string name)
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
            {
                throw new NotSupportedException("This method is only supported on HoloLens.");
            }

            string payload = string.Format(
                "recording={0}",
                name);

            await this.Delete(HolographicSimulationPlaybackFileApi, payload);
        }

        /// <summary>
        /// Gets the playback state of a Holographic Simulation recording.
        /// </summary>
        /// <param name="name">The name of the recording (ex: testsession.xef).</param>
        /// <returns>HolographicSimulationPlaybackStates enum value describing the state of the recording.</returns>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task<HolographicSimulationPlaybackStates> GetHolographicSimulationPlaybackState(string name)
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
            {
                throw new NotSupportedException("This method is only supported on HoloLens.");
            }

            HolographicSimulationPlaybackStates playbackState = HolographicSimulationPlaybackStates.Unknown;

            string payload = string.Format(
                "recording={0}",
                name);

            Uri uri = Utilities.BuildEndpoint(
                this.deviceConnection.Connection,
                HolographicSimulationPlaybackStateApi,
                payload);

            using (Stream dataStream = await this.Get(uri))
            {
                if ((dataStream != null) &&
                    (dataStream.Length != 0))
                {
                    // Try to get the session state.
                    try
                    {
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(HolographicSimulationPlaybackSessionState));
                        HolographicSimulationPlaybackSessionState sessionState = (HolographicSimulationPlaybackSessionState)serializer.ReadObject(dataStream);
                        playbackState = sessionState.State;
                    }
                    catch 
                    {
                        // We did not receive the session state, check to see if we received a simulation error.
                        dataStream.Position = 0;
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(HolographicSimulationError));
                        HolographicSimulationError error = (HolographicSimulationError)serializer.ReadObject(dataStream);
                        throw new InvalidOperationException(error.Reason);
                    }
                }
            }

            return playbackState;
        }

        /// <summary>
        /// Loads the specified Holographic Simulation recording.
        /// </summary>
        /// <param name="name">The name of the recording to load (ex: testsession.xef).</param>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task LoadHolographicSimulationRecording(string name)
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
            {
                throw new NotSupportedException("This method is only supported on HoloLens.");
            }

            string payload = string.Format(
                "recording={0}",
                name);

            await this.Post(HolographicSimulationPlaybackSessionFileApi, payload);
        }

        /// <summary>
        /// Unloads the specified Holographic Simulation recording.
        /// </summary>
        /// <param name="name">The name of the recording to unload (ex: testsession.xef).</param>
        /// <remarks>This method is only supported on HoloLens devices.</remarks>
        public async Task UnloadHolographicSimulationRecording(string name)
        {
            if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily))
            {
                throw new NotSupportedException("This method is only supported on HoloLens.");
            }

            string payload = string.Format(
                "recording={0}",
                name);

            await this.Delete(HolographicSimulationPlaybackSessionFileApi, payload);
        }

        #region Data contract
        /// <summary>
        /// Enumeration describing the available Holgraphic Simulation playback states.
        /// </summary>
        public enum HolographicSimulationPlaybackStates
        {
            Unknown = -1,
            Stopped = 0,
            Playing,
            Paused,
            Complete,

            Unexpected = 9999
        }

        /// <summary>
        /// Object representation of the Holographic Simulation playback state
        /// </summary>
        [DataContract]
        public class HolographicSimulationPlaybackSessionState
        {   
            /// <summary>
            /// Gets the state value as a string
            /// </summary>
            [DataMember(Name = "state")]
            public string stateRaw { get; private set; }

            /// <summary>
            /// Gets the playback session state
            /// </summary>
            public HolographicSimulationPlaybackStates State
            {
                get 
                {
                    HolographicSimulationPlaybackStates state = HolographicSimulationPlaybackStates.Unknown;

                    switch (stateRaw)
                    {
                        case "stopped":
                            state = HolographicSimulationPlaybackStates.Stopped;
                            break;

                        case "playing":
                            state = HolographicSimulationPlaybackStates.Playing;
                            break;

                        case "paused":
                            state = HolographicSimulationPlaybackStates.Paused;
                            break;

                        case "end":
                            state = HolographicSimulationPlaybackStates.Complete;
                            break;

                        default:
                            state = HolographicSimulationPlaybackStates.Unexpected;
                            break;
                    }

                    return state;
                }
            }
        }
        #endregion // Data contract
    }
}
+6 −5
Original line number Diff line number Diff line
@@ -104,13 +104,13 @@ namespace Microsoft.Tools.WindowsDevicePortal
                if ((dataStream != null) &&
                    (dataStream.Length != 0))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(HolographicSimulationStopRecordingError));
                    HolographicSimulationStopRecordingError error = null;
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(HolographicSimulationError));
                    HolographicSimulationError error = null;
 
                    try
                    {
                        // Try to get / interpret an error response.
                        error = (HolographicSimulationStopRecordingError)serializer.ReadObject(dataStream);
                        error = (HolographicSimulationError)serializer.ReadObject(dataStream);
                    }
                    catch
                    {
@@ -133,9 +133,10 @@ namespace Microsoft.Tools.WindowsDevicePortal

        #region Data contract
        /// <summary>
        /// Object representation of a Holographic Simulation Stop Recording error.
        /// Object representation of a Holographic Simulation (playback or recording) error.
        /// </summary>
        public class HolographicSimulationStopRecordingError
        [DataContract]
        public class HolographicSimulationError
        {
            /// <summary>
            /// Gets the Reason string.