Ejemplo n.º 1
0
        protected override void OnReciveTextPacket(WebSocketProtocol aSender, IWebSocketPacket e)
        {
            if (recivePacket != null)
            {
                recivePacket(aSender, e);
            }
            try
            {
                JsonObject lTextjson = new JsonObject(e.GetString());

                IToken lToken = PacketToToken(e);
                string lType  = lToken.GetType();

                lock (PendingResponseQueue)
                {
                    if (!lType.Equals(WebSocketMessage.WELCOME) && !lType.Equals(WebSocketMessage.GOODBYTE))
                    {
                        try
                        {
                            int lUTID = lToken.GetInt(WebSocketMessage.UTID);
                            int lCode = lToken.GetInt(WebSocketMessage.CODE);

                            PendingResponseQueue lPRQI = PendingResponseQueue[lUTID];
                            if (lPRQI != null)
                            {
                                bool lSuccess = false;
                                if (lCode == 0)
                                {
                                    lSuccess = true;
                                }

                                TokenResponse lResponse = new TokenResponse(mPendingResponseQueue[lUTID].Token, lToken, lSuccess);
                                lPRQI.PendingResponse.Invoke(this, lResponse);
                                PendingResponseQueue.Remove(lUTID);
                            }
                        }
                        catch (Exception) { }
                    }
                }
                OnReciveTokenText(lToken);
            }
            catch (Exception) { }
        }
Ejemplo n.º 2
0
        public static IToken PacketToToken(IWebSocketPacket aDataPacket)
        {
            try
            {
                JsonObject json = new JsonObject(aDataPacket.GetString());
                Dictionary <string, object> lDictionary = new Dictionary <string, object>();

                for (int i = 0; i < json.Count; i++)
                {
                    lDictionary.Add(json.Keys.ElementAt(i), json.Values.ElementAt(i));
                }

                return(new Token(lDictionary));
            }
            catch (Exception lEx)
            {
                if (mLog.IsErrorEnabled)
                {
                    mLog.Error(lEx.Source + WebSocketMessage.SEPARATOR + lEx.Message);
                }
                return(null);
            }
        }
Ejemplo n.º 3
0
        protected override void OnReciveTextPacket(WebSocketProtocol aSender, IWebSocketPacket e)
        {
            if (recivePacket != null)
                recivePacket(aSender, e);
            try
            {
                JsonObject lTextjson = new JsonObject(e.GetString());

                IToken lToken = PacketToToken(e);
                string lType = lToken.GetType();

                lock (PendingResponseQueue)
                {
                    if (!lType.Equals(WebSocketMessage.WELCOME) && !lType.Equals(WebSocketMessage.GOODBYTE))
                    {
                        try
                        {
                            int lUTID = lToken.GetInt(WebSocketMessage.UTID);
                            int lCode = lToken.GetInt(WebSocketMessage.CODE);

                            PendingResponseQueue lPRQI = PendingResponseQueue[lUTID];
                            if (lPRQI != null)
                            {
                                bool lSuccess = false;
                                if (lCode == 0)
                                    lSuccess = true;

                                TokenResponse lResponse = new TokenResponse(mPendingResponseQueue[lUTID].Token, lToken, lSuccess);
                                lPRQI.PendingResponse.Invoke(this, lResponse);
                                PendingResponseQueue.Remove(lUTID);
                            }
                        }
                        catch (Exception) { }
                    }
                }
                OnReciveTokenText(lToken);
            }
            catch (Exception) { }
        }