public void RemoveNotLoginUser(ref TcpClient MyTcpClientObj) { try { //Monitor.Enter(MyLoginUserList); string TempSocketInfor = MyTcpClientObj.Client.RemoteEndPoint.ToString(); for (int i = 0; i < MyLoginUserList.Count; i++) { if (MyLoginUserList[i].SocketInfor == TempSocketInfor) { //TempString = MyLoginUserList[i].SocketInfor; MyLoginUserList[i].MyReadWriteSocketChannel.MyTCPClient.Close(); MyLeaveLoginIDList.Add(MyLoginUserList[i].LoginID);//回收分配的通道Id MyLoginUserList.RemoveAt(i); LockConnectCount--; break; } } //------------------------------------------------------------------------------------------------- DisplayResultInfor(4, ""); //DisplayResultInfor(1, TempSocketInfor + ":因没有注册已断开连接!"); DisplayResultInfor(1, string.Format("当前锁端连接数[{0}]", LockConnectCount)); } catch (Exception InforEx) { DisplayResultInfor(1, string.Format("断开连接错误[{0}]", InforEx.Message)); } finally { ;//Monitor.Exit(MyLoginUserList); } }
public new void CRUDLoginUserListForDelete(ref TcpClient MyTcpClientObj) { try { Monitor.Enter(MyLoginUserList); //--1.-------------------------------------------------------------------------------------------- string TempMobileIDString = null; string TempLockIDString = null; //LoginUser BindedLoginUser = null; string InSocketInfor = MyTcpClientObj.Client.RemoteEndPoint.ToString(); //---1.--------------------------------------------------------------------------------------------- for (int i = 0; i < MyLoginUserList.Count; i++) { if (MyLoginUserList[i].SocketInfor == InSocketInfor) { MyLoginUserList[i].MyReadWriteSocketChannel.MyTCPClient.Close(); MyLeaveLoginIDList.Add(MyLoginUserList[i].LoginID);//回收分配的通道Id TempMobileIDString = MyLoginUserList[i].MobileID; TempLockIDString = MyLoginUserList[i].LockID; MyLoginUserList.RemoveAt(i); break; } } //--2.------------------------------------------------------------------------------------- for (int i = 0; i < MyLongFileReceiveProcList.Count; i++) { if (MyLongFileReceiveProcList[i].SocketInfor == InSocketInfor) { MyLongFileReceiveProcList.RemoveAt(i); break; } } if (TempMobileIDString != null) { OffLineResponseToMobile(TempMobileIDString, TempLockIDString); } //------------------------------------------------------------------------------------------------- DisplayResultInfor(4, ""); //DisplayResultInfor(0, MyTcpClientObj.Client.RemoteEndPoint.ToString() + ":已主动断开连接!"); LockConnectCount--; DisplayResultInfor(1, string.Format("当前锁端连接数[{0}]", LockConnectCount)); } catch (Exception InforEx) { DisplayResultInfor(1, string.Format("断开连接错误[{0}]", InforEx.Message)); } finally { Monitor.Exit(MyLoginUserList); } }
///override// public void CRUDLoginUserList(ref SocketServiceReadWriteChannel MyReadWriteChannel, int CRUDFlag) { try { //Monitor.Enter(MyLoginUserList); switch (CRUDFlag) { case 0: // ★New Add ★ LockConnectCount++; NewLoginUserObj = new LoginUser(); if (LockConnectCount == 1) { NewLoginUserObj.LockID = "***************"; NewLoginUserObj.MobileID = "***************"; NewLoginUserObj.ChannelStatus = 0; } //NewLoginUserObj.LoginID =CreateLoginID();//CurrentMaxLoginID;// MyLoginUserList.Count + 1; NewLoginUserObj.SocketInfor = MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString(); //NewLoginUserObj.MyReadWriteSocketChannel = MyReadWriteChannel; MyLoginUserList.Add(NewLoginUserObj); DisplayResultInfor(4, ""); //DisplayResultInfor(0, MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString() + ":已连接!"); DisplayResultInfor(1, string.Format("当前锁端连接数[{0}]", LockConnectCount)); break; case 1: for (int i = 0; i < MyLoginUserList.Count; i++) { //if (MyLoginUserList[i].GetRemoteEndIP == MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString()) if (MyLoginUserList[i].SocketInfor == MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString()) { MyLoginUserList[i].SetKeepTime = DateTime.Now; MyLoginUserList[i].WorkCountSum = MyLoginUserList[i].WorkCountSum + 1; break; } } DisplayResultInfor(4, ""); DisplayResultInfor(0, MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString() + ":正在收发数据!"); // MyCoudLockSeverMainForm.InvokeLoginUserRefresh(); // MyCoudLockSeverMainForm.MyRefreshPrimeNotifyIconCallBack(MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString() + ":正在收发数据!"); //DataGridLoginUser.Invoke(this.MyRefreshDataGridCallBack); //MyRefreshPrimeNotifyIconCallBackCallback.Invoke(MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString() + ":提交业务!"); break; case 2: for (int i = 0; i < MyLoginUserList.Count; i++) { //if (MyLoginUserList[i].GetRemoteEndIP == MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString()) if (MyLoginUserList[i].SocketInfor == MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString()) { MyLoginUserList.RemoveAt(i); //break; } } DisplayResultInfor(4, ""); DisplayResultInfor(0, MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString() + ":已断开连接!"); //MyCoudLockSeverMainForm.InvokeLoginUserRefresh (); ///MyCoudLockSeverMainForm.MyRefreshPrimeNotifyIconCallBack(MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString() + ":已断开连接!"); //DataGridLoginUser.Invoke(this.MyRefreshDataGridCallBack); //MyRefreshPrimeNotifyIconCallBackCallback.Invoke(MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString() + "已断开连接!"); break; default: break; } } catch (Exception InforEx) { DisplayResultInfor(1, string.Format("增加Socket连接错误[{0}]", InforEx.Message)); } finally { ; //Monitor.Exit(MyLoginUserList); } }