示例#1
0
        private void SetStatus(State myState)
        {
            m_State = myState;

            // construct an kai message wrapper
            KaiMessageWrap myWrap = new KaiMessageWrap();
            string myTemp = "";
            switch (m_State)
            {
                case  State.closed:
                    myTemp = GatewayStatus.CLOSED;
                    break;
                case State.closing:
                    myTemp = GatewayStatus.CLOSING;
                    break;
                case State.open:
                    myTemp = GatewayStatus.OPEN;
                    break;
                case State.opening:
                    myTemp = GatewayStatus.OPENING;
                    break;
                default:
                    myTemp = GatewayStatus.NONE;
                    break;
            }
            myWrap.Data = m_EndPoint;
            myWrap.Label = myTemp;
            myWrap.CorrelationID = "";
            myWrap.Tag = m_Tag;

            if (m_Status != null)
            {
                m_Status(myWrap);
            }
        }
示例#2
0
        private void EventGatewayClients(ref string myContent, string myLabel, ref Socket myHandler)
        {
            try
            {
                // get my end point
                m_EndPoint = myHandler.RemoteEndPoint.ToString();

                // construct an kai message wrapper
                KaiMessageWrap myWrap = new KaiMessageWrap();

                myWrap.Data = myContent;
                myWrap.Label = myLabel;

                // Use the Corrlation ID to store the endpoint
                // all return messages with that correlationID will
                // be sent down the relevant socket
                myWrap.CorrelationID = m_EndPoint;
                myWrap.Tag = m_Tag;
                // event our gateway clients
                m_Receiver(myWrap);
            }
            catch
            {
                ////m_Log.Error("EventGatewayClients", myE);
            }
        }
示例#3
0
 private void send(ref KaiMessageWrap myMsg, Socket myClient)
 {
     string myData;
     StreamHelper.WriteMsg(out myData,  myMsg);
     send(m_Client, myData);
 }
示例#4
0
 public void Send(KaiMessageWrap myMsg)
 {
     send(ref myMsg, null);
 }
示例#5
0
 public static void WriteMsg(out string myData, KaiMessageWrap myKaiMsg)
 {
     myData = strTok;
     myData += myKaiMsg.Label;
     myData += strDelim;
     myData += myKaiMsg.ClientID;
     myData += strDelim;
     myData += myKaiMsg.Data.Length.ToString();
     myData += strEndTok;
     myData += myKaiMsg.Data;
 }
示例#6
0
        /// <summary>
        /// Inform the client of a status change, if a correlationID(EndPoint) is
        /// specified that status relates to a particular connection.
        /// </summary>
        /// <param name="myState"></param>
        /// <param name="myCorrelationID">socket connecton affected , empty string => all</param>
        private void SetStatus(State myState, string myCorrelationID)
        {
            m_State = myState;

            // construct a kai message wrapper
            KaiMessageWrap myWrap = new KaiMessageWrap();
            myWrap.Data = myCorrelationID;
            myWrap.CorrelationID = myCorrelationID;

            switch (m_State)
            {
                case State.closed:
                    myWrap.Label = "CLOSED";
                    break;
                case State.closing:
                    myWrap.Label = "CLOSING";
                    break;
                case State.open:
                    myWrap.Label = "OPEN";
                    break;
                case State.opening:
                    myWrap.Label = "OPENING";
                    break;
                default:
                    myWrap.Label = "NOTKNOWN";
                    break;
            }

            if (m_Status != null)
            {
                m_Status(myWrap);
            }
        }
示例#7
0
        private void EventGatewayClients(ref string myContent, string myLabel, ref Socket myHandler)
        {
            try
            {
                // get my end point
                string myRemoteEP = myHandler.RemoteEndPoint.ToString();

                // construct an kai msg wrapper
                KaiMessageWrap myWrap = new KaiMessageWrap();
                myWrap.Data = myContent;
                myWrap.Label = myLabel;

                // Use the Corrlation ID to store the endpoint
                // all return messages with that correlationID will
                // be sent down the relevant socket
                myWrap.CorrelationID = myRemoteEP;

                // event our gateway clients
                m_Receiver(myWrap);
            }
            catch (Exception myE)
            {
                //m_Log.Error("EventGatewayClients", myE);
                setStatus(State.open, ErrorLevel.recoverableError);
            }
        }
示例#8
0
        public void Send(ref KaiMessageWrap myMsg)
        {
            try
            {
                // try to get the socket from the map - using the correlationID
                if (myMsg.CorrelationID.Length > 0)
                {
                    if (m_Handlers.ContainsKey(myMsg.CorrelationID))
                    {
                        Socket myHandler = m_Handlers[myMsg.CorrelationID] as Socket;

                        // add our message headers
                        string myData;
                        StreamHelper.WriteMsg(out myData, myMsg);
                        Send(myHandler, myData);
                    }
                    else
                    {
                        Exception myE = new Exception("Handler not found for:" + myMsg.CorrelationID);
                        setStatus(State.open, ErrorLevel.recoverableError);
                        throw (myE);
                    }
                }
                else
                {
                    Exception myE = new Exception("No correlation ID - can't send message");
                    throw (myE);
                }
            }
            catch (Exception myE)
            {
                if (m_Handlers.ContainsKey(myMsg.CorrelationID))
                {
                    //m_Log.Warn("Send - correlation ID removed from handler list due to fault:" + myMsg.CorrelationID);
                    m_Handlers.Remove(myMsg.CorrelationID);
                }
                try
                {
                    setStatus(State.closed, ErrorLevel.normal, myMsg.CorrelationID);
                }
                catch
                {
                }
                throw (myE);
            }
        }