Ejemplo n.º 1
0
        public async Task Format2_LoadAndWrite_XMind()
        {
            using (Record())
            {
                renderer.Expect(x => x.FindColor(null)).Repeat.Any().IgnoreArguments().Return(color);

                color.Expect(x => x.Normal).Repeat.Any().Return(new Vector3(1, 0, 0));
            }

            using (Playback())
            {
                var file = Resources.Format2;

                var document = JsonDocumentSerializer.Deserialize(file);

                var exporter = new XMindExporter();
                var importer = new XMindImporter();

                var stream = new MemoryStream();

                await exporter.ExportAsync(document, renderer, stream);

                stream = new MemoryStream(stream.ToArray());

                var imported = await importer.ImportAsync(stream, "Name");

                Assert.Equal(1, imported.Count);
                Assert.Equal("Test", imported[0].Name);

                document = imported[0].Document;

                AssertDocument(document, false);
            }
        }
Ejemplo n.º 2
0
        public void Format2_LoadAndWrite()
        {
            var file = Resources.Format2;

            var document = JsonDocumentSerializer.Deserialize(file);

            JsonDocumentSerializer.Serialize(new JsonHistory(document));
        }
Ejemplo n.º 3
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);
            }));
        }
        public void SerializeObject_WhenObjectIsNotRegisteredAsShorthandType_ReturnsJson()
        {
            var idValue    = Guid.NewGuid();
            var obj        = new TestAggregateCreated(idValue);
            var serializer = new JsonDocumentSerializer();

            var json = serializer.SerializeObject(obj);

            json.Should().Contain("\"$type\":\"Brickweave.EventStore.Tests.Models.TestAggregateCreated, Brickweave.EventStore.Tests\"");

            _output.WriteLine(json);
        }
        public void SerializeObject_WhenObjectIsRegisteredAsShorthandType_ReturnsJson()
        {
            var idValue    = Guid.NewGuid();
            var obj        = new TestAggregateCreated(idValue);
            var serializer = new JsonDocumentSerializer(typeof(TestAggregateCreated));

            var json = serializer.SerializeObject(obj);

            json.Should().Contain("\"$type\":\"TestAggregateCreated\"");

            _output.WriteLine(json);
        }
Ejemplo n.º 6
0
 public static Task <Document> OpenDocumentQueuedAsync(this StorageFile file)
 {
     return(FileQueue.EnqueueAsync(async() =>
     {
         try
         {
             using (IRandomAccessStream stream = await file.OpenReadAsync())
             {
                 return stream.Size > 0 ? JsonDocumentSerializer.Deserialize(stream.AsStreamForRead()) : Document.CreateNew(file.DisplayName);
             }
         }
         catch (Exception e)
         {
             HockeyClient.Current.TrackException(e, GetExceptionProperies(file, "Open"));
             throw;
         }
     }));
 }
Ejemplo n.º 7
0
        public Task <List <ImportResult> > ImportAsync(Stream stream, string name)
        {
            Guard.NotNull(stream, nameof(stream));

            return(Task.Run(() =>
            {
                var result = new List <ImportResult>();

                if (!string.IsNullOrWhiteSpace(name))
                {
                    var document = JsonDocumentSerializer.Deserialize(stream);

                    result.Add(new ImportResult(document, name));
                }

                return result;
            }));
        }
Ejemplo n.º 8
0
        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();
                }
            });
        }
Ejemplo n.º 9
0
        static async Task Main(string[] args)
        {
            // Initialize dependencies.
            var jsonSerializer = new JsonDocumentSerializer();
            var xmlSerializer  = new XmlDocumentSerializer();
            var converter      = new ConverterBase <Document>(new ISerializer <Document>[] { jsonSerializer, xmlSerializer, });

            var webStorage        = new WebStorage();
            var fileSystemStorage = new FileSystemStorage();
            var storageProvider   = new StorageProvider.Storage.StorageProvider(new IStorage[] { webStorage, fileSystemStorage, });

            var app = new Application(converter, storageProvider);

            // Run application.
            var fromUri = new Uri("https://gist.githubusercontent.com/daywee/155b9145f00967cffac2933869614d6c/raw/835a0feef86d671077a210b92e11f318abd0acb5/rwsDocument.json");

            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var    toUri         = new Uri(Path.Combine(documentsPath, "rwsHomework.xml"));

            await app.Convert(fromUri, toUri);
        }
Ejemplo n.º 10
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;
                }
            });
        }
Ejemplo n.º 11
0
        private static void TestFileLoading(byte[] file)
        {
            var document = JsonDocumentSerializer.Deserialize(file);

            AssertDocument(document);
        }