示例#1
0
        public QueryResult FolderQuery(FolderQueryFlags queryFlags, QueryFilter queryFilter, SortBy[] sortColumns, ICollection <PropertyDefinition> dataColumns)
        {
            EnumValidator.ThrowIfInvalid <FolderQueryFlags>(queryFlags, "queryFlags");
            Util.ThrowOnNullArgument(dataColumns, "dataColumns");
            HierarchyTableFlags hierarchyTableFlags = HierarchyTableFlags.None;

            if ((queryFlags & FolderQueryFlags.NoNotifications) == FolderQueryFlags.NoNotifications)
            {
                hierarchyTableFlags |= HierarchyTableFlags.NoNotifications;
            }
            if ((queryFlags & FolderQueryFlags.SuppressNotificationsOnMyActions) == FolderQueryFlags.SuppressNotificationsOnMyActions)
            {
                hierarchyTableFlags |= HierarchyTableFlags.SuppressNotificationsOnMyActions;
            }
            if ((queryFlags & FolderQueryFlags.SoftDeleted) == FolderQueryFlags.SoftDeleted)
            {
                hierarchyTableFlags |= HierarchyTableFlags.ShowSoftDeletes;
            }
            if ((queryFlags & FolderQueryFlags.DeepTraversal) == FolderQueryFlags.DeepTraversal)
            {
                hierarchyTableFlags |= HierarchyTableFlags.ConvenientDepth;
            }
            else
            {
                hierarchyTableFlags |= HierarchyTableFlags.DeferredErrors;
            }
            if ((queryFlags & FolderQueryFlags.DeepTraversal) == FolderQueryFlags.DeepTraversal && sortColumns != null)
            {
                throw new NotSupportedException(ServerStrings.ExSortNotSupportedInDeepTraversalQuery);
            }
            MapiTable   mapiTable   = null;
            QueryResult queryResult = null;
            bool        flag        = false;
            QueryResult result;

            try
            {
                StoreSession storeSession = this.session;
                bool         flag2        = false;
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.BeginMapiCall();
                        storeSession.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    mapiTable = this.MapiFolder.GetHierarchyTable(hierarchyTableFlags);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotGetHierarchyTable, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("Folder::FolderQuery.", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotGetHierarchyTable, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("Folder::FolderQuery.", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (storeSession != null)
                        {
                            storeSession.EndMapiCall();
                            if (flag2)
                            {
                                storeSession.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                queryResult = this.CreateQueryResult(mapiTable, queryFilter, sortColumns, dataColumns);
                flag        = true;
                result      = queryResult;
            }
            finally
            {
                if (!flag)
                {
                    if (queryResult != null)
                    {
                        queryResult.Dispose();
                        queryResult = null;
                    }
                    if (mapiTable != null)
                    {
                        mapiTable.Dispose();
                        mapiTable = null;
                    }
                }
            }
            return(result);
        }
        private Dictionary <string, DefaultFolderManager.FolderData> ReadFolderData()
        {
            MapiFolder   mapiFolder   = null;
            StoreSession storeSession = this.Session;
            bool         flag         = false;

            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                mapiFolder = this.session.Mailbox.MapiStore.GetNonIpmSubtreeFolder();
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.ExCannotReadFolderData, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("DefaultFolderManager::ReadFolderData.", new object[0]),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.ExCannotReadFolderData, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("DefaultFolderManager::ReadFolderData.", new object[0]),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            Dictionary <string, DefaultFolderManager.FolderData> result;

            using (mapiFolder)
            {
                HierarchyTableFlags flags         = HierarchyTableFlags.ConvenientDepth;
                MapiTable           mapiTable     = null;
                StoreSession        storeSession2 = this.Session;
                bool   flag2 = false;
                byte[] inboxFolderEntryId;
                try
                {
                    if (storeSession2 != null)
                    {
                        storeSession2.BeginMapiCall();
                        storeSession2.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    mapiTable          = mapiFolder.GetHierarchyTable(flags);
                    inboxFolderEntryId = this.Session.Mailbox.MapiStore.GetInboxFolderEntryId();
                }
                catch (MapiPermanentException ex3)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ExCannotReadFolderData, ex3, storeSession2, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("DefaultFolderManager::ReadFolderData.", new object[0]),
                        ex3
                    });
                }
                catch (MapiRetryableException ex4)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ExCannotReadFolderData, ex4, storeSession2, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("DefaultFolderManager::ReadFolderData.", new object[0]),
                        ex4
                    });
                }
                finally
                {
                    try
                    {
                        if (storeSession2 != null)
                        {
                            storeSession2.EndMapiCall();
                            if (flag2)
                            {
                                storeSession2.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                using (mapiTable)
                {
                    PropTag[] columns = new PropTag[]
                    {
                        (PropTag)InternalSchema.EntryId.PropertyTag,
                        (PropTag)InternalSchema.DisplayName.PropertyTag,
                        (PropTag)InternalSchema.ContainerClass.PropertyTag,
                        (PropTag)InternalSchema.ParentEntryId.PropertyTag,
                        (PropTag)InternalSchema.MapiFolderType.PropertyTag,
                        (PropTag)InternalSchema.AdminFolderFlags.PropertyTag,
                        (PropTag)InternalSchema.IsHidden.PropertyTag,
                        (PropTag)InternalSchema.SystemFolderFlags.PropertyTag,
                        (PropTag)InternalSchema.ExtendedFolderFlagsInternal.PropertyTag,
                        (PropTag)InternalSchema.DefaultFoldersLocaleId.PropertyTag
                    };
                    PropValue[][] array         = null;
                    StoreSession  storeSession3 = this.Session;
                    bool          flag3         = false;
                    try
                    {
                        if (storeSession3 != null)
                        {
                            storeSession3.BeginMapiCall();
                            storeSession3.BeginServerHealthCall();
                            flag3 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        mapiTable.SetColumns(columns);
                        array = mapiTable.QueryRows(StorageLimits.Instance.DefaultFolderDataCacheMaxRowCount);
                    }
                    catch (MapiPermanentException ex5)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.ExCannotReadFolderData, ex5, storeSession3, this, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("DefaultFolderManager::ReadFolderData.", new object[0]),
                            ex5
                        });
                    }
                    catch (MapiRetryableException ex6)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.ExCannotReadFolderData, ex6, storeSession3, this, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("DefaultFolderManager::ReadFolderData.", new object[0]),
                            ex6
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (storeSession3 != null)
                            {
                                storeSession3.EndMapiCall();
                                if (flag3)
                                {
                                    storeSession3.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                    if (array.Length == StorageLimits.Instance.DefaultFolderDataCacheMaxRowCount)
                    {
                        ExTraceGlobals.DefaultFoldersTracer.TraceDebug <int>((long)this.GetHashCode(), "DefaultFolderManager::ReadFolderData. There are too many folders under IpmSubtree. Some of default folders may have been ignored. Query Rows = {0}.", array.Length);
                    }
                    string      inboxDisplayName = null;
                    CultureInfo stampedCulture   = null;
                    Dictionary <string, DefaultFolderManager.FolderData> dictionary = new Dictionary <string, DefaultFolderManager.FolderData>();
                    foreach (PropValue[] array3 in array)
                    {
                        byte[]            array4              = array3[0].IsError() ? null : array3[0].GetBytes();
                        string            text                = array3[1].IsError() ? null : array3[1].GetString();
                        string            containerClass      = array3[2].IsError() ? null : array3[2].GetString();
                        byte[]            parentEntryId       = array3[3].IsError() ? null : array3[3].GetBytes();
                        FolderType?       arg                 = array3[4].IsError() ? null : new FolderType?((FolderType)array3[4].GetInt());
                        ELCFolderFlags?   elcFolderFlags      = array3[5].IsError() ? null : new ELCFolderFlags?((ELCFolderFlags)array3[5].GetInt());
                        bool              isHidden            = !array3[6].IsError() && array3[6].GetBoolean();
                        SystemFolderFlags?systemFolderFlags   = array3[7].IsError() ? null : new SystemFolderFlags?((SystemFolderFlags)array3[7].GetInt());
                        byte[]            extendedFolderFlags = array3[8].IsError() ? null : array3[8].GetBytes();
                        if (array4 != null && text != null && arg != null)
                        {
                            string key = Convert.ToBase64String(array4);
                            if (dictionary.ContainsKey(key))
                            {
                                ExTraceGlobals.DefaultFoldersTracer.TraceError <string, string, FolderType?>((long)this.GetHashCode(), "DefaultFolderManager::ReadFolderData. Store returns duplicate entries from hierarch query. Mailbox = {0}. displayName = {1}, folderType = {2}.", this.Session.DisplayName, text, arg);
                            }
                            else
                            {
                                dictionary.Add(key, new DefaultFolderManager.FolderData(text, arg.Value, containerClass, parentEntryId, elcFolderFlags, isHidden, systemFolderFlags, extendedFolderFlags));
                                if (array4.SequenceEqual(inboxFolderEntryId))
                                {
                                    int?num = new int?(array3[9].GetInt());
                                    if (num != null && num.Value >= 0)
                                    {
                                        stampedCulture = LocaleMap.GetCultureFromLcid(num.Value);
                                    }
                                }
                            }
                        }
                    }
                    this.session.SharedDataManager.DefaultFoldersCulture = this.GetBestCulture(stampedCulture, inboxDisplayName, this.session);
                    result = dictionary;
                }
            }
            return(result);
        }
        /// <summary>
        /// Parse the RopGetHierarchyTableRequest structure.
        /// </summary>
        /// <param name="s">An stream containing RopGetHierarchyTableRequest structure.</param>
        public override void Parse(Stream s)
        {
            base.Parse(s);

            this.RopId = (RopIdType)ReadByte();
            this.LogonId = ReadByte();
            this.InputHandleIndex = ReadByte();
            this.OutputHandleIndex = ReadByte();
            this.TableFlags = (HierarchyTableFlags)ReadByte();
        }