/// <summary> /// Restores the AudioController from suspension. /// </summary> /// <remarks>This method should only be called from the constructor.</remarks> private async Task DeserializeAsync() { StorageFile file = null; TrackQueue deserializedQueue = null; try { file = await ApplicationData.Current.LocalFolder.GetFileAsync(QUEUE_SUSPENSION_XML); using (IInputStream stream = await file.OpenReadAsync()) { DataContractSerializer dcs = new DataContractSerializer(typeof(TrackQueue)); deserializedQueue = (TrackQueue)dcs.ReadObject(stream.AsStreamForRead()); } } catch (Exception) { // Justification: deserialization failure should assume corrupt file and fail gracefully } if (deserializedQueue != null) { MutateQueue(() => _queue = deserializedQueue); OnPropertyChanged("UpcomingTracks"); // In this case, a new object was deserialized. if (_queue.Current != null) { Status = AudioControllerStatus.Paused; } } if (file != null) { await file.DeleteAsync(); } }
/// <summary> /// Restores the AudioController from suspension. /// </summary> /// <remarks>This method should only be called from the constructor.</remarks> private async Task DeserializeAsync() { StorageFile file = null; TrackQueue deserializedQueue = null; try { file = await ApplicationData.Current.LocalFolder.GetFileAsync(QUEUE_SUSPENSION_XML); using (IInputStream stream = await file.OpenReadAsync()) { DataContractSerializer dcs = new DataContractSerializer(typeof(TrackQueue)); deserializedQueue = (TrackQueue)dcs.ReadObject(stream.AsStreamForRead()); } } catch (Exception) { // Justification: deserialization failure should assume corrupt file and fail gracefully } if (deserializedQueue != null) { MutateQueue(() => _queue = deserializedQueue); OnPropertyChanged("UpcomingTracks"); // In this case, a new object was deserialized. if (_queue.Current != null) Status = AudioControllerStatus.Paused; } if (file != null) { await file.DeleteAsync(); } }