Exemple #1
0
 public static void QueueWebChatMessage(WebChatMessage message)
 {
     lock (SyncRoot)
     {
         Messages.Add(message);
     }
 }
Exemple #2
0
        ///<summary>Inserts one WebChatMessage into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(WebChatMessage webChatMessage, bool useExistingPK)
        {
            string command = "INSERT INTO webchatmessage (";

            if (useExistingPK)
            {
                command += "WebChatMessageNum,";
            }
            command += "WebChatSessionNum,UserName,MessageText,MessageType) VALUES(";
            if (useExistingPK)
            {
                command += POut.Long(webChatMessage.WebChatMessageNum) + ",";
            }
            command +=
                POut.Long(webChatMessage.WebChatSessionNum) + ","
                + "'" + POut.String(webChatMessage.UserName) + "',"
                //DateT can only be set by MySQL
                + "'" + POut.String(webChatMessage.MessageText) + "',"
                + POut.Int((int)webChatMessage.MessageType) + ")";
            if (useExistingPK)
            {
                Db.NonQ(command);
            }
            else
            {
                webChatMessage.WebChatMessageNum = Db.NonQ(command, true, "WebChatMessageNum", "webChatMessage");
            }
            return(webChatMessage.WebChatMessageNum);
        }
        /// <summary>
        /// 处理用户消息
        /// </summary>
        /// <param name="webChatAuthConfig"></param>
        /// <param name="wxConfig"></param>
        /// <param name="xml"></param>
        /// <param name="errCode">错误码</param>
        public WebChatMessage ProcessRequest(WebChatAuthConfig webChatAuthConfig, WxConfig wxConfig, string xml,
                                             int?errCode = null)
        {
            WebChatMessage refundReponse = null;

            try
            {
                if (!string.IsNullOrEmpty(Auth(webChatAuthConfig, wxConfig)))
                {
                    throw new BusinessException("签名错误", HttpStatus.Err.Id);
                }

                refundReponse = _xmlProvider.Deserialize <WebChatMessage>(xml);
                if (refundReponse == null)
                {
                    throw new BusinessException("参数错误", HttpStatus.Err.Id);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("接受用户信息错误:", ex.ExtractAllStackTrace());
            }

            return(refundReponse);
        }
        /// <summary>
        /// 处理用户消息
        /// </summary>
        /// <param name="webChatAuthConfig"></param>
        /// <param name="wxConfig"></param>
        /// <param name="xml"></param>
        /// <param name="errCode">错误码</param>
        public WebChatMessage ProcessRequest(WebChatAuthConfig webChatAuthConfig, WxConfig wxConfig, string xml,
                                             int?errCode = null)
        {
            WebChatMessage refundReponse = null;

            try
            {
                if (!string.IsNullOrEmpty(Auth(webChatAuthConfig, wxConfig)))
                {
                    throw new BusinessException("签名错误");
                }

                refundReponse = _xmlProvider.Deserialize <WebChatMessage>(xml);
                if (refundReponse == null)
                {
                    throw new BusinessException("参数错误");
                }
            }
            catch (System.Exception e)
            {
                _logService.Error("接受用户信息错误:", e);
            }

            return(refundReponse);
        }
Exemple #5
0
        ///<summary>Updates one WebChatMessage in the database.</summary>
        public static void Update(WebChatMessage webChatMessage)
        {
            string command = "UPDATE webchatmessage SET "
                             + "WebChatSessionNum=  " + POut.Long(webChatMessage.WebChatSessionNum) + ", "
                             + "UserName         = '******', "
                             //DateT can only be set by MySQL
                             + "MessageText      = '" + POut.String(webChatMessage.MessageText) + "', "
                             + "MessageType      =  " + POut.Int((int)webChatMessage.MessageType) + " "
                             + "WHERE WebChatMessageNum = " + POut.Long(webChatMessage.WebChatMessageNum);

            Db.NonQ(command);
        }
Exemple #6
0
        ///<summary>Updates one WebChatMessage in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(WebChatMessage webChatMessage, WebChatMessage oldWebChatMessage)
        {
            string command = "";

            if (webChatMessage.WebChatSessionNum != oldWebChatMessage.WebChatSessionNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "WebChatSessionNum = " + POut.Long(webChatMessage.WebChatSessionNum) + "";
            }
            if (webChatMessage.UserName != oldWebChatMessage.UserName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UserName = '******'";
            }
            //DateT can only be set by MySQL
            if (webChatMessage.MessageText != oldWebChatMessage.MessageText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MessageText = '" + POut.String(webChatMessage.MessageText) + "'";
            }
            if (webChatMessage.MessageType != oldWebChatMessage.MessageType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MessageType = " + POut.Int((int)webChatMessage.MessageType) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE webchatmessage SET " + command
                      + " WHERE WebChatMessageNum = " + POut.Long(webChatMessage.WebChatMessageNum);
            Db.NonQ(command);
            return(true);
        }
Exemple #7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <WebChatMessage> TableToList(DataTable table)
        {
            List <WebChatMessage> retVal = new List <WebChatMessage>();
            WebChatMessage        webChatMessage;

            foreach (DataRow row in table.Rows)
            {
                webChatMessage = new WebChatMessage();
                webChatMessage.WebChatMessageNum = PIn.Long(row["WebChatMessageNum"].ToString());
                webChatMessage.WebChatSessionNum = PIn.Long(row["WebChatSessionNum"].ToString());
                webChatMessage.UserName          = PIn.String(row["UserName"].ToString());
                webChatMessage.DateT             = PIn.DateT(row["DateT"].ToString());
                webChatMessage.MessageText       = PIn.String(row["MessageText"].ToString());
                webChatMessage.MessageType       = (OpenDentBusiness.WebChatMessageType)PIn.Int(row["MessageType"].ToString());
                retVal.Add(webChatMessage);
            }
            return(retVal);
        }
Exemple #8
0
 ///<summary>Returns true if Update(WebChatMessage,WebChatMessage) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(WebChatMessage webChatMessage, WebChatMessage oldWebChatMessage)
 {
     if (webChatMessage.WebChatSessionNum != oldWebChatMessage.WebChatSessionNum)
     {
         return(true);
     }
     if (webChatMessage.UserName != oldWebChatMessage.UserName)
     {
         return(true);
     }
     //DateT can only be set by MySQL
     if (webChatMessage.MessageText != oldWebChatMessage.MessageText)
     {
         return(true);
     }
     if (webChatMessage.MessageType != oldWebChatMessage.MessageType)
     {
         return(true);
     }
     return(false);
 }
Exemple #9
0
        public static void RedisSubsrcMessage(CSRedis.CSRedisClient.SubscribeMessageEventArgs e)
        {
            //注意:redis服务重启以后,需要重新启动服务,不然redis通道无法重连
            try {
                var msg = WebChatMessage.Parse(e.Body);
                switch (msg.Type)
                {
                case WebChatMessageType.发送消息:
                    var data = msg.GetData <(string sender, string[] receives, string content, bool receipt)>();
                    Console.WriteLine($"收到消息:{data.content}" + (data.receipt ? "【需回执】" : ""));

                    var outgoing = new ArraySegment <byte>(Encoding.UTF8.GetBytes(data.content));
                    foreach (var uid in data.receives)
                    {
                        List <WebSocketHandler> sock = null;
                        if (_websockets.TryGetValue(uid, out sock) == false)
                        {
                            //Console.WriteLine($"websocket{uid} 离线了,{data.content}" + (data.receipt ? "【需回执】" : ""));
                            if (uid != data.sender && data.receipt)
                            {
                                WebChatHelper.SendMsg(Guid.Parse(uid), new Guid[] { Guid.Parse(data.sender) }, new {
                                    data.content,
                                    receipt = "用户不在线"
                                });
                            }
                            //未找到socket
                            continue;
                        }

                        WebSocketHandler[] sockarray;
                        try {
                            sockarray = sock.ToArray();
                        } catch {
                            lock (_websockets_lock)
                                sockarray = sock.ToArray();
                        }

                        //如果接收消息人是发送者,并且接口端只有1个以下,则不发送
                        //只有接口者为多端时,才转发消息通知其他端
                        if (uid == data.sender && sockarray.Length <= 1)
                        {
                            continue;
                        }

                        foreach (WebSocketHandler sh in sockarray)
                        {
                            sh.socket.SendAsync(outgoing, WebSocketMessageType.Text, true, CancellationToken.None);
                        }

                        if (uid != data.sender && data.receipt)
                        {
                            WebChatHelper.SendMsg(Guid.Parse(uid), new Guid[] { Guid.Parse(data.sender) }, new {
                                data.content,
                                receipt = "发送成功"
                            });
                        }
                    }
                    break;

                case WebChatMessageType.线:
                    lock (_websockets_lock)
                        _websockets.Remove(string.Concat(msg.Data));
                    break;

                case WebChatMessageType.线:
                    break;
                }
            } catch (Exception ex) {
                Console.WriteLine($"订阅方法出错了:{ex.Message}");
            }
        }
Exemple #10
0
 ///<summary>Inserts one WebChatMessage into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(WebChatMessage webChatMessage)
 {
     return(InsertNoCache(webChatMessage, false));
 }