private async Task <CallOpenApiWorkerMethodResponse> CallResult(RemoteJsOpenApiDocs remoteApi, CallOpenApiWorkerMethod requestModel) { var responseRecord = await HttpClient.PostAsync(remoteApi.Description.HostUrl, remoteApi.Description.Name, HttpPaths.HandleCall, requestModel); ExecutionContext.ExecutionLogs.Add(new JsExecutionLog { EventIdName = EventIds.CallRemoteApi.CallLogged, Message = "Логгирование удаленного запроса", DataJson = ZooSerializer.Serialize(responseRecord) }); try { //Task<RemoteApiResponseRecord> PostAsync<TRequest>(string hostUrl, string hostName, string path, TRequest request) return(responseRecord.GetResult <CallOpenApiWorkerMethodResponse>()); } catch (Exception ex) { ExecutionContext.ExecutionLogs.Add(new JsExecutionLog { EventIdName = EventIds.CallRemoteApi.ResponseDeserializationError, Message = "Ошибка при дессериализации", DataJson = ZooSerializer.Serialize(responseRecord) }); return(new CallOpenApiWorkerMethodResponse { IsSucceeded = false, ExcepionData = ExcepionData.Create(ex) }); } }
private async Task <HttpResponseRecord> CallInner(HttpResponseRecord result, Func <HttpClient, Task <HttpResponseMessage> > funcOnClient) { HttpResponseMessage httpResult; try { httpResult = await funcOnClient(HttpClient); } catch (Exception ex) { result.ExcepionData = ExcepionData.Create(ex); return(result); } result.ResponseStatusCode = (int)httpResult.StatusCode; result.Response = await httpResult.Content.ReadAsStringAsync(); return(result); }
/// <summary> /// Вызвать метод рабочего класса. /// <para></para> /// Данный метод не возвращает исключений. Его нужно испльзовать как внешюю точку доступа. /// </summary> /// <param name="requestModel"></param> /// <returns></returns> public CallOpenApiWorkerMethodResponse CallWorkerMethod(CallOpenApiWorkerMethod requestModel) { if (requestModel == null) { return(new CallOpenApiWorkerMethodResponse { IsSucceeded = false, ExcepionData = ExcepionData.Create(new Exception("request is null onjcet")) }); } var parameters = new JsWorkerMethodCallParametersFromSerialized(requestModel.SerializedParameters); try { var jsContext = GetContext(); using var scope = ServiceProvider.CreateScope(); var result = Components .GetJsWorker(requestModel.WorkerName, jsContext) .HandleCall(requestModel.MethodName, scope.ServiceProvider, parameters, jsContext, Logger); return(new CallOpenApiWorkerMethodResponse { IsSucceeded = true, ResponseJson = ZooSerializer.Serialize(result.Result) }); } catch (Exception ex) { Logger.LogError(ex, "CallWorkerMethod.Error"); return(new CallOpenApiWorkerMethodResponse { IsSucceeded = false, ExcepionData = ExcepionData.Create(ex) }); } }