Exemplo n.º 1
0
        protected virtual async Task <byte[]> ConvertSnapshotToBytesAsync(ISnapshot snapshot)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var zip = new ZipFile())
                {
                    var metadata = new Dictionary <string, string>();
                    metadata["title"]    = snapshot.Title;
                    metadata["category"] = snapshot.Category ?? string.Empty;
                    metadata["created"]  = snapshot.Created.ToString("yyyy-MM-dd HH:mm:ss");

                    zip.AddEntry("metadata", GetMetadataBytes(metadata));

                    var snapshotBytes = await snapshot.GetAllBytesAsync();

                    zip.AddEntry("data", snapshotBytes);

                    zip.Save(memoryStream);
                }

                return(memoryStream.ToArray());
            }
        }
        protected virtual async Task <byte[]> ConvertSnapshotToBytesAsync(ISnapshot snapshot)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                {
                    var metadata = new Dictionary <string, string>();
                    metadata["title"]    = snapshot.Title;
                    metadata["category"] = snapshot.Category ?? string.Empty;
                    metadata["created"]  = snapshot.Created.ToString("yyyy-MM-dd HH:mm:ss");

                    var metadataEntry = archive.CreateEntry("metadata");
                    await metadataEntry.OpenAndWriteAsync(GetMetadataBytes(metadata));

                    var snapshotBytes = await snapshot.GetAllBytesAsync();

                    var dataEntry = archive.CreateEntry("data");
                    await dataEntry.OpenAndWriteAsync(snapshotBytes);
                }

                return(memoryStream.ToArray());
            }
        }