コード例 #1
0
        public void Format2_LoadAndWrite()
        {
            var file = Resources.Format2;

            var document = JsonDocumentSerializer.Deserialize(file);

            JsonDocumentSerializer.Serialize(new JsonHistory(document));
        }
コード例 #2
0
        public Task ExportAsync(Document document, IRenderer renderer, Stream stream, PropertiesBag properties = null)
        {
            Guard.NotNull(document, nameof(document));
            Guard.NotNull(stream, nameof(stream));

            return(Task.Run(() =>
            {
                JsonDocumentSerializer.Serialize(new JsonHistory(document), stream);
            }));
        }
コード例 #3
0
ファイル: BackupMaker.cs プロジェクト: Win10Mindapp/Mindmap
        public static async Task MakeBackupAsync(IEnumerable <DocumentFile> files)
        {
            var backupFile = await LocalStore.CreateOrOpenFileQueuedAsync("Backup.zip");

            var histories = new Dictionary <string, JsonHistory>();

            foreach (var file in files.Where(x => x.Document != null))
            {
                var name = file.Name + ".mmd";

                if (file.Path != null)
                {
                    name = file.Path;
                    name = name.Replace('/', '_');
                    name = name.Replace(':', '_');
                    name = name.Replace('\\', '_');
                }

                histories.Add(name, new JsonHistory(file.Document));
            }

            await FileQueue.EnqueueAsync(async() =>
            {
                using (var transaction = await backupFile.OpenTransactedWriteAsync())
                {
                    using (var archive = new ZipArchive(transaction.Stream.AsStream(), ZipArchiveMode.Update))
                    {
                        foreach (var kvp in histories)
                        {
                            var entry = archive.GetEntry(kvp.Key) ?? archive.CreateEntry(kvp.Key);

                            using (var entrySteam = entry.Open())
                            {
                                JsonDocumentSerializer.Serialize(kvp.Value, entrySteam);
                            }
                        }
                    }

                    await transaction.CommitAsync();
                }
            });
        }
コード例 #4
0
        public static async Task SaveDocumentQueuedAsync(this StorageFile file, Document document)
        {
            var history = new JsonHistory(document);

            await FileQueue.EnqueueAsync(async() =>
            {
                try
                {
                    using (var transaction = await file.OpenTransactedWriteAsync())
                    {
                        JsonDocumentSerializer.Serialize(history, transaction.Stream.AsStreamForWrite());

                        await transaction.CommitAsync();
                    }
                }
                catch (Exception e)
                {
                    HockeyClient.Current.TrackException(e, GetExceptionProperies(file, "Open"));
                    throw;
                }
            });
        }