コード例 #1
0
        private SortOrder GetSortOrder(MapiTable table, SortBy[] sortColumns, GroupByAndOrder[] groupBy, int expandCount, ref List <PropTag> alteredProperties)
        {
            if ((sortColumns == null || sortColumns.Length == 0) && (groupBy == null || groupBy.Length == 0))
            {
                return(null);
            }
            SortOrder sortOrder = new SortOrder();

            if (groupBy != null)
            {
                for (int i = 0; i < groupBy.Length; i++)
                {
                    NativeStorePropertyDefinition nativeGroupBy = InternalSchema.ToStorePropertyDefinition(groupBy[i].GroupByColumn).GetNativeGroupBy();
                    PropTag   sortPropertyTag  = this.GetSortPropertyTag(nativeGroupBy, ref alteredProperties);
                    GroupSort nativeGroupSort  = InternalSchema.ToStorePropertyDefinition(groupBy[i].GroupSortColumn.ColumnDefinition).GetNativeGroupSort(groupBy[i].GroupSortColumn.SortOrder, groupBy[i].GroupSortColumn.Aggregate);
                    PropTag   sortPropertyTag2 = this.GetSortPropertyTag((NativeStorePropertyDefinition)nativeGroupSort.ColumnDefinition, ref alteredProperties);
                    SortFlags sortFlag;
                    switch (nativeGroupSort.Aggregate)
                    {
                    case Aggregate.Min:
                        sortFlag = SortFlags.CategoryMin;
                        break;

                    case Aggregate.Max:
                        sortFlag = SortFlags.CategoryMax;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("groupBy", nativeGroupSort.Aggregate, ServerStrings.ExInvalidAggregate);
                    }
                    sortOrder.AddCategory(sortPropertyTag, QueryExecutor.SortOrderToSortFlags(nativeGroupSort.SortOrder));
                    if (sortPropertyTag != sortPropertyTag2)
                    {
                        sortOrder.Add(sortPropertyTag2, sortFlag);
                    }
                }
                sortOrder.ExpandCount = expandCount;
            }
            if (sortOrder.GetSortCount() > 4)
            {
                throw new ArgumentException(ServerStrings.ExTooComplexGroupSortParameter, "groupBy");
            }
            if (sortColumns != null && sortColumns.Length > 0)
            {
                SortBy[] nativeSortBy = QueryExecutor.GetNativeSortBy(sortColumns);
                if (nativeSortBy.Length + sortOrder.GetSortCount() > 6)
                {
                    throw new ArgumentOutOfRangeException("sortColumns", ServerStrings.ExTooManySortColumns);
                }
                for (int j = 0; j < nativeSortBy.Length; j++)
                {
                    PropertyDefinition columnDefinition = nativeSortBy[j].ColumnDefinition;
                    PropTag            sortPropertyTag3 = this.GetSortPropertyTag((NativeStorePropertyDefinition)columnDefinition, ref alteredProperties);
                    sortOrder.Add(sortPropertyTag3, QueryExecutor.SortOrderToSortFlags(nativeSortBy[j].SortOrder));
                }
            }
            return(sortOrder);
        }
コード例 #2
0
 public GroupByAndOrder(PropertyDefinition groupByColumn, GroupSort groupSortColumn)
 {
     this.GroupByColumn   = groupByColumn;
     this.GroupSortColumn = groupSortColumn;
 }
コード例 #3
0
        public GroupedQueryResult GroupedItemQuery(QueryFilter queryFilter, PropertyDefinition groupBy, GroupSort groupSort, SortBy[] sortColumns, params PropertyDefinition[] dataColumns)
        {
            if (groupBy == null)
            {
                throw new ArgumentNullException("groupBy");
            }
            if (groupSort == null)
            {
                throw new ArgumentNullException("groupSort");
            }
            if (dataColumns == null)
            {
                throw new ArgumentNullException("dataColumns");
            }
            int  rowTypeColumnIndex = 0;
            bool flag = false;

            for (int i = 0; i < dataColumns.Length; i++)
            {
                if (InternalSchema.RowType.Equals(dataColumns[i]))
                {
                    rowTypeColumnIndex = i;
                    flag = true;
                    break;
                }
            }
            PropertyDefinition[] array = dataColumns;
            if (!flag)
            {
                array = new PropertyDefinition[dataColumns.Length + 1];
                dataColumns.CopyTo(array, 0);
                array[dataColumns.Length] = InternalSchema.RowType;
                rowTypeColumnIndex        = dataColumns.Length;
            }
            MapiTable          mapiTable          = this.GetContentsTable(ContentsTableFlags.DeferredErrors);
            GroupedQueryResult groupedQueryResult = null;
            bool flag2 = false;
            int  estimatedItemCount = 0;
            GroupedQueryResult result;

            try
            {
                List <PropTag> alteredProperties = null;
                this.SetTableFilter(mapiTable, queryFilter);
                StoreSession storeSession = this.session;
                bool         flag3        = false;
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.BeginMapiCall();
                        storeSession.BeginServerHealthCall();
                        flag3 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    estimatedItemCount = mapiTable.GetRowCount();
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotGetRowCount, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("Folder::GroupedItemQuery.", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotGetRowCount, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("Folder::GroupedItemQuery.", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (storeSession != null)
                        {
                            storeSession.EndMapiCall();
                            if (flag3)
                            {
                                storeSession.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                SortOrder sortOrder = this.GetSortOrder(mapiTable, sortColumns, new GroupByAndOrder[]
                {
                    new GroupByAndOrder(groupBy, groupSort)
                }, 1, ref alteredProperties);
                groupedQueryResult = new GroupedQueryResult(mapiTable, array, alteredProperties, rowTypeColumnIndex, flag, this.Session, estimatedItemCount, sortOrder);
                if (this.Session != null)
                {
                    this.Session.MessagesWereDownloaded = true;
                }
                flag2  = true;
                result = groupedQueryResult;
            }
            finally
            {
                if (!flag2)
                {
                    if (groupedQueryResult != null)
                    {
                        groupedQueryResult.Dispose();
                        groupedQueryResult = null;
                    }
                    if (mapiTable != null)
                    {
                        mapiTable.Dispose();
                        mapiTable = null;
                    }
                }
            }
            return(result);
        }