private JsonRpcResponse ReceiveMessage(string message) { JsonRpcResponse response; long messageId = 0; try { JsonRpcMessage jsonRpcMessage = JsonConvert.DeserializeObject <JsonRpcMessage>(message); messageId = jsonRpcMessage.Id; try { response = new JsonRpcResponse(jsonRpcMessage.Id, TryCallMethod(jsonRpcMessage).Result); } catch (Exception e) { throw e.InnerException; } } catch (Exception e) { response = e switch { JsonSerializationException _ => new JsonRpcResponse(messageId, JsonRpcErrors.ParseError), MethodNotFoundException _ => new JsonRpcResponse(messageId, JsonRpcErrors.MethodNotFound), InvalidParametersException _ => new JsonRpcResponse(messageId, JsonRpcErrors.InvalidParams), FormatException _ => new JsonRpcResponse(messageId, JsonRpcErrors.InvalidParams), _ => new JsonRpcResponse(messageId, JsonRpcErrors.InternalError) }; } return(response); }
public AbstractPropertyConverterAttribute(Type converter) { Type IPropertyConverter = typeof(IPropertyConverter <,>); if (!ReflectionUtils.IsAssignableToGenericType(converter, IPropertyConverter)) { throw new InterfaceNotImplementedException("Type " + converter.AssemblyQualifiedName + " does not implement interface " + IPropertyConverter.AssemblyQualifiedName); } _converterType = converter; _convertToSourceMethod = _converterType.GetMethod(CONVERT_TO_SOURCE_METHOD_NAME, ReflectionUtils.GetPublicBindingFlags()); _convertToDestinationMethod = _converterType.GetMethod(CONVERT_TO_DESTINATION_METHOD_NAME, ReflectionUtils.GetPublicBindingFlags()); if (_convertToSourceMethod == null) { throw MethodNotFoundException.CreateInstance(_converterType, IPropertyConverter.AssemblyQualifiedName, CONVERT_TO_SOURCE_METHOD_NAME); } if (_convertToDestinationMethod == null) { throw MethodNotFoundException.CreateInstance(_converterType, IPropertyConverter.AssemblyQualifiedName, CONVERT_TO_DESTINATION_METHOD_NAME); } _sourceType = _convertToSourceMethod.ReturnType; _destinationType = _convertToDestinationMethod.ReturnType; _converterInstance = ReflectionUtils.CreateInstance(_converterType); }
public string Invoke(params object[] parameters) { var testScopeStarted = StartInvocationScope(out Guid id); currentTestId = id; var parameterTypes = parameters .Select(p => p?.GetType()) .ToArray(); if (TypesMatchable(entryPointParameters, parameterTypes)) { string result; try { try { result = entryPointMethod.Invoke(action, parameters) + ""; if (testScopeStarted) { SetTestInfo(); } } catch (TargetInvocationException e) { throw e.InnerException; } } catch (SlimException e) { if (testScopeStarted) { SetTestInfo(); Builder.EndTest(id, LogStatus.Fail, e.InnerMessage); } throw new TargetInvocationException(e); } catch (Exception e) { if (testScopeStarted) { SetTestInfo(); Builder.EndTest(id, LogStatus.Error, e); } throw new TargetInvocationException(e); } if (testScopeStarted) { Builder.EndTest(id, LogStatus.Pass); } return(result); } var errorException = new MethodNotFoundException(actionType.Name, parameterTypes); if (testScopeStarted) { Builder.EndTest(id, LogStatus.Error, errorException); } throw errorException; }