Пример #1
0
        public void EnqueueCb(byte[] buffer)
        {
            uint func = CDEFMessage.GetFunc(buffer,0);

            if ((FuncCode)func == FuncCode.Session_Establishment_Connect)
            {
                if (!CheckSessionState())
                {
                    if (CDEFMessage.IsReponse(buffer, 0))
                    {
                        CDEFMessage3308R resp = new CDEFMessage3308R(buffer);

                        if (resp.ConnectCode != 0)
                        {
                            if (resp.TimeDifference > 0)
                            {
                                Int32 t = resp.TimeDifference;
                                RaiseEvent((int)EtSessionEvents.eSessionConnectFailed, t);
                                //mOwner.SessionConnectFailedEvt(resp.TimeDifference);
                            }
                            else
                            {
                                Int32 t = 0;
                                RaiseEvent((int)EtSessionEvents.eSessionConnectFailed, 0);
                                //mOwner.SessionConnectFailedEvt(0);
                            }
                            LogError("CDEFSession::Connect failed with message: "
                                + resp.ConnectionText + " Reconnecting in: " + resp.TimeDifference.ToString());

                            if (mAutoConnect)
                            {
                                mReconSessTimer.Change(resp.TimeDifference, Timeout.Infinite);
                            }
                        }
                        else
                        {
                            mConn.EnableHeartbeats();
                            mFrom.SalesLocation = resp.ToDesc.SalesLocation;
                            mSessionEstablished.Set();
                            LogMessage("CDEFSession::Connect Msg Resp ok. Sales Location: "
                                + resp.ToDesc.SalesLocation.ToString() + " Local Port: " + mConn.LocalPort.ToString());
                            RaiseEvent((int)EtSessionEvents.eSessionConnected);
                            //mOwner.SessionConnectedEvt();
                        }
                    }
                }
                else
                {
                    LogError("CDEFSession::Enqueue Received another Connect msg but session already active");
                }
            }
            else if (CheckSessionState())
            {
                if ((FuncCode)CDEFMessage.GetFunc(buffer,0) == FuncCode.Session_Establishment_Disconnect)
                {
                    CDEFMessage3309 discon = new CDEFMessage3309(buffer);
                    mSessionEstablished.Reset();
                    //LogError("CDEFSession::ConnectSession Session disconnected. Reason: " + discon.DisconnectionText);
                    RaiseEvent((int)EtSessionEvents.eSessionDisconnect);

                    if (mAutoConnect)
                    {
                        mReconSessTimer.Change(DEFAULT_RECON_SESS_TIME, Timeout.Infinite);
                    }
                }
                else
                {
                    mReceiveQ.Enqueue(buffer);
                    RaiseEvent((int)EtSessionEvents.eMsgReady);
                }
            }
            else
            {
                LogError("CDEFSession::Enqueue NO active session but received msg: " + String.Format("{0:X}",func));
            }
        }
Пример #2
0
        public bool DisconnectSession(string reason, bool disconnectAfterSend)
        {
            bool ret = true;

            if (CheckSessionState())
            {
                CDEFMessage3309 disconnectMsg = new CDEFMessage3309();
                disconnectMsg.FromDesc = mFrom;
                disconnectMsg.ToDesc = mTo;
                disconnectMsg.ConnectCode = 0x42;
                disconnectMsg.DisconnectionText = reason;
                mConn.Disconnect(disconnectMsg, disconnectAfterSend);
                mSessionEstablished.Reset();
            }
            else
            {
                mConn.Disconnect();
            }
            return ret;
        }