Esempio n. 1
0
        private CancelInvocationMessage BindCancelInvocationMessage(JObject json)
        {
            var invocationId = JsonUtils.GetRequiredProperty <string>(json, InvocationIdPropertyName, JTokenType.String);
            var metadata     = JsonUtils.GetOptionalMetadataDictionary(json, MetadataPropertyName);

            return(new CancelInvocationMessage(invocationId, metadata));
        }
Esempio n. 2
0
        private StreamItemMessage BindStreamItemMessage(JObject json, IInvocationBinder binder)
        {
            var invocationId = JsonUtils.GetRequiredProperty <string>(json, InvocationIdPropertyName, JTokenType.String);
            var metadata     = JsonUtils.GetOptionalMetadataDictionary(json, MetadataPropertyName);
            var result       = JsonUtils.GetRequiredProperty <JToken>(json, ItemPropertyName);

            var returnType = binder.GetReturnType(invocationId);

            return(new StreamItemMessage(invocationId, result?.ToObject(returnType, PayloadSerializer), metadata));
        }
Esempio n. 3
0
        private StreamInvocationMessage BindStreamInvocationMessage(JObject json, IInvocationBinder binder)
        {
            var invocationId = JsonUtils.GetRequiredProperty <string>(json, InvocationIdPropertyName, JTokenType.String);
            var metadata     = JsonUtils.GetOptionalMetadataDictionary(json, MetadataPropertyName);

            var target = JsonUtils.GetRequiredProperty <string>(json, TargetPropertyName, JTokenType.String);
            var args   = JsonUtils.GetRequiredProperty <JArray>(json, ArgumentsPropertyName, JTokenType.Array);

            var paramTypes = binder.GetParameterTypes(target);

            try
            {
                var arguments = BindArguments(args, paramTypes);
                return(new StreamInvocationMessage(invocationId, metadata, target, arguments: arguments));
            }
            catch (Exception ex)
            {
                return(new StreamInvocationMessage(invocationId, metadata, target, ExceptionDispatchInfo.Capture(ex)));
            }
        }
Esempio n. 4
0
        private CompletionMessage BindCompletionMessage(JObject json, IInvocationBinder binder)
        {
            var invocationId = JsonUtils.GetRequiredProperty <string>(json, InvocationIdPropertyName, JTokenType.String);
            var metadata     = JsonUtils.GetOptionalMetadataDictionary(json, MetadataPropertyName);
            var error        = JsonUtils.GetOptionalProperty <string>(json, ErrorPropertyName, JTokenType.String);
            var resultProp   = json.Property(ResultPropertyName);

            if (error != null && resultProp != null)
            {
                throw new InvalidDataException("The 'error' and 'result' properties are mutually exclusive.");
            }

            if (resultProp == null)
            {
                return(new CompletionMessage(invocationId, metadata, error, result: null, hasResult: false));
            }

            var returnType = binder.GetReturnType(invocationId);
            var payload    = resultProp.Value?.ToObject(returnType, PayloadSerializer);

            return(new CompletionMessage(invocationId, metadata, error, result: payload, hasResult: true));
        }