Пример #1
0
        private async Task <Blog> BuildBlog(BlogDocument blogDocument)
        {
            if (blogDocument is null)
            {
                throw new ArgumentNullException(nameof(blogDocument));
            }

            var uncompressedBody = new MemoryStream();

            using (var zip = new GZipStream(blogDocument.Body, CompressionMode.Decompress, true))
            {
                await zip.CopyToAsync(uncompressedBody);
            }

            uncompressedBody.Position = 0L;

            var blog = new Blog(
                new Guid(blogDocument.Id),
                blogDocument.Version,
                blogDocument.Created,
                blogDocument.Updated,
                blogDocument.Author,
                uncompressedBody);

            return(blog);
        }
Пример #2
0
        public async Task <Blog> Save(Blog inputBlog)
        {
            Blog loadedBlog;

            using (var context = new DynamoDBContext(_Client))
            {
                if (inputBlog is null)
                {
                    throw new ArgumentNullException(nameof(inputBlog));
                }

                var compressedStream = new MemoryStream();

                using (var zip = new GZipStream(compressedStream, CompressionMode.Compress, true))
                {
                    await inputBlog.Body.CopyToAsync(zip);
                }

                var blogId = inputBlog.Id ?? Guid.NewGuid();

                var blogDoc = new BlogDocument
                {
                    Id      = blogId.ToString(),
                    Version = inputBlog.Version,
                    Created = inputBlog.Created,
                    Updated = inputBlog.Updated,
                    Author  = inputBlog.Author,
                    Body    = compressedStream
                };

                await context.SaveAsync <BlogDocument>(blogDoc);

                loadedBlog = await LoadBlog(context, blogId);
            }

            return(loadedBlog);
        }