/// <summary> /// Descripción: Método para guardar los mensajes de chat uno a uno. /// </summary> /// <param name="pdb">Instancia de la Base de Datos.</param> /// <param name="objMensaje">Instancia del ObjMensaje.</param> public void m_SaveMensages(Database pdb, clsMensagesCCModel objMensaje) { Int32 i = 0; try { //Se convierte la fecha de segundos a DateTime DateTime dtTime = new DateTime((Convert.ToInt32(objMensaje.sTimestamp) * SecInNasec) / OneTick); dtTime = dtTime.AddYears(AnioBase); DbCommand oCmd = pdb.GetStoredProcCommand("app_sva_Menssages_Ins"); pdb.AddInParameter(oCmd, "piMessage_id", DbType.Int32, objMensaje.iMessage_id); pdb.AddInParameter(oCmd, "psSender_uid", DbType.String, objMensaje.sSender_uid); pdb.AddInParameter(oCmd, "psReciever_uid", DbType.String, objMensaje.sReciever_uid); pdb.AddInParameter(oCmd, "psMessage", DbType.String, objMensaje.sMessage); pdb.AddInParameter(oCmd, "psTimestamp", DbType.DateTime, dtTime); pdb.AddInParameter(oCmd, "psRead", DbType.String, objMensaje.sRead); pdb.AddInParameter(oCmd, "psVisibility", DbType.String, objMensaje.sVisibility); pdb.AddInParameter(oCmd, "pbGrupo", DbType.Boolean, false); i = pdb.ExecuteNonQuery(oCmd); if ((i == 0)) { throw new Exception("No se Guardo el Registro. Intente de Nuevo"); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Descripción: Método para guardar los mensajes uno a uno. /// </summary> /// <param name="psURL">Dirección compuesta por directiva y resource de la api.</param> /// <param name="psApiKey">Key de la API.</param> /// <param name="plistParametros">Lista con los parametros necesarios para el API.</param> /// <param name="iUltimoMSG">Ultimo mensaje almacenado en la DB.</param> ///<param name = "psUID"> UID del usuario solicitado.</param> /// <param name="pdb">Instancia de la Base de Datos.</param> public void m_GetMessages(string psURL, string psApiKey, List <string> plistParametros, int iUltimoMSG, string psUID, Database pdb) { try { WebClient wcCometChat = new WebClient(); wcCometChat.Headers.Add("api-key", psApiKey); foreach (string sParametro in plistParametros) { string[] sParametroSplit = sParametro.Split(','); wcCometChat.QueryString.Add(sParametroSplit[0], sParametroSplit[1]); } var data = wcCometChat.UploadValues(psURL, "POST", wcCometChat.QueryString); // data here is optional, in case we recieve any string data back from the POST request. string sRespJson = UnicodeEncoding.UTF8.GetString(data); JObject objJSON = JObject.Parse(sRespJson); if (!sRespJson.Substring(0, 15).Contains("failed")) { foreach (JObject content in objJSON["success"]["data"][psUID]["one-on-one"].Children <JObject>()) { clsMensagesCCModel objMensaje = new clsMensagesCCModel(); objMensaje.iMessage_id = (int)content.GetValue("message_id"); objMensaje.sSender_uid = (string)content.GetValue("sender_uid"); objMensaje.sReciever_uid = (string)content.GetValue("reciever_uid"); objMensaje.sMessage = (string)content.GetValue("message"); objMensaje.sTimestamp = (string)content.GetValue("timestamp"); objMensaje.sRead = (string)content.GetValue("read"); objMensaje.sVisibility = (string)content.GetValue("visibility"); //Si el mensaje anterior guardado es menor al actual se guarda el actual if (objMensaje.iMessage_id > iUltimoMSG) { try { gbloclsCometChatRepository.m_SaveMensages(pdb, objMensaje); } catch (Exception) { //Bitacora } } } } } catch (WebException webex) { HttpWebResponse webResp = (HttpWebResponse)webex.Response; throw new Exception("Plataforma CC. Error " + webResp.StatusCode); } catch (Exception) { throw new Exception("Por el momento no esta disponible el servicio. Reintente más tarde. Error: Plataforma CC."); } }