Exemplo n.º 1
0
        static TimeSpan GetInvokeDeviceMethodOperationTimeout(MethodInvokeRequest methodInvokeRequest)
        {
            // For InvokeDeviceMethod, we need to take into account the timeouts specified
            // for the Device to connect and send a response. We also need to take into account
            // the transmission time for the request send/receive
            TimeSpan timeout = TimeSpan.FromSeconds(15); // For wire time

            timeout += TimeSpan.FromSeconds(methodInvokeRequest.ConnectionTimeoutInSeconds ?? 0);
            timeout += TimeSpan.FromSeconds(methodInvokeRequest.ResponseTimeoutInSeconds ?? 0);
            return(timeout <= DefaultMethodOperationTimeout ? DefaultMethodOperationTimeout : timeout);
        }
Exemplo n.º 2
0
        internal Task <MethodInvokeResponse> InvokeMethodAsync(MethodInvokeRequest methodInvokeRequest, Uri uri, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(this.moduleId))
            {
                throw new InvalidOperationException("ModuleId is required.");
            }

            TimeSpan timeout       = GetInvokeDeviceMethodOperationTimeout(methodInvokeRequest);
            var      customHeaders = new Dictionary <string, string>
            {
                { CustomHeaderConstants.ModuleId, $"{this.deviceId}/{this.moduleId}" }
            };

            return(this.httpClientHelper.PostAsync <MethodInvokeRequest, MethodInvokeResponse>(
                       uri,
                       methodInvokeRequest,
                       null,
                       customHeaders,
                       cancellationToken));
        }
Exemplo n.º 3
0
        public T InvokeMethod <T>(ServiceReference reference, int methodId, object[] arguments, InvokeMethodOptions options = InvokeMethodOptions.None)
        {
            var request = new MethodInvokeRequest();

            request.MethodId  = methodId;
            request.Arguments = arguments;

            var message = new Message();

            message.Guid       = Guid.NewGuid();
            message.Target     = reference.InterfaceId;
            message.BodyObject = request;
            message.Direction  = Message.Directions.Request;
            if (clientOptions.Credentials != null)
            {
                message.Authorization = clientOptions.Credentials.Create();
            }

            return((T)clientRuntime.SendRequest(message, clientOptions.RequestTimeout));
        }
Exemplo n.º 4
0
 public object Invoke(MethodInvokeRequest request)
 {
     return(Invoker.Invoke(Service, request));
 }