Ejemplo n.º 1
0
        public bool SaveSession(SessionData sessionData)
        {
            bool status = false;

            if (sessionData != null)
            {
                var session = (SessionData) HttpRuntime.Cache[sessionData.SessionId];
                if (session != null)
                {
                    try
                    {
                        HttpRuntime.Cache.Insert(sessionData.SessionId, sessionData, null, DateTime.Now.AddMinutes(15),
                                                 Cache.NoSlidingExpiration,
                                                 CacheItemPriority.Normal,
                                                 null);
                        status = true;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex, Source, "SaveSession", Severity.Critical);
                        status = false;
                    }
                }
            }
            return status;
        }
Ejemplo n.º 2
0
 public bool UpdateSession(string sessionId, string authenticationId, SessionData sessionData,
     out string errorMessage)
 {
     errorMessage = string.Empty;
     var session = (SessionData) HttpRuntime.Cache[sessionId];
     bool status = false;
     if (session == null)
         errorMessage = "No session found";
     else if (!string.Equals(session.AuthenticationId, authenticationId, StringComparison.OrdinalIgnoreCase))
         errorMessage = "Authorization Failed.";
     else
     {
         sessionData.AuthenticationId = authenticationId;
         sessionData.SessionId = sessionId;
         try
         {
             HttpRuntime.Cache.Insert(sessionId, sessionData, null, DateTime.Now.AddMinutes(15),
                                      Cache.NoSlidingExpiration,
                                      CacheItemPriority.Normal,
                                      null);
             status = true;
         }
         catch (Exception exception)
         {
             errorMessage = exception.Message;
         }
     }
     return status;
 }
Ejemplo n.º 3
0
        public string CreateSession(SessionData session)
        {
            ISessionDataProvider sessionDataProvider = SessionDataProviderFactory.CreateSessionDataProvider();

            if (sessionDataProvider != null)
            {
                return sessionDataProvider.CreateSession(session);
            }
            return null;
        }
Ejemplo n.º 4
0
 public string AddRequestToSession(SessionData session)
 {
     ISessionDataProvider sessionDataProvider = SessionDataProviderFactory.CreateSessionDataProvider();
     if (sessionDataProvider != null)
     {
         if(sessionDataProvider.SaveSession(session))
             return session.SessionId;
     }
     return null;
 }
Ejemplo n.º 5
0
 public void CreateSessionTest()
 {
     if (string.IsNullOrEmpty(sessionId))
     {
         var target = new MockSessionProvider();
         var session = new SessionData();
         string actual;
         actual = target.CreateSession(session);
         Assert.IsNotNull(actual);
         sessionId = actual;
     }
 }
Ejemplo n.º 6
0
 public string CreateSession(SessionData session)
 {
     string key = Guid.NewGuid().ToString();
     if (session != null)
         session.SessionId = key;
     try
     {
         HttpRuntime.Cache.Add(key, session, null, DateTime.Now.AddMinutes(15),
                               Cache.NoSlidingExpiration,
                               CacheItemPriority.Normal,
                               null);
     }
     catch (Exception exception)
     {
         Logger.LogException(exception, Source, "CreateSession", Severity.Normal);
     }
     return key;
 }
Ejemplo n.º 7
0
 public string CreateSession(SessionData session)
 {
     string key = session == null || string.IsNullOrEmpty(session.SessionId)
                      ? Guid.NewGuid().ToString()
                      : session.SessionId;
     try
     {
         var existingSession = (SessionData)HttpRuntime.Cache[key];
         if (existingSession == null)
         {
             session.SessionId = key;
             HttpRuntime.Cache.Insert(key, session, null, DateTime.Now.AddMinutes(15),
                                      Cache.NoSlidingExpiration,
                                      CacheItemPriority.Normal,
                                      null);
         }
     }
     catch (Exception ex)
     {
         Logger.LogException(ex, Source, "CreateSession", Severity.Critical);
     }
     return key;
 }
Ejemplo n.º 8
0
 public void UpdateSessionTest()
 {
     try
     {
         AssignSessionTest();
     }
     catch
     {
     }
     var target = new MockSessionProvider();
     var sessionData = new SessionData();
     string errorMessage = string.Empty;
     string errorMessageExpected = string.Empty;
     bool expected = true;
     bool actual;
     actual = target.UpdateSession(sessionId, authenticationId, sessionData, out errorMessage);
     Assert.AreEqual(errorMessageExpected, errorMessage);
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 9
0
 public void SaveSessionTest()
 {
     var target = new SessionDataProvider();
     var sessionData = new SessionData {SessionId = sessionId};
     bool expected = true;
     bool actual;
     actual = target.SaveSession(sessionData);
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 10
0
        public bool UpdateSession(string sessionId, string authenticationId, SessionData sessionData,
            out string errorMessage)
        {
            ISessionDataProvider sessionDataProvider = SessionDataProviderFactory.CreateSessionDataProvider();

            errorMessage = string.Empty;
            if (sessionDataProvider != null && _authenticationProvider != null &&
                _authenticationProvider.Validate(authenticationId))
            {
                SessionData storedSession = sessionDataProvider.GetSession(sessionId);

                if (storedSession != null)
                {
                    if (!string.IsNullOrEmpty(storedSession.AuthenticationId) &&
                        !string.Equals(storedSession.AuthenticationId, authenticationId,
                                       StringComparison.OrdinalIgnoreCase))
                    {
                        errorMessage = "Session already assigned.";
                        return false;
                    }

                    sessionData.AuthenticationId = authenticationId;
                    sessionData.SessionId = sessionId;

                    return sessionDataProvider.SaveSession(sessionData);
                }
                errorMessage = "Session not found.";
            }
            return false;
        }
Ejemplo n.º 11
0
 public string AddRequestToSession(SessionData session)
 {
     throw new NotImplementedException();
 }