protected override void SendMessageForString(Byte[] InSendMessageBuffers, SocketServiceReadWriteChannel InputReadWriteChannel)
        {
            //--向从移动端发的回显消息
            //string MyTimeMarkerStr = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string MyTimeMarkerStr = string.Format("{0:HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);

            string SendMessageString = null;

            //把来自移动端的消息字符串显示-----------------------------------------------------------------------------------------------------------------------

            /*
             * if (InSendMessageBuffers[2] == 254)
             * {
             *
             *     SendMessageString = Encoding.Unicode.GetString(InSendMessageBuffers, 3, InSendMessageBuffers.Length - 3);
             *
             * }
             * else
             * {
             *     SendMessageString = Encoding.ASCII.GetString(InSendMessageBuffers, 3, InSendMessageBuffers.Length - 3);
             * }
             */

            SendMessageString = Encoding.UTF8.GetString(InSendMessageBuffers, 3, InSendMessageBuffers.Length - 3);
            this.DisplayResultInfor(3, string.Format(MyTimeMarkerStr + "[{0}]{1}", InputReadWriteChannel.MyTCPClient.Client.RemoteEndPoint, SendMessageString));
        }
        protected void ManagerLoginAuthtication(string ManagerCertID, SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel)
        {
            int    ReturnCode             = -1;
            string ReplyCommandMessageStr = "managerlogin";
            //----1--------------------------------------------------------------
            string      UserName = ManagerCertID.Substring(0, ManagerCertID.IndexOf("-"));
            string      UserPass = ManagerCertID.Substring(ManagerCertID.IndexOf("-") + 1);
            Manager     MyManager;
            ManagerCRUD MyManagerCRUD = new ManagerCRUD();

            MyManager = MyManagerCRUD.FindManager(UserName);

            if (MyManager == null)
            {
                ReturnCode             = -1;
                ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[10]!";
            }
            else
            {
                if (MyManager.LoginName == UserName && MyManager.PassWord == UserPass)
                {
                    ReturnCode             = MyManager.ManagerID;
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]{1}!", ReturnCode, MyManager.RightType);//尾随ID码与权力码
                }
                else
                {
                    ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[11]!";
                }
            }
            //----2.---------------------------------------------------------

            ResponseToSynchClient(InputSocketServiceReadWriteChannel, ReplyCommandMessageStr);
        }
        protected void FromDBGetImage(string InLockSnapID, SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel)
        {
            string LockID = InLockSnapID.Substring(0, 15);
            string SnapID = InLockSnapID.Substring(16);
            string ReplyCommandMessageStr = "getimage#" + LockID + "";
            //----------------------------------------------------------------------------------------------------
            SnapManager MySnapManager = new SnapManager();

            byte[] MyImageBytes = MySnapManager.DownImageFromDB(long.Parse(SnapID), LockID);


            if (MyImageBytes == null)
            {
                ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[10]!";
                ResponseToSynchClient(InputSocketServiceReadWriteChannel, ReplyCommandMessageStr);
            }
            else
            {
                int ImageLenght = MyImageBytes.Length;
                ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]!", ImageLenght);//N个字节头

                ResponseToSynchClientEx(InputSocketServiceReadWriteChannel, ReplyCommandMessageStr, MyImageBytes);
                this.DisplayResultInfor(1, string.Format("发送图像应答消息[{0}]", ImageLenght));
            }
            //----------------------------------------------------------------------------------------------------
        }
        protected virtual void SendMessageForString(Byte[] InSendMessageBuffers, SocketServiceReadWriteChannel InputReadWriteChannel)
        {
            //string MyTimeMarker = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string MyTimeMarker      = string.Format("{0:HH:mm:ss}", DateTime.Now);
            string SendMessageString = null;

            if (InSendMessageBuffers[2] < 250)
            {
                //1.全部转换为16进制字符串表示---------------------------------------------------------------------------------------------------------

                for (int i = 0; i < InSendMessageBuffers.Length; i++)
                {
                    SendMessageString = SendMessageString + string.Format("{0:X2}", InSendMessageBuffers[i]);
                }

                //SendMessageForSaveDB(InSendMessageBuffers);//测试需要!
            }
            else
            {
                //2.把来自移动端的消息字符串显示-----------------------------------------------------------------------------------------------------------------------

                if (InSendMessageBuffers[2] == 254)
                {
                    SendMessageString = Encoding.Unicode.GetString(InSendMessageBuffers, 3, InSendMessageBuffers.Length - 3);
                }
                else
                {
                    SendMessageString = Encoding.UTF8.GetString(InSendMessageBuffers, 3, InSendMessageBuffers.Length - 3);
                }
            }

            this.DisplayResultInfor(3, string.Format(MyTimeMarker + " Tx[{0}]{1}", InputReadWriteChannel.MyTCPClient.Client.RemoteEndPoint, SendMessageString));
        }
        protected void ResponseToSynchClientEx(SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel, string ResultStr, byte[] ImageBuffer)
        {
            //专程发送图像
            string ReplyCommandMessageStr = ResultStr;

            byte[] MySendBaseMessageBytes = Encoding.UTF8.GetBytes(ReplyCommandMessageStr);

            int nBuffersLenght       = MySendBaseMessageBytes.Length;
            int FixSendMessageLenght = nBuffersLenght + ImageBuffer.Length + 3;

            byte[] MySendMessageBytes = new byte[FixSendMessageLenght];

            MySendMessageBytes[2] = (byte)nBuffersLenght;// 第三个字节为消息头长度(成功:37);
            //填充消息头--之内
            for (int i = 0; i < nBuffersLenght; i++)
            {
                MySendMessageBytes[3 + i] = MySendBaseMessageBytes[i];
            }

            int ImageIndex = nBuffersLenght + 3;

            ImageBuffer.CopyTo(MySendMessageBytes, ImageIndex);

            StartAsynchSendMessage(InputSocketServiceReadWriteChannel, MySendMessageBytes);
        }
        //==============Write Start===================================================================================================================================

        public void StartAsynchSendMessage(SocketServiceReadWriteChannel MyReadWriteChannel, byte[] SendMessageBuffers)
        {
            //------12.26改进:
            try
            {
                MyReadWriteChannel.MyWriteBuffers = SendMessageBuffers;// Encoding.UTF8.GetBytes(Sendstr);
                MyReadWriteChannel.MyNetWorkStream.BeginWrite(MyReadWriteChannel.MyWriteBuffers, 0, MyReadWriteChannel.MyWriteBuffers.Length, new AsyncCallback(AsynchWriteMessageCallback), MyReadWriteChannel);
                MyReadWriteChannel.MyNetWorkStream.Flush();

                /*
                 * string MyTimeMarkerStr = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + DateTime.Now.Millisecond.ToString();//DateTime.Now.ToString()
                 * //1.全部转换为16进制字符串表示---------------------------------------------------------------------------------------------------------
                 * string HexSendMessageString = null;
                 * for (int i = 0; i < SendMessageBuffers.Length; i++)
                 * {
                 *
                 *  HexSendMessageString = HexSendMessageString + string.Format("{0:X2}", SendMessageBuffers[i]);
                 *
                 * }
                 * this.DisplayResultInfor(3, string.Format(MyTimeMarkerStr + "--[{0}]{1}", MyReadWriteObject.MyTCPClient.Client.RemoteEndPoint, HexSendMessageString));
                 */
            }
            catch (Exception ExceptionInfor)
            {
                //string MyTimeMarker = DateTime.Now.ToString() + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
                //string MyTimeMarker = DateTime.Now.ToString() + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
                string MyTimeMarker = string.Format("{0:HH:mm:ss}", DateTime.Now);
                DisplayResultInfor(1, string.Format(MyTimeMarker + "向[{0}]发送数据失败(1)\r\n", MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint));
                //System.Diagnostics.Debug.WriteLine(ExceptionInfor.Message);
            }
        }
        //===========同步方法==============================================================================
        protected void FromDBAuthtication(string UserCertID, SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel)
        {
            int    ReturnCode             = -1;
            string ReplyCommandMessageStr = "authtication";
            //----1--------------------------------------------------------------
            string          UserName          = UserCertID.Substring(0, UserCertID.IndexOf("-"));
            string          UserPass          = UserCertID.Substring(UserCertID.IndexOf("-") + 1);
            CustomerManager MyCustomerManager = new CustomerManager();
            Customer        MyCustomer        = MyCustomerManager.FindCustomer(UserName);

            if (MyCustomer == null)
            {
                ReturnCode             = -1;
                ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[10]!";
            }
            else
            {
                if (MyCustomer.LoginName == UserName && MyCustomer.Password == UserPass)
                {
                    ReturnCode             = MyCustomer.CustomerID;
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]!", ReturnCode);
                }
                else
                {
                    ReturnCode             = 0;
                    ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[11]!";
                }
            }
            //----2.---------------------------------------------------------

            ResponseToSynchClient(InputSocketServiceReadWriteChannel, ReplyCommandMessageStr);
        }
        protected void LockStatusManagerment(string LockStatusStr, SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel)
        {
            string ReplyCommandMessageStr = "lockstatus";
            //----1------------------------------------------------------------------------------------------------

            string ManagerIDStr = LockStatusStr.Substring(0, LockStatusStr.IndexOf(":"));
            int    IndexStart   = LockStatusStr.IndexOf(":") + 1;
            string LockID       = LockStatusStr.Substring(IndexStart, LockStatusStr.IndexOf("-") - IndexStart);
            string StatusIDStr  = LockStatusStr.Substring(LockStatusStr.IndexOf("-") + 1);
            int    StatusID     = 0;

            if (StatusIDStr == "create")
            {
                StatusID = 1;
                Lock        MyLock        = new Lock(LockID, StatusID);
                LockManager MyLockManager = new LockManager();

                if (MyLockManager.InsertLockEx(MyLock, int.Parse(ManagerIDStr)) != 0)
                {
                    //登记云锁失败
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[{0}]!", StatusIDStr);
                }
                else
                {
                    //登记云锁成功
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]!", StatusIDStr);
                }
            }
            if (StatusIDStr == "sale")
            {
                StatusID = 2;
                LockManager MyLockManager     = new LockManager();// (CloudLockConnectString.ConnectionString);
                string      MyRegisterCodeStr = MyLockManager.UpdateLockForSale(LockID, int.Parse(ManagerIDStr));

                if (MyRegisterCodeStr == null)
                {
                    //出售云锁操作失败;
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[{0}]!", StatusIDStr);
                }
                else
                {
                    //出售云锁注册码操作成功!;
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]!", MyRegisterCodeStr); //尾随注册码
                }
            }
            if (StatusIDStr == "line")
            {
                StatusID = 3;
            }
            if (StatusIDStr == "none")
            {
                StatusID = 0;
            }



            //----2.Reply-----------------------------------------------------------------------------
            ResponseToSynchClient(InputSocketServiceReadWriteChannel, ReplyCommandMessageStr);
        }
示例#9
0
 public LoginUser(int InLoginID, ref SocketServiceReadWriteChannel MeSocketServiceReadWriteChannel)
 {
     this.LoginID = InLoginID;
     this.MyReadWriteSocketChannel = MeSocketServiceReadWriteChannel;
     this.SetLoginTime             = DateTime.Now;
     this.SetKeepTime   = DateTime.Now;
     this.SocketInfor   = MeSocketServiceReadWriteChannel.MyRemoteEndPointStr; //.Client.RemoteEndPoint.ToString();
     this.WorkStatus    = 0;                                                   //默认为:0
     this.ChannelStatus = 1;                                                   //默认为:1
     //this.ViewManner = 0;
     //MyLongFileReceiveProc = new LockServerLib.LongFileReceiveProc();
 }
        public void MessageRountToEndpoit(byte[] RecieveMessageBytes, int RecieveCount)
        {
            string BaseMessageString;


            BaseMessageString = Encoding.UTF8.GetString(RecieveMessageBytes, 3, RecieveCount - 3);
            string MySrcMobileID    = BaseMessageString.Substring(BaseMessageString.IndexOf("#") + 1, 15);
            string MyDesMobileID    = BaseMessageString.Substring(BaseMessageString.IndexOf("-") + 1, 15);
            string MyCommandMessage = BaseMessageString.Substring(0, BaseMessageString.IndexOf("#"));

            //string MyTimeMarkerStr = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string MyTimeMarkerStr = string.Format("{0:HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);

            //--找移动端通道--------------------------------------------------------------------------------


            FindMobileChannel MyFindMobileChannel = new FindMobileChannel(MyDesMobileID, 10);
            LoginUser         MyLoginUser         = this.MyManagerLoginMobileUser.MyLoginUserList.Find(new Predicate <LoginUser>(MyFindMobileChannel.BindedMobileChannel));

            if (MyLoginUser == null)
            {
                //不存在或者不在线
                this.DisplayResultInfor(1, string.Format("[{0}]对方通道不在线", MyDesMobileID));
                //this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "|<-{0}",  BaseMessageString));
                //this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + "[<-{0}]{1}", ClientSocketEndPointStr, BaseMessageString));
                return;
            }
            else
            {
                //string ClientSocketEndPointStr = MyLoginUser.MyReadWriteSocketChannel.MyTCPClient.Client.LocalEndPoint.ToString();
                //this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "[<-{0}]{1}", ClientSocketEndPointStr, BaseMessageString));
            }
            //--再转发出去-----------------------------------------------------------------------------------
            SocketServiceReadWriteChannel MyMobileSocketChannel = MyLoginUser.MyReadWriteSocketChannel;

            if (MyMobileSocketChannel != null)
            {
                byte[] MySendMessageBytes = new byte[RecieveCount];

                for (int i = 0; i < RecieveCount; i++)
                {
                    MySendMessageBytes[i] = RecieveMessageBytes[i];
                }

                StartAsynchSendMessage(MyMobileSocketChannel, MySendMessageBytes);
            }
            else
            {
                this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + "[{0}]IM转发命令{1}出错!", MyDesMobileID, MyCommandMessage));
            }
        }
        protected void MobileLoginAuthtication(string UserCertID, SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel)
        {
            int    ReturnCode             = -1;
            string ChannelIDStr           = null;
            string ReplyCommandMessageStr = "mobilelogin";
            //----1--------------------------------------------------------------
            string          UserName          = UserCertID.Substring(0, UserCertID.IndexOf("-"));
            string          UserPass          = UserCertID.Substring(UserCertID.IndexOf("-") + 1);
            CustomerManager MyCustomerManager = new CustomerManager();
            Customer        MyCustomer        = MyCustomerManager.FindCustomer(UserName);//这个地方存在IO瓶紧

            if (MyCustomer == null)
            {
                ReturnCode             = -1;
                ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[10]!";
            }
            else
            {
                if (MyCustomer.LoginName == UserName && MyCustomer.Password == UserPass)
                {
                    ReturnCode = MyCustomer.CustomerID;
                    //ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]!", ReturnCode);
                    Channel        MyChannel;
                    ChannelManager MyChannelManager = new ChannelManager();
                    MyChannel = MyChannelManager.FindChannel(MyCustomer.CustomerID);
                    if (MyChannel == null)
                    {
                        ChannelIDStr           = null;
                        ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[10]!";
                    }
                    else
                    {
                        ChannelIDStr           = MyChannel.LockID + "-" + MyChannel.MobileID;
                        ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]!", ChannelIDStr);
                    }
                }
                else
                {
                    ReturnCode             = 0;
                    ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[11]!";
                }
            }
            //----2.---------------------------------------------------------

            ResponseToSynchClient(InputSocketServiceReadWriteChannel, ReplyCommandMessageStr);
        }
示例#12
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);

            // }
        }
示例#13
0
        public int AuthChannel(ref SocketServiceReadWriteChannel MyReadWriteChannel)
        {
            int ReturnCode = 1;

            try
            {
                for (int i = 0; i < MyLongFileReceiveProcList.Count; i++)
                {
                    if (MyLoginUserList[i].SocketInfor == MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint.ToString())
                    {
                        ReturnCode = MyLoginUserList[i].ChannelStatus;
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(ReturnCode);
        }
        protected void DirectResponsePing(SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel)
        {
            //老版本
            string ReplyCommandMessageStr = "ping";

            ReplyCommandMessageStr = ReplyCommandMessageStr + "#true!";
            byte[] MySendBaseMessageBytes = Encoding.UTF8.GetBytes(ReplyCommandMessageStr);

            int nBuffersLenght = MySendBaseMessageBytes.Length;

            byte[] MySendMessageBytes = new byte[nBuffersLenght + 3];

            MySendMessageBytes[2] = 255;
            //填充
            for (int i = 0; i < nBuffersLenght; i++)
            {
                MySendMessageBytes[3 + i] = MySendBaseMessageBytes[i];
            }

            StartAsynchSendMessage(InputSocketServiceReadWriteChannel, MySendMessageBytes);
        }
        private void AsynchWriteMessageCallback(IAsyncResult InIAsyncResult)
        {
            SocketServiceReadWriteChannel MyReadWriteChannel = (SocketServiceReadWriteChannel)InIAsyncResult.AsyncState;

            try
            {
                MyReadWriteChannel.MyNetWorkStream.EndWrite(InIAsyncResult);
                SendMessageForString(MyReadWriteChannel.MyWriteBuffers, MyReadWriteChannel);
                //-----------判断关闭该通道-------------------------------------------------------
                if (MyReadWriteChannel.IsCloseSocket)
                {
                    MyReadWriteChannel.MyTCPClient.Client.Close();
                }
            }
            catch (Exception ExceptionInfor)            {
                //string MyTimeMarker = DateTime.Now.ToString() + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
                string MyTimeMarker = string.Format("{0:HH:mm:ss}", DateTime.Now);
                DisplayResultInfor(1, string.Format(MyTimeMarker + "向客户端发送数据失败(2)[{0}]\r\n", ExceptionInfor));
                //DisplayResultInfor(1, string.Format(MyTimeMarker + "向[{0}]发送数据失败(2)\r\n", MyReadWriteChannel.MyTCPClient.Client.RemoteEndPoint));
            }
        }
        protected void ResponseToSynchClient(SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel, string ResultStr)
        {
            //string ReplyCommandMessageStr = "authtication";
            //ReplyCommandMessageStr = ReplyCommandMessageStr + "#true!";

            string ReplyCommandMessageStr = ResultStr;

            byte[] MySendBaseMessageBytes = Encoding.UTF8.GetBytes(ReplyCommandMessageStr);

            int nBuffersLenght = MySendBaseMessageBytes.Length;

            byte[] MySendMessageBytes = new byte[nBuffersLenght + 3];

            MySendMessageBytes[2] = (byte)nBuffersLenght;// 255;
            //填充
            for (int i = 0; i < nBuffersLenght; i++)
            {
                MySendMessageBytes[3 + i] = MySendBaseMessageBytes[i];
            }

            StartAsynchSendMessage(InputSocketServiceReadWriteChannel, MySendMessageBytes);
        }
        protected void FromDBGetChannel(string CustomerIDStr, SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel)
        {
            string ChannelIDStr;
            string ReplyCommandMessageStr = "getchannel";
            //----------------------------------------------------------------------------------------------------
            int            CustomerID = int.Parse(CustomerIDStr);
            Channel        MyChannel;
            ChannelManager MyChannelManager = new ChannelManager();

            MyChannel = MyChannelManager.FindChannel(CustomerID);
            if (MyChannel == null)
            {
                ChannelIDStr           = null;
                ReplyCommandMessageStr = ReplyCommandMessageStr + "#false[10]!";
            }
            else
            {
                ChannelIDStr           = MyChannel.LockID + "-" + MyChannel.MobileID;
                ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]!", ChannelIDStr);
            }
            //----------------------------------------------------------------------------------------------------

            ResponseToSynchClient(InputSocketServiceReadWriteChannel, ReplyCommandMessageStr);
        }
示例#18
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);
            }
        }
 protected override void SendMessageForString(Byte[] InSendMessageBuffers, SocketServiceReadWriteChannel InputReadWriteChannel)
 {
     ;
 }
 public override void CommandDefineDispatch(SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel, byte[] MyReadBuffers, int RecieveMessageFlag, int InputRecieveCount)
 {
     ;
 }
 public override void CommandDefineDispatch(SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel, byte[] MyReadBuffers, int RecieveMessageFlag, int InputRecieveCount)
 {
     /*
      *  byte WebFlagID = MyReadBuffers[1];
      *
      *  string BaseMessageString = null;
      *
      *  BaseMessageString = Encoding.UTF8.GetString(MyReadBuffers, 3, InputRecieveCount - 3);
      *
      *  string MyTimeMarkerStr = string.Format("{0:MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
      *  DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "[{0}]{1}", InputSocketServiceReadWriteChannel.MyTCPClient.Client.RemoteEndPoint, BaseMessageString));
      *
      *  if (WebFlagID == 0)//非Web:第二个字节为0:异步Socket客户端;1:同步Socket客户端
      *  {
      *    string CommandMessageStr = BaseMessageString.Substring(0, BaseMessageString.IndexOf("#"));
      *
      *    switch (CommandMessageStr)
      *    {
      *      case "login":
      *          MobileAppServerLib.MobileLoginManager MyMobileLoginManager;
      *          MyMobileLoginManager = new MobileAppServerLib.MobileLoginManager(this, InputSocketServiceReadWriteChannel, InputRecieveCount);
      *          MyMobileLoginManager.CompleteCommand();
      *          break;
      *
      *      case "ping":
      *          DirectResponsePing(InputSocketServiceReadWriteChannel);
      *          break;
      *
      *
      *      default:
      *          //直接转发给云锁服务器!
      *          byte[] MySendMessageBytes = new byte[InputRecieveCount];
      *          for (int i = 0; i < InputRecieveCount; i++)
      *          {
      *
      *              MySendMessageBytes[i] = MyReadBuffers[i];
      *
      *          }
      *          MyMobileServerClientAPI.SynchSendCommand(MySendMessageBytes);
      *          break;
      *
      *   }
      * }
      * else //Web:同步Socket客户端和其他各种同步客户端
      * {
      *   string CommandMessageStr = BaseMessageString.Substring(0, BaseMessageString.IndexOf("#"));
      *   int IndexStart = BaseMessageString.IndexOf("#") + 1;
      *   switch (CommandMessageStr)
      *   {
      *       case "authtication":
      *           string UserCertID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
      *           FromDBAuthtication(UserCertID, InputSocketServiceReadWriteChannel);
      *           break;
      *
      *       case "getchannel":
      *           string CustomerID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
      *           FromDBGetChannel(CustomerID, InputSocketServiceReadWriteChannel);
      *           break;
      *
      *
      *       case "getimage":
      *           string LockSnapID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
      *           FromDBGetImage(LockSnapID, InputSocketServiceReadWriteChannel);
      *           break;
      *
      *
      *       case "getkeylist":
      *           //string CustomerID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
      *           //FromDBGetChannel(CustomerID, InputSocketServiceReadWriteChannel);
      *           break;
      *
      *       case "getopenlist":
      *           //string CustomerID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
      *           //FromDBGetChannel(CustomerID, InputSocketServiceReadWriteChannel);
      *           break;
      *
      *       case "getsnaplist":
      *           //string CustomerID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
      *           //FromDBGetChannel(CustomerID, InputSocketServiceReadWriteChannel);
      *           break;
      *
      *       default:
      *           MobileAppServerLib.SynchTcpClientChannel MySynchTcpClientChannel;
      *           MySynchTcpClientChannel = new MobileAppServerLib.SynchTcpClientChannel(this, InputSocketServiceReadWriteChannel, InputRecieveCount);
      *           MySynchTcpClientChannel.CompleteCommand();
      *          break;
      *
      *   }
      *
      *
      * }
      */
 }
        protected void CustomerCreateManagerment(string CustomerInforStr, SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel)
        {
            string ReplyCommandMessageStr = "customercreate";
            //----1------------------------------------------------------------------------------------------------
            string ActionID = CustomerInforStr.Substring(0, CustomerInforStr.IndexOf(":"));

            if (ActionID == "authenlockid")
            {
                int         IndexStart    = CustomerInforStr.IndexOf(":") + 1;
                string      LockID        = CustomerInforStr.Substring(IndexStart, CustomerInforStr.IndexOf("-") - IndexStart);
                LockManager MyLockManager = new LockManager();
                Lock        MyLock        = MyLockManager.FindLock(LockID);
                if (MyLock == null)
                {
                    //MessageBox.Show("此锁ID号不存在!");
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[110]!");
                }
                if (MyLock.Status != 2)
                {
                    //MessageBox.Show("此锁ID号不没有出售或授权!");
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[120]!");
                }
                else
                {
                    string TempStr       = CustomerInforStr.Substring(CustomerInforStr.IndexOf("-") + 1);
                    string RegsisterCode = TempStr;//循环截取

                    RegisterCodeCRUD MyRegisterCodeCRUD = new RegisterCodeCRUD();
                    RegisterCode     MyRegisterCode     = MyRegisterCodeCRUD.FindRegisterCode(LockID);
                    if (MyRegisterCode == null)
                    {
                        //MessageBox.Show("此注册号码不存在!");
                        ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[130]!");
                    }
                    if (MyRegisterCode.RegisterCodeStr != RegsisterCode)
                    {
                        //MessageBox.Show("此注册号码有错误!");
                        ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[140]!");
                    }
                    else
                    {
                        ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[0]!");
                    }
                }
            }

            if (ActionID == "authenloginid")
            {
                int             IndexStart        = CustomerInforStr.IndexOf(":") + 1;
                string          LockID            = CustomerInforStr.Substring(IndexStart, CustomerInforStr.IndexOf("-") - IndexStart);
                string          TempStr           = CustomerInforStr.Substring(CustomerInforStr.IndexOf("-") + 1);
                string          CustomerLoginID   = TempStr;//循环截取
                CustomerManager MyCustomerManager = new CustomerManager();
                Customer        MyCustomer        = MyCustomerManager.FindCustomer(CustomerLoginID);

                if (MyCustomer != null)
                {
                    //已经注册;
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[210]!");
                }
                else
                {
                    //还没有注册;
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[0]!");
                }
            }


            if (ActionID == "createcustomer")
            {
                int    IndexStart = CustomerInforStr.IndexOf(":") + 1;
                string LockID     = CustomerInforStr.Substring(IndexStart, CustomerInforStr.IndexOf(",") - IndexStart);

                IndexStart = CustomerInforStr.IndexOf(",") + 1;
                string TempStr       = CustomerInforStr.Substring(IndexStart);
                string RegsisterCode = TempStr.Substring(0, TempStr.IndexOf(",")); //循环截取

                IndexStart = TempStr.IndexOf(",") + 1;
                TempStr    = TempStr.Substring(IndexStart);
                string CustomerName = TempStr.Substring(0, TempStr.IndexOf(",")); //循环截取

                IndexStart = TempStr.IndexOf(",") + 1;
                TempStr    = TempStr.Substring(IndexStart);
                string LoginName = TempStr.Substring(0, TempStr.IndexOf(",")); //循环截取

                IndexStart = TempStr.IndexOf(",") + 1;
                TempStr    = TempStr.Substring(IndexStart);
                string PassWord = TempStr.Substring(0, TempStr.IndexOf(",")); //循环截取

                IndexStart = TempStr.IndexOf(",") + 1;
                TempStr    = TempStr.Substring(IndexStart);
                string PersonID = TempStr.Substring(0, TempStr.IndexOf(",")); //循环截取

                IndexStart = TempStr.IndexOf(",") + 1;
                TempStr    = TempStr.Substring(IndexStart);
                string TeleCode = TempStr.Substring(0, TempStr.IndexOf(",")); //循环截取


                IndexStart = TempStr.IndexOf(",") + 1;
                TempStr    = TempStr.Substring(IndexStart);
                string EMail = TempStr.Substring(0, TempStr.IndexOf(",")); //循环截取


                IndexStart = TempStr.IndexOf(",") + 1;
                TempStr    = TempStr.Substring(IndexStart);
                string Address = TempStr; //最后截取

                Channel MyChannel;
                MyChannel                 = new Channel();
                MyChannel.LockID          = LockID;
                MyChannel.RegisterCodeStr = RegsisterCode;

                Customer MyNewCustomer = new Customer();;

                MyNewCustomer.CustomerName = CustomerName;
                MyNewCustomer.LoginName    = LoginName;
                MyNewCustomer.PersonID     = PersonID;
                MyNewCustomer.TeleCode     = TeleCode;
                MyNewCustomer.Password     = PassWord;
                MyNewCustomer.EMail        = EMail;
                MyNewCustomer.Address      = Address;


                CustomerManager MyCustomerManager = new CustomerManager();

                string MobileID = MyCustomerManager.InsertCustomerExxx(MyNewCustomer, MyChannel);
                if (MobileID != null)
                {
                    Customer MyCustomer;
                    MyCustomer = MyCustomerManager.FindCustomerEx(MobileID);
                    if (MyCustomer != null)
                    {
                        // 注册操作成功,客户ID:" + MyCustomer.CustomerID + " ,云锁ID:" + MyChannel.LockID + ", 移动端ID:" + MobileID + "\r\n");
                        ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#true[{0}]!", MyCustomer.CustomerID + "," + MyChannel.LockID + "," + MobileID);
                    }
                    else
                    {
                        //注册操作失败!;
                        ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[310]!");
                    }
                }
                else
                {
                    //注册操作失败!;
                    ReplyCommandMessageStr = string.Format(ReplyCommandMessageStr + "#false[320]!");
                }
            }
            //----2.Reply-----------------------------------------------------------------------------
            ResponseToSynchClient(InputSocketServiceReadWriteChannel, ReplyCommandMessageStr);
        }
        public void CommandDefineDispatchEx(LoginUser MeLoginUser, int InputRecieveCount)
        {
            /*
             * //byte[] MyReadBuffer = MeLoginUser.MyReadWriteSocketChannel.MyReadBuffers;
             * //string MessageString = null;
             * // MessageString = Encoding.UTF8.GetString(MyReadBuffer, 0, InputRecieveCount);
             * // string MyTimeMarker = string.Format("{0:HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
             * // DisplayResultInfor(2, string.Format(MyTimeMarker + "[{0}]{1}]", MeLoginUser.MyReadWriteSocketChannel.MyTCPClient.Client.RemoteEndPoint, MessageString));
             * // DisplayResultInfor(1, string.Format("[{0}]{1}", MeLoginUser.MyReadWriteSocketChannel.MyTCPClient.Client.RemoteEndPoint, MessageString));
             * //return;
             */
            if (InputRecieveCount < 5)
            {
                return;
            }

            byte[] MyReadBuffers = MeLoginUser.MyReadWriteSocketChannel.MyReadBuffers;
            SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel = MeLoginUser.MyReadWriteSocketChannel;
            byte MessageFlagID = MyReadBuffers[1];

            string BaseMessageString = null;

            BaseMessageString = Encoding.UTF8.GetString(MyReadBuffers, 3, InputRecieveCount - 3);

            //string MyTimeMarkerStr = string.Format("{0:MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string MyTimeMarkerStr = string.Format("{0:HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);

            DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "[{0}]{1}", InputSocketServiceReadWriteChannel.MyTCPClient.Client.RemoteEndPoint, BaseMessageString));

            if (MessageFlagID == 0 || MessageFlagID == 16)//第二个字节为0、16:异步Socket客户端;1:同步Socket客户端(非Web):
            {
                string CommandMessageStr = BaseMessageString.Substring(0, BaseMessageString.IndexOf("#"));

                switch (CommandMessageStr)
                {
                case "login":
                    MobileAppServerLib.MobileLoginManager MyMobileLoginManager;
                    MyMobileLoginManager = new MobileAppServerLib.MobileLoginManager(this, MeLoginUser, InputRecieveCount);
                    MyMobileLoginManager.CompleteCommand();
                    break;

                case "ping":
                    //DirectResponsePing(InputSocketServiceReadWriteChannel);
                    DirectResponsePingEx(MeLoginUser);
                    break;

                case "close":
                    DirectCloseLoginUser(MeLoginUser);
                    break;


                default:
                    //直接转发给云锁服务器!
                    byte[] MySendMessageBytes = new byte[InputRecieveCount];
                    for (int i = 0; i < InputRecieveCount; i++)
                    {
                        MySendMessageBytes[i] = MyReadBuffers[i];
                    }
                    MyMobileServerClientAPI.SynchSendCommand(MySendMessageBytes);
                    break;
                }
            }
            else
            {
                if (MessageFlagID == 100)//第二个字节为100:IM
                {
                    MessageRountToEndpoit(MyReadBuffers, InputRecieveCount);
                }
                else//同步Socket客户端
                {
                    string CommandMessageStr = BaseMessageString.Substring(0, BaseMessageString.IndexOf("#"));
                    int    IndexStart        = BaseMessageString.IndexOf("#") + 1;
                    switch (CommandMessageStr)
                    {
                    case "authtication":
                        string UserCertID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
                        FromDBAuthtication(UserCertID, InputSocketServiceReadWriteChannel);    //通过客户LoginID号获得通道
                        break;

                    case "getchannel":
                        string CustomerID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
                        FromDBGetChannel(CustomerID, InputSocketServiceReadWriteChannel);    //通过客户ID号获得通道[为TOMCAT定制]
                        break;

                    case "mobilelogin":
                        string UserPassCertID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
                        MobileLoginAuthtication(UserPassCertID, InputSocketServiceReadWriteChannel);
                        break;


                    case "managerlogin":
                        string managerPassCertID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
                        ManagerLoginAuthtication(managerPassCertID, InputSocketServiceReadWriteChannel);
                        break;


                    case "lockstatus":
                        string LockStatusIDStr = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
                        LockStatusManagerment(LockStatusIDStr, InputSocketServiceReadWriteChannel);
                        break;


                    case "customercreate":
                        string customercreateStr = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
                        CustomerCreateManagerment(customercreateStr, InputSocketServiceReadWriteChannel);
                        break;

                    case "getimage":
                        string LockSnapID = BaseMessageString.Substring(IndexStart, BaseMessageString.LastIndexOf("#") - IndexStart);
                        FromDBGetImage(LockSnapID, InputSocketServiceReadWriteChannel);
                        break;


                    case "getkeylist":

                        break;

                    case "getopenlist":

                        break;

                    case "getsnaplist":

                        break;

                    default:
                        MobileAppServerLib.SynchTcpClientChannel MySynchTcpClientChannel;
                        MySynchTcpClientChannel = new MobileAppServerLib.SynchTcpClientChannel(this, MeLoginUser, InputRecieveCount);
                        MySynchTcpClientChannel.CompleteCommand();
                        break;
                    }
                }
            }
        }
        //========================================================================================
        public override void SocketClientResponseCallBack(byte[] RecieveMessageBytes, int RecieveCount)
        {
            string BaseMessageString;

            /*
             * if (RecieveMessageBytes[2] == 254)
             * {
             * BaseMessageString = Encoding.Unicode.GetString(RecieveMessageBytes, 3, RecieveCount - 3);
             * }
             * else
             * {
             * BaseMessageString = Encoding.ASCII.GetString(RecieveMessageBytes, 3, RecieveCount - 3);
             * }
             */

            BaseMessageString = Encoding.UTF8.GetString(RecieveMessageBytes, 3, RecieveCount - 3);
            string MyMobileID       = BaseMessageString.Substring(BaseMessageString.IndexOf("#") + 1, 15);
            string MyLockID         = BaseMessageString.Substring(BaseMessageString.IndexOf("-") + 1, 15);
            string MyCommandMessage = BaseMessageString.Substring(0, BaseMessageString.IndexOf("#"));

            //string MyTimeMarkerStr = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string MyTimeMarkerStr         = string.Format("{0:HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string ClientSocketEndPointStr = MyMobileServerClientAPI.MyTcpClient.Client.LocalEndPoint.ToString();
            //--找移动端通道--------------------------------------------------------------------------------

            /*
             * LGJAsynchSocketService.LockServerLib.FindMobileChannel MyBindedMobileChannel = new LGJAsynchSocketService.LockServerLib.FindMobileChannel(MyMobileID);
             * SocketServiceReadWriteChannel MyReadWriteSocketChannel;
             *
             *
             * try
             * {
             * MyReadWriteSocketChannel = this.MyManagerSocketLoginUser.MyLoginUserList.Find(new Predicate<LoginUser>(MyBindedMobileChannel.SelectMobileChannel)).MyReadWriteSocketChannel;
             * }
             * catch
             * {
             * MyReadWriteSocketChannel = null;
             * }
             */

            FindMobileChannel MyFindMobileChannel = new FindMobileChannel(MyLockID);
            LoginUser         MyLoginUser         = this.MyManagerLoginMobileUser.MyLoginUserList.Find(new Predicate <LoginUser>(MyFindMobileChannel.BindedMobileChannel));

            if (MyLoginUser == null)
            {
                //不存在或者不在线
                this.DisplayResultInfor(1, string.Format("[{0}]所绑定的移动端通道不在线", MyLockID));

                //this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "|<-{0}",  BaseMessageString));
                this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + "[<-{0}]{1}", ClientSocketEndPointStr, BaseMessageString));
                return;
            }
            else
            {
                //this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "|<-{0}",  BaseMessageString));
                this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "[<-{0}]{1}", ClientSocketEndPointStr, BaseMessageString));
            }
            //下一步处理
            SocketServiceReadWriteChannel MyMobileSocketChannel = MyLoginUser.MyReadWriteSocketChannel;

            //--再转发出去-----------------------------------------------------------------------------------
            if (MyMobileSocketChannel != null)
            {
                byte[] MySendMessageBytes = new byte[RecieveCount];

                for (int i = 0; i < RecieveCount; i++)
                {
                    MySendMessageBytes[i] = RecieveMessageBytes[i];
                }


                StartAsynchSendMessage(MyMobileSocketChannel, MySendMessageBytes);
                //MyTimeMarkerStr = string.Format("{0:MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
                //MyTimeMarkerStr = string.Format("{0:HH:mm:ss}", DateTime.Now);
                //this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + " 接收云智能总线[{0}]响应命令:{1}", MyLockID, MyCommandMessage));
            }
            else
            {
                this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + "[{0}]转发命令{1}出错!", MyLockID, MyCommandMessage));
            }
        }
        public virtual void CommandDefineDispatch(SocketServiceReadWriteChannel InputSocketServiceReadWriteChannel, byte[] MyReadBuffers, int RecieveMessageFlag, int InputRecieveCount)
        {
            //虚函数,子类实现具体方法

            /*
             * string BaseMessageString = null;
             * string HexSendMessageIDString = null;
             * if (RecieveMessageFlag < 250)
             * {
             *  //1.缓冲区按原样全部转换为16进制字符串表示---------------------------------------------------------------------------------------------------------
             *  if (InputRecieveCount < 256)
             *  {
             *      for (int i = 0; i < InputRecieveCount; i++)
             *      {
             *
             *          BaseMessageString = BaseMessageString + string.Format("{0:X2}", MyReadBuffers[i]);
             *
             *      }
             *  }
             *  else
             *  {
             *
             *      if (InputRecieveCount <=65536)
             *      {
             *          BaseMessageString = string.Format("{0:X2}", MyReadBuffers[1]);
             *          BaseMessageString = BaseMessageString + string.Format("{0:X2}", MyReadBuffers[0]);
             *          UInt16 RecieveMessageLenght = Convert.ToUInt16(BaseMessageString, 16);
             *          BaseMessageString = string.Format("文件传输[{0}]", RecieveMessageLenght);
             *
             *      }
             *      else
             *      {
             *          BaseMessageString = string.Format("{0:X2}", MyReadBuffers[21]);
             *          BaseMessageString = BaseMessageString + string.Format("{0:X2}", MyReadBuffers[20]);
             *          BaseMessageString = BaseMessageString + string.Format("{0:X2}", MyReadBuffers[19]);
             *          BaseMessageString = BaseMessageString + string.Format("{0:X2}", MyReadBuffers[18]);
             *
             *          UInt32 RecieveMessageLenght = Convert.ToUInt32(BaseMessageString, 16);
             *          BaseMessageString = string.Format("文件传输[{0}]", RecieveMessageLenght);
             *      }
             *
             *
             *
             *
             *
             *  }
             *
             *  //-------------------------------------
             *
             *  if (DataFormateFlag)
             *  {
             *      HexSendMessageIDString = string.Format("{0:X2}", MyReadBuffers[9]) + string.Format("{0:X2}", MyReadBuffers[8]);
             *  }
             *  else
             *  {
             *      HexSendMessageIDString = string.Format("{0:X2}", MyReadBuffers[8]) + string.Format("{0:X2}", MyReadBuffers[9]);
             *  }
             *
             *
             * }
             * else
             * {
             *  //2.把来自移动端的消息字符串显示-----------------------------------------------------------------------------------------------------------------------
             *    /*
             *  if (RecieveMessageFlag == 254)
             *  {
             *      BaseMessageString = Encoding.Unicode.GetString(MyReadBuffers, 3, InputRecieveCount - 3);
             *  }
             *  else
             *  {
             *      BaseMessageString = Encoding.UTF8.GetString(MyReadBuffers, 3, InputRecieveCount - 3);
             *  }
             */
            //BaseMessageString = Encoding.UTF8.GetString(MyReadBuffers, 3, InputRecieveCount - 3);

            //}

            /*
             * string MyTimeMarkerStr = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
             * DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "[{0}]{1}", InputSocketServiceReadWriteChannel.MyTCPClient.Client.RemoteEndPoint, BaseMessageString ));
             *
             * //====================================================================================
             * switch (RecieveMessageFlag)
             * {
             *  case 0:
             *       //智能锁响应消息
             *      SamrtLockResponseMessage(InputSocketServiceReadWriteChannel, InputRecieveCount, HexSendMessageIDString);
             *      break;
             *  case 1:
             *      //智能锁主动上传消息
             *      SamrtLockRequestMessage(InputSocketServiceReadWriteChannel, InputRecieveCount, HexSendMessageIDString);
             *
             *      break;
             *
             *  case 255:
             *      //移动端请求消息[]ASCII]
             *      SamrtMobileRequestMessage(InputSocketServiceReadWriteChannel, InputRecieveCount);
             *      break;
             *
             *  case 254:
             *      //移动端请求消息[UNICODE]
             *      SamrtMobileRequestMessage(InputSocketServiceReadWriteChannel, InputRecieveCount);
             *
             *
             *      break;
             *  default:
             *      break;
             *
             * }
             */
        }
示例#26
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);
            }
        }
        private void AcceptTcpClientConnectCallback(IAsyncResult InputAsynchResult)
        {
            try
            {
                //这个函数在另外一个线程中执行
                MyEventWaitAllDone.Set();  //侦听线程继续等待写一个客户端连接

                TcpListener MyListener  = (TcpListener)InputAsynchResult.AsyncState;
                TcpClient   MyTCPClient = MyListener.EndAcceptTcpClient(InputAsynchResult);

                MyTCPClient.Client.IOControl(IOControlCode.KeepAliveValues, SetkeepalivInPARA(), null);//  here set keep-alive

                //---------------------------------------------------------------------------------------------------------------------
                //if (AroundDisplay == 1)
                ///{
                //MyRefreshPrimeNotifyIconCallBackCallback.Invoke(MyTimeMarker.Substring(0,MyTimeMarker.IndexOf("[")) + "已接受客户连接:" + MyTCPClient.Client.RemoteEndPoint);
                //DisplayResultInfor(1, string.Format(MyTimeMarker + "已接受客户端[{0}]连接\r\n", MyTCPClient.Client.RemoteEndPoint));

                //}
                //-----------------------------------------------------------------------------------------------------------------------
                //----回显信息--------------------------------------------------------------------------------------------------------
                //string MyTimeMarker = DateTime.Now.ToString() + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond) + "[" + DateTime.Now.Ticks.ToString() + "]";
                //string MyTimeMarker = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
                string MyTimeMarker = string.Format("{0:HH:mm:ss}", DateTime.Now);

                //DisplayResultInfor(1, string.Format(MyTimeMarker + "已接受客户端[{0}]连接", MyTCPClient.Client.RemoteEndPoint));

                if (MySocketServiceTypeID == SocketServiceTypeID.lockServer)
                {
                    DisplayResultInfor(1, string.Format(MyTimeMarker + " I[{0}]连接", MyTCPClient.Client.RemoteEndPoint));
                }
                if (MySocketServiceTypeID == SocketServiceTypeID.MobileAppServer)
                {
                    DisplayResultInfor(1, string.Format(MyTimeMarker + " M[{0}]连接", MyTCPClient.Client.RemoteEndPoint));
                }

                //---添加通道【涉及递归、无锁化设计、Proactor模式】---------------------------------------------------------------------------------------------------------
                SocketServiceReadWriteChannel MyReadWriteChannel = new SocketServiceReadWriteChannel(MyTCPClient);

                //MyReadWriteChannel.MyNetWorkStream.BeginRead(MyReadWriteChannel.MyReadBuffers, 0, MyReadWriteChannel.MyReadBuffers.Length, AsynchReadClientCallback, MyReadWriteChannel);
                //MyManagerSocketLoginUser.CRUDLoginUserList(MyReadWriteChannel, 0);
                //LGJMessageEntity MyLGJMessageEntity = new LGJMessageEntity("create", 0, MyReadWriteChannel);
                //MyMessageEntityManager.AddMessageEntity(MyLGJMessageEntity);

                //增加会话状态记录
                LoginID++;
                LoginUser MyLoginUser = new LoginUser(LoginID, ref MyReadWriteChannel);

                this.MyManagerSocketLoginUser.MyLoginUserList.Add(MyLoginUser);

                MyReadWriteChannel.MyNetWorkStream.BeginRead(MyReadWriteChannel.MyReadBuffers, 0, MyReadWriteChannel.MyReadBuffers.Length, AsynchReadClientCallback, MyLoginUser);

                //MyEventWaitAllDone.Set();  //新改进!继续等待写一个客户端连接

                this.DisplayResultInfor(4, "");


                //MySocketServiceList.Add(MyReadWriteObject);
                //CommandFromInOut = 1;
                //CommandDefine(MyReadWriteObject, "#login!");
                //MySocketServiceList.Add(MyReadWriteObject);
                //CRUDLoginUserList(ref MyTCPClient, 0);
                //ClientListComboBox.Invoke(setComboBoxCallback, MyTCPClient.Client.RemoteEndPoint.ToString());
                //OnReceiveCommand(new CommandMessageEventArgs(MyReadWriteObject,"#login!","",0));
            }
            catch (Exception ExceptionInfor)
            {
                //DisplayResultInfor(1, "侦听器关闭[停止客户连接服务]" + "\r\n");
                DisplayResultInfor(1, string.Format("服务器侦听错误[{0}][10030]", ExceptionInfor.Message));
                //return;
            }
        }