Пример #1
0
        public DataBlock GetItemBlock(IEnumerable <ItemIdentity> items, IEnumerable <string> columnNames)
        {
            // Build a query for them
            string query = String.Format("SELECT [System.Id] FROM WorkItems WHERE [System.Id] IN ({0})", String.Join(", ", items.Select((ii) => ii.ID)));
            Query  q     = new Query(this.Store, query, null, false);

            // Ask for fields we'll be populating to avoid additional network requests
            q.DisplayFieldList.Clear();
            foreach (string columnName in columnNames)
            {
                if (this.Store.FieldDefinitions.Contains(columnName))
                {
                    q.DisplayFieldList.Add(this.Store.FieldDefinitions[columnName]);
                }
                else if (columnName.Equals("attachments", StringComparison.OrdinalIgnoreCase))
                {
                    // Add AttachedFileCount to greatly speed loading attachments (if this is the only collection; rare)
                    q.DisplayFieldList.Add(this.Store.FieldDefinitions[CoreField.AttachedFileCount]);
                }
            }

            // Build a list of typed column details for the columns being used
            List <ColumnDetails> selectedDetails = new List <ColumnDetails>();

            foreach (string columnName in columnNames)
            {
                selectedDetails.Add(this.Columns[columnName]);
            }

            // Run the query
            ICancelableAsyncResult car            = q.BeginQuery();
            WorkItemCollection     itemCollection = q.EndQuery(car);

            // Copy the item field values into a DataBlock and track the last cutoff per group
            DataBlock result = new DataBlock(selectedDetails, items.Count());

            for (int itemIndex = 0; itemIndex < result.RowCount; ++itemIndex)
            {
                WorkItem item = itemCollection[itemIndex];

                int fieldIndex = 0;
                foreach (string columnName in columnNames)
                {
                    try
                    {
                        result[itemIndex, fieldIndex] = ItemProviderUtilities.Canonicalize(GetFieldValue(item, columnName));
                    }
                    catch (Exception ex)
                    {
                        result[itemIndex, fieldIndex] = null;
                        Trace.WriteLine(String.Format("Error Getting '{0}' from item {1}. Skipping field. Detail: {2}", columnName, item.Id, ex.ToString()));
                    }

                    fieldIndex++;
                }
            }

            return(result);
        }
Пример #2
0
        private List <ItemIdentity> ExtractOneSet(string query, List <ItemIdentity> result)
        {
            Query q = new Query(this.Store, query, null, false);

            // Ask for ID only - we don't need anything else
            q.DisplayFieldList.Clear();
            q.DisplayFieldList.Add(this.Store.FieldDefinitions[CoreField.Id]);
            q.DisplayFieldList.Add(this.Store.FieldDefinitions[CoreField.ChangedDate]);

            // Sort by ChangedDate ascending for restartability
            q.SortFieldList.Clear();
            q.SortFieldList.Add(this.Store.FieldDefinitions[CoreField.ChangedDate].Name, SortType.Ascending);

            try
            {
                // Run the query
                ICancelableAsyncResult car   = q.BeginQuery();
                WorkItemCollection     items = q.EndQuery(car);
                // Set PageSize to Maximum, since we'll be reading all of them anyway.
                items.PageSize = 200;

                // Record the IDs to load
                int count = items.Count;

                for (int i = 0; i < count; ++i)
                {
                    WorkItem item = items[i];
                    result.Add(new ItemIdentity(item.Id, ItemProviderUtilities.CanonicalizeDateTime(item.ChangedDate)));
                }
            }
            catch (VerbatimMessageException ex)
            {
                Match match = Regex.Match(ex.Message, @"VS402337: The number of work items returned exceeds the size limit of (?<BatchSize>\d+)\.");
                if (match.Success)
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(result);
        }