Exemplo n.º 1
0
        /// <summary>
        /// Descripción: Método para guardar los mensajes de chat grupal uno a uno.
        /// </summary>
        /// <param name="pdb">Instancia de la Base de Datos.</param>
        /// <param name="objMensaje">Instancia del ObjMensaje.</param>
        public void m_SaveMsgGroup(Database pdb, clsMsgGroupCCModel objMensaje)
        {
            Int32 i = 0;

            try
            {
                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.sGuid);
                pdb.AddInParameter(oCmd, "psMessage", DbType.String, objMensaje.sMessage);
                pdb.AddInParameter(oCmd, "psTimestamp", DbType.String, objMensaje.sTimestamp);
                pdb.AddInParameter(oCmd, "psRead", DbType.String, "");
                pdb.AddInParameter(oCmd, "psVisibility", DbType.String, "");
                pdb.AddInParameter(oCmd, "pbGrupo", DbType.Boolean, objMensaje.bGrupo);

                i = pdb.ExecuteNonQuery(oCmd);

                if ((i == 0))
                {
                    throw new Exception("No se Guardo el Registro. Intente de Nuevo");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Descripción: Método para guardar los mensajes de los grupos.
        /// </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="psGrupo">UID del Grupo solicitado.</param>
        /// <param name="pdb">Instancia de la Base de Datos.</param>
        public void m_GetMessagesGroup(string psURL, string psApiKey, List <string> plistParametros, int iUltimoMSG, string psGrupo, 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"][psGrupo]["groupchats"].Children <JObject>())
                    {
                        clsMsgGroupCCModel objMsgGroup = new clsMsgGroupCCModel();

                        objMsgGroup.iMessage_id = (int)content.GetValue("message_id");
                        objMsgGroup.sGuid       = (string)content.GetValue("guid");
                        objMsgGroup.sSender_uid = (string)content.GetValue("sender_uid");
                        objMsgGroup.sMessage    = (string)content.GetValue("message");
                        objMsgGroup.sTimestamp  = (string)content.GetValue("timestamp");
                        objMsgGroup.bGrupo      = true;
                        //Si el mensaje anterior guardado es menor al actual se guarda el actual
                        if (objMsgGroup.iMessage_id > iUltimoMSG)
                        {
                            try
                            {
                                gbloclsCometChatRepository.m_SaveMsgGroup(pdb, objMsgGroup);
                            }
                            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.");
            }
        }