public async Task GetHolographicSimulationPlaybackStateAsync()

in WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/HoloLens/PerceptionSimulationPlayback.cs [175:224]


        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;
        }