예제 #1
0
        private async Task <Autogenerated.InvokeBindingResponse> MakeInvokeBindingRequestAsync <TContent>(
            string name,
            string operation,
            TContent data,
            IReadOnlyDictionary <string, string> metadata = default,
            CancellationToken cancellationToken           = default)
        {
            var envelope = new Autogenerated.InvokeBindingRequest()
            {
                Name      = name,
                Operation = operation
            };

            if (data != null)
            {
                envelope.Data = TypeConverters.ToJsonByteString(data, this.jsonSerializerOptions);
            }

            if (metadata != null)
            {
                foreach (var kvp in metadata)
                {
                    envelope.Metadata.Add(kvp.Key, kvp.Value);
                }
            }

            return(await this.MakeGrpcCallHandleError(
                       options => client.InvokeBindingAsync(envelope, options),
                       cancellationToken));
        }
        private async Task <InvokeBindingResponse> MakeInvokeBindingRequestAsync <TContent>(
            string name,
            string operation,
            TContent data,
            Dictionary <string, string> metadata = default,
            CancellationToken cancellationToken  = default)
        {
            var envelope = new Autogenerated.InvokeBindingRequest()
            {
                Name      = name,
                Operation = operation
            };

            if (data != null)
            {
                envelope.Data = ConvertToByteStringAsync(data, this.jsonSerializerOptions);
            }

            if (metadata != null)
            {
                envelope.Metadata.Add(metadata);
            }

            return(await this.MakeGrpcCallHandleError(
                       (options) =>
            {
                return client.InvokeBindingAsync(envelope, options);
            },
                       cancellationToken));
        }
예제 #3
0
        private async Task <Autogenerated.InvokeBindingResponse> MakeInvokeBindingRequestAsync(
            string name,
            string operation,
            ByteString data,
            IReadOnlyDictionary <string, string> metadata = default,
            CancellationToken cancellationToken           = default)
        {
            var envelope = new Autogenerated.InvokeBindingRequest()
            {
                Name      = name,
                Operation = operation
            };

            if (data != null)
            {
                envelope.Data = data;
            }

            if (metadata != null)
            {
                foreach (var kvp in metadata)
                {
                    envelope.Metadata.Add(kvp.Key, kvp.Value);
                }
            }

            var options = CreateCallOptions(headers: null, cancellationToken);

            try
            {
                return(await client.InvokeBindingAsync(envelope, options));
            }
            catch (RpcException ex)
            {
                throw new DaprException("Binding operation failed: the Dapr endpoint indicated a failure. See InnerException for details.", ex);
            }
        }