コード例 #1
0
 public void PushSession(Session_Info _data)
 {
     if (Common.c_User_Info != null && _data.User_Name != Common.c_User_Info.User_Name)
     {
         Common_Event.c_NVSEvent.WhenReceiveCallBackData(Key_Raise_Event.Session, _data);
     }
 }
コード例 #2
0
        void c_NVSEvent_WhenReceiveCallBackDataEvent(object sender, NVSEventArgs e)
        {
            try
            {
                string _sender = (string)sender;
                if (_sender == Key_Raise_Event.Message)
                {
                    Message_Info _Message_Info = (Message_Info)e.Obj;
                    if (_Message_Info.From_User_Name == Common.c_User_Info.User_Name)
                    {
                        return;
                    }
                    _Message_Info.Type = (int)Enum_Message_Type.Receive;

                    Add_msg_ToDic(_Message_Info);

                    if (c_User_To != null && _Message_Info.To_User_Name != c_User_To.User_Name)
                    {
                        Common_Alert(_Message_Info);
                    }
                    else if (c_User_To == null)
                    {
                        Common_Alert(_Message_Info);
                    }

                    //if (_Message_Info.From_User_Name != c_User_To.User_Name && c_User_To.User_Name != "ManTT8ChemGio") return;

                    if (_Message_Info.To_User_Name != c_User_To.User_Name)
                    {
                        return;
                    }
                    UpdateListView(_Message_Info);
                }
                else if (_sender == Key_Raise_Event.Session)
                {
                    Session_Info _Session_Info = (Session_Info)e.Obj;
                    Change_User_OnlineStatus(_Session_Info);
                    return;
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                NaviCommon.Common.log.Error(ex.ToString());
            }
        }
コード例 #3
0
        void Change_User_OnlineStatus(Session_Info _Session_Info)
        {
            try
            {
                if (c_dic_User.ContainsKey(_Session_Info.User_Name))
                {
                    c_dic_User[_Session_Info.User_Name].Online_Status = _Session_Info.Online_Status;

                    if (_Session_Info.Online_Status == (int)Enum_Session_Status.LogIn)
                    {
                        c_dic_User[_Session_Info.User_Name].ShowOnline = Visibility.Visible;
                    }
                    else
                    {
                        c_dic_User[_Session_Info.User_Name].ShowOnline = Visibility.Collapsed;
                    }
                }
            }
            catch (Exception ex)
            {
                NaviCommon.Common.log.Error(ex.ToString());
            }
        }
コード例 #4
0
ファイル: Auto_Push_Data.cs プロジェクト: dangtq72/Chat_Lan
        public static void Broadcast_Session(Session_Info p_Session_Info)
        {
            try
            {
                List <string> _lst_inactiveClients = new List <string>();

                foreach (KeyValuePair <string, NvsService_Callback> item in DBMemory.c_dic_identifi_callback_client)
                {
                    // kiểm tra xem kết nối có ok hay không
                    if ((((IChannel)item.Value).State != CommunicationState.Opened))
                    {
                        _lst_inactiveClients.Add(item.Key);
                    }

                    string _data = item.Key + Common_Event.MESSAGETYPE_SPLIT + DateTime.Now.ToString("hh:MM:ss:fff") + Common_Event.MESSAGETYPE_SPLIT + DateTime.Now.ToString("hh:MM:ss:fff");
                    try
                    {
                        item.Value.PushSession(p_Session_Info);
                    }
                    catch (Exception exx)
                    {
                        //NaviCommon.Common.log.Error("Error when " + DateTime.Now.ToString("hh:MM:ss:fff"));
                        NaviCommon.Common.log.Error(exx.ToString());

                        // add những thằng nào bị lỗi vào list inactive để tý nữa xóa nó đi
                        _lst_inactiveClients.Add(item.Key);

                        // tắt ở task manager
                        // The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it has been Aborted.

                        // rút dây mạng
                        // The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server NaviCommon.Common.

                        //// hủy kết nối của nó đi
                        //if (exx.ToString().Contains("Aborted"))
                        //{
                        //    lock (DBMemory.c_object_lock)
                        //    {
                        //        DBMemory.c_dic_identifi_callback_client.Remove(item.Key);
                        //        NaviCommon.Common.log.Error("Client " + item.Key + " UnSubscribe because ServiceChannel has been Aborted");
                        //    }
                        //}
                    }
                }

                // xóa những thằng nào bị lỗi đi
                if (_lst_inactiveClients.Count > 0)
                {
                    foreach (string client in _lst_inactiveClients)
                    {
                        lock (DBMemory.c_object_lock)
                        {
                            DBMemory.c_dic_identifi_callback_client.Remove(client);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NaviCommon.Common.log.Error(ex.ToString());
            }
        }