private void P2p_receiveServerEvent(byte command, string text)
 {
     try
     {
         _baseModel _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <_baseModel>(text);
         try
         {
             int       count  = ConnObjlist.Count;
             ConnObj[] coobjs = new ConnObj[count];
             ConnObjlist.CopyTo(0, coobjs, 0, count);
             foreach (ConnObj coob in coobjs)
             {
                 if (coob != null)
                 {
                     if (coob.Token == _0x01.Token)
                     {
                         coob.Soc.Send(_0x01.GetRoot <byte[]>());
                         return;
                     }
                 }
             }
         }
         catch (Exception ex) { EventMylog("转发", ex.Message); }
     }
     catch { }
 }
Beispiel #2
0
        internal int ConnectToServer()
        {
            int result = 0;

            if (this.m_connObj == null)
            {
                Debug.WriteLine("SessionController - ConnterToServer - ConObj is null, making a new one");
                this.m_connObj = new ConnObj(this.m_SessionData.ConnectionInfo.IpA, this.m_SessionData.ConnectionInfo.Port);
                result         = 1;
            }

            if (SocketHandler.Connect(this.m_connObj))
            {
                this.m_decoder               = new MMudTerm_Protocols.AnsiProtocolCmds.AnsiProtocolDecoder();
                this.m_connObj.Rcvr         += new RcvMsgCallback(ConnHandler_Rcvr);
                this.m_connObj.Disconnected += new EventHandler(ConnHandler_Disconnected);
                result = 2;
            }
            else
            {
                this.m_connObj.mySocket.Close();
                this.m_connObj = null;
                result         = 3;
            }

            return(result);
        }
Beispiel #3
0
        internal int DisconnectFromServer()
        {
            int result = 0;

            if (this.m_connObj == null && this.m_currentSessionState.State == SessionStates.OFFLINE)
            {
                result = 1;
            }
            else if (this.m_connObj != null && this.m_currentSessionState.State != SessionStates.OFFLINE)
            {
                result = 2;
            }
            else
            {
                throw new Exception("Invalid coonObj state and session state!");
            }

            if (result == 2)
            {
                SocketHandler.Disconnect(this.m_connObj);
                this.m_connObj = null;
                SetState(SessionStates.OFFLINE);
                result = 1;
            }
            return(result);
        }
Beispiel #4
0
        public PDBErrorCode ExecuteInsert(string tabName, DataTable dataTable)
        {
            PDBErrorCode retVal = PDBErrorCode.PdbE_OK;

            lock (ConnObj)
            {
                byte[] sendPacket = MakeInsertTableRequestPacket(tabName, dataTable);
                ConnObj.Request(sendPacket);

                byte[] recvPacket = ConnObj.Recv();
                DecodeInsertTablePacket(recvPacket, out retVal);
            }

            return(retVal);
        }
Beispiel #5
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="sql">要执行的SQL语句列表</param>
        /// <returns>执行结果</returns>
        public PDBErrorCode ExecuteInsert(string sql)
        {
            PDBErrorCode retVal = PDBErrorCode.PdbE_OK;

            lock (ConnObj)
            {
                byte[] sendPacket = MakeRequestPacket(ProtoHeader.MethodCmdInsertReq, sql);
                ConnObj.Request(sendPacket);

                byte[] recvPacket = ConnObj.Recv();
                DecodeInsertPacket(recvPacket, out retVal);
            }

            return(retVal);
        }
        private void DTUSer_EventUpdataConnSoc(System.Net.Sockets.Socket soc)
        {
            ConnObj cobj = new ConnObj();

            cobj.Soc = soc;
            //IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint;
            //cobj.Token = EncryptDES(clientipe.Address.ToString() + "|" + DateTime.Now.ToString(), "lllssscc");

            try
            {
                IPEndPoint clientipe = (IPEndPoint)soc.RemoteEndPoint;
                cobj.Token = clientipe.Address.ToString() + "|" + clientipe.Port;// EncryptDES(clientipe.Address.ToString() + "|" + DateTime.Now.ToString(), "lllssscc");
                ConnObjlist.Add(cobj);
            }
            catch { }
        }
Beispiel #7
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sql">执行的SQL</param>
        /// <returns>查询的结果集</returns>
        public DataTable ExecuteQuery(string sql)
        {
            SuccessCount = 0;
            PDBErrorCode retVal = 0;

            DataTable dtResult = new DataTable();

            lock (ConnObj)
            {
                byte[] sendPacket = MakeRequestPacket(ProtoHeader.MethodCmdQueryReq, sql);
                ConnObj.Request(sendPacket);

                byte[] recvPacket = ConnObj.Recv();
                DecodePacket(recvPacket, out retVal, dtResult);
                if (retVal != PDBErrorCode.PdbE_OK)
                {
                    throw new PDBException(retVal);
                }
            }
            return(dtResult);
        }
        private void DTUSer_EventDeleteConnSoc(System.Net.Sockets.Socket soc)
        {
            ConnObj[] coobjs = new ConnObj[0];
            int       count  = 0;

            try
            {
                count  = ConnObjlist.Count;
                coobjs = new ConnObj[count];
                ConnObjlist.CopyTo(coobjs);
            }
            catch { }
            foreach (ConnObj coob in coobjs)
            {
                if (coob != null)
                {
                    if (coob.Soc.Equals(soc))
                    {
                        ConnObjlist.Remove(coob);
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 其他,例如:添加用户,删除用户,删除数据 等等..
        /// </summary>
        /// <param name="sql">执行的SQL</param>
        public void ExecuteNonQuery(string sql)
        {
            SuccessCount = 0;
            lock (ConnObj)
            {
                byte[] sendPacket = MakeRequestPacket(ProtoHeader.MethodCmdNonQueryReq, sql);
                ConnObj.Request(sendPacket);

                byte[]      recvPacket = ConnObj.Recv();
                ProtoHeader proHdr     = new ProtoHeader(recvPacket);

                if (proHdr.GetMethod() != ProtoHeader.MethodCmdNonQueryRep)
                {
                    throw new PDBException(PDBErrorCode.PdbE_PACKET_ERROR, "报文错误:Error Packet");
                }

                PDBErrorCode errCode = (PDBErrorCode)proHdr.GetReturnVal();

                if (errCode != PDBErrorCode.PdbE_OK)
                {
                    throw new PDBException(errCode);
                }
            }
        }