Ejemplo n.º 1
0
        protected override void ProcessRecordInEH()
        {
            WorkItemStore       workItemStore = EnsureWorkItemStore();
            WorkItemLinkTypeEnd linkTypeEnd   = EnsureWorkItemLinkTypeEnd(workItemStore);

            WorkItem[] workItems = QueryFromWorkItems(workItemStore).ToArray();
            if (workItems.Length == 0)
            {
                return;
            }

            WorkItem toWorkItem = workItemStore.GetWorkItem(RelatedWorkItemId);

            if (toWorkItem == null)
            {
                throw new ArgumentException(string.Format("Invalid to work item id: {0}.", RelatedWorkItemId));
            }

            foreach (var workItem in workItems)
            {
                workItem.Links.Add(new RelatedLink(linkTypeEnd, toWorkItem.Id));
                WriteObject(workItem);
            }

            workItemStore.BatchSave(workItems, SaveFlags.MergeLinks);
        }
Ejemplo n.º 2
0
        private List <WorkItem> SaveWorkItems(WorkItemsStageConfiguration mapping, WitMappingIndex index, WorkItemStore destWIStore, List <WorkItem> changedWorkItems, bool testOnly)
        {
            var failedWorkItems = new List <WorkItem>();

            if (testOnly)
            {
                eventSink.SavingSkipped();
            }
            else
            {
                var errors = destWIStore.BatchSave(changedWorkItems.ToArray(), SaveFlags.MergeAll);
                failedWorkItems = ExamineSaveErrors(errors, index);
            }//if

            var validWorkItems = changedWorkItems.Except(failedWorkItems);

            // some succeeded: their Ids could be changed, so refresh index
            if (!testOnly)
            {
                UpdateIndex(index, validWorkItems, mapping);
                foreach (var item in validWorkItems)
                {
                    this.ChangeLog.AddEntry(
                        new WorkItemChangeEntry(
                            index.GetSourceIdFromTargetId(item.Id),
                            item.Id,
                            item.IsNew ? WorkItemChangeEntry.Change.New : WorkItemChangeEntry.Change.Update));
                } //for
            }     //if

            return(validWorkItems.ToList());
        }
Ejemplo n.º 3
0
 private void SaveLinks(WorkItemsStageConfiguration mapping, WitMappingIndex index, WorkItemStore destWIStore, IEnumerable <WorkItem> changedWorkItems, bool testOnly)
 {
     if (testOnly)
     {
         eventSink.SavingSkipped();
     }
     else
     {
         var errors = destWIStore.BatchSave(changedWorkItems.ToArray(), SaveFlags.MergeAll);
         ExamineSaveErrors(errors, index);
     }//if
 }
Ejemplo n.º 4
0
        protected override void ProcessRecordInEH()
        {
            PrepareForProcessing();

            WorkItemStore workItemStore = EnsureWorkItemStore();

            WorkItem[] workItems = QueryFromWorkItems(workItemStore).ToArray();
            if (workItems.Length == 0)
            {
                return;
            }

            foreach (var workItem in workItems)
            {
                // If any link needs to be removed, add it into pending removing list and remove it later.
                // We do this to avoid potential errors in removing during enumeration.
                List <Link> pendingRemovingLinks = new List <Link>();

                foreach (Link link in workItem.Links)
                {
                    bool needsToBeRemoved = false;

                    switch (link.BaseType)
                    {
                    case BaseLinkType.RelatedLink:
                        needsToBeRemoved = NeedsToBeRemovedDueToWorkItemRelationMatched(link as RelatedLink);
                        break;

                    case BaseLinkType.Hyperlink:
                        needsToBeRemoved = NeedsToBeRemovedDueToHyperlinkMatched(link as Hyperlink);
                        break;
                    }

                    if (needsToBeRemoved)
                    {
                        pendingRemovingLinks.Add(link);
                    }
                }

                foreach (var pendingRemovingLink in pendingRemovingLinks)
                {
                    workItem.Links.Remove(pendingRemovingLink);
                }
            }

            workItemStore.BatchSave(workItems, SaveFlags.MergeLinks);

            foreach (var workItem in workItems)
            {
                WriteObject(workItem);
            }
        }
Ejemplo n.º 5
0
        protected override void ProcessRecordInEH()
        {
            WorkItemStore workItemStore = EnsureWorkItemStore();

            WorkItem[] workItems = QueryFromWorkItems(workItemStore).ToArray();
            if (workItems.Length == 0)
            {
                return;
            }

            AddWorkItemRelationLinkToWorkItemsIfNeeded(workItemStore, workItems);
            AddHyperlinkToWorkItemsIfNeeded(workItems);
            workItemStore.BatchSave(workItems, SaveFlags.MergeLinks);

            foreach (var workItem in workItems)
            {
                WriteObject(workItem);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the work items.
        /// </summary>
        /// <param name="baseWorkItemIds">The base work item ids.</param>
        /// <param name="selectedPlanningTemplate">The selected planning template.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">
        /// Invalid WorkItemType
        /// or
        /// or
        /// Invalid WorkItemLinkType
        /// </exception>
        public WorkItem[] CreateRelatedWorkItems(int[] baseWorkItemIds, PlanningTemplate selectedPlanningTemplate)
        {
            TfsTeamProjectCollection projectCollection = this.GetTeamProjectCollection();
            WorkItemStore            store             = projectCollection.GetService <WorkItemStore>();

            Dictionary <WorkItemField, String> workItemFieldMatches = new Dictionary <WorkItemField, string>(ConfigurationManager.CurrentConfiguration.WorkItemFieldMatches.Count);

            // Load default fields from configuration
            foreach (WorkItemFieldMatch workItemFieldMatch in ConfigurationManager.CurrentConfiguration.WorkItemFieldMatches)
            {
                workItemFieldMatches.Add(workItemFieldMatch.Field, workItemFieldMatch.Value);
            }


            List <WorkItem> workItemsToSave = new List <WorkItem>();

            foreach (int workItemId in baseWorkItemIds)
            {
                WorkItem baseWorkItem = store.GetWorkItem(workItemId);
                Project  project      = baseWorkItem.Project;

                foreach (TaskTemplate taskTemplate in selectedPlanningTemplate.TasksToCreateCollection)
                {
                    // If Task Quantity is zero, ignore it
                    if (taskTemplate.Quantity <= 0)
                    {
                        continue;
                    }

                    #region Get Work Item Type

                    // Check if the Work Item Type exists
                    if (!project.WorkItemTypes.Contains(taskTemplate.WorkItemType))
                    {
                        throw new ArgumentException("Invalid WorkItemType");
                    }

                    WorkItemType wiType = project.WorkItemTypes[taskTemplate.WorkItemType];

                    #endregion

                    // Predefined fields match
                    foreach (KeyValuePair <WorkItemField, String> fields in workItemFieldMatches)
                    {
                        if (!wiType.FieldDefinitions.Contains(workItemFieldMatches[WorkItemField.AssignedTo]))
                        {
                            throw new ArgumentException(String.Format("WorkItem {0} doesn't contain field with name {1}", taskTemplate.WorkItemType, workItemFieldMatches[WorkItemField.AssignedTo]));
                        }
                    }

                    // Get the relation link type
                    if (!store.WorkItemLinkTypes.Contains(taskTemplate.WorkItemLinkType))
                    {
                        throw new ArgumentException("Invalid WorkItemLinkType");
                    }

                    WorkItemLinkTypeEnd relationLinkType = store.WorkItemLinkTypes[taskTemplate.WorkItemLinkType].ReverseEnd;

                    foreach (TaskTemplateInstance taskTemplateInstance in taskTemplate.InstancesCollection)
                    {
                        WorkItem newWorkItem = wiType.NewWorkItem();

                        newWorkItem.AreaId        = baseWorkItem.AreaId;
                        newWorkItem.AreaPath      = baseWorkItem.AreaPath;
                        newWorkItem.IterationPath = baseWorkItem.IterationPath;

                        // Copy Tags
                        if (!String.IsNullOrWhiteSpace(baseWorkItem.Tags))
                        {
                            newWorkItem["Tags"] = baseWorkItem.Tags;
                        }

                        newWorkItem.Title = String.Format("{0}{1}{2}", taskTemplate.Prefix, baseWorkItem.Title, taskTemplate.Sufix);

                        // AssignedTo
                        newWorkItem.UpdateField(workItemFieldMatches[WorkItemField.AssignedTo], taskTemplateInstance.AssignedTo);

                        // Original Estimate
                        newWorkItem.UpdateField(workItemFieldMatches[WorkItemField.OriginalEstimate], taskTemplateInstance.EstimatedTime);

                        // Remaining Work
                        newWorkItem.UpdateField(workItemFieldMatches[WorkItemField.RemainingWork], taskTemplateInstance.EstimatedTime);

                        // Custom Properties
                        if (taskTemplate.CustomProperties != null && taskTemplate.CustomProperties.Count > 0)
                        {
                            foreach (TaskTemplateCustomProperty customProperty in taskTemplate.CustomProperties)
                            {
                                newWorkItem.UpdateField(customProperty.Name, customProperty.Value);
                            }
                        }

                        if (taskTemplate.IsCopyDescriptionEnabled)
                        {
                            newWorkItem.Description = baseWorkItem.Description;

                            if (String.IsNullOrWhiteSpace(newWorkItem.Description))
                            {
                                // Maybe this is a bug
                                if (baseWorkItem.Fields.Contains("Repro Steps"))
                                {
                                    newWorkItem.Description = baseWorkItem.Fields["Repro Steps"].Value.ToString();
                                }
                            }
                        }

                        newWorkItem.Links.Add(new RelatedLink(relationLinkType, baseWorkItem.Id));

                        workItemsToSave.Add(newWorkItem);
                    }
                }
            }

            var witems = workItemsToSave.ToArray();

            store.BatchSave(witems);

            return(witems);
        }