private static DispatchStepResult DispatchIfLanguagePost(RequestContext requestContext)
 {
     ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::DispatchIfLanguagePost] entry.");
     Canary15Cookie.CanaryValidationResult canaryValidationResult;
     if (requestContext.RequestType == OwaRequestType.LanguagePost && HttpUtilities.IsPostRequest(requestContext.HttpContext.Request) && Canary15Cookie.ValidateCanaryInHeaders(requestContext.HttpContext, OwaRequestHandler.GetOriginalIdentitySid(requestContext.HttpContext), Canary15Profile.Owa, out canaryValidationResult))
     {
         OwaDiagnostics.TracePfd(25865, "The request is a post from the language selection page, processing this request...", new object[0]);
         ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::DispatchIfLanguagePost] Dispatching.");
         HttpRequest request = requestContext.HttpContext.Request;
         CultureInfo culture;
         string      timeZoneKeyName;
         bool        isOptimized;
         string      destination;
         RequestDispatcherUtilities.GetLanguagePostFormParameters(requestContext, request, out culture, out timeZoneKeyName, out isOptimized, out destination);
         ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::DispatchIfLanguagePost] Dispatching language post request locally...");
         return(RequestDispatcher.HandleLanguagePost(requestContext, culture, timeZoneKeyName, isOptimized, destination));
     }
     return(DispatchStepResult.Continue);
 }
        private static DispatchStepResult ValidateAndSetThreadCulture(RequestContext requestContext)
        {
            ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::ValidateAndSetThreadCulture] entry.");
            CultureInfo     cultureInfo     = null;
            EcpUserSettings ecpUserSettings = (EcpUserSettings)0U;
            UserContext     userContext     = requestContext.UserContext as UserContext;

            if (requestContext.UserContext != null && userContext == null)
            {
                throw new OwaInvalidOperationException(string.Format("Context was expected to be of type UserContext, but it is of type {0}", requestContext.UserContext.GetType()));
            }
            if (RequestDispatcherUtilities.TryReadUpdatedUserSettingsCookie(requestContext, out ecpUserSettings))
            {
                cultureInfo = RequestDispatcherUtilities.GetUserCultureFromEcpCookie(requestContext, ecpUserSettings);
                if (userContext != null)
                {
                    userContext.RefreshUserSettings(cultureInfo, ecpUserSettings);
                }
                RequestDispatcherUtilities.DeleteUserSettingsCookie(requestContext);
            }
            if (cultureInfo == null)
            {
                bool flag = requestContext.RequestType == OwaRequestType.SuiteServiceProxyPage;
                if (requestContext.LanguagePostUserCulture != null)
                {
                    cultureInfo = requestContext.LanguagePostUserCulture;
                }
                else if (userContext != null && !flag)
                {
                    cultureInfo = Culture.GetPreferredCultureInfo(userContext.ExchangePrincipal);
                    if (cultureInfo == null && userContext.IsExplicitLogon)
                    {
                        cultureInfo             = ClientCultures.GetPreferredCultureInfo(userContext.LogonIdentity.GetOWAMiniRecipient().Languages);
                        userContext.UserCulture = cultureInfo;
                    }
                    if (cultureInfo == null)
                    {
                        if (string.IsNullOrEmpty(requestContext.DestinationUrlQueryString))
                        {
                            requestContext.DestinationUrlQueryString = requestContext.HttpContext.Request.QueryString.ToString();
                        }
                        bool        flag2 = string.IsNullOrEmpty(requestContext.HttpContext.Request.Headers["X-SuiteServiceProxyOrigin"]);
                        CultureInfo culture;
                        string      timeZoneKeyName;
                        if (OfflineClientRequestUtilities.IsRequestFromMOWAClient(requestContext.HttpContext.Request, requestContext.HttpContext.Request.UserAgent) && RequestDispatcherUtilities.TryReadMowaGlobalizationSettings(requestContext, out culture, out timeZoneKeyName))
                        {
                            return(RequestDispatcher.HandleLanguagePost(requestContext, culture, timeZoneKeyName, false, requestContext.DestinationUrl));
                        }
                        if (flag2)
                        {
                            requestContext.DestinationUrl = RequestDispatcherUtilities.GetDestinationForRedirectToLanguagePage(requestContext);
                            requestContext.HttpContext.Response.AppendHeader("X-OWA-Version", Globals.ApplicationVersion);
                            requestContext.HttpContext.Response.AppendToLog("&redir=lang");
                            return(DispatchStepResult.RedirectToUrl);
                        }
                        requestContext.HttpContext.Response.Headers["X-OWA-Error"] = "OwaInvalidUserLanguageException";
                        requestContext.HttpStatusCode = HttpStatusCode.NoContent;
                        return(DispatchStepResult.EndResponse);
                    }
                    else if (userContext.IsUserCultureExplicitlySet)
                    {
                        cultureInfo = userContext.UserCulture;
                    }
                }
            }
            if (cultureInfo != null)
            {
                Culture.InternalSetThreadPreferredCulture(cultureInfo);
            }
            else
            {
                Culture.InternalSetThreadPreferredCulture();
            }
            return(DispatchStepResult.Continue);
        }