コード例 #1
0
        private static DataFile CreateDataFile(INoteRepository repo)
        {
            var notes    = repo.GetAllNotes();
            var dataFile = new DataFile
            {
                RichTextNotes = notes.Where(note => note.TypeOfNote == NoteType.RichText)
                                .Cast <RichTextNote>()
                                .ToList(),
                ToDoNotes = notes.Where(note => note.TypeOfNote == NoteType.ToDo)
                            .Cast <ToDoListNote>()
                            .ToList()
            };

            return(dataFile);
        }
コード例 #2
0
        private async Task SaveDataFileToDisk(string fileName, DataFile data)
        {
            try
            {
                StorageFile savedDataFile = await ApplicationData.Current.LocalFolder
                                            .CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                using (Stream writeStream = await savedDataFile.OpenStreamForWriteAsync())
                {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(DataFile));
                    serializer.WriteObject(writeStream, data);
                }
            }
            catch (Exception ex)
            {
                // Unable to save data file
            }
        }