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)); }
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)); }
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))); } }
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)); }