Пример #1
0
        public Task SaveAsync(ComposableCatalog catalog, Stream cacheStream, CancellationToken cancellationToken = default(CancellationToken))
        {
            Requires.NotNull(catalog, nameof(catalog));
            Requires.NotNull(cacheStream, nameof(cacheStream));

            return(Task.Run(() =>
            {
                using (var writer = new BinaryWriter(cacheStream, TextEncoding, leaveOpen: true))
                {
                    var context = new SerializationContext(writer, catalog.Parts.Count * 4, catalog.Resolver);
                    context.Write(catalog);
                    context.FinalizeObjectTableCapacity();
                }
            }));
        }
Пример #2
0
        public Task SaveAsync(RuntimeComposition composition, Stream cacheStream, CancellationToken cancellationToken = default(CancellationToken))
        {
            Requires.NotNull(composition, nameof(composition));
            Requires.NotNull(cacheStream, nameof(cacheStream));
            Requires.Argument(cacheStream.CanWrite, "cacheStream", Strings.WritableStreamRequired);

            return(Task.Run(() =>
            {
                using (var writer = new BinaryWriter(cacheStream, TextEncoding, leaveOpen: true))
                {
                    var context = new SerializationContext(writer, composition.Parts.Count * 5, composition.Resolver);
                    context.Write(composition);
                    context.FinalizeObjectTableCapacity();
                }
            }));
        }