Beispiel #1
0
        void appServer_NewSessionConnected(WebSocketSession session)
        {
            TheBaseAssets.MySYSLOG.WriteToLog(4343, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("TheSWSServer", string.Format("New Session: {0} ID:{1}", session.RemoteEndPoint.ToString(), session.SessionID)));
            try
            {
                TheWSProcessor tProcessor = new TheWSProcessor(session);
                mSessionList.TryAdd(session.SessionID, tProcessor);

                TheRequestData tRequestData = new TheRequestData();
                tRequestData.RequestUri = new Uri(session.UriScheme + "://" + session.Host + session.Path); // pContext.Request.Url;
                tRequestData.Header = new cdeConcurrentDictionary<string, string>();
                foreach (var tKey in session.Items)
                {
                    switch (tKey.Key.ToString().ToLower())
                    {
                        case "user-agent": //tRequestData.UserAgent = pContext.Request.UserAgent;
                            tRequestData.UserAgent = tKey.Value.ToString();
                            break;
                        case "content-type": //tRequestData.ResponseMimeType = pContext.Request.ContentType;
                            tRequestData.ResponseMimeType = tKey.Value.ToString();
                            break;
                    }
                    tRequestData.Header.TryAdd(tKey.Key.ToString(), tKey.Value.ToString());
                }
                tRequestData.ServerTags = null;
                tProcessor.SetRequest(tRequestData);
            }
            catch (Exception e)
            {
                TheBaseAssets.MySYSLOG.WriteToLog(4343, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("TheSWSServer", "Error during new Session-Connect", eMsgLevel.l1_Error,e.ToString()));
            }
        }
Beispiel #2
0
 void appServer_NewDataReceived(WebSocketSession session, byte[] value)
 {
     if (mSessionList.Count == 0) return;
     TheWSProcessor tPross = null;
     if (mSessionList.TryGetValue(session.SessionID, out tPross) && tPross!=null)
     {
         tPross.ProcessIncomingData(null, value);
     }
 }
Beispiel #3
0
 void appServer_NewMessageReceived(WebSocketSession session, string message)
 {
     if (mSessionList.Count == 0) return;
     TheWSProcessor tPross = null;
     if (mSessionList.TryGetValue(session.SessionID, out tPross) && tPross != null)
     {
         tPross.ProcessIncomingData(message, null);
     }
 }
Beispiel #4
0
 void appServer_SessionClosed(WebSocketSession session, CloseReason value)
 {
     TheBaseAssets.MySYSLOG.WriteToLog(4343, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("TheSWSServer", string.Format("Session-Closed: {0} ID:{1}", session.RemoteEndPoint.ToString(), session.SessionID)));
     TheWSProcessor tPross = null;
     if (mSessionList.TryRemove(session.SessionID, out tPross))
     {
         if (tPross!=null)
             tPross.Shutdown(true);
     }
 }
        protected override void OnOpen()
        {
            TheBaseAssets.MySYSLOG.WriteToLog(43710, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("TheCSWSServer", string.Format("New Session: {0} URI:{1}", Context.ServerEndPoint,Context.RequestUri)));
            try
            {
                mProcessor = new TheWSProcessor(this);

                TheRequestData tRequestData = new TheRequestData
                {
                    RequestUri = Context.RequestUri,
                    HttpMethod = "GET",
                    Header = new cdeConcurrentDictionary<string, string>()
                };
                foreach (string tKey in Context.Headers.AllKeys)
                {
                    switch (tKey.ToLower())
                    {
                        case "user-agent": //tRequestData.UserAgent = pContext.Request.UserAgent;
                            tRequestData.UserAgent = Context.Headers[tKey];
                            break;
                        case "content-type": //tRequestData.ResponseMimeType = pContext.Request.ContentType;
                            tRequestData.ResponseMimeType = Context.Headers[tKey];
                            break;
                    }
                    tRequestData.Header.TryAdd(tKey, Context.Headers[tKey]);
                }
                tRequestData.ServerTags = null;
                mProcessor.SetRequest(tRequestData);
                if (tRequestData?.StatusCode!=200)
                    mProcessor?.Shutdown(true, $"{tRequestData?.StatusCode}:OnOpen resulted in not-ok StatusCode {tRequestData?.StatusCode} - Closing Connection");
            }
            catch (Exception e)
            {
                TheBaseAssets.MySYSLOG.WriteToLog(43711, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM("TheSWSServer", "Error during new Session-Connect", eMsgLevel.l1_Error, e.ToString()));
            }
        }