protected override bool InternalExecute()
        {
            UserContext userContext = UserContextManager.GetUserContext(CallContext.Current.HttpContext, CallContext.Current.EffectiveCaller, true);

            new ConfigurationContext(userContext);
            MailboxSession mailboxIdentityMailboxSession            = base.CallContext.SessionCache.GetMailboxIdentityMailboxSession();
            UserConfigurationPropertyDefinition propertyDefinition  = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.ShowSenderOnTopInListView);
            UserConfigurationPropertyDefinition propertyDefinition2 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.ShowPreviewTextInListView);
            UserConfigurationPropertyDefinition propertyDefinition3 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.ConversationSortOrder);
            UserConfigurationPropertyDefinition propertyDefinition4 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.HideDeletedItems);
            UserConfigurationPropertyDefinition propertyDefinition5 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.GlobalReadingPanePosition);
            UserConfigurationPropertyDefinition propertyDefinition6 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.ShowReadingPaneOnFirstLoad);

            new UserOptionsType
            {
                ShowSenderOnTopInListView  = this.newSettings.ShowSenderOnTopInListView,
                ShowPreviewTextInListView  = this.newSettings.ShowPreviewTextInListView,
                ConversationSortOrder      = this.newSettings.ConversationSortOrder,
                HideDeletedItems           = this.newSettings.HideDeletedItems,
                GlobalReadingPanePosition  = this.newSettings.GlobalReadingPanePosition,
                ShowReadingPaneOnFirstLoad = this.newSettings.ShowFirstMessageOnSignIn
            }.Commit(mailboxIdentityMailboxSession, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition,
                propertyDefinition2,
                propertyDefinition3,
                propertyDefinition4,
                propertyDefinition5,
                propertyDefinition6
            });
            InferenceSettingsType.UpdateUserPreferenceFlag(mailboxIdentityMailboxSession, userContext, this.newSettings.ShowInferenceUiElements);
            return(true);
        }
示例#2
0
 internal void Load(MailboxSession mailboxSession, IList <UserConfigurationPropertyDefinition> properties, bool ignoreOverQuotaException)
 {
     try
     {
         using (IReadableUserConfiguration readOnlyConfiguration = this.GetReadOnlyConfiguration(mailboxSession))
         {
             if (readOnlyConfiguration != null)
             {
                 IDictionary dictionary = readOnlyConfiguration.GetDictionary();
                 for (int i = 0; i < properties.Count; i++)
                 {
                     UserConfigurationPropertyDefinition userConfigurationPropertyDefinition = properties[i];
                     object originalValue = dictionary[userConfigurationPropertyDefinition.PropertyName];
                     this.optionProperties[userConfigurationPropertyDefinition] = userConfigurationPropertyDefinition.GetValidatedProperty(originalValue);
                     ExTraceGlobals.UserOptionsDataTracer.TraceDebug((long)this.GetHashCode(), "Loaded property: {0}", new object[]
                     {
                         this.optionProperties[userConfigurationPropertyDefinition]
                     });
                 }
             }
         }
     }
     catch (QuotaExceededException ex)
     {
         ExTraceGlobals.UserContextCallTracer.TraceDebug <string>(0L, "UserConfigurationBaseType: Load failed. Exception: {0}", ex.Message);
         if (!ignoreOverQuotaException)
         {
             throw;
         }
     }
 }
示例#3
0
 public void DoLogoffCleanup()
 {
     base.LogBreadcrumb("DoLogoffCleanup");
     if (!this.isMailboxSessionCreated)
     {
         ExTraceGlobals.UserContextTracer.TraceDebug((long)this.GetHashCode(), "DoLogoffCleanup - No mailbox session on the user context, no cleanup necessary");
         return;
     }
     try
     {
         this.LockAndReconnectMailboxSession();
         UserConfigurationPropertyDefinition propertyDefinition = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.EmptyDeletedItemsOnLogoff);
         UserOptionsType userOptionsType = new UserOptionsType();
         userOptionsType.Load(base.MailboxSession, new UserConfigurationPropertyDefinition[]
         {
             propertyDefinition
         });
         if (userOptionsType.EmptyDeletedItemsOnLogoff)
         {
             ExTraceGlobals.UserContextTracer.TraceDebug((long)this.GetHashCode(), "DoLogoffCleanup - Emptying deleted items folder.");
             base.MailboxSession.DeleteAllObjects(DeleteItemFlags.SoftDelete, base.MailboxSession.GetDefaultFolderId(DefaultFolderType.DeletedItems));
         }
     }
     catch (OwaLockTimeoutException)
     {
         ExTraceGlobals.UserContextTracer.TraceDebug((long)this.GetHashCode(), "DoLogoffCleanup - Encountered OwaLockTimeoutException");
     }
     finally
     {
         base.UnlockAndDisconnectMailboxSession();
     }
 }
示例#4
0
 protected object this[UserConfigurationPropertyId propertyID]
 {
     get
     {
         UserConfigurationPropertyDefinition propertyDefinition = this.Schema.GetPropertyDefinition(propertyID);
         object obj;
         if (this.OptionProperties.ContainsKey(propertyDefinition) && this.OptionProperties[propertyDefinition] != null)
         {
             obj = this.OptionProperties[propertyDefinition];
         }
         else
         {
             obj = propertyDefinition.GetValidatedProperty(null);
         }
         ExTraceGlobals.UserOptionsDataTracer.TraceDebug <string, object>((long)this.GetHashCode(), "Get property: '{0}'; value: '{1}'", propertyDefinition.PropertyName, obj);
         return(obj);
     }
     set
     {
         UserConfigurationPropertyDefinition propertyDefinition = this.Schema.GetPropertyDefinition(propertyID);
         object value2 = propertyDefinition.GetValidatedProperty(value);
         if (!this.OptionProperties.ContainsKey(propertyDefinition))
         {
             this.OptionProperties.Add(propertyDefinition, value2);
         }
         else
         {
             this.OptionProperties[propertyDefinition] = value2;
         }
         ExTraceGlobals.UserOptionsDataTracer.TraceDebug <string, object>((long)this.GetHashCode(), "Set property: '{0}'; value: '{1}'", propertyDefinition.PropertyName, this.OptionProperties[propertyDefinition]);
     }
 }
示例#5
0
        protected override bool InternalExecute()
        {
            UserConfigurationPropertyDefinition propertyDefinition = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.TimeZone);

            new UserOptionsType
            {
                TimeZone = this.newTimeZone
            }.Commit(base.CallContext, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition
            });
            return(true);
        }
示例#6
0
        private Theme LoadUserTheme()
        {
            ConfigurationContext configurationContext = new ConfigurationContext(this);
            Theme result;

            if (configurationContext.IsFeatureEnabled(Feature.Themes))
            {
                string text = null;
                try
                {
                    base.LockAndReconnectMailboxSession(30000);
                    UserConfigurationPropertyDefinition propertyDefinition = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.ThemeStorageId);
                    UserOptionsType userOptionsType = new UserOptionsType();
                    userOptionsType.Load(base.MailboxSession, new UserConfigurationPropertyDefinition[]
                    {
                        propertyDefinition
                    });
                    text = userOptionsType.ThemeStorageId;
                }
                catch (Exception)
                {
                    ExTraceGlobals.ThemesTracer.TraceError(0L, "Failed to find the user's theme from UserOptions");
                }
                finally
                {
                    base.UnlockAndDisconnectMailboxSession();
                }
                if (string.IsNullOrEmpty(text))
                {
                    result = this.DefaultTheme;
                }
                else
                {
                    uint idFromStorageId = ThemeManagerFactory.GetInstance(this.CurrentOwaVersion).GetIdFromStorageId(text);
                    if (idFromStorageId == 4294967295U)
                    {
                        result = this.DefaultTheme;
                    }
                    else
                    {
                        result = ThemeManagerFactory.GetInstance(this.CurrentOwaVersion).Themes[(int)((UIntPtr)idFromStorageId)];
                    }
                }
            }
            else
            {
                result = this.DefaultTheme;
            }
            return(result);
        }
示例#7
0
        // Token: 0x06001BC7 RID: 7111 RVA: 0x0006AEE4 File Offset: 0x000690E4
        protected override bool InternalExecute()
        {
            CultureInfo cultureInfo;

            try
            {
                cultureInfo = new CultureInfo(this.newUserLocale);
            }
            catch (CultureNotFoundException ex)
            {
                ExTraceGlobals.CoreTracer.TraceDebug <string, string>(0L, "{0} is not a valid culture. Exception Message-{1}", this.newUserLocale, ex.Message);
                return(false);
            }
            if (!SetUserLocale.IsSupportedCulture(cultureInfo))
            {
                ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "SetUserLocale::IsSupportedCulture- {0} is not a supported culture.", this.newUserLocale);
                return(false);
            }
            UserContext       userContext       = UserContextManager.GetUserContext(CallContext.Current.HttpContext, CallContext.Current.EffectiveCaller, true);
            ExchangePrincipal exchangePrincipal = userContext.ExchangePrincipal;
            PreferredCultures preferredCultures = new PreferredCultures(exchangePrincipal.PreferredCultures);

            preferredCultures.AddSupportedCulture(cultureInfo, new Predicate <CultureInfo>(SetUserLocale.IsSupportedCulture));
            this.SaveCultures(exchangePrincipal.ObjectId, userContext.MailboxSession.GetADRecipientSession(false, ConsistencyMode.FullyConsistent), preferredCultures);
            userContext.ExchangePrincipal = exchangePrincipal.WithPreferredCultures(preferredCultures);
            UserConfigurationPropertyDefinition propertyDefinition  = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.DateFormat);
            UserConfigurationPropertyDefinition propertyDefinition2 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.TimeFormat);

            new UserOptionsType
            {
                DateFormat = MailboxRegionalConfiguration.GetDefaultDateFormat(cultureInfo),
                TimeFormat = MailboxRegionalConfiguration.GetDefaultTimeFormat(cultureInfo)
            }.Commit(base.CallContext, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition,
                propertyDefinition2
            });
            if (this.localizeFolderNames && !this.LocalizeFolders(cultureInfo))
            {
                return(false);
            }
            CallContext.Current.HttpContext.Response.Cookies.Add(new HttpCookie("mkt", cultureInfo.Name));
            CallContext.Current.HttpContext.Response.Cookies.Add(new HttpCookie("UpdatedUserSettings", 32.ToString()));
            return(true);
        }
示例#8
0
        // Token: 0x06001BC3 RID: 7107 RVA: 0x0006AE30 File Offset: 0x00069030
        protected override bool InternalExecute()
        {
            UserConfigurationPropertyDefinition propertyDefinition  = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.AutoAddSignatureOnMobile);
            UserConfigurationPropertyDefinition propertyDefinition2 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.SignatureTextOnMobile);
            UserConfigurationPropertyDefinition propertyDefinition3 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.UseDesktopSignature);

            new UserOptionsType
            {
                AutoAddSignatureOnMobile = this.newAutoAddSignature,
                SignatureTextOnMobile    = this.newSignatureText,
                UseDesktopSignature      = this.useDesktopSignature
            }.Commit(base.CallContext, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition,
                propertyDefinition2,
                propertyDefinition3
            });
            return(true);
        }
示例#9
0
        protected override bool InternalExecute()
        {
            UserConfigurationPropertyDefinition propertyDefinition  = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.EnableReminders);
            UserConfigurationPropertyDefinition propertyDefinition2 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.EnableReminderSound);
            UserConfigurationPropertyDefinition propertyDefinition3 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.NewItemNotify);

            new UserOptionsType
            {
                EnableReminders     = this.settings.EnableReminders,
                EnableReminderSound = this.settings.EnableReminderSound,
                NewItemNotify       = (NewNotification)this.settings.NewItemNotify
            }.Commit(base.CallContext, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition,
                propertyDefinition2,
                propertyDefinition3
            });
            return(true);
        }
示例#10
0
        // Token: 0x06001A73 RID: 6771 RVA: 0x0006215C File Offset: 0x0006035C
        protected override OptionSummary InternalExecute()
        {
            OptionSummary optionSummary   = new OptionSummary();
            string        currentTimeZone = GetTimeZone.GetSetting(base.CallContext, false).CurrentTimeZone;
            ExTimeZone    exTimeZone;

            if (ExTimeZoneEnumerator.Instance.TryGetTimeZoneByName(currentTimeZone, out exTimeZone))
            {
                optionSummary.TimeZone = exTimeZone.LocalizableDisplayName.ToString(CultureInfo.CurrentUICulture);
            }
            else
            {
                optionSummary.TimeZone = currentTimeZone;
            }
            UserOofSettingsType setting = GetUserOofSettings.GetSetting(base.MailboxIdentityMailboxSession, exTimeZone);

            optionSummary.Oof = setting.IsOofOn;
            EmailSignatureConfiguration setting2 = GetEmailSignature.GetSetting(base.CallContext);

            optionSummary.Signature = new EmailSignatureConfiguration();
            optionSummary.Signature.AutoAddSignature     = setting2.AutoAddSignature;
            optionSummary.Signature.UseDesktopSignature  = setting2.UseDesktopSignature;
            optionSummary.Signature.SignatureText        = setting2.SignatureText;
            optionSummary.Signature.DesktopSignatureText = setting2.DesktopSignatureText;
            UserConfigurationPropertyDefinition propertyDefinition  = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.AlwaysShowBcc);
            UserConfigurationPropertyDefinition propertyDefinition2 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.AlwaysShowFrom);
            UserConfigurationPropertyDefinition propertyDefinition3 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.ShowSenderOnTopInListView);
            UserConfigurationPropertyDefinition propertyDefinition4 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.ShowPreviewTextInListView);
            UserOptionsType userOptionsType = new UserOptionsType();

            userOptionsType.Load(base.CallContext, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition,
                propertyDefinition2,
                propertyDefinition3,
                propertyDefinition4
            });
            optionSummary.AlwaysShowBcc             = userOptionsType.AlwaysShowBcc;
            optionSummary.AlwaysShowFrom            = userOptionsType.AlwaysShowFrom;
            optionSummary.ShowSenderOnTopInListView = userOptionsType.ShowSenderOnTopInListView;
            optionSummary.ShowPreviewTextInListView = userOptionsType.ShowPreviewTextInListView;
            return(optionSummary);
        }
        // Token: 0x06001BCE RID: 7118 RVA: 0x0006B2E4 File Offset: 0x000694E4
        protected override SetUserThemeResponse InternalExecute()
        {
            UserContext          userContext          = UserContextManager.GetUserContext(CallContext.Current.HttpContext, CallContext.Current.EffectiveCaller, true);
            ConfigurationContext configurationContext = new ConfigurationContext(userContext);
            SetUserThemeResponse setUserThemeResponse = new SetUserThemeResponse
            {
                OwaSuccess  = false,
                O365Success = false
            };

            if (!configurationContext.IsFeatureEnabled(Feature.Themes) || string.IsNullOrEmpty(this.request.ThemeId))
            {
                return(setUserThemeResponse);
            }
            uint idFromStorageId = ThemeManagerFactory.GetInstance(userContext.CurrentOwaVersion).GetIdFromStorageId(this.request.ThemeId);

            this.tracer.TraceDebug <uint>(1L, "SetUserTheme.InternalExecute::id='{0}'", idFromStorageId);
            if (idFromStorageId == 4294967295U)
            {
                throw new OwaInvalidOperationException("The theme doesn't exist any more on the server");
            }
            string userPrincipalName = userContext.LogonIdentity.GetOWAMiniRecipient().UserPrincipalName;

            setUserThemeResponse.O365Success = this.UpdateO365Theme(this.request.ThemeId, userPrincipalName, userContext);
            if (this.request.ThemeId == userContext.DefaultTheme.StorageId)
            {
                this.request.ThemeId = string.Empty;
            }
            UserConfigurationPropertyDefinition propertyDefinition = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.ThemeStorageId);

            new UserOptionsType
            {
                ThemeStorageId = this.request.ThemeId
            }.Commit(base.CallContext, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition
            });
            setUserThemeResponse.OwaSuccess = true;
            userContext.ClearCachedTheme();
            return(setUserThemeResponse);
        }
示例#12
0
 internal void Commit(MailboxSession mailboxSession, IList <UserConfigurationPropertyDefinition> properties)
 {
     using (IUserConfiguration configuration = this.GetConfiguration(mailboxSession))
     {
         IDictionary dictionary     = configuration.GetDictionary();
         Type        typeFromHandle = typeof(int);
         for (int i = 0; i < properties.Count; i++)
         {
             UserConfigurationPropertyDefinition userConfigurationPropertyDefinition = properties[i];
             string propertyName = userConfigurationPropertyDefinition.PropertyName;
             if (userConfigurationPropertyDefinition.PropertyType == typeFromHandle)
             {
                 dictionary[userConfigurationPropertyDefinition.PropertyName] = (int)this.optionProperties[userConfigurationPropertyDefinition];
             }
             else
             {
                 dictionary[userConfigurationPropertyDefinition.PropertyName] = this.optionProperties[userConfigurationPropertyDefinition];
             }
             ExTraceGlobals.UserOptionsDataTracer.TraceDebug((long)this.GetHashCode(), "Committed property: {0}", new object[]
             {
                 this.optionProperties[userConfigurationPropertyDefinition]
             });
         }
         try
         {
             configuration.Save();
         }
         catch (StoragePermanentException ex)
         {
             ExTraceGlobals.UserOptionsDataTracer.TraceDebug <string, string>((long)this.GetHashCode(), "Failed to save configuration data. Error: {0}. Stack: {1}.", ex.Message, ex.StackTrace);
             throw;
         }
         catch (StorageTransientException ex2)
         {
             ExTraceGlobals.UserOptionsDataTracer.TraceDebug <string, string>((long)this.GetHashCode(), "Failed to save configuration data. Error: {0}. Stack: {1}.", ex2.Message, ex2.StackTrace);
             throw;
         }
     }
 }
示例#13
0
        public static EmailSignatureConfiguration GetSetting(CallContext callContext)
        {
            EmailSignatureConfiguration         emailSignatureConfiguration = new EmailSignatureConfiguration();
            UserConfigurationPropertyDefinition propertyDefinition          = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.AutoAddSignatureOnMobile);
            UserConfigurationPropertyDefinition propertyDefinition2         = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.SignatureTextOnMobile);
            UserConfigurationPropertyDefinition propertyDefinition3         = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.UseDesktopSignature);
            UserConfigurationPropertyDefinition propertyDefinition4         = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.SignatureText);
            UserOptionsType userOptionsType = new UserOptionsType();

            userOptionsType.Load(callContext, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition,
                propertyDefinition2,
                propertyDefinition3,
                propertyDefinition4
            });
            emailSignatureConfiguration.AutoAddSignature     = userOptionsType.AutoAddSignatureOnMobile;
            emailSignatureConfiguration.SignatureText        = userOptionsType.SignatureTextOnMobile;
            emailSignatureConfiguration.UseDesktopSignature  = userOptionsType.UseDesktopSignature;
            emailSignatureConfiguration.DesktopSignatureText = userOptionsType.SignatureText;
            return(emailSignatureConfiguration);
        }
        // Token: 0x06001AC9 RID: 6857 RVA: 0x00065434 File Offset: 0x00063634
        public static TimeZoneConfiguration GetSetting(CallContext callContext, bool needTimeZoneList)
        {
            TimeZoneConfiguration timeZoneConfiguration = new TimeZoneConfiguration();

            if (needTimeZoneList)
            {
                List <TimeZoneEntry> list = new List <TimeZoneEntry>();
                foreach (ExTimeZone timezone in ExTimeZoneEnumerator.Instance)
                {
                    list.Add(new TimeZoneEntry(timezone));
                }
                timeZoneConfiguration.TimeZoneList = list.ToArray();
            }
            UserConfigurationPropertyDefinition propertyDefinition = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.TimeZone);
            UserOptionsType userOptionsType = new UserOptionsType();

            userOptionsType.Load(callContext, new UserConfigurationPropertyDefinition[]
            {
                propertyDefinition
            });
            timeZoneConfiguration.CurrentTimeZone = userOptionsType.TimeZone;
            return(timeZoneConfiguration);
        }
示例#15
0
        // Token: 0x060008C4 RID: 2244 RVA: 0x0001CD20 File Offset: 0x0001AF20
        public override bool Equals(object value)
        {
            UserConfigurationPropertyDefinition userConfigurationPropertyDefinition = value as UserConfigurationPropertyDefinition;

            return(userConfigurationPropertyDefinition != null && (string.Equals(this.name, userConfigurationPropertyDefinition.name, StringComparison.OrdinalIgnoreCase) && this.guid.Equals(userConfigurationPropertyDefinition.guid)) && this.type.Equals(userConfigurationPropertyDefinition.type));
        }
示例#16
0
        private static DispatchStepResult HandleLanguagePost(RequestContext requestContext, CultureInfo culture, string timeZoneKeyName, bool isOptimized, string destination)
        {
            ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::HandleLanguagePost] entry.");
            if (requestContext.UserContext == null)
            {
                throw new OwaInvalidOperationException("UserContext should be created by the time language post is handled");
            }
            requestContext.LanguagePostUserCulture = culture;
            requestContext.HttpContext.Response.Cookies.Set(new HttpCookie("mkt", culture.Name));
            if (!string.IsNullOrWhiteSpace(destination) && (destination.StartsWith("/ecp/", StringComparison.OrdinalIgnoreCase) || destination.StartsWith("/owa/", StringComparison.OrdinalIgnoreCase)))
            {
                requestContext.DestinationUrl = destination;
            }
            else
            {
                requestContext.DestinationUrl = string.Empty;
            }
            Culture.InternalSetThreadPreferredCulture(culture);
            MailboxSession mailboxSession = null;

            try
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <string, bool>(0L, "[RequestDispatcher::HandleLanguagePost] Attempting to save the timeZoneKeyName (tzid={0}) and isOptimized={1} in the mailbox.", timeZoneKeyName, isOptimized);
                OwaIdentity logonIdentity = requestContext.UserContext.LogonIdentity;
                mailboxSession = logonIdentity.CreateMailboxSession(requestContext.UserContext.ExchangePrincipal, culture);
                if (requestContext.UserContext.IsExplicitLogon && !mailboxSession.CanActAsOwner)
                {
                    throw new OwaExplicitLogonException("User has no access rights to the mailbox", "ErrorExplicitLogonAccessDenied");
                }
                try
                {
                    ExTraceGlobals.CoreCallTracer.TraceDebug <int>(0L, "[RequestDispatcher::HandleLanguagePost] Trying to save the culture to the AD (lcid={0})", culture.LCID);
                    PreferredCultures preferredCultures = new PreferredCultures(requestContext.UserContext.ExchangePrincipal.PreferredCultures);
                    preferredCultures.AddSupportedCulture(culture, new Predicate <CultureInfo>(ClientCultures.IsSupportedCulture));
                    Culture.SetPreferredCulture(requestContext.UserContext.ExchangePrincipal, preferredCultures, mailboxSession.GetADRecipientSession(false, ConsistencyMode.FullyConsistent));
                    requestContext.UserContext.ExchangePrincipal = requestContext.UserContext.ExchangePrincipal.WithPreferredCultures(preferredCultures);
                }
                catch (Exception ex)
                {
                    if (!(ex is ADOperationException) && !(ex is InvalidOperationException))
                    {
                        throw;
                    }
                    requestContext.FailedToSaveUserCulture = true;
                    if (ExTraceGlobals.CoreCallTracer.IsTraceEnabled(TraceType.ErrorTrace))
                    {
                        StringBuilder stringBuilder = new StringBuilder("Failed to save user's culture in the AD.");
                        stringBuilder.Append("\n\nException: ");
                        stringBuilder.Append(ex.GetType().ToString());
                        stringBuilder.Append("\n");
                        stringBuilder.Append(ex.Message);
                        stringBuilder.Append(")");
                        if (!string.IsNullOrEmpty(ex.StackTrace))
                        {
                            stringBuilder.Append("\n\nCallstack:\n");
                            stringBuilder.Append(ex.StackTrace);
                        }
                        ExTraceGlobals.CoreCallTracer.TraceError(0L, stringBuilder.ToString());
                    }
                }
                UserOptionsType userOptionsType = new UserOptionsType();
                bool            flag            = true;
                try
                {
                    userOptionsType.Load(mailboxSession, false, false);
                }
                catch (QuotaExceededException ex2)
                {
                    ExTraceGlobals.UserContextCallTracer.TraceDebug <string>(0L, "[RequestDispatcher::HandleLanguagePost] UserOptions.LoadAll failed. Exception: {0}.", ex2.Message);
                    flag = false;
                }
                userOptionsType.TimeZone = timeZoneKeyName;
                userOptionsType.IsOptimizedForAccessibility = isOptimized;
                userOptionsType.UserOptionsMigrationState   = UserOptionsMigrationState.WorkingHoursTimeZoneFixUp;
                if (flag)
                {
                    UserConfigurationPropertyDefinition propertyDefinition  = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.TimeZone);
                    UserConfigurationPropertyDefinition propertyDefinition2 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.IsOptimizedForAccessibility);
                    UserConfigurationPropertyDefinition propertyDefinition3 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.UserOptionsMigrationState);
                    userOptionsType.Commit(mailboxSession, new UserConfigurationPropertyDefinition[]
                    {
                        propertyDefinition,
                        propertyDefinition2,
                        propertyDefinition3
                    });
                }
                RequestDispatcher.InitializeFavorites(mailboxSession);
            }
            finally
            {
                if (mailboxSession != null)
                {
                    UserContextUtilities.DisconnectStoreSession(mailboxSession);
                    mailboxSession.Dispose();
                    mailboxSession = null;
                }
            }
            return(DispatchStepResult.Continue);
        }