private void SaveCultures(IRecipientSession adRecipientSession)
        {
            PreferredCultures preferredCultures = new PreferredCultures(base.Principal.PreferredCultures);

            preferredCultures.AddSupportedCulture(this.Language, (CultureInfo culture) => true);
            ADUser aduser = adRecipientSession.Read(base.Principal.ObjectId) as ADUser;

            if (aduser != null)
            {
                aduser.Languages.Clear();
                Util.AddRange <CultureInfo, CultureInfo>(aduser.Languages, preferredCultures);
                try
                {
                    adRecipientSession.Save(aduser);
                }
                catch (DataValidationException innerException)
                {
                    throw new CorruptDataException(ServerStrings.ExCannotSaveInvalidObject(aduser), innerException);
                }
                catch (DataSourceOperationException ex)
                {
                    throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, null, "MailboxRegionalConfiguration::SaveCultures. Failed due to directory exception {0}.", new object[]
                    {
                        ex
                    });
                }
                catch (DataSourceTransientException ex2)
                {
                    throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, null, "MailboxRegionalConfiguration::SaveCultures. Failed due to directory exception {0}.", new object[]
                    {
                        ex2
                    });
                }
            }
        }
示例#2
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);
        }
示例#3
0
 // Token: 0x0600085C RID: 2140 RVA: 0x0003E370 File Offset: 0x0003C570
 public static void UpdateUserCulture(UserContext userContext, CultureInfo culture, bool updateAD)
 {
     if (culture == null)
     {
         throw new ArgumentNullException("culture");
     }
     if (userContext == null)
     {
         throw new OwaInvalidOperationException("Shouldn't call UpdateUserCulture without a session");
     }
     if (updateAD)
     {
         PreferredCultures preferredCultures = new PreferredCultures(userContext.ExchangePrincipal.PreferredCultures);
         preferredCultures.AddSupportedCulture(culture, new Predicate <CultureInfo>(Culture.IsSupportedCulture));
         Culture.SetPreferredCulture(userContext.ExchangePrincipal, preferredCultures, userContext.MailboxSession.GetADRecipientSession(false, ConsistencyMode.FullyConsistent));
         userContext.ExchangePrincipal = userContext.ExchangePrincipal.WithPreferredCultures(preferredCultures);
     }
     userContext.UserCulture = culture;
     Culture.InternalSetThreadCulture(culture);
     userContext.RecreateMailboxSession(OwaContext.Get(HttpContext.Current));
     userContext.RecreatePublicFolderSessions();
 }
        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);
        }