internal UserConfiguration Get(UserConfigurationName configName, StoreObjectId folderId)
        {
            bool flag = false;
            UserConfigurationCacheEntry userConfigurationCacheEntry;

            if (!this.SharedCacheEntryManager.TryGetUserConfigurationCachedEntry(configName, folderId, out userConfigurationCacheEntry))
            {
                ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName, StoreObjectId>((long)this.GetHashCode(), "UserConfigurationCache::Get. Miss the cache. ConfigName = {0}, folderId = {1}.", configName, folderId);
                return(null);
            }
            StoreObjectId     itemId            = userConfigurationCacheEntry.ItemId;
            ConfigurationItem configurationItem = null;
            bool flag2 = false;
            UserConfiguration result;

            try
            {
                configurationItem = ConfigurationItem.Bind(this.mailboxSession, itemId);
                ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName>((long)this.GetHashCode(), "UserConfigurationCache::Get. Hit the item in the cache. ConfigName = {0}.", configName);
                object obj = configurationItem.TryGetProperty(InternalSchema.UserConfigurationType);
                if (!(obj is int))
                {
                    ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName, object>((long)this.GetHashCode(), "UserConfigurationCache::Get. The type has been corrupted. ConfigName = {0}. Actual = {1}.", configName, configurationItem.TryGetProperty(InternalSchema.UserConfigurationType));
                    ExTraceGlobals.UserConfigurationTracer.TraceError((long)this.GetHashCode(), "UserConfiguration::Get. The configuration type has been corrupted. PropValue = {0}.", new object[]
                    {
                        configurationItem.TryGetProperty(InternalSchema.UserConfigurationType)
                    });
                    throw new CorruptDataException(ServerStrings.ExConfigDataCorrupted("ConfigurationType"));
                }
                UserConfigurationTypes type = UserConfiguration.CheckUserConfigurationType((int)obj);
                ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName>((long)this.GetHashCode(), "UserConfigurationCache::Get. Hit the cache. ConfigName = {0}.", configName);
                UserConfiguration userConfiguration = new UserConfiguration(configurationItem, folderId, configName, type, true);
                flag2  = true;
                result = userConfiguration;
            }
            catch (ObjectNotFoundException)
            {
                ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName>((long)this.GetHashCode(), "UserConfigurationCache::Get. Miss the cache. The object has been deleted. ConfigName = {0}.", configName);
                ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName>((long)this.GetHashCode(), "The user configuration object cannot be found though we hold its itemId in cache. ConfigName = {0}.", configName);
                this.Remove(configName, folderId);
                flag   = true;
                result = null;
            }
            finally
            {
                if (!flag2)
                {
                    if (configurationItem != null)
                    {
                        configurationItem.Dispose();
                    }
                    if (flag && this.mailboxSession.LogonType == LogonType.Owner)
                    {
                        this.Save();
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        private static UserConfiguration BuildConfigurationFromQueryItem(Folder folder, IStorePropertyBag row, bool hasLoadedUserConfigurationData)
        {
            if (PropertyError.IsPropertyError(row.TryGetProperty(InternalSchema.ItemClass)))
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "The configuration data's field has been corrupted. Field = ItemClass.");
                throw new CorruptDataException(ServerStrings.ExConfigDataCorrupted("ItemClass"));
            }
            if (PropertyError.IsPropertyError(row.TryGetProperty(InternalSchema.ItemId)))
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "The configuration data's field has been corrupted. Field = Id.");
                throw new CorruptDataException(ServerStrings.ExConfigDataCorrupted("Id"));
            }
            if (PropertyError.IsPropertyError(row.TryGetProperty(InternalSchema.UserConfigurationType)))
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "The configuration data's field has been corrupted. Field = UserConfigurationType.");
                throw new CorruptDataException(ServerStrings.ExConfigDataCorrupted("UserConfigurationType"));
            }
            string name = (string)row[InternalSchema.ItemClass];

            if (!UserConfigurationName.IsValidName(name, ConfigurationNameKind.ItemClass))
            {
                return(null);
            }
            UserConfigurationName configurationName = new UserConfigurationName(name, ConfigurationNameKind.ItemClass);

            if (hasLoadedUserConfigurationData)
            {
                object dictionaryObject = UserConfiguration.CheckDictionaryData(row.TryGetProperty(InternalSchema.UserConfigurationDictionary));
                return(new UserConfiguration(configurationName, folder.Session, folder.Id.ObjectId, (VersionedId)row[InternalSchema.ItemId], dictionaryObject, UserConfiguration.CheckUserConfigurationType((int)row[InternalSchema.UserConfigurationType]), row));
            }
            return(new UserConfiguration(configurationName, folder.Session, folder.Id.ObjectId, (VersionedId)row[InternalSchema.ItemId], null, UserConfiguration.CheckUserConfigurationType((int)row[InternalSchema.UserConfigurationType]), row));
        }