Ejemplo n.º 1
0
        /// <summary>
        /// 更新群Card,无数据则添加
        /// </summary>
        /// <param name="RoomID"></param>
        /// <param name="e"></param>
        public static void UpdateRoomVcard(string RoomID, IMLibrary3.Protocol.Element e)
        {
            //string sql = "delete from RoomsVcard  ";

            string sql = "update RoomsVcard set Vcard=@Vcard where RoomID=@RoomID";

            System.Data.SQLite.SQLiteParameter[] parameters = new System.Data.SQLite.SQLiteParameter[] {
                new System.Data.SQLite.SQLiteParameter("@RoomID", RoomID),
                new System.Data.SQLite.SQLiteParameter("@Vcard", IMLibrary3.Protocol.Factory.CreateXMLMsg(e))
            };
            if (SQLiteDBHelper.ExecuteNonQuery(sql, parameters) == 0)
            {
                sql = "insert into RoomsVcard(RoomID,Vcard) values(@RoomID,@Vcard)";
                SQLiteDBHelper.ExecuteNonQuery(sql, parameters);
            }
        }
Ejemplo n.º 2
0
        void msgServer_RequestUsersPresence(object sender, MsgServerEventArgs e)
        {
            int i = 0;
            Element element =new Element();

            ///将在线用户的ShowType发送给登录用户
            foreach (TCPServerSession se in msgServer.GetTcpServerSession())
            {
                if (se.IsAuthenticated)//如果是已认证的TCP客户端
                {
                    UserVcard userTemp = se.Tag as UserVcard;//获得TCP客户端绑定的用户
                    Presence pretemp = new Presence();
                    pretemp.from = userTemp.UserID;
                    pretemp.ShowType = userTemp.ShowType;
                    pretemp.Status = pretemp.Status;

                    element.Data.Add(pretemp);
                }
                i++;

                if (i == 80)//一次发送80个用户
                {
                    SendMessageToUser(e.RequestUser, element);
                    i = 0;
                    element = new Element();
                }
            }
            if (i>0)//最一次发送在线用户状态
                SendMessageToUser(e.RequestUser, element);
                 

            ///广播登录用户上线消息 
            Presence pre = new Presence();
            pre.from = e.RequestUser.UserID;
            pre.ShowType = e.RequestUser.ShowType;
            BroadcastingMessageToOnlineUser(pre);


            //发送离线消息
            List<string> offlineMsg = DBHelper.GetOfflineMessage(e.RequestUser.UserID, 50);//获取最后50条离线消息
            foreach (string msgXML in offlineMsg)
                SendMessageToUser(e.RequestUser, msgXML);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 发送消息给一个用户
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="e">Element</param>
        public void SendMessageToUser(User user, Element e)
        {
            if (user.ShowType == IMLibrary3.Enmu.ShowType.Offline && e is Message)
                DBHelper.addMessageToDB(e as Message);

            if (user != null && user.Tag is TCP_ServerSession)
            {
                msgServer.SendMessage(user.Tag as TCPServerSession, e);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 发送消息给一个用户
 /// </summary>
 /// <param name="userID">用户编号</param>
 /// <param name="e">Element</param>
 private void SendMessageToUser(string userID, Element e)
 {
     UserVcard user = getUser(userID);
     SendMessageToUser(user, e);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 向在线用户广播消息
 /// </summary>
 /// <param name="e">Element</param>
 public void BroadcastingMessageToOnlineUser(Element e)
 {
     msgServer.BroadcastingMessage(e);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 发送消息至服务器 
 /// </summary>
 /// <param name="e"></param>
 public void SendMessageToServer(Element  e)
 {
     e.from = MyAuth.UserID;//此处告之服务器,消息由自己发送
     if (tcpClient!=null && !tcpClient.IsDisposed && tcpClient.IsConnected)
         tcpClient.Write(e);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// TCP发送消息到文件代理服务器
 /// </summary>
 /// <param name="e"></param>
 protected void TCPSendMsg(Element e)
 {
     if (ServerEP != null && tcpClient.IsConnected)
     {
         if (e is ImageFileMsg)
         {
             ImageFileMsg finfo = e as ImageFileMsg;
             finfo.MD5 = TFileInfo.MD5;
             finfo.Extension = TFileInfo.Extension;
         }
         tcpClient.TcpStream.WriteLine(Factory.CreateXMLMsg(e));
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 发送消息到文件客户端
 /// </summary>
 /// <param name="e"></param>
 private void sendFileMsg(Element e, TCPServerSession se)
 {
     if (se != null && se.IsConnected)
         tcpFileServer.SendMessageToSession(se, Factory.CreateXMLMsg(e));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 处理用户请求获得所有在线联系人的在线状态
        /// </summary>
        /// <param name="pre"></param>
        /// <param name="session"></param>
        private void onGetUsersPresence(Presence pre, TCPServerSession session)
        {
            ///将在线用户的Presence发送给登录用户
            Element e = new Element();
            foreach (TCPServerSession se in tcpMessageServer.Sessions.ToArray())
                if (se.IsAuthenticated)//如果是已认证的TCP客户端
                {
                    UserVcard userTemp = se.Tag as UserVcard;//获得TCP客户端绑定的用户
                    Presence pretemp = new Presence();
                    pretemp.from = userTemp.UserID;
                    pretemp.ShowType = userTemp.ShowType;
                    pretemp.Status = pretemp.Status;

                    e.Data.Add(pretemp);
                }
            tcpMessageServer.SendMessageToSession(session, e);

            ///广播登录用户上线消息
            UserVcard user = session.Tag as UserVcard;
            pre = new Presence();
            pre.from = user.UserID;
            pre.ShowType = user.ShowType;
            BroadcastingMessageToOnlineUser(pre);

            //发送离线消息
            List<string> offlineMsg = DBHelper.GetOfflineMessage(user.UserID, 50);//获取最后50条离线消息
            foreach (string msgXML in offlineMsg)
                SendMessageToUser(user, msgXML);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 发送消息给一个用户
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="e">Element</param>
        public void SendMessageToUser(User user, Element e)
        {
            if (user.ShowType == IMLibrary3.Enmu.ShowType.Offline && e is Message)
                DBHelper.addMessageToDB(e as Message);

            if (user != null && user.Tag is TCP_ServerSession)
            {
                //tcpMessageServer.SendMessageToSession(user.Tag as TCPServerSession, Factory.CreateXMLMsg(e));
                msgServer.SendMessage(user.Tag as TCPServerSession, e);
            }
        }