Ejemplo n.º 1
0
        /// <summary>
        /// Gets further details of the links in support of the GetWorkItemsById method
        /// </summary>
        /// <param name="links">The list of work items to get the details for</param>
        /// <param name="q">The query to execute</param>
        /// <returns>A WorkItemCollection containing all requested links</returns>
        private WorkItemCollection GetWorkItemsFromLinkInfo(WorkItemLinkInfo[] links, Query q)
        {
            //Check to see if there are any links to queryy
            if (links == null || links.GetLength(0) < 1)
            {
                return(null);
            }

            //Holds the list of work item ID's to query for
            List <int> wisInBatch = new List <int>();

            // Get IDs for work items represented by post items:
            BatchReadParameterCollection batchReadParameters = new BatchReadParameterCollection();

            try
            {
                //Add all of the work item target ID's to the batch parameters for querying
                for (int wiIndex = 0; wiIndex < links.Length; ++wiIndex)
                {
                    int wiId = links[wiIndex].TargetId;
                    if (wiId != -1 && !wisInBatch.Contains(wiId))
                    {
                        batchReadParameters.Add(new BatchReadParameter(wiId));
                        wisInBatch.Add(wiId);
                    }
                }
                //Get the work item collection which contains all of the ID's
                return(_wis.Query(batchReadParameters, "select [System.Id] from WorkItems"));
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        private WorkItemCollection GetWorkItems(int startIndex, int length)
        {
            Debug.Assert(startIndex >= 0, "startIndex < 0");
            Debug.Assert(length >= 0, "length < 0");
            Debug.Assert(m_idsInQueryResult != null, "m_idsInQueryResult is NULL");

            BatchReadParameterCollection readParams = new BatchReadParameterCollection();
            int index = startIndex;

            for (; length > 0 && index < m_idsInQueryResult.Length; ++index)
            {
                readParams.Add(new BatchReadParameter(m_idsInQueryResult[index]));
                --length;
            }

            if (readParams.Count == 0)
            {
                return(null);
            }

            WorkItemCollection items = m_store.Query(readParams, BatchReadQuery);

            m_firstItemIdInNextPage = index;
            return(items);
        }
Ejemplo n.º 3
0
        internal static BatchReadParameterCollectionWrapper GetInstance()
        {
            var real = new BatchReadParameterCollection();

            RealInstanceFactory(ref real);
            var instance = (BatchReadParameterCollectionWrapper)BatchReadParameterCollectionWrapper.GetWrapper(real);

            InstanceFactory(ref instance);
            if (instance == null)
            {
                Assert.Inconclusive("Could not Create Test Instance");
            }
            return(instance);
        }
Ejemplo n.º 4
0
        private void GetWorkItems(int startIndex, int length)
        {
            Debug.Assert(startIndex >= 0, "startIndex < 0");
            Debug.Assert(length >= 0, "length < 0");
            Debug.Assert(m_idsInQueryResult != null, "m_idsInQueryResult is NULL");

            BatchReadParameterCollection readParams = new BatchReadParameterCollection();
            int index = startIndex;

            for (; length > 0 && index < m_idsInQueryResult.Length; ++index)
            {
                readParams.Add(new BatchReadParameter(m_idsInQueryResult[index]));
                --length;
            }

            if (readParams.Count == 0)
            {
                m_items           = null;
                m_indexInCurrPage = 0;
                return;
            }

            WorkItemCollection itemsBkup = m_items;
            int pageIndexBkup            = m_indexInCurrPage;
            int collectionIndexBkup      = m_firstItemIdInNextPage;

            try
            {
                m_items                 = m_store.Query(readParams, BatchReadQuery);
                m_indexInCurrPage       = 0;
                m_firstItemIdInNextPage = index;
            }
            catch (Exception)
            {
                m_items                 = itemsBkup;
                m_indexInCurrPage       = pageIndexBkup;
                m_firstItemIdInNextPage = collectionIndexBkup;
                throw;
            }
        }
Ejemplo n.º 5
0
        public void ApplyConfiguration(IConfiguration configuration)
        {
            if (TeamProjectCollection == null)
            {
                return;
            }
            if (configuration == null)
            {
                return;
            }
            if (configuration.QueryId == Guid.Empty)
            {
                var errorMessage = StatusService.EnqueueStatusItem("InvalidQuery");
                errorMessage.Message = "There is no query defined in the configuration. Please choose a query by clicking \"Edit\"";
                return;
            }

            // Before refreshing the data we should verify whether there are unsaved changes that need to be saved
            if (!VerifySaveRequest())
            {
                return;
            }

            var statusItem = StatusService.EnqueueStatusItem("ApplyConfiguration");

            statusItem.Message                 = string.Format("Applying configuration for team project {0}", TeamProject.Name);
            statusItem.IsProgressing           = true;
            statusItem.IsProgressIndeterminate = true;
            // Run the query in order to provide the result data
            var store = TeamProjectCollection.GetService <WorkItemStore>();
            // Get the query based on the Id we keep in the configuration
            QueryDefinition queryDefinition = SaveGetQueryDefinition(store, configuration.QueryId);
            Query           query           = GetQuery(queryDefinition);

            // Only if the query is a link query we perform the fullblown request for data
            if ((query != null) && (query.IsLinkQuery))
            {
                // First get the linking information
                WorkItemLinkInfos = query.RunLinkQuery();
                // Get the configured link type in order to respect it when retrieving the work items
                var linkType = (!string.IsNullOrEmpty(configuration.LinkType)) ? store.WorkItemLinkTypes.FirstOrDefault(type => type.ReferenceName == configuration.LinkType) : null;
                // Now put all TargetIds into a BatchReadParameterCollection in order to get the work items for the links
                // Attention: Consider handling the link types correctly
                var batchReadParams = new BatchReadParameterCollection();
                foreach (var linkInfo in WorkItemLinkInfos)
                {
                    if (linkType == null)
                    {
                        // If there is no link type there is nothing we can check explicitly and therefor we respect any child
                        if (!batchReadParams.Contains(linkInfo.TargetId))
                        {
                            batchReadParams.Add(new BatchReadParameter(linkInfo.TargetId));
                        }
                    }
                    else
                    {
                        // Debug.WriteLink("Link: {0} Source: {1} Target: {2} RefName: {3} Forward: {4} Reverse: {5}", linkInfo.LinkTypeId, linkInfo.SourceId, linkInfo.TargetId, linkType.ReferenceName, linkType.ForwardEnd.Id, linkType.ReverseEnd.Id);
                        // We need to respect the link type.
                        if (IsValidLinkInfo(linkInfo, linkType))
                        {
                            // When the link info is valid according to the current configuration then we consider the work item in our query.
                            if (!batchReadParams.Contains(linkInfo.TargetId))
                            {
                                batchReadParams.Add(new BatchReadParameter(linkInfo.TargetId));
                            }
                        }
                        // When the link type is not valid we also do not consider the item.
                    }
                }
                // Now construct the query to get the work items
                string        batchQuery       = "SELECT {0} FROM WorkItems";
                List <string> displayFields    = (from FieldDefinition fieldDefinition in query.DisplayFieldList select fieldDefinition.ReferenceName).ToList();
                string        displayFieldPart = string.Join(",", displayFields.ToArray());
                if (batchReadParams.Count != 0)
                {
                    batchQuery = string.Format(batchQuery, displayFieldPart);
                    // Run the query and remember the results
                    WorkItems = store.Query(batchReadParams, batchQuery);
                    BuildBacklogItemsList(configuration);
                    BuildChildItemsList(configuration);
                }
                else
                {
                    ApplyChildrenChangesOnUIThread(new List <BacklogChildren>());
                }
            }
            else
            {
                WorkItemLinkInfos = null;
                WorkItems         = query != null?query.RunQuery() : null;

                if (AllChildren != null)
                {
                    AllChildren.Clear();
                }
                if (BacklogChildren.Count > 0)
                {
                    BacklogChildren.Clear();
                }
                if (BackLogItems != null)
                {
                    BackLogItems.Clear();
                }
            }
            PrepareTransitionsMap(configuration);
            OnConfigurationApplied();
        }
        /// <summary>
        /// Gets further details of the links in support of the GetWorkItemsById method
        /// </summary>
        /// <param name="links">The list of work items to get the details for</param>
        /// <param name="q">The query to execute</param>
        /// <returns>A WorkItemCollection containing all requested links</returns>
        private WorkItemCollection GetWorkItemsFromLinkInfo(WorkItemLinkInfo[] links, Query q)
        {
            //Check to see if there are any links to queryy
            if (links == null || links.GetLength(0) < 1)
                return null;

            //Holds the list of work item ID's to query for
            List<int> wisInBatch = new List<int>();

            // Get IDs for work items represented by post items:
            BatchReadParameterCollection batchReadParameters = new BatchReadParameterCollection();

            try
            {
                //Add all of the work item target ID's to the batch parameters for querying
                for (int wiIndex = 0; wiIndex < links.Length; ++wiIndex)
                {
                    int wiId = links[wiIndex].TargetId;
                    if (wiId != -1 && !wisInBatch.Contains(wiId))
                    {
                        batchReadParameters.Add(new BatchReadParameter(wiId));
                        wisInBatch.Add(wiId);
                    }
                }
                //Get the work item collection which contains all of the ID's
                return _wis.Query(batchReadParameters, "select [System.Id] from WorkItems");
            }
            catch
            {
                return null;
            }
        }
 /// <summary>
 /// Performs the Query asynchronously.
 /// </summary>
 /// <param name="workItemStore">The WorkItemStore to query.</param>
 /// <param name="wiql">The query string to execute.</param>
 /// <param name="batchReadParameters">A collection of WorkItem ID and revision pairs.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 public static Task <WorkItemCollection> QueryAsync(this WorkItemStore workItemStore, string wiql, BatchReadParameterCollection batchReadParameters, CancellationToken cancellationToken = new CancellationToken())
 {
     if (workItemStore == null)
     {
         throw new ArgumentNullException("workItemStore");
     }
     return(new Query(workItemStore, wiql, batchReadParameters).RunQueryAsync(cancellationToken));
 }
Ejemplo n.º 8
0
 static partial void RealInstanceFactory(ref BatchReadParameterCollection real, [CallerMemberName] string callerName = "");