private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var result = await entry.Func(remoteInvokeMessage.Parameters); resultMessage.Result = result; //if (result.GetType() == typeof(Task)) //{ // resultMessage.Result = null; //} //else //{ // var task = result as Task<ActionResult>; // resultMessage.Result = await task; //} } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError("执行本地逻辑时候发生了错误。", exception); } resultMessage.ExceptionMessage = GetExceptionMessage(exception); } }
private async Task LocalExecuteAsync(ServiceEntry entry, HttpMessage httpMessage, HttpResultMessage <object> resultMessage) { try { var result = await entry.Func(httpMessage.ServiceKey, httpMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Entity = result; resultMessage.IsSucceed = resultMessage.Entity != null; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Entity = taskType.GetProperty("Result").GetValue(task); } resultMessage.IsSucceed = resultMessage.Entity != null; } } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(exception, "执行本地逻辑时候发生了错误。"); } resultMessage.StatusCode = exception.HResult; } }
private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var result = await entry.Func(remoteInvokeMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Result = result; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(exception, "执行本地逻辑时候发生了错误。"); } resultMessage.StatusCode = 500; resultMessage.ExceptionMessage = GetExceptionMessage(exception); } }
private async Task <HttpResultMessage <object> > LocalExecuteAsync(ServiceEntry entry, HttpRequestMessage httpMessage) { var resultMessage = new HttpResultMessage <object>(); try { var result = await entry.Func(httpMessage.ServiceKey, httpMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Result = result; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } resultMessage.IsSucceed = resultMessage.Result != null; resultMessage.StatusCode = resultMessage.IsSucceed ? (int)StatusCode.Success : (int)StatusCode.RequestError; } catch (ValidateException validateException) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(validateException, $"执行本地逻辑时候发生了错误:{validateException.Message}", validateException); } resultMessage.Message = validateException.Message; resultMessage.StatusCode = validateException.HResult; } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(exception, $"执行本地逻辑时候发生了错误:{exception.Message}"); } resultMessage.StatusCode = exception.HResult; resultMessage.Message = "执行发生了错误。"; resultMessage.Message = ExceptionPrompt.GetPrompt(exception); } return(resultMessage); }
private async Task <HttpResultMessage <object> > LocalExecuteAsync(ServiceEntry entry, HttpMessage httpMessage) { HttpResultMessage <object> resultMessage = new HttpResultMessage <object>(); try { var result = await entry.Func(httpMessage.ServiceKey, httpMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Data = result; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Data = taskType.GetProperty("Result").GetValue(task); } } resultMessage.IsSucceed = resultMessage.Data != null; resultMessage.StatusCode = resultMessage.IsSucceed ? StatusCode.OK : StatusCode.RequestError; //StatusCode.Success : (int)StatusCode.RequestError; } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(exception, "执行本地逻辑时候发生了错误。"); } //resultMessage.Message = "执行发生了错误。"; //resultMessage.StatusCode = exception.HResult; //if (exception is CPlatformException) //{ // resultMessage.StatusCode = ((CPlatformException)exception).ExceptionCode; //} //else //{ // resultMessage.StatusCode = StatusCode.UnKnownError; //} resultMessage.StatusCode = GetGetExceptionStatusCode(exception); resultMessage.Message = GetExceptionMessage(exception); resultMessage.IsSucceed = false; } return(resultMessage); }
private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var result = await entry.Func(remoteInvokeMessage.ServiceKey, remoteInvokeMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Result = result; } else { if (!task.IsCompletedSuccessfully) { await task; } var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } if (remoteInvokeMessage.DecodeJOject && !(resultMessage.Result is IConvertible && UtilityType.ConvertibleType.GetTypeInfo().IsAssignableFrom(resultMessage.Result.GetType()))) { if (resultMessage.Result != null) { resultMessage.Result = _serializer.Serialize(resultMessage.Result); //JsonConvert.SerializeObject(resultMessage.Result); } else { resultMessage.Result = resultMessage.Result; //JsonConvert.SerializeObject(resultMessage.Result); } } } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(exception, "执行本地逻辑时候发生了错误。"); } resultMessage.ExceptionMessage = exception.GetExceptionMessage(); resultMessage.StatusCode = exception.GetExceptionStatusCode(); } }
private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var cancelTokenSource = new CancellationTokenSource(); var result = await entry.Func(remoteInvokeMessage.ServiceKey, remoteInvokeMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Result = result; } else { await task; var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } if (remoteInvokeMessage.DecodeJOject && !(resultMessage.Result is IConvertible && UtilityType.ConvertibleType.GetTypeInfo().IsAssignableFrom(resultMessage.Result.GetType()))) { resultMessage.Result = _serializer.Serialize(resultMessage.Result, true); //JsonConvert.SerializeObject(resultMessage.Result); } } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(exception, "执行本地逻辑时候发生了错误。"); } resultMessage.ExceptionMessage = GetExceptionMessage(exception); if (exception is CPlatformException) { resultMessage.StatusCode = ((CPlatformException)exception).ExceptionCode; } else { resultMessage.StatusCode = StatusCode.UnKnownError; } } }
private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var result = await entry.Func(remoteInvokeMessage.ServiceKey, remoteInvokeMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Result = result; } else { if (!task.IsCompletedSuccessfully) { await task; } var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } if (remoteInvokeMessage.DecodeJOject) { resultMessage.Result = JsonConvert.SerializeObject(resultMessage.Result); } } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(exception, "执行本地逻辑时候发生了错误。"); } resultMessage.ExceptionMessage = GetExceptionMessage(exception); resultMessage.StatusCode = exception.HResult; } finally { RpcContext.RemoveContext(); } }
private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var cancelTokenSource = new CancellationTokenSource(); await OnAuthorization(entry, remoteInvokeMessage, resultMessage, cancelTokenSource); if (!cancelTokenSource.IsCancellationRequested) { var result = await entry.Func(remoteInvokeMessage.ServiceKey, remoteInvokeMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Result = result; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } if (remoteInvokeMessage.DecodeJOject && !(resultMessage.Result is IConvertible && UtilityType.ConvertibleType.GetTypeInfo().IsAssignableFrom(resultMessage.Result.GetType()))) { resultMessage.Result = JsonConvert.SerializeObject(resultMessage.Result); } } } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(exception, "执行本地逻辑时候发生了错误。"); } resultMessage.ExceptionMessage = GetExceptionMessage(exception); resultMessage.StatusCode = exception.HResult; } }
private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var result = await entry.Func(remoteInvokeMessage.Parameters); if (!(result is Task task)) { resultMessage.Result = result; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } }
private async Task <HttpResultMessage <object> > LocalExecuteAsync(ServiceEntry entry, HttpMessage httpMessage) { HttpResultMessage <object> resultMessage = new HttpResultMessage <object>(); try { var result = await entry.Func(httpMessage.ServiceKey, httpMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Entity = result; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Entity = taskType.GetProperty("Result").GetValue(task); } } resultMessage.IsSucceed = resultMessage.Entity != null; resultMessage.StatusCode = resultMessage.IsSucceed ? (int)StatusCode.Success : (int)StatusCode.RequestError; } catch (Exception ex) { Console.WriteLine("执行本地逻辑时候发生了错误。"); resultMessage.Message = ex.Message; resultMessage.StatusCode = ex.HResult; } return(resultMessage); }
private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var cancelTokenSource = new CancellationTokenSource(); await OnAuthorization(entry, remoteInvokeMessage, resultMessage, cancelTokenSource); if (!cancelTokenSource.IsCancellationRequested) { var result = await entry.Func(remoteInvokeMessage.ServiceKey, remoteInvokeMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Result = result; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) { resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } } } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError("执行本地逻辑时候发生了错误。", exception); } resultMessage.ExceptionMessage = GetExceptionMessage(exception); } }
private async Task LocalExecuteAsync(ServiceEntry entry, RemoteInvokeMessage remoteInvokeMessage, RemoteInvokeResultMessage resultMessage) { try { var result = await entry.Func(remoteInvokeMessage.Parameters); var task = result as Task; if (task == null) { resultMessage.Result = result; } else { task.Wait(); var taskType = task.GetType().GetTypeInfo(); if (taskType.IsGenericType) resultMessage.Result = taskType.GetProperty("Result").GetValue(task); } } catch (Exception exception) { if (_logger.IsEnabled(LogLevel.Error)) _logger.LogError("执行本地逻辑时候发生了错误。", exception); resultMessage.ExceptionMessage = GetExceptionMessage(exception); } }