public async Task <Settings> WriteSettingsAsync(Settings settings) { var localFolder = ApplicationData.Current.LocalFolder; StorageFile file = await localFolder.CreateFileAsync(SettingsName, CreationCollisionOption.ReplaceExisting); //await FileIO.WriteBufferAsync(file, buffer); var formatter = new DataContractSerializer(typeof(Settings)); var stream = await file.OpenAsync(FileAccessMode.ReadWrite); using (var outputStream = stream.GetOutputStreamAt(0)) { using (var dataWriter = new Windows.Storage.Streams.DataWriter(outputStream)) { dataWriter.WriteString(settings.FileSystemDirectory); dataWriter.WriteBoolean(settings.IsFileSystemEnabled); await dataWriter.StoreAsync(); await outputStream.FlushAsync(); } } //formatter.WriteObject(outStream, settings); Debug.WriteLine("SavedSettings"); return(settings); }
public async void SaveData() { var fileList = await ApplicationData.Current.LocalFolder.GetFilesAsync(); System.IO.MemoryStream ms = new System.IO.MemoryStream(); var scratchFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(localScratchFileName, CreationCollisionOption.ReplaceExisting); using (var storageTransaction = await scratchFile.OpenTransactedWriteAsync()) { using (var dw = new Windows.Storage.Streams.DataWriter(storageTransaction.Stream)) { dw.WriteInt32(Items.Count); for (int x = 0; x < Items.Count; x++) { TrackItem item = Items[x]; dw.WriteDateTime(item.Start); dw.WriteDateTime(item.End.Value); dw.WriteInt32(item.Topic.Length); dw.WriteString(item.Topic); } if (CurrentItem == null) { dw.WriteBoolean(false); } else { dw.WriteBoolean(true); dw.WriteDateTime(CurrentItem.Start); dw.WriteInt32(CurrentItem.Topic.Length); dw.WriteString(CurrentItem.Topic); } storageTransaction.Stream.Size = await dw.StoreAsync(); await storageTransaction.CommitAsync(); } } await scratchFile.RenameAsync(localFileName, NameCollisionOption.ReplaceExisting); }