コード例 #1
0
ファイル: IMMainPage.xaml.cs プロジェクト: chenmj201601/UMP
        /// <summary>
        /// 创建cookie对象和一个聊天窗口
        /// </summary>
        private TabItem CreateChatWindow(ContacterInListBox con)
        {
            TabItem tab       = new TabItem();
            string  strHeader = string.Empty;

            if (con.UserName.Length > 10)
            {
                strHeader = con.UserName.Substring(0, 6) + "...";
            }
            else
            {
                strHeader = con.UserName;
            }
            tab.Header = strHeader;
            ChartWindow chatWin = new ChartWindow();

            chatWin.con               = lstContacters.Where(p => p.UserID == con.UserID).ToList().First();
            chatWin.CloseChatEvent   += chartWin_CloseChatEvent;
            chatWin.SendChatMsgEvent += chartWin_SendChatMsgEvent;
            tab.Content               = chatWin;
            tabChatWins.Items.Add(tab);
            tab.Tag        = con.UserID;
            tab.IsSelected = true;
            return(tab);
        }
コード例 #2
0
ファイル: IMMainPage.xaml.cs プロジェクト: chenmj201601/UMP
        /// <summary>
        /// 设置资源(会话从一个资源 切换到另一个资源 使得本次聊天的内容与该资源关联)
        /// </summary>
        /// <param name="strContacterName">联系人的名字</param>
        /// <param name="lContacterID">联系人的ID</param>
        /// <param name="lResourceID">要关联的资源ID</param>
        public OperationReturn SetResource(string strContacterName, long lContacterID, long lResourceID)
        {
            OperationReturn           optReturn        = new OperationReturn();
            List <ContacterInListBox> lstContacterByID = lstContacters.Where(p => p.UserID == lContacterID).ToList();

            if (lstContacterByID.Count <= 0)
            {
                optReturn.Result = false;
                optReturn.Code   = (int)S1600WcfError.NotInContacterList;
                return(optReturn);
            }
            ContacterInListBox con        = lstContacterByID.First();
            CookieEntity       currCookie = null;
            //判断是否有未读消息 有未读消息 说明窗口没有打开 将创建新的cookie信息和聊天窗口
            List <ChatMessage> lstUnReadMsgByID = lstUnReadMsg.Where(p => p.SenderID == lContacterID).ToList();

            if (lstUnReadMsgByID.Count > 0)
            {
                currCookie = new CookieEntity();
                //有未读消息 判断对方是否在线 如果在线 再判断最后一条消息所属的会话是否关闭
                //如果关闭 则之前的会话视为无效 新会话的资源ID为新传入的ID, 反之 则接收最后一条消息的cookieID和ResourceID作为本次会话的cookieID和ResourceID
                if (con.Status == "0")  //离线
                {
                    currCookie.ResourceID    = lResourceID;
                    currCookie.CookieCreated = 0;
                    currCookie.CookieID      = 0;
                }
                else
                {
                    //判断最后一条消息的会话是否关闭
                    long   lLastResID        = long.Parse(lstUnReadMsgByID.Last().ResourceID.ToString());
                    string strLastCookieID   = lstUnReadMsgByID.Last().CookieID.ToString();
                    bool   boCookieEffective = GetCookieStatusByID(strLastCookieID);
                    currCookie.ResourceID    = boCookieEffective ? lLastResID : lResourceID;
                    currCookie.CookieCreated = boCookieEffective ? 2 : 0;
                    currCookie.CookieID      = boCookieEffective ? long.Parse(strLastCookieID) : 0;
                }
                currCookie.UserID   = lContacterID;
                currCookie.UserName = strContacterName;

                //创建聊天窗口
                currCookie.ChatTab = CreateChatWindow(con);
                (currCookie.ChatTab.Content as ChartWindow).cookie = currCookie;
                dicCookies.Add(lContacterID, currCookie);
                //将消息写入聊天窗口 并让头像停止闪烁
                WriteUnReadMsgToWin(lContacterID, currCookie.ChatTab.Content as ChartWindow);
                dicImgThread[con.UserID].Stop();
                dicImgThread[con.UserID].Dispose();
                dicImgThread[con.UserID].Close();
                dicImgThread.Remove(con.UserID);
                con.IMGOpacity = "1";

                if (currCookie.CookieID == 0)
                {
                    //如果会话ID是0 证明前一次会话已经结束 可能会开启一次新的会话 所以需要给timer赋值
                    currCookie.CookieTimer = CreateTimer(currCookie, lContacterID);
                }

                optReturn.Result = true;
                return(optReturn);
            }
            //如果没有未读消息 判断窗口是否被打开了
            List <string> lstParamsForEndCookie = new List <string>();

            if (dicCookies.Keys.Contains(lContacterID))
            {
                //如果聊天窗口已经打开了 需要结束上一个会话 资源ID改为传入的ID 如果timer不为null 需要停掉timer重新开始计时
                currCookie = dicCookies[lContacterID];
                lstParamsForEndCookie.Clear();
                lstParamsForEndCookie.Add(currCookie.CookieID.ToString());
                lstParamsForEndCookie.Add(session.UserID.ToString());
                lstParamsForEndCookie.Add(lContacterID.ToString());
                if (currCookie.CookieID != 0)
                {
                    iClient.EndCookieByID(lstParamsForEndCookie);
                }
                dicCookies[lContacterID].CookieID      = 0;
                dicCookies[lContacterID].CookieCreated = 0;
                dicCookies[lContacterID].ResourceID    = 0;
                dicCookies[lContacterID].CookieTimer   = null;
                //dicCookies.Remove(lContacterID);
            }
            else
            {
                currCookie          = new CookieEntity();
                currCookie.ChatTab  = CreateChatWindow(con);
                currCookie.UserID   = lContacterID;
                currCookie.UserName = strContacterName;
            }
            currCookie.CookieID      = 0;
            currCookie.CookieCreated = 0;
            if (currCookie.CookieTimer != null)
            {
                currCookie.CookieTimer.Stop();
            }
            else
            {
                currCookie.CookieTimer = CreateTimer(currCookie, lContacterID);
            }

            currCookie.ResourceID         = lResourceID;
            currCookie.ChatTab.IsSelected = true;
            (currCookie.ChatTab.Content as ChartWindow).cookie = currCookie;
            if (dicCookies.Keys.Contains(lContacterID))
            {
                dicCookies.Remove(lContacterID);
            }
            dicCookies.Add(lContacterID, currCookie);
            return(optReturn);
        }
コード例 #3
0
ファイル: IMMainPage.xaml.cs プロジェクト: chenmj201601/UMP
        /// <summary>
        /// 接收到联系人发来的消息
        /// </summary>
        /// <param name="mstObj"></param>
        void IService16001Callback.ReceiveChatMsg(ChatMessage msgObj)
        {
            List <ContacterInListBox> cons = lstContacters.Where(p => p.UserID == msgObj.SenderID).ToList();

            if (cons.Count <= 0)
            {
                // MessageBox.Show(strSender + " not my contacter");
                return;
            }
            //如果窗口已经打开 则直接显示消息 并修改header的颜色
            if (dicCookies.Keys.Contains(msgObj.SenderID))
            {
                TabItem item = dicCookies[msgObj.SenderID].ChatTab;
                if (item.IsSelected == false)
                {
                    item.Foreground = Brushes.Orange;
                }
                ChartWindow chartWin = item.Content as ChartWindow;
                chartWin.txtRecord.Text += msgObj.MsgContent;
                if (dicCookies[msgObj.SenderID].CookieTimer != null)
                {
                    //把会话的timer时间重置
                    dicCookies[msgObj.SenderID].CookieTimer.Stop();
                    dicCookies[msgObj.SenderID].CookieTimer.Start();
                }
            }
            else
            {
                //如果没有打开窗口 则先把消息保存进dicUnReadMsg 在打开窗口时检查是否有该联系人的消息 如果有 就显示进聊天窗口
                //UnReadMsg unRead = new UnReadMsg(strSender, strMsg);
                //lstUnReadMsg.Add(unRead);
                lstUnReadMsg.Add(msgObj);
                StatusChangeEvent((int)UserStatusChangeType.NewMsg, lstUnReadMsg.Count.ToString());
                #region 闪烁
                //开启线程 修改头像的透明度  无论是否打开了窗口 头像都要闪动 直到tab获得焦点为止  但如果窗口本身就是获得焦点的 就不用闪烁
                ContacterInListBox conSender = null;
                ContacterInListBox con       = null;
                for (int i = 0; i < lbContacter.Items.Count; i++)
                {
                    con = lbContacter.Items[i] as ContacterInListBox;
                    if (con.UserID == msgObj.SenderID)
                    {
                        conSender = con;
                        break;
                    }
                }
                if (conSender == null)
                {
                    return;
                }
                if (!dicImgThread.Keys.Contains(msgObj.SenderID))
                {
                    Timer imgTimer = new Timer();
                    imgTimer.Interval  = 200;
                    imgTimer.AutoReset = true;
                    imgTimer.Elapsed  += (s, e) =>
                    {
                        if (con.IMGOpacity == "1")
                        {
                            Dispatcher.Invoke(new Action(() => con.IMGOpacity = "0.1"));
                        }
                        else
                        {
                            Dispatcher.Invoke(new Action(() => con.IMGOpacity = "1"));
                        }
                    };
                    dicImgThread.Add(msgObj.SenderID, imgTimer);
                    imgTimer.Start();
                }
                #endregion
            }
        }
コード例 #4
0
ファイル: IMMainPage.xaml.cs プロジェクト: chenmj201601/UMP
        /// <summary>
        /// 双击新建一个好友聊天窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListBoxItem_MouseDoubleClick(object sender, RoutedEventArgs e)
        {
            ContacterInListBox con = lbContacter.SelectedValue as ContacterInListBox;

            SetResource(con.UserName, con.UserID, 0);
        }
コード例 #5
0
ファイル: IMMainPage.xaml.cs プロジェクト: chenmj201601/UMP
        /// <summary>
        /// 初始化好友列表
        /// </summary>
        /// <param name="lstFriends"></param>
        void IService16001Callback.InitFriendList(List <string> lstFriends)
        {
            lstContacters.Clear();
            if (lstFriends.Count <= 0)
            {
                //MessageBox.Show("您没有可以管理的用户和坐席");
                return;
            }
            lbContacter.ItemsSource = lstContacters;
            OperationReturn    optReturn = null;
            Contacter          con       = null;
            ContacterInListBox conInList = null;

            for (int i = 0; i < lstFriends.Count; i++)
            {
                optReturn = XMLHelper.DeserializeObject <Contacter>(lstFriends[i]);
                if (optReturn.Result)
                {
                    con       = optReturn.Data as Contacter;
                    conInList = new ContacterInListBox();
                    List <ContacterInListBox> lstExists = lstContacters.Where(p => p.UserID == con.UserID).ToList();
                    if (lstExists.Count > 0)
                    {
                        continue;
                    }
                    conInList.UserID      = con.UserID;
                    conInList.UserName    = S16001EncryptOperation.DecryptWithM004(con.UserName);
                    conInList.FullName    = S16001EncryptOperation.DecryptWithM004(con.UserName) + " (" + S16001EncryptOperation.DecryptWithM004(con.FullName) + ")";
                    conInList.OrgID       = con.OrgID;
                    conInList.OrgName     = S16001EncryptOperation.DecryptWithM004(con.OrgName);
                    conInList.ParentOrgID = con.ParentOrgID;
                    conInList.Status      = con.Status;
                    conInList.IMGOpacity  = "1";
                    string strType = conInList.UserID.ToString().Substring(0, 3);
                    if (strType == ConstValue.RESOURCE_AGENT.ToString())
                    {
                        if (conInList.Status == "1")
                        {
                            conInList.Icon = "Themes/Default/UMP1600/Images/AgentOnline.png";
                        }
                        else
                        {
                            conInList.Icon = "Themes/Default/UMP1600/Images/AgentOffline.png";
                        }
                    }
                    else
                    {
                        if (conInList.Status == "1")
                        {
                            conInList.Icon = "Themes/Default/UMP1600/Images/UserOnline.png";
                        }
                        else
                        {
                            conInList.Icon = "Themes/Default/UMP1600/Images/UserOffline.png";
                        }
                    }
                    if (conInList.Status == "1")
                    {
                        conInList.ForegGround = Brushes.Red;
                    }
                    else
                    {
                        conInList.ForegGround = Brushes.Gray;
                    }

                    lstContacters.Add(conInList);
                }
            }
            ListSorter.SortList <ObservableCollection <ContacterInListBox>, ContacterInListBox>(ref lstContacters, "Status", SortDirection.Descending);
        }