/// <summary> /// Stops a Holographic Simulation recording session. /// </summary> /// <returns>Byte array containing the recorded data.</returns> /// <exception cref="InvalidOperationException">No recording was in progress.</exception> /// <remarks>This method is only supported on HoloLens.</remarks> public async Task <byte[]> StopHolographicSimulationRecordingAsync() { if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily)) { throw new NotSupportedException("This method is only supported on HoloLens."); } Uri uri = Utilities.BuildEndpoint( this.deviceConnection.Connection, StopHolographicSimulationRecordingApi); byte[] dataBytes = null; using (Stream dataStream = await this.GetAsync(uri)) { if (dataStream != null) { using (MemoryStream outStream = new MemoryStream()) { dataStream.CopyTo(outStream); if (outStream.Length != 0) { outStream.Seek(0, SeekOrigin.Begin); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(HolographicSimulationError)); HolographicSimulationError error = null; try { // Try to get / interpret an error response. error = (HolographicSimulationError)serializer.ReadObject(outStream); } catch { } if (error != null) { // We received an error response. throw new InvalidOperationException(error.Reason); } // Getting here indicates that we have file data to return. dataBytes = new byte[outStream.Length]; await outStream.ReadAsync(dataBytes, 0, dataBytes.Length); } } } } return(dataBytes); }
/// <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.</remarks> public async Task <HolographicSimulationPlaybackStates> GetHolographicSimulationPlaybackStateAsync(string name) { if (!Utilities.IsHoloLens(this.Platform, this.DeviceFamily)) { throw new NotSupportedException("This method is only supported on HoloLens."); } HolographicSimulationPlaybackStates playbackState = HolographicSimulationPlaybackStates.Unexpected; string payload = string.Format( "recording={0}", name); Uri uri = Utilities.BuildEndpoint( this.deviceConnection.Connection, HolographicSimulationPlaybackStateApi, payload); using (Stream dataStream = await this.GetAsync(uri)) { if (dataStream != null) { using (MemoryStream outStream = new MemoryStream()) { dataStream.CopyTo(outStream); if (outStream.Length != 0) { outStream.Seek(0, SeekOrigin.Begin); // 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); }