private void SetupThreadContext(UserContextData contextData, SessionId id) { if (contextData == null) { return; } IPrincipal principal = TryGetPrincipal(); if (principal != null) { if (!(principal is GenericPrincipal)) { // Debug.Fail("It has to be the same principal!"); } contextData.OriginalPrincipal = principal; } principal = new UserContextPrincipal(contextData); SetPrincipal(principal); AppliactionContext.Log.Debug(this, String.Format("User '{0}' with sessionId '{1}' was attached to the thread.", User.Username, SessionId)); if (ExecutionContext.IsFlowSuppressed()) { ExecutionContext.RestoreFlow(); } }
private static UserContextPrincipal TryGetUserContextPrincipal() { UserContextPrincipal principal = Thread.CurrentPrincipal as UserContextPrincipal; if (principal == null) { if (HttpContext.Current != null) { principal = HttpContext.Current.User as UserContextPrincipal; } } return(principal); }
private UserContextData GetCurrentContextData() { UserContextPrincipal principal = TryGetUserContextPrincipal(); if (principal == null) { return(null); } if (principal.Context == null) { return(null); } return(principal.Context); }
private void DetachThreadExecutionContext(SessionId id) { UserContextData contextData = Instance.ContextData; if (contextData == null) { return; } if (contextData.SessionId != id) { AppliactionContext.Log.Error(this, String.Format("Different sessionId '{0}'. Context sessionId sessiosId '{1}'.", id, contextData.SessionId)); } UserContextPrincipal principal = TryGetUserContextPrincipal(); if (principal != null) { AppliactionContext.Log.Debug(this, String.Format("Detaching user '{0}' with sessiosId '{1}' from the thread.", User.Username, SessionId)); SetPrincipal(contextData.OriginalPrincipal); contextData.OriginalPrincipal = null; } }