예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        protected override void StartCleanGarbageChannel()
        {
            MyTimeSpanValue = 90;
            FindGarbageChannel MyFindGarbageChannel = new FindGarbageChannel(MyTimeSpanValue);
            //LoginUser MyLoginUser = MyLoginUserList.Find(new Predicate<LoginUser>(MyFindGarbageChannel.SelectGarbageChannel));
            List <LoginUser> MyLoginGarbageList = MyLoginUserList.FindAll(new Predicate <LoginUser>(MyFindGarbageChannel.SelectGarbageChannel));

            foreach (LoginUser MyLoginUser in MyLoginGarbageList)
            {
                MyLoginUser.MyReadWriteSocketChannel.MyTCPClient.Client.Close();
                MyLoginUserList.Remove(MyLoginUser);
            }
        }
예제 #4
0
        public void AddLoginUserToList(SocketServiceReadWriteChannel MeSocketServiceReadWriteChannel)
        {
            //try
            //{
            //Monitor.Enter(MyLoginUserList);


            NewLoginUserObj         = new LoginUser(1, ref MeSocketServiceReadWriteChannel);
            NewLoginUserObj.LoginID = MyLoginUserList.Count + 1;
            MyLoginUserList.Add(NewLoginUserObj);

            DisplayResultInfor(4, "");
            DisplayResultInfor(0, MeSocketServiceReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString() + ":已连接!");


            //Monitor.Exit(MyLoginUserList);

            // }
        }
예제 #5
0
        /*
         * public override void CRUDLoginUserList(ref TcpClient MyTcpClientObj, int CRUDFlag)
         * {
         *  try
         *  {
         *      //Monitor.Enter(MyLoginUserList);
         *      switch (CRUDFlag)
         *      {
         *
         *              case 0://****New Add***
         *
         *              //NewLoginUserObj = new LoginUser(ref MyTcpClientObj);
         *              //NewLoginUserObj.LoginID = MyLoginUserList.Count + 1;
         *              //MyLoginUserList.Add(NewLoginUserObj);
         *
         *              //DisplayResultInfor(4, "");
         *              //DisplayResultInfor(0, MyTcpClientObj.Client.RemoteEndPoint.ToString() + ":已连接!");
         *
         *              break;
         *
         *             case 1: //Update通道活动时间
         *              for (int i = 0; i < MyLoginUserList.Count; i++)
         *              {
         *
         *                  if (MyLoginUserList[i].SocketInfor == MyTcpClientObj.Client.RemoteEndPoint.ToString())
         *                  {
         *
         *                      MyLoginUserList[i].SetKeepTime = DateTime.Now;
         *                      MyLoginUserList[i].WorkCountSum = MyLoginUserList[i].WorkCountSum + 1;
         *                      break;
         *                  }
         *
         *              }
         *
         *              DisplayResultInfor(4, "");
         *              DisplayResultInfor(0, MyTcpClientObj.Client.RemoteEndPoint.ToString() + ":正在收发数据!");
         *
         *              break;
         *
         *          case 2://主动Close Socket
         *
         *              //--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() + ":已主动断开连接!");
         *              DisplayResultInfor(1, string.Format("当前锁端连接数[{0}]", MyLoginUserList.Count-1));
         *              break;
         *
         *              case 3:
         *
         *              if (MyLoginUserList.Count > 0)
         *              {
         *                  for (int i = 0; i < MyLoginUserList.Count; i++)
         *                  {
         *
         *                      MyTimeSpan = DateTime.Now.Subtract(MyLoginUserList[i].KeepTime);
         *                      if (MyTimeSpan.Seconds > 5)
         *                      {
         *
         *                          MyLoginUserList[i].MyReadWriteSocketChannel.MyTCPClient.Close();
         *                          MyLeaveLoginIDList.Add(MyLoginUserList[i].LoginID);
         *                          MyLoginUserList.RemoveAt(i);
         *
         *                      }
         *
         *
         *                  }
         *                  //-----------------------------------------------------------------
         *                  for (int i = 0; i < MyLongFileReceiveProcList.Count; i++)
         *                  {
         *
         *                      if (MyLongFileReceiveProcList[i].SocketInfor == MyTcpClientObj.Client.RemoteEndPoint.ToString())
         *                      {
         *
         *                          MyLongFileReceiveProcList.RemoveAt(i);
         *
         *
         *                          break;
         *
         *                      }
         *
         *                  }
         *                  //-----------------------------------------------------------------
         *              }
         *
         *              DisplayResultInfor(4, "");
         *              //DisplayResultInfor(0, MyTcpClientObj.Client.RemoteEndPoint.ToString() + ":已自动断开连接!");
         *              DisplayResultInfor(1, string.Format("当前锁端连接数[{0}]", MyLoginUserList.Count - 1));
         *           ;
         *              break;
         *
         *              default:
         *              break;
         *
         *
         *      }
         *  }
         *  catch (Exception InforEx)
         *  {
         *      DisplayResultInfor(1, string.Format("断开连接错误[{0}]", InforEx.Message));
         *  }
         *  finally
         *  {
         *
         *      ;//Monitor.Exit(MyLoginUserList);
         *
         *  }
         *
         *
         * }
         */
        public void CRUDLoginUserListForCreate(SocketServiceReadWriteChannel MyReadWriteChannel)
        {
            try
            {
                Monitor.Enter(MyLoginUserList);
                //★New Add ★
                NewLoginUserObj = new LoginUser();
                //NewLoginUserObj.LoginID =CreateLoginID();//CurrentMaxLoginID;// MyLoginUserList.Count + 1;
                NewLoginUserObj.SocketInfor = MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString();
                NewLoginUserObj.MyReadWriteSocketChannel = MyReadWriteChannel;
                MyLoginUserList.Add(NewLoginUserObj);

                DisplayResultInfor(4, "");
                DisplayResultInfor(1, string.Format("当前锁端连接数[{0}]", MyLoginUserList.Count - 1));
            }
            catch (Exception InforEx)
            {
                DisplayResultInfor(1, string.Format("增加连接错误[{0}]", InforEx.Message));
            }
            finally
            {
                Monitor.Exit(MyLoginUserList);
            }
        }
예제 #6
0
        ///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);
            }
        }