public WorkItemLinkInfoDetails(WorkItemLinkInfo linkInfo, WorkItem sourceWorkItem,
     WorkItem targetWorkItem,WorkItemLinkType linkType)
 {
     this.LinkInfo = linkInfo;
     this.SourceWorkItem = sourceWorkItem;
     this.TargetWorkItem = targetWorkItem;
     this.LinkType = linkType;
 }
        /// <summary>
        /// Configures a query shim to simulate Run on TFS Query objects
        /// </summary>
        private void SetupQueryShim(FakeTfsContext tfsContext)
        {
            ShimQuery.ConstructorWorkItemStoreString = (q, ws, wi) =>
            {
                ShimQuery query = new ShimQuery();

                query.QueryStringGet = () => wi;

                q = query;
            };

            var workItem = new ShimWorkItem();
            workItem.IdGet = () => 5;
            workItem.TitleGet = () => "Linked Work Item";

            var workItemLinkInfo = new WorkItemLinkInfo();
            workItemLinkInfo.TargetId = 5;

            tfsContext.AddWorkItem(workItem);

            ShimWorkItemCollection collection = SetupWorkItemCollection(workItem);

            ShimQuery.AllInstances.IsLinkQueryGet = (q) => false;
            ShimQuery.AllInstances.RunQuery = (q) => collection;
            ShimQuery.AllInstances.RunLinkQuery = (q) => new List<WorkItemLinkInfo>() { workItemLinkInfo }.ToArray();
        }
        public bool TryGetOneHopQueryDefinitionWorkItemLinkInfo(out WorkItemLinkInfo[] workItemLinkInfos, TfsTeamProjectCollection tfsTeamProjectCollection, QueryDefinition queryDefinition, string projectName)
        {
            try
            {
                workItemLinkInfos = _teamPilgrimTfsService.GetLinkQueryDefinitionWorkItemLinkInfo(tfsTeamProjectCollection, queryDefinition, projectName);
                return true;
            }
            catch (Exception ex)
            {
                this.Logger().DebugException(ex);
                LastException = ex;
            }

            workItemLinkInfos = null;
            return false;
        }
        /// <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>
        /// Batch retrieves work items based on the ID
        /// </summary>
        /// <param name="links">The list of work item ID's to retrieve the full work item for</param>
        /// <param name="q">The query</param>
        /// <returns>A dictionary where the key is the Work Item ID and the value is the Work Item</returns>
        private Dictionary<int, WorkItem> GetWorkItemsById(WorkItemLinkInfo[] links, Query q)
        {
            //Some place to store the work items and their ID's
            Dictionary<int, WorkItem> results = new Dictionary<int, WorkItem>();

            // Do batch read of work items from collected IDs
            WorkItemCollection workItems = GetWorkItemsFromLinkInfo(links, q);

            //Add the work items to the dictionary. This is necessary because when we
            //construct the layout of the results, we need to get the work items from
            //the ID's so they are ordered correctly.
            if (workItems != null)
            {
                foreach (WorkItem wi in workItems)
                    results.Add(wi.Id, wi);
            }

            return results;
        }
        /// <summary>
        /// 从WorkItemLinkInfo对象中获取WorkItemLinkInfoDetails。
        /// </summary>
        public WorkItemLinkInfoDetails GetDetailsFromWorkItemLinkInfo(WorkItemLinkInfo linkInfo)
        {
            if (linkInfo == null)
            {
                throw new ArgumentNullException("linkInfo");
            }

            if (this.LinkTypes.ContainsKey(linkInfo.LinkTypeId))
            {
                WorkItemLinkInfoDetails details = new WorkItemLinkInfoDetails(
                   linkInfo,
                   this.WorkItemStore.GetWorkItem(linkInfo.SourceId),
                   this.WorkItemStore.GetWorkItem(linkInfo.TargetId),
                   this.LinkTypes[linkInfo.LinkTypeId]);
                return details;
            }
            else
            {
                throw new ApplicationException("Cannot find WorkItemLinkType!");
            }
        }