Esempio n. 1
0
        public ClientMessage[] GetClientMessages()
        {
            ClientMessage[] messages;
            lock (this.clientRequestLock)
            {
                bool flag = false;
                lock (this.sessionStateLock)
                {
                    PowwaSession.SessionState state = this.State;
                    switch (state)
                    {
                    case PowwaSession.SessionState.Available:
                    {
                        break;
                    }

                    case PowwaSession.SessionState.ExecutingCommand:
                    case PowwaSession.SessionState.CancellingCommand:
                    {
                        flag = true;
                        break;
                    }

                    case PowwaSession.SessionState.Closed:
                    {
                        throw PowwaException.CreateInvalidSessionException();
                    }

                    default:
                    {
                        break;
                    }
                    }
                }
                if (flag)
                {
                    this.messageQueue.WaitForMessages();
                }
                lock (this.sessionStateLock)
                {
                    if (this.State != PowwaSession.SessionState.Closed)
                    {
                        messages = this.messageQueue.GetMessages();
                    }
                    else
                    {
                        PowwaEvents.PowwaEVENT_DEBUG_LOG1("GetClientMessages() Invalid Session State", "SessionState", this.State.ToString());
                        throw PowwaException.CreateInvalidSessionException();
                    }
                }
            }
            return(messages);
        }
Esempio n. 2
0
        private static PowwaReturnValue <T> HttpEndpointWrapper <T>(string sessionKey, Func <PowwaSession, T> function)
        {
            PowwaReturnValue <T> powwaReturnValue;
            PowwaSession         session = null;

            try
            {
                try
                {
                    session = PowwaSessionManager.Instance.GetSession(SessionHelper.GetSessionId());
                }
                catch (ArgumentException argumentException)
                {
                    powwaReturnValue = PowwaReturnValue <T> .CreateError(PowwaException.CreateInvalidSessionException());

                    return(powwaReturnValue);
                }
                if (string.Compare(sessionKey, session.SessionKey, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (string.Compare(SessionHelper.GetAuthenticatedUser(), session.UserName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        powwaReturnValue = PowwaReturnValue <T> .CreateSuccess(function(session));
                    }
                    else
                    {
                        PowwaEvents.PowwaEVENT_INVALID_SESSION_USER(session.Name, SessionHelper.GetAuthenticatedUser(), session.UserName, SessionHelper.GetSourceIPAddressRemoteAddr(), SessionHelper.GetSourceIPAddressHttpXForwardedFor());
                        powwaReturnValue = PowwaReturnValue <T> .CreateError(PowwaException.CreateInvalidSessionException());
                    }
                }
                else
                {
                    PowwaEvents.PowwaEVENT_INVALID_SESSION_KEY(session.Name, SessionHelper.GetAuthenticatedUser(), SessionHelper.GetSourceIPAddressRemoteAddr(), SessionHelper.GetSourceIPAddressHttpXForwardedFor());
                    powwaReturnValue = PowwaReturnValue <T> .CreateError(PowwaException.CreateInvalidSessionException());
                }
            }
            catch (PowwaException powwaException1)
            {
                PowwaException powwaException = powwaException1;
                powwaReturnValue = PowwaReturnValue <T> .CreateError(powwaException);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                PowwaEvents.PowwaEVENT_GENERIC_FAILURE(session.Name, exception.Message);
                powwaReturnValue = PowwaReturnValue <T> .CreateGenericError(exception);
            }
            return(powwaReturnValue);
        }