async void OnLoadAsync(object sender, RoutedEventArgs e) { var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".gif"); openPicker.FileTypeFilter.Add(".isf"); Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync(); if (null != file) { using (var stream = await file.OpenSequentialReadAsync()) { try { await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream); } catch (Exception ex) { rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage); } } rootPage.NotifyUser(inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Count + " stroke(s) loaded!", NotifyType.StatusMessage); } }
async void OnLoadAsync(object sender, RoutedEventArgs e) { //load image var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".gif"); openPicker.FileTypeFilter.Add(".isf"); Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync(); if (null != file) { using (var stream = await file.OpenSequentialReadAsync()) { try { await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream); } catch (Exception ex) { rootPage.ShowMessage(ex.Message); } } } }
private async Task <byte[]> filetobytes(Windows.Storage.StorageFile file) { using (var inputStream = await file.OpenSequentialReadAsync()) { var readStream = inputStream.AsStreamForRead(); var byteArray = new byte[readStream.Length]; await readStream.ReadAsync(byteArray, 0, byteArray.Length); return(byteArray); } }
public static async Task<List<Session>> DeserializeLocalSessions(StorageFile file) { using (var stream = await file.OpenSequentialReadAsync()) { using (var dr = new Windows.Storage.Streams.DataReader(stream)) { var numberOfSessions = dr.ReadInt32(); List<Session> rv = new List<Session>(numberOfSessions); for (int x = 0; x < numberOfSessions; x++) { rv.Add(LoadSession(dr)); } return rv; } } }
public async Task<List<Avalon>> Restore(StorageFile file) { List<Avalon> Return = new List<Avalon>(); List<SerializableAvalon> temp = new List<SerializableAvalon>(); using (IInputStream Stream = await file.OpenSequentialReadAsync()) { DataContractSerializer dcs = new DataContractSerializer(typeof(List<SerializableAvalon>)); temp = (List<SerializableAvalon>)dcs.ReadObject(Stream.AsStreamForRead()); } foreach (SerializableAvalon item in temp) { Avalon Pizza = Produce(item.Definition); Pizza.RestorState(item); Return.Add(Pizza); } return Return; }
public static async Task<Object> DeserializeFromFileAsync(Type objectType, StorageFile file, bool deleteFile = false) { if (file == null) return null; try { Object obj; AppEventSource.Log.Debug("Suspension: Checking file..." + file.Name); // Get the input stream for the file using (IInputStream inStream = await file.OpenSequentialReadAsync()) { // Deserialize the Session State DataContractSerializer serializer = new DataContractSerializer(objectType); obj = serializer.ReadObject(inStream.AsStreamForRead()); } AppEventSource.Log.Debug("Suspension: Object loaded from file. " + objectType.ToString()); // Delete the file if (deleteFile) { await file.DeleteAsync(); deleteFile = false; AppEventSource.Log.Info("Suspension: File deleted. " + file.Name); } return obj; } catch (Exception e) { AppEventSource.Log.Error("Suspension: Error when deserializing object. Exception: " + e.Message); MessageDialog messageDialog = new MessageDialog("Error when deserializing App settings: " + file.Name + "\n" + "The PDF file is not affected.\n " + "Details: \n" + e.Message); messageDialog.Commands.Add(new UICommand("Reset Settings", null, 0)); messageDialog.Commands.Add(new UICommand("Ignore", null, 1)); IUICommand command = await messageDialog.ShowAsync(); switch ((int)command.Id) { case 0: // Delete file deleteFile = true; break; default: deleteFile = false; break; } return null; } finally { // Delete the file if error occured if (deleteFile) { await file.DeleteAsync(); AppEventSource.Log.Info("Suspension: File deleted due to error. " + file.Name); } } }
async Task PlayFile(StorageFile sf) { if (sf == null) { Exit(); return; } byte[] module = new byte[ASAPInfo.MaxModuleLength]; int moduleLen; using (IInputStream iis = await sf.OpenSequentialReadAsync()) { IBuffer buf = await iis.ReadAsync(module.AsBuffer(), (uint) ASAPInfo.MaxModuleLength, InputStreamOptions.None); moduleLen = (int) buf.Length; } ASAP asap = new ASAP(); asap.Load(sf.Name, module, moduleLen); ASAPInfo info = asap.GetInfo(); int song = info.GetDefaultSong(); int duration = info.GetLoop(song) ? -1 : info.GetDuration(song); asap.PlaySong(song, duration); this.MyMedia = new MediaElement { AudioCategory = AudioCategory.BackgroundCapableMedia, Volume = 1, AutoPlay = true }; Window.Current.Content = this.MyMedia; await Task.Yield(); this.MyMedia.SetSource(new ASAPRandomAccessStream(asap, duration), "audio/x-wav"); MediaControl.TrackName = info.GetTitleOrFilename(); MediaControl.ArtistName = info.GetAuthor(); MediaControl.PlayPressed += MediaControl_PlayPressed; MediaControl.PausePressed += MediaControl_PausePressed; MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed; MediaControl.StopPressed += MediaControl_StopPressed; MediaControl.IsPlaying = true; }