Ejemplo n.º 1
0
 /// <summary>
 /// Materializes the operation's resource into a Memory{byte} wrapping a byte array.
 /// </summary>
 /// <param name="serializer">Serializer to serialize user provided objects to JSON.</param>
 /// <param name="cancellationToken"><see cref="CancellationToken"/> for cancellation.</param>
 internal virtual async Task MaterializeResourceAsync(CosmosSerializer serializer, CancellationToken cancellationToken)
 {
     if (this.body.IsEmpty && this.ResourceStream != null)
     {
         this.body = await BatchExecUtils.StreamToMemoryAsync(this.ResourceStream, Constants.MaxResourceSizeInBytes, cancellationToken);
     }
 }
        /// <summary>
        /// Encrypts (if encryption options are set) and materializes the operation's resource into a Memory{byte} wrapping a byte array.
        /// </summary>
        /// <param name="serializerCore">Serializer to serialize user provided objects to JSON.</param>
        /// <param name="cancellationToken"><see cref="CancellationToken"/> for cancellation.</param>
        internal virtual async Task EncryptAndMaterializeResourceAsync(CosmosSerializerCore serializerCore, CancellationToken cancellationToken)
        {
            if (this.body.IsEmpty && this.ResourceStream != null)
            {
                Stream stream = this.ResourceStream;
                if (this.ContainerCore != null && this.RequestOptions?.EncryptionOptions != null)
                {
                    stream = await this.ContainerCore.ClientContext.EncryptItemAsync(
                        stream,
                        this.RequestOptions.EncryptionOptions,
                        (DatabaseCore)this.ContainerCore.Database,
                        this.DiagnosticsContext,
                        cancellationToken);
                }

                this.body = await BatchExecUtils.StreamToMemoryAsync(stream, cancellationToken);
            }
        }