/// <summary> /// /// </summary> /// <param name="req"></param> public static int MessageBot_u_BotCreatedDateObtained(EnqueueCommentBotReq req) { int modifiedRecords = 0; var json = Fwk.HelperFunctions.SerializationFunctions.SerializeObjectToJson <EnqueueCommentBotReq>(req); var connectionString = Common.GetCnn(Common.CnnStringNameepiron).ConnectionString; try { using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlCommand cmd = new SqlCommand("[Api].[MessageBot_u_BotCreatedDateObtained]", cnn) { CommandType = System.Data.CommandType.StoredProcedure }) { cnn.Open(); SqlParameter outParam = new SqlParameter("@modifiedRecords", SqlDbType.Int); outParam.Direction = ParameterDirection.Output; cmd.Parameters.Add(outParam); cmd.Parameters.AddWithValue("@CaseCommentGUID", req.CaseCommentGUID); cmd.Parameters.AddWithValue("@CaseId", req.CaseId); cmd.Parameters.AddWithValue("@BotJson", json); cmd.ExecuteNonQuery(); modifiedRecords = (System.Int32)outParam.Value; } } catch (Exception ex) { throw ex; } return(modifiedRecords); }
public async Task <IActionResult> enqueueBotComment(EnqueueCommentBotReq req) { try { await this.epironService.Bot_update_sendStatus(req); return(Ok(new ApiOkResponse("Ok enviado CaseId = " + req.CaseId + " url " + apiAppSettings.serverSettings.apiConfig.api_bootApiHoock))); } catch (Exception ex) { return(BadRequest(new ApiErrorResponse(HttpStatusCode.InternalServerError, ex.Message))); } }
/// <summary> /// 1 - actualiza la BD BotCreatedDateObtained /// 2 - Envia al moderardor /// 3 - update_delivery /// </summary> /// <param name="req"></param> /// <returns></returns> public async Task Bot_update_sendStatus(EnqueueCommentBotReq req) { string msgError = ""; try { int count = EpironDAC.MessageBot_u_BotCreatedDateObtained(req); if (count == 0) { msgError = " No se encontro CaseCommentGUID " + req.CaseCommentGUID; throw new Exception(msgError); } var res = await sendMessaged_async(req); if (res.StatusCode == HttpStatusCode.OK) { //TODO: desserializar y leer el resultado //Podria venir internamente un error var content = res.Content.ReadAsStringAsync().Result; EpironDAC.Bot_update_delivery(req.CaseCommentGUID, req.CaseId); } else { if (res.StatusCode == HttpStatusCode.Unauthorized) { msgError = "No tiene autorización para acceder a " + apiAppSettings.serverSettings.apiConfig.api_bootApiHoock; } else { msgError = res.ReasonPhrase; } //var msg = await res.RequestMessage.Content.ReadAsStringAsync(); //EpironDAC.MessageBot_u_BotCreatedDateObtained(req); //EpironDAC.Bot_update_sendStatus(req.CaseCommentGUID, "Error", msg); } } catch (Exception ex) { msgError = ex.Message; // EpironDAC.Bot_update_sendStatus(req.CaseCommentGUID, "Error", ex.Message); } if (!string.IsNullOrEmpty(msgError)) { throw new Exception(msgError); } }
public IActionResult moderateBotComment(EnqueueCommentBotReq comment) { try { // almacenar el msg para ser moderado en la app frontend de test comment.ArrivedDate = System.DateTime.Now; QueueEnjine.encolar_stored(comment); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
async Task <HttpResponseMessage> sendMessaged_async(EnqueueCommentBotReq message) { AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false); // var url = string.Format("{0}/api/bot/moderateBotComment", apiAppSettings.serverSettings.apiConfig.api_bootApiHoock); var url = apiAppSettings.serverSettings.apiConfig.api_bootApiHoock; if (string.IsNullOrEmpty(url)) { throw new Exception("Falta configurar api_bootApiHoock "); } Uri uri = new Uri(url); try { var httpHandler = apiAppSettings.getProxy_HttpClientHandler(); // using (var httpClient = new HttpClient(httpHandler)) using (var httpClient = new HttpClient()) { string jsonContnt = Fwk.HelperFunctions.SerializationFunctions.SerializeObjectToJson_Newtonsoft(message); HttpContent content = new StringContent(jsonContnt, Encoding.UTF8, "application/json"); HttpRequestMessage request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = uri, Content = content }; //httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //httpClient.DefaultRequestHeaders.TryAddWithoutValidation("AuthenticationToken", currenToken); HttpResponseMessage result = await httpClient.PostAsync(uri, content); // if (response.IsSuccessStatusCode) // { // var readTask = result.Content.ReadAsAsync<String>(); // readTask.Wait(); // res = readTask.Result; // } // else // { // res = result.StatusCode.ToString(); // Fwk.Exceptions.TechnicalException te = //new Fwk.Exceptions.TechnicalException("Error al intentar enviar un msg a " + apiAppSettings.apiConfig.api_epironHoockApi + " StatusCode : " + result.StatusCode.ToString()); // } return(result); } } catch (Exception ex) { Exception e = new Exception("Error al enviar el mensaje al moderador ", ex); return(apiAppSettings.getHttpResponseMessage(e)); } }