예제 #1
0
        internal static void Delete(Folder folder, string searchString, UserConfigurationSearchFlags searchFlags)
        {
            EnumValidator.AssertValid <UserConfigurationSearchFlags>(searchFlags);
            if (searchFlags != UserConfigurationSearchFlags.SubString && searchFlags != UserConfigurationSearchFlags.FullString && searchFlags != UserConfigurationSearchFlags.Prefix)
            {
                ExTraceGlobals.StorageTracer.TraceError <UserConfigurationSearchFlags>(0L, "UserConfiguration::FindItems. The search flag is not supported. searchFlags = {0}.", searchFlags);
                throw new NotSupportedException();
            }
            IList <IStorePropertyBag> list = null;

            try
            {
                list = UserConfiguration.QueryConfigurations(folder, null, new UserConfigurationName(searchString, ConfigurationNameKind.PartialName), searchFlags, StorageLimits.Instance.UserConfigurationMaxSearched, new PropertyDefinition[0]);
            }
            catch (InvalidOperationException innerException)
            {
                throw new InvalidOperationException(ServerStrings.ExCannotQueryAssociatedTable, innerException);
            }
            List <VersionedId> list2 = new List <VersionedId>();

            for (int i = 0; i < list.Count; i++)
            {
                list2.Add((VersionedId)list[i][InternalSchema.ItemId]);
                if (i == list.Count - 1 || list2.Count > 100)
                {
                    AggregateOperationResult result = folder.Session.Delete(DeleteItemFlags.SoftDelete, list2.ToArray());
                    UserConfiguration.CheckOperationResults(result, "Delete");
                    list2.Clear();
                }
            }
        }
예제 #2
0
        private static void AddToConfigurationCache(Folder folder, IList <IStorePropertyBag> items)
        {
            if (items == null || items.Count == 0)
            {
                return;
            }
            MailboxSession mailboxSession = folder.Session as MailboxSession;

            if (mailboxSession == null)
            {
                throw new NotSupportedException();
            }
            UserConfigurationManager userConfigurationManager = mailboxSession.UserConfigurationManager;
            List <VersionedId>       list = new List <VersionedId>();

            new List <int>();
            string a = null;

            for (int i = 0; i < items.Count; i++)
            {
                IStorePropertyBag storePropertyBag = items[i];
                if (PropertyError.IsPropertyError(storePropertyBag.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(storePropertyBag.TryGetProperty(InternalSchema.ItemId)))
                {
                    ExTraceGlobals.StorageTracer.TraceError(0L, "The configuration data's field has been corrupted. Field = Id.");
                    throw new CorruptDataException(ServerStrings.ExConfigDataCorrupted("Id"));
                }
                string b = storePropertyBag.TryGetProperty(InternalSchema.ItemClass) as string;
                if (a == b)
                {
                    list.Add((VersionedId)storePropertyBag[InternalSchema.ItemId]);
                    items.RemoveAt(i);
                    i--;
                }
                else
                {
                    string name = (string)storePropertyBag[InternalSchema.ItemClass];
                    if (UserConfigurationName.IsValidName(name, ConfigurationNameKind.ItemClass))
                    {
                        userConfigurationManager.UserConfigurationCache.Add(folder.Id.ObjectId, new UserConfigurationName(name, ConfigurationNameKind.ItemClass), ((VersionedId)storePropertyBag[InternalSchema.ItemId]).ObjectId);
                    }
                }
                a = (storePropertyBag.TryGetProperty(InternalSchema.ItemClass) as string);
            }
            if (folder.Session.LogonType == LogonType.Owner)
            {
                userConfigurationManager.UserConfigurationCache.Save();
            }
            AggregateOperationResult result = folder.Session.Delete(DeleteItemFlags.SoftDelete, list.ToArray());

            UserConfiguration.CheckOperationResults(result, "DeleteDuplicates");
        }
예제 #3
0
        internal static UserConfiguration GetIgnoringCache(UserConfigurationManager manager, Folder folder, UserConfigurationName configurationName, UserConfigurationTypes freefetchType)
        {
            EnumValidator.AssertValid <UserConfigurationTypes>(freefetchType);
            UserConfiguration userConfiguration = null;

            PropertyDefinition[] columns;
            if ((freefetchType & UserConfigurationTypes.Dictionary) > (UserConfigurationTypes)0)
            {
                columns = new PropertyDefinition[]
                {
                    InternalSchema.UserConfigurationDictionary
                };
            }
            else
            {
                columns = UserConfiguration.ZeroProperties;
            }
            SortBy[] sorts = new SortBy[]
            {
                new SortBy(InternalSchema.CreationTime, SortOrder.Ascending),
                new SortBy(InternalSchema.MID, SortOrder.Ascending)
            };
            IList <IStorePropertyBag> list = null;

            try
            {
                ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName>(0L, "UserConfiguration::GetIgnoringCache. Hit Query. ConfigName = {0}.", configurationName);
                list = UserConfiguration.QueryConfigurations(folder, sorts, configurationName, UserConfigurationSearchFlags.FullString, 2, columns);
            }
            catch (InvalidOperationException innerException)
            {
                throw new InvalidOperationException(ServerStrings.ExCannotQueryAssociatedTable, innerException);
            }
            if (list.Count <= 0)
            {
                ExTraceGlobals.StorageTracer.TraceError <UserConfigurationName, UserConfigurationTypes>(0L, "UserConfiguration::GetIgnoringCache. The configuration object was not found. Name = {0}, type = {1}.", configurationName, freefetchType);
                throw new ObjectNotFoundException(ServerStrings.ExConfigurationNotFound(configurationName.Name));
            }
            ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName>(0L, "UserConfiguration::GetIgnoringCache. Find the config item and build user config object from it. ConfigName = {0}.", configurationName);
            bool flag = false;
            UserConfiguration result2;

            try
            {
                userConfiguration = UserConfiguration.BuildConfigurationFromQueryItem(folder, list[0], (freefetchType & UserConfigurationTypes.Dictionary) > (UserConfigurationTypes)0);
                if (list.Count > 1)
                {
                    ExTraceGlobals.UserConfigurationTracer.TraceDebug <UserConfigurationName>(0L, "UserConfiguration::GetIgnoringCache. Found duplicate items. Conflict resolution. ConfigName = {0}.", configurationName);
                    List <VersionedId> list2 = new List <VersionedId>();
                    list = UserConfiguration.QueryConfigurations(folder, sorts, configurationName, UserConfigurationSearchFlags.FullString, 100, new PropertyDefinition[0]);
                    for (int i = 1; i < list.Count; i++)
                    {
                        list2.Add((VersionedId)list[i][InternalSchema.ItemId]);
                    }
                    if (list2.Count > 0)
                    {
                        AggregateOperationResult result = folder.Session.Delete(DeleteItemFlags.HardDelete, list2.ToArray());
                        UserConfiguration.CheckOperationResults(result, "DeleteDuplicates");
                    }
                }
                flag    = true;
                result2 = userConfiguration;
            }
            finally
            {
                if (!flag && userConfiguration != null)
                {
                    userConfiguration.Dispose();
                }
            }
            return(result2);
        }