Example #1
0
        public static List <WorkItemTypeMapping> CreateWorkItemTypeMapping(WorkItemTypeCollection workItemTypes1, WorkItemTypeCollection workItemTypes2, Dictionary <string, string> manualMappings)
        {
            var result = new List <WorkItemTypeMapping>();

            foreach (WorkItemType sourceWorkItemType in workItemTypes1)
            {
                var query = workItemTypes2.Cast <WorkItemType>().Where(p => p.Name == sourceWorkItemType.Name);
                var targetWorkItemType = query.FirstOrDefault();
                if (targetWorkItemType != null)
                {
                    result.Add(new WorkItemTypeMapping()
                    {
                        SourceWorkItemType    = sourceWorkItemType.Name,
                        TargetWorkItemType    = targetWorkItemType.Name,
                        WorkItemFieldMappings = CreateFieldMapping(sourceWorkItemType, targetWorkItemType).ToArray()
                    });
                }
                else if (manualMappings.ContainsKey(sourceWorkItemType.Name))
                {
                    Trace.WriteLine("adding a manual mapping");

                    targetWorkItemType = workItemTypes2.Cast <WorkItemType>().Where(p => p.Name == manualMappings[sourceWorkItemType.Name]).FirstOrDefault();
                    if (targetWorkItemType != null)
                    {
                        result.Add(new WorkItemTypeMapping()
                        {
                            SourceWorkItemType    = sourceWorkItemType.Name,
                            TargetWorkItemType    = targetWorkItemType.Name,
                            WorkItemFieldMappings = CreateFieldMapping(sourceWorkItemType, targetWorkItemType).ToArray()
                        });
                    }
                    else
                    {
                        Trace.TraceError($"The target WorkItemType manually mapped with {sourceWorkItemType.Name}:{manualMappings[sourceWorkItemType.Name]} was not found in the TargetProject");
                    }
                }
                else
                {
                    Trace.WriteLine($"WorkItemType {sourceWorkItemType.Name} was not found in targetproject!");
                }
            }

            return(result);
        }
Example #2
0
        /// <summary>
        ///     Finds the type of the work item.
        /// </summary>
        /// <param name="workItemTypeName">Name of the work item type.</param>
        /// <returns>WorkItemType.</returns>
        internal static WorkItemType FindWorkItemType(string workItemTypeName)
        {
            CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml");
            var uri = new Uri(credentials.VsoCollection);
            var tpc = new TfsTeamProjectCollection(uri);

            tpc.EnsureAuthenticated();
            var                    workItemStore = tpc.GetService <WorkItemStore>();
            const string           projectName   = "RestPlaypen";
            Project                item          = workItemStore.Projects[projectName];
            WorkItemTypeCollection workItemTypes = item.WorkItemTypes;
            WorkItemType           workItemType  = workItemTypes.Cast <WorkItemType>().First(entry => entry.Name == workItemTypeName);

            return(workItemType);
        }