Exemplo n.º 1
0
 public static IEnumerable <TOutput> ConvertAll <TOutput>(this WorkItemTypeCollection collection, Converter <WorkItemType, TOutput> converter)
 {
     foreach (WorkItemType item in collection)
     {
         yield return(converter(item));
     }
 }
Exemplo n.º 2
0
 public static void ForEach(this WorkItemTypeCollection collection, Action <WorkItemType> action)
 {
     foreach (WorkItemType item in collection)
     {
         action(item);
     }
 }
Exemplo n.º 3
0
        /* Compare work item type definitions and add fields from source work item types and replace workflow */
        public void SetFieldDefinitions(WorkItemTypeCollection workItemTypesSource, Hashtable fieldList)
        {
            foreach (WorkItemType workItemTypeSource in workItemTypesSource)
            {
                WorkItemType workItemTypeTarget = null;
                if (workItemTypeSource.Name == "User Story")
                {
                    workItemTypeTarget = workItemTypes["Product Backlog Item"];
                }
                else if (workItemTypeSource.Name == "Issue")
                {
                    workItemTypeTarget = workItemTypes["Impediment"];
                }
                else
                {
                    workItemTypeTarget = workItemTypes[workItemTypeSource.Name];
                }

                XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false);
                XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false);

                workItemTypeXmlTarget = AddNewFields(workItemTypeXmlSource, workItemTypeXmlTarget, (List <object>)fieldList[workItemTypeTarget.Name]);

                try
                {
                    WorkItemType.Validate(store.Projects[projectName], workItemTypeXmlTarget.InnerXml);
                    store.Projects[projectName].WorkItemTypes.Import(workItemTypeXmlTarget.InnerXml);
                }
                catch (XmlException)
                {
                    logger.Info("XML import falied for " + workItemTypeSource.Name);
                }
            }
        }
 public WorkItemRead(TfsTeamProjectCollection tfs, Project sourceProject)
 {
     this.tfs = tfs;
     projectName = sourceProject.Name;
     store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
     queryCol = store.Projects[sourceProject.Name].QueryHierarchy;
     workItemTypes = store.Projects[sourceProject.Name].WorkItemTypes;
 }
        private void LoadWorkItemTypes()
        {
            WorkItemTypeCollection typesFromServer = TaskBoardService.GetWorkItemTypes();

            WorkItemTypes = typesFromServer;
            OnPropertyChanged("WorkItemTypes");
            LoadWorkItemStates();
        }
Exemplo n.º 6
0
 public WorkItemRead(TfsTeamProjectCollection tfs, Project sourceProject)
 {
     this.tfs      = tfs;
     projectName   = sourceProject.Name;
     store         = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
     queryCol      = store.Projects[sourceProject.Name].QueryHierarchy;
     workItemTypes = store.Projects[sourceProject.Name].WorkItemTypes;
 }
Exemplo n.º 7
0
        internal static WorkItemTypeCollection GetRealInstance()
        {
            WorkItemStore          workItemStore = WorkItemStoreWrapper_UnitTests.GetRealInstance();
            Project                teamProject   = workItemStore.Projects["RestPlaypen"];
            WorkItemTypeCollection real          = teamProject.WorkItemTypes;

            return(real);
        }
        public TPWiWrapper(TeamExplorerIntergator teamExpolorer)
        {
            tpCollection    = teamExpolorer.tpCollection;
            teamProjectName = teamExpolorer.tpName;

            wiStore = (WorkItemStore)tpCollection.GetService(typeof(WorkItemStore));
            qh      = wiStore.Projects[teamProjectName].QueryHierarchy;
            wiTypes = wiStore.Projects[teamProjectName].WorkItemTypes;
        }
        public TPWiWrapper(string tpCollectionUrl, string aTeamProjectName)
        {
            tpCollection    = new TfsTeamProjectCollection(new Uri(tpCollectionUrl));
            teamProjectName = aTeamProjectName;

            wiStore = (WorkItemStore)tpCollection.GetService(typeof(WorkItemStore));
            qh      = wiStore.Projects[teamProjectName].QueryHierarchy;
            wiTypes = wiStore.Projects[teamProjectName].WorkItemTypes;
        }
Exemplo n.º 10
0
        internal static WorkItem GetRealInstance()
        {
            WorkItem real;
            WorkItemTypeCollection workItemTypes = WorkItemTypeCollectionWrapper_UnitTests.GetRealInstance();
            WorkItemType           workItemType  = workItemTypes["Task"];

            real = new WorkItem(workItemType);
            return(real);
        }
Exemplo n.º 11
0
 public static IEnumerable <WorkItemType> Where <WorkItemType>(this WorkItemTypeCollection collection, Func <WorkItemType, bool> predicate)
 {
     foreach (WorkItemType item in collection)
     {
         if (predicate(item))
         {
             yield return(item);
         }
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Create a new instance of TFSAPI Class
        /// </summary>
        /// <param name="TfsCollectionURI">URI to access the TFS Server and project collection</param>
        /// <param name="ProjectName">Default project</param>
        public TFSAPI(Uri TfsCollectionURI, string ProjectName)
        {
            teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(TfsCollectionURI);
            teamProjectCollection.Connect(Microsoft.TeamFoundation.Framework.Common.ConnectOptions.IncludeServices);
            teamProjectCollection.EnsureAuthenticated();

            wiStore = new WorkItemStore(teamProjectCollection);

            workItemTypeCollection = wiStore.Projects[ProjectName].WorkItemTypes;
        }
Exemplo n.º 13
0
        public string ReplaceWorkFlow(WorkItemTypeCollection workItemTypesSource, List <object> fieldList)
        {
            string error = "";

            for (int i = 0; i < fieldList.Count; i++)
            {
                object[] list = (object[])fieldList[i];
                if ((bool)list[1])
                {
                    WorkItemType workItemTypeTarget = workItemTypes[(string)list[0]];

                    WorkItemType workItemTypeSource = null;
                    if (workItemTypesSource.Contains((string)list[0]))
                    {
                        workItemTypeSource = workItemTypesSource[(string)list[0]];
                    }
                    else if (workItemTypeTarget.Name == "Product Backlog Item")
                    {
                        workItemTypeSource = workItemTypesSource["User Story"];
                    }
                    else if (workItemTypeTarget.Name == "Impediment")
                    {
                        workItemTypeSource = workItemTypesSource["Issue"];
                    }

                    XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false);
                    XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false);

                    XmlNodeList transitionsListSource = workItemTypeXmlSource.GetElementsByTagName("WORKFLOW");
                    XmlNode     transitions           = transitionsListSource[0];

                    XmlNodeList transitionsListTarget = workItemTypeXmlTarget.GetElementsByTagName("WORKFLOW");
                    XmlNode     transitionsTarget     = transitionsListTarget[0];
                    string      defTarget             = "";
                    try
                    {
                        string def            = workItemTypeXmlTarget.InnerXml;
                        string workflowSource = transitions.OuterXml;
                        string workflowTarget = transitionsTarget.OuterXml;

                        defTarget = def.Replace(workflowTarget, workflowSource);
                        WorkItemType.Validate(store.Projects[projectName], defTarget);
                        store.Projects[projectName].WorkItemTypes.Import(defTarget);
                        fieldList.Remove(list);
                        i--;
                    }
                    catch (Exception ex)
                    {
                        logger.Info("Error Replacing work flow");
                        error = error + "Error Replacing work flow for " + (string)list[0] + ":" + ex.Message + "\n";
                    }
                }
            }
            return(error);
        }
Exemplo n.º 14
0
 public WorkItemWrite(TfsTeamProjectCollection tfs, Project destinationProject)
 {
     this.tfs = tfs;
     projectName = destinationProject.Name;
     this.destinationProject = destinationProject;
     store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
     queryCol = store.Projects[destinationProject.Name].QueryHierarchy;
     workItemTypes = store.Projects[destinationProject.Name].WorkItemTypes;
     itemMap = new Hashtable();
     itemMapCIC = new Hashtable();
 }
Exemplo n.º 15
0
 public WorkItemWrite(TfsTeamProjectCollection tfs, Project destinationProject)
 {
     this.tfs = tfs;
     projectName = destinationProject.Name;
     this.destinationProject = destinationProject;
     store = new WorkItemStore(tfs, WorkItemStoreFlags.BypassRules);
     queryCol = store.Projects[destinationProject.Name].QueryHierarchy;
     workItemTypes = store.Projects[destinationProject.Name].WorkItemTypes;
     itemMap = new Hashtable();
     itemMapCIC = new Hashtable();
 }
Exemplo n.º 16
0
 public WorkItemWrite(TfsTeamProjectCollection tfs, Project destinationProject)
 {
     this.tfs                = tfs;
     projectName             = destinationProject.Name;
     this.destinationProject = destinationProject;
     store         = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
     queryCol      = store.Projects[destinationProject.Name].QueryHierarchy;
     workItemTypes = store.Projects[destinationProject.Name].WorkItemTypes;
     itemMap       = new Hashtable();
     itemMapCIC    = new Hashtable();
 }
 public WorkItemWrite(TfsTeamProjectCollection tfs, Project destinationProject)
 {
     this.tfs                = tfs;
     projectName             = destinationProject.Name;
     this.destinationProject = destinationProject;
     store         = new WorkItemStore(tfs, WorkItemStoreFlags.BypassRules);
     queryCol      = store.Projects[destinationProject.Name].QueryHierarchy;
     workItemTypes = store.Projects[destinationProject.Name].WorkItemTypes;
     itemMap       = new Hashtable();
     itemMapCIC    = new Hashtable();
 }
Exemplo n.º 18
0
        /// <summary>
        /// Create a new instance of TFSAPI Class
        /// </summary>
        /// <param name="TfsCollectionURI">URI to access the TFS Server and project collection</param>
        /// <param name="ProjectName">Default project</param>
        public TFSAPI(Uri TfsCollectionURI, string ProjectName)
        {
            teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(TfsCollectionURI);
            teamProjectCollection.Connect(Microsoft.TeamFoundation.Framework.Common.ConnectOptions.IncludeServices);
            teamProjectCollection.EnsureAuthenticated();

            wiStore = new WorkItemStore(teamProjectCollection);


            workItemTypeCollection = wiStore.Projects[ProjectName].WorkItemTypes;
        }
Exemplo n.º 19
0
        public TestPlanMigration(TfsTeamProjectCollection sourceTfs, TfsTeamProjectCollection destinationTfs, string sourceProject, string destinationProject, Hashtable workItemMap, ProgressBar progressBar)
        {
            this.sourceproj      = GetProject(sourceTfs, sourceProject);
            this.destinationproj = GetProject(destinationTfs, destinationProject);
            this.workItemMap     = workItemMap;
            this.progressBar     = progressBar;
            projectName          = sourceProject;
            store         = (WorkItemStore)destinationTfs.GetService(typeof(WorkItemStore));
            workItemTypes = store.Projects[destinationProject].WorkItemTypes;

            ims    = (IIdentityManagementService)sourceTfs.GetService(typeof(IIdentityManagementService));
            UserID = ims.ReadIdentity(IdentitySearchFactor.MailAddress, "*****@*****.**", MembershipQuery.Direct, ReadIdentityOptions.None);
        }
        internal static WorkItemTypeCollectionWrapper GetInstance()
        {
            WorkItemTypeCollection real = default(WorkItemTypeCollection);

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

            InstanceFactory(ref instance);
            if (instance == null)
            {
                Assert.Inconclusive("Could not Create Test Instance");
            }
            return(instance);
        }
Exemplo n.º 21
0
        public static bool CheckIfProjectIsTypeCodeReview()
        {
            bool value = false;
            WorkItemTypeCollection wiTypeColl = wiStore.Projects[tfsExt.ActiveProjectContext.ProjectName].WorkItemTypes;

            foreach (WorkItemType type in wiTypeColl)
            {
                if (type.Name == "CodeReview")
                {
                    value = true;
                }
            }
            return(value);
        }
Exemplo n.º 22
0
        public static void ImportToCurrituck(Microsoft.TeamFoundation.WorkItemTracking.Client.Project VSTSProj, string witdFile)
        {
            try
            {
                /* first check if the FORM section has Layout in this.. this is possible if the customer
                 * doesn't modifies the generated WITD in Analyze phase
                 */
                Display.StartProgressDisplay(UtilityMethods.Format(
                                                 VSTSResource.VstsSchemaImporting, witdFile));
                string witDefinition;
                using (StreamReader stream = new StreamReader(witdFile))
                {
                    witDefinition = stream.ReadToEnd();
                }

                WorkItemTypeCollection wits = VSTSProj.WorkItemTypes;
                Logger.Write(LogSource.WorkItemTracking, TraceLevel.Verbose, "Provisioning Work Item Type : {0}", witdFile);

                wits.Import(witDefinition);
            }
            // Any changes made in this catch block should be reproduced in the below catch block too;
            // This is to get rid of the nonclscompliant message from FxCop
            catch (XmlSchemaValidationException e)
            {
                Logger.WriteException(LogSource.WorkItemTracking, e);
                string errMsg = UtilityMethods.Format(
                    VSTSResource.VstsWITValidationFailed, witdFile,
                    e.LineNumber, e.LinePosition, e.Message);
                Common.ConverterMain.MigrationReport.WriteIssue(string.Empty, errMsg, string.Empty, null,
                                                                IssueGroup.Witd.ToString(), ReportIssueType.Critical);

                throw new ConverterException(errMsg, e);
            }
            catch (Exception e)
            {
                Logger.WriteException(LogSource.WorkItemTracking, e);
                string errMsg = UtilityMethods.Format(
                    VSTSResource.VstsWITProvisionFailed, witdFile, e.Message);
                Common.ConverterMain.MigrationReport.WriteIssue(string.Empty,
                                                                errMsg, string.Empty, null, IssueGroup.Witd.ToString(), ReportIssueType.Critical);

                throw new ConverterException(errMsg, e);
            }
            finally
            {
                Logger.Write(LogSource.WorkItemTracking, TraceLevel.Verbose, "Work Item Type Provisioning Done : {0}", witdFile);
                Display.StopProgressDisplay();
            }
        } // end of ImportToCurrituck
Exemplo n.º 23
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);
        }
Exemplo n.º 24
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);
        }
        public static WorkItemTypeMap MapTypes(TfsProject source, TfsProject target)
        {
            WorkItemTypeCollection workItemTypes = target.project.WorkItemTypes;
            WorkItemTypeMap        fieldMap      = new WorkItemTypeMap();

            foreach (WorkItemType workItemTypeSource in source.project.WorkItemTypes)
            {
                List <List <string> > fieldList          = new List <List <string> >();
                List <string>         sourceList         = new List <string>();
                List <string>         targetList         = new List <string>();
                WorkItemType          workItemTypeTarget = null;
                if (workItemTypes.Contains(workItemTypeSource.Name))
                {
                    workItemTypeTarget = workItemTypes[workItemTypeSource.Name];
                }
                else if (workItemTypeSource.Name == "User Story")
                {
                    workItemTypeTarget = workItemTypes["Product Backlog Item"];
                }
                else if (workItemTypeSource.Name == "Issue")
                {
                    workItemTypeTarget = workItemTypes["Impediment"];
                }
                else
                {
                    // not automatically mapped
                    continue;
                }

                WorkItemFieldMap m = new WorkItemFieldMap(workItemTypeSource, workItemTypeTarget);
                m.GenerateDefaultMap();
                fieldMap.fieldMapping.Add(m);
                fieldMap.mapping[workItemTypeSource] = workItemTypeTarget;
            }

            return(fieldMap);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Bind combobox to tfs core field
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="coreField"></param>
        private void BindComboBox(ComboBox comboBox, CoreField coreField)
        {
            using (var tfs = new TfsTeamProjectCollection(new Uri(this.textbox_tfsUrl.Text)))
            {
                WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

                Project project = workItemStore.Projects[this.textbox_defaultProject.Text];


                // workType
                WorkItemTypeCollection workItemTypes = project.WorkItemTypes;

                WorkItemType workItemType = workItemTypes[combobox_workItemType.Text];
                if (workItemType != null)
                {
                    var allowedValues = workItemType.FieldDefinitions[coreField].AllowedValues;
                    comboBox.Items.Clear();
                    foreach (string value in allowedValues)
                    {
                        comboBox.Items.Add(value);
                    }
                }
            }
        }
Exemplo n.º 27
0
        public void BatchSave(IEnumerable <IWorkItem> workItems)
        {
            // First: Fix up the work items and save them to our dictionary

            foreach (var item in workItems)
            {
                Save(item);
            }

            // Second: Update the links for the work items We need to save first so we can create recipricol links if required (e.g. parent -> child also needs a child -> parent)
            foreach (var item in workItems)
            {
                SaveLinks(item);
            }

            // Third: If any of the work items have types that are missing from their project, add those
            var missingWits = new Dictionary <IProject, HashSet <IWorkItemType> >();

            foreach (var item in workItems)
            {
                var      projectName = item[CoreFieldRefNames.TeamProject].ToString();
                var      witName     = item[CoreFieldRefNames.WorkItemType].ToString();
                IProject project;
                try
                {
                    project = Projects[projectName];
                }
                catch (DeniedOrNotExistException)
                {
                    Trace.TraceWarning("Project {0} missing from work item store.", projectName);
                    project = new MockProject(this);
                }

                if (!project.WorkItemTypes.Contains(witName))
                {
                    Trace.TraceWarning("Project {0} is missing work item type definition {1}", project, witName);
                    missingWits.TryAdd(project, new HashSet <IWorkItemType>(WorkItemTypeComparer.Default));

                    var t = item.Type as MockWorkItemType;
                    if (t?.Store != this)
                    {
                        t.Store = this;
                    }

                    missingWits[project].Add(item.Type);
                }
            }

            // Fourth: If there are any missing wits update the project and reset the project collection
            if (!missingWits.Any())
            {
                return;
            }
            var changesRequired = false;

            var newProjects = new List <IProject>();

            foreach (var project in Projects)
            {
                if (!missingWits.ContainsKey(project))
                {
                    newProjects.Add(project);
                    continue;
                }

                var wits = missingWits[project];

                if (!wits.Any())
                {
                    newProjects.Add(project);
                }
                else
                {
                    changesRequired = true;
                    wits.UnionWith(project.WorkItemTypes);
                    var w = new WorkItemTypeCollection(wits.ToList());
                    var p = new MockProject(project.Guid, project.Name, project.Uri, w, project.AreaRootNodes, project.IterationRootNodes);
                    newProjects.Add(p);
                }
            }

            if (changesRequired)
            {
                _projects = new Lazy <IProjectCollection>(() => new MockProjectCollection(newProjects));
            }
        }
		private Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType GetTfsWorkItemType(BoardMapping boardMapping, WorkItemTypeCollection workItemTypes, long cardTypeId)
		{			
			if (boardMapping != null && 
				boardMapping.Types != null && 
				boardMapping.ValidCardTypes != null && 
				boardMapping.Types.Any() && 
				boardMapping.ValidCardTypes.Any() )
			{				
				var lkType = boardMapping.ValidCardTypes.FirstOrDefault(x => x.Id == cardTypeId);
				if (lkType != null)
				{
					// first check for mapped type
					var mappedType = boardMapping.Types.FirstOrDefault(x => x.LeanKit.ToLowerInvariant() == lkType.Name.ToLowerInvariant());
					if (mappedType != null) 
					{
						if (workItemTypes.Contains(mappedType.Target))
							return workItemTypes[mappedType.Target];
					}
					// now check for implicit type
					if (workItemTypes.Contains(lkType.Name))
						return workItemTypes[lkType.Name];
				}

			}
			// else just return the first type from list of types from TFS
			return workItemTypes[0];
		}
Exemplo n.º 29
0
 private static void AddAdditionalTasks(WorkItemTypeCollection workItemTypes, WorkItem parentWorkItem, IEnumerable<Story> additionalTaskTitles)
 {
     foreach (var workitemTask in additionalTaskTitles.Select(story => new WorkItem(workItemTypes[SprintBacklogItem])
         {
             Title = story.Name,
             Description = story.Description,
             IterationPath = parentWorkItem.IterationPath
         }))
     {
         workitemTask.Fields[HistoryField].Value = parentWorkItem.Fields[HistoryField].Value;
         workitemTask.Save();
         parentWorkItem.Links.Add(new RelatedLink(workitemTask.Id));
     }
 }
Exemplo n.º 30
0
        private static void AddPivotalTasksAsLinkedWorkItems(WorkItemTypeCollection workItemTypes, WorkItem workItem,
		                                                     Story pivotalStoryToAdd)
        {
            if (pivotalStoryToAdd.Tasks == null)
                return;
            foreach (var task in pivotalStoryToAdd.Tasks.tasks)
            {
                var workitemTask = new WorkItem(workItemTypes[SprintBacklogItem])
                    {
                        Title = task.Description,
                        IterationPath = workItem.IterationPath
                    };
                workitemTask.Fields[HistoryField].Value = workItem.Fields[HistoryField].Value;
                workitemTask.Save();
                workItem.Links.Add(new RelatedLink(workitemTask.Id));
            }
        }
Exemplo n.º 31
0
        public Hashtable MapFields(WorkItemTypeCollection workItemTypesSource)
        {
            Hashtable fieldMap = new Hashtable();

            foreach (WorkItemType workItemTypeSource in workItemTypesSource)
            {
                List<List<string>> fieldList = new List<List<string>>();
                List<string> sourceList = new List<string>();
                List<string> targetList = new List<string>();

                WorkItemType workItemTypeTarget = null;
                if (workItemTypes.Contains(workItemTypeSource.Name))
                {
                    workItemTypeTarget = workItemTypes[workItemTypeSource.Name];
                }
                else if (workItemTypeSource.Name == "User Story")
                {
                    workItemTypeTarget = workItemTypes["Product Backlog Item"];
                }
                else if (workItemTypeSource.Name == "Issue")
                {
                    workItemTypeTarget = workItemTypes["Impediment"];
                }
                else
                {
                    continue;
                }

                XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false);
                XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false);

                XmlNodeList fieldListSource = workItemTypeXmlSource.GetElementsByTagName("FIELD");
                XmlNodeList fieldListTarget = workItemTypeXmlTarget.GetElementsByTagName("FIELD");

                foreach (XmlNode field in fieldListSource)
                {
                    if (field.Attributes["name"] != null)
                    {
                        XmlNodeList tempList = workItemTypeXmlTarget.SelectNodes("//FIELD[@name='" + field.Attributes["name"].Value + "']");
                        if (tempList.Count == 0)
                        {
                            sourceList.Add(field.Attributes["name"].Value);
                        }
                    }
                }
                fieldList.Add(sourceList);

                foreach (XmlNode field in fieldListTarget)
                {
                    if (field.Attributes["name"] != null)
                    {
                        XmlNodeList tempList = workItemTypeXmlSource.SelectNodes("//FIELD[@name='" + field.Attributes["name"].Value + "']");
                        if (tempList.Count == 0)
                        {
                            targetList.Add(field.Attributes["name"].Value);
                        }
                    }
                }
                fieldList.Add(targetList);
                fieldMap.Add(workItemTypeTarget.Name, fieldList);
            }
            return fieldMap;
        }
 static partial void RealInstanceFactory(ref WorkItemTypeCollection real, [CallerMemberName] string callerName        = "");
Exemplo n.º 33
0
        /* Compare work item type definitions and add fields from source work item types and replace workflow */
        public void SetFieldDefinitions(WorkItemTypeCollection workItemTypesSource, Hashtable fieldList)
        {
            foreach (WorkItemType workItemTypeSource in workItemTypesSource)
            {
                WorkItemType workItemTypeTarget = null;
                if (workItemTypeSource.Name == "User Story")
                {
                    workItemTypeTarget = workItemTypes["Product Backlog Item"];
                }
                else if (workItemTypeSource.Name == "Issue")
                {
                    workItemTypeTarget = workItemTypes["Impediment"];
                }
                else
                {
                    workItemTypeTarget = workItemTypes[workItemTypeSource.Name];
                }

                XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false);
                XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false);

                workItemTypeXmlTarget = AddNewFields(workItemTypeXmlSource, workItemTypeXmlTarget, (List<object>)fieldList[workItemTypeTarget.Name]);

                try
                {
                    WorkItemType.Validate(store.Projects[projectName], workItemTypeXmlTarget.InnerXml);
                    store.Projects[projectName].WorkItemTypes.Import(workItemTypeXmlTarget.InnerXml);
                }
                catch (XmlException)
                {
                    logger.Info("XML import falied for " + workItemTypeSource.Name);
                }
            }
        }
        static partial void RealInstanceFactory(ref WorkItemType real, string callerName)
        {
            WorkItemTypeCollection workItemTypes = WorkItemTypeCollectionWrapper_UnitTests.GetRealInstance();

            real = workItemTypes["Task"];
        }
Exemplo n.º 35
0
 private Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType GetTfsWorkItemType(BoardMapping boardMapping, WorkItemTypeCollection workItemTypes, long cardTypeId)
 {
     if (boardMapping != null &&
         boardMapping.Types != null &&
         boardMapping.ValidCardTypes != null &&
         boardMapping.Types.Any() &&
         boardMapping.ValidCardTypes.Any())
     {
         var lkType = boardMapping.ValidCardTypes.FirstOrDefault(x => x.Id == cardTypeId);
         if (lkType != null)
         {
             // first check for mapped type
             var mappedType = boardMapping.Types.FirstOrDefault(x => x.LeanKit.ToLowerInvariant() == lkType.Name.ToLowerInvariant());
             if (mappedType != null)
             {
                 if (workItemTypes.Contains(mappedType.Target))
                 {
                     return(workItemTypes[mappedType.Target]);
                 }
             }
             // now check for implicit type
             if (workItemTypes.Contains(lkType.Name))
             {
                 return(workItemTypes[lkType.Name]);
             }
         }
     }
     // else just return the first type from list of types from TFS
     return(workItemTypes[0]);
 }
Exemplo n.º 36
0
        public string ReplaceWorkFlow(WorkItemTypeCollection workItemTypesSource, List<object> fieldList)
        {
            string error = "";
            for (int i = 0; i < fieldList.Count; i++)
            {
                object[] list = (object[])fieldList[i];
                if ((bool)list[1])
                {
                    WorkItemType workItemTypeTarget = workItemTypes[(string)list[0]];

                    WorkItemType workItemTypeSource = null;
                    if (workItemTypesSource.Contains((string)list[0]))
                    {
                        workItemTypeSource = workItemTypesSource[(string)list[0]];
                    }
                    else if (workItemTypeTarget.Name == "Product Backlog Item")
                    {
                        workItemTypeSource = workItemTypesSource["User Story"];
                    }
                    else if (workItemTypeTarget.Name == "Impediment")
                    {
                        workItemTypeSource = workItemTypesSource["Issue"];
                    }

                    XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false);
                    XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false);

                    XmlNodeList transitionsListSource = workItemTypeXmlSource.GetElementsByTagName("WORKFLOW");
                    XmlNode transitions = transitionsListSource[0];

                    XmlNodeList transitionsListTarget = workItemTypeXmlTarget.GetElementsByTagName("WORKFLOW");
                    XmlNode transitionsTarget = transitionsListTarget[0];
                    string defTarget = "";
                    try
                    {
                        string def = workItemTypeXmlTarget.InnerXml;
                        string workflowSource = transitions.OuterXml;
                        string workflowTarget = transitionsTarget.OuterXml;

                        defTarget = def.Replace(workflowTarget, workflowSource);
                        WorkItemType.Validate(store.Projects[projectName], defTarget);
                        store.Projects[projectName].WorkItemTypes.Import(defTarget);
                        fieldList.Remove(list);
                        i--;
                    }
                    catch (Exception ex)
                    {
                        logger.Error("Error Replacing work flow");
                        error = error + "Error Replacing work flow for " + (string)list[0] + ":" + ex.Message + "\n";
                    }
                }
            }
            return error;
        }
Exemplo n.º 37
0
        private void BindScreen()
        {
            if (!string.IsNullOrEmpty(this.textbox_tfsUrl.Text))
            {
                try
                {
                   using (var tfs = new TfsTeamProjectCollection(new Uri(this.textbox_tfsUrl.Text)))
                   {
                        WorkItemStore workItemStore = tfs.GetService<WorkItemStore>();
                        if (workItemStore != null)
                        {
                            Project project = workItemStore.Projects[this.textbox_defaultProject.Text];

                            // workType
                            WorkItemTypeCollection workItemTypes = project.WorkItemTypes;
                            combobox_workItemType.Items.Clear();
                            foreach (WorkItemType workItemType in workItemTypes)
                            {
                                combobox_workItemType.Items.Add(workItemType.Name);
                            }

                            combobox_workItemType.SelectedValue = config.TfsWorkItemType;
                            if (combobox_workItemType.SelectedItem == null)
                            {
                                combobox_workItemType.SelectedIndex = 0;
                            }

                            this.BindScreenByItemType();

                            // area
                            combobox_AreaPath.Items.Clear();
                            combobox_AreaPath.Items.Add(project.Name);
                            this.BindComboBoxTree(combobox_AreaPath, project.Name, project.AreaRootNodes);
                            combobox_AreaPath.SelectedValue = config.TfsAreaPath;
                            if (combobox_AreaPath.SelectedItem == null && combobox_AreaPath.Items.Count > 0)
                            {
                                combobox_AreaPath.SelectedIndex = 0;
                            }

                            // iteration
                            combobox_IterationPath.Items.Clear();
                            combobox_IterationPath.Items.Add(project.Name);
                            this.BindComboBoxTree(combobox_IterationPath, project.Name, project.IterationRootNodes);
                            combobox_IterationPath.SelectedValue = config.TfsIterationPath;
                            if (combobox_IterationPath.SelectedItem == null && combobox_IterationPath.Items.Count > 0)
                            {
                                combobox_IterationPath.SelectedIndex = 0;
                            }

                            textbox_Priority.Value = config.TfsPriority;
                        }
                        else
                        {
                            MessageBox.Show("No WorkItem Found!");
                        }
                    }
                }
                catch (Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException eError)
                {
                    MessageBox.Show("Login fail");
                }
            }
        }
Exemplo n.º 38
0
        private void BindScreenByItemType()
        {
            //disabled control not in workItem and bind combobox
            using (var tfs = new TfsTeamProjectCollection(new Uri(this.textbox_tfsUrl.Text)))
            {
                WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
                WorkItemTypeCollection workItemTypes = workItemStore.Projects[this.textbox_defaultProject.Text].WorkItemTypes;
                WorkItemType workItemType = workItemTypes[combobox_workItemType.Text];

                foreach (TabPage tabPage in tabControl_Field.TabPages)
                {
                    foreach (Control ctl in tabPage.Controls)
                    {
                        if (ctl.Tag != null)
                        {
                            ctl.Enabled = false;
                            if (workItemType.FieldDefinitions.Contains(ctl.Tag.ToString()))
                            {
                                var fieldDefinition = workItemType.FieldDefinitions[ctl.Tag.ToString()];
                                ctl.Enabled = (fieldDefinition.IsEditable && ! fieldDefinition.IsComputed);
                                
                                if(! string.IsNullOrEmpty(fieldDefinition.HelpText))
                                {
                                    tooltip_Main.SetToolTip(ctl, fieldDefinition.HelpText);
                                }

                                if (ctl is ComboBox)
                                {
                                    ((ComboBox)ctl).Items.Clear();
                                    foreach (var allowedValue in fieldDefinition.AllowedValues)
                                    {
                                        ((ComboBox)ctl).Items.Add(allowedValue);
                                    }
                                }
                            }
                        }
                    }

                }
            }

            combobox_AssignTo.SelectedValue = config.TfsAssignedTo;

            if (combobox_severity.SelectedItem == null && combobox_severity.Items.Count > 0)
            {
                combobox_severity.SelectedIndex = 0;
            }

            combobox_state.SelectedValue = config.TfsState;
            if (combobox_state.SelectedItem == null && combobox_state.Items.Count > 0)
            {
                combobox_state.SelectedIndex = 0;
            }

            combobox_reason.SelectedValue = config.TfsState;
            if (combobox_reason.SelectedItem == null && combobox_reason.Items.Count > 0)
            {
                // set to new if exist
                combobox_reason.SelectedItem = "New";

                if (combobox_reason.SelectedItem == null && combobox_reason.Items.Count > 0)
                {
                    combobox_reason.SelectedIndex = 0;
                }
            }
        }
Exemplo n.º 39
0
        public Hashtable MapFields(WorkItemTypeCollection workItemTypesSource)
        {
            Hashtable fieldMap = new Hashtable();

            foreach (WorkItemType workItemTypeSource in workItemTypesSource)
            {
                List <List <string> > fieldList  = new List <List <string> >();
                List <string>         sourceList = new List <string>();
                List <string>         targetList = new List <string>();

                WorkItemType workItemTypeTarget = null;
                if (workItemTypes.Contains(workItemTypeSource.Name))
                {
                    workItemTypeTarget = workItemTypes[workItemTypeSource.Name];
                }

                else if (workItemTypeSource.Name == "Issue")
                {
                    workItemTypeTarget = workItemTypes["Impediment"];
                }
                else if (workItemTypeSource.Name == "User Story")
                {
                    workItemTypeTarget = workItemTypes["Product Backlog Item"];
                }
                else
                {
                    continue;
                }

                XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false);
                XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false);

                XmlNodeList fieldListSource = workItemTypeXmlSource.GetElementsByTagName("FIELD");
                XmlNodeList fieldListTarget = workItemTypeXmlTarget.GetElementsByTagName("FIELD");

                foreach (XmlNode field in fieldListSource)
                {
                    if (field.Attributes["name"] != null)
                    {
                        XmlNodeList tempList = workItemTypeXmlTarget.SelectNodes("//FIELD[@name='" + field.Attributes["name"].Value + "']");
                        if (tempList.Count == 0)
                        {
                            sourceList.Add(field.Attributes["name"].Value);
                        }
                    }
                }
                fieldList.Add(sourceList);

                foreach (XmlNode field in fieldListTarget)
                {
                    if (field.Attributes["name"] != null)
                    {
                        XmlNodeList tempList = workItemTypeXmlSource.SelectNodes("//FIELD[@name='" + field.Attributes["name"].Value + "']");
                        if (tempList.Count == 0)
                        {
                            targetList.Add(field.Attributes["name"].Value);
                        }
                    }
                }
                fieldList.Add(targetList);
                fieldMap.Add(workItemTypeTarget.Name, fieldList);
            }
            return(fieldMap);
        }
Exemplo n.º 40
0
        private void button_save_Click(object sender, EventArgs e)
        {
            try
            {
                ////http://social.technet.microsoft.com/wiki/contents/articles/3280.tfs-2010-api-create-workitems-bugs.aspx
                TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(this.textbox_tfsUrl.Text));

                WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

                WorkItemTypeCollection workItemTypes = workItemStore.Projects[this.textbox_defaultProject.Text].WorkItemTypes;

                WorkItemType workItemType = workItemTypes[combobox_workItemType.Text];

                // Assign values to each mandatory field
                var workItem = new WorkItem(workItemType);

                workItem.Title = textbox_title.Text;
                workItem.Description = textbox_description.Text;

                var fieldAssignTo = "System.AssignedTo";
                if (combobox_AssignTo.SelectedItem != null && workItem.Fields.Contains(fieldAssignTo))
                {
                    workItem.Fields[fieldAssignTo].Value = combobox_AssignTo.Text;
                }

                var fieldSeverity="Microsoft.VSTS.Common.Severity";
                if (combobox_severity.SelectedItem != null &&  workItem.Fields.Contains(fieldSeverity))
                {
                    workItem.Fields[fieldSeverity].Value = combobox_severity.Text;
                }

                var fieldPriority = "Microsoft.VSTS.Common.Priority";
                if (workItem.Fields.Contains(fieldPriority))
                {
                    workItem.Fields[fieldPriority].Value = textbox_Priority.Text;
                }

                if (combobox_AreaPath.SelectedItem != null)
                {
                    workItem.AreaPath = combobox_AreaPath.Text;
                }

                if (combobox_IterationPath.SelectedItem != null)
                {
                    workItem.IterationPath = combobox_IterationPath.Text;
                }

                var fieldState = "System.State";
                if (combobox_state.SelectedItem != null && workItem.Fields.Contains(fieldState))
                {
                    workItem.Fields[fieldState].Value = combobox_state.Text;
                }

                var fieldReason = "System.Reason";
                if (combobox_reason.SelectedItem != null && workItem.Fields.Contains(fieldReason))
                {
                    workItem.Fields["System.Reason"].Value = combobox_reason.Text;
                }

                string fieldSystenInfo = "Microsoft.VSTS.TCM.SystemInfo";
                if (workItem.Fields.Contains(fieldSystenInfo))
                {
                    if (workItem.Fields[fieldSystenInfo].FieldDefinition.FieldType == FieldType.Html)
                    {
                        workItem.Fields[fieldSystenInfo].Value = textbox_SystemInfo.Text.Replace(Environment.NewLine,"<br/>");
                    }
                    else
                    {
                        workItem.Fields[fieldSystenInfo].Value = textbox_SystemInfo.Text;
                    }

                }

                string fieldsReproStreps = "Microsoft.VSTS.TCM.ReproSteps";
                if (workItem.Fields.Contains(fieldsReproStreps))
                {
                    workItem.Fields[fieldsReproStreps].Value = textbox_ReproStep.Text;
                    if (string.IsNullOrEmpty(textbox_ReproStep.Text))
                    {
                        workItem.Fields[fieldsReproStreps].Value = workItem.Description;
                    }
                }

                // add image
                string tempFile = Path.Combine(Environment.CurrentDirectory, this.Filename);
                File.WriteAllBytes(tempFile, this.ImageData);

                workItem.Attachments.Add(new Attachment(tempFile));

                // Link the failed test case to the Bug
                // workItem.Links.Add(new RelatedLink(testcaseID));

                // Check for validation errors before saving the Bug
                ArrayList validationErrors = workItem.Validate();

                if (validationErrors.Count == 0)
                {
                    workItem.Save();

                    if (this.TFSInfo == null)
                    {
                        this.TFSInfo = new TFSInfo();
                    }

                    this.TFSInfo.ID = workItem.Id.ToString();
                    this.TFSInfo.Title = workItem.Title;
                    this.TFSInfo.Description = workItem.Description;

                    // http://stackoverflow.com/questions/6466441/how-to-map-a-tfs-item-url-to-something-viewable
                    var testManagementService = tfs.GetService<ILinking>();
                    this.TFSInfo.WebDetailUrl = testManagementService.GetArtifactUrlExternal(workItem.Uri.ToString());
                    
                    var myService = tfs.GetService<TswaClientHyperlinkService>();
                   this.TFSInfo.WebEditUrl = myService.GetWorkItemEditorUrl(workItem.Id).ToString();
                    

                    if (checkbox_description_addImage.Checked)
                    {
                        if (workItem.Fields["System.Description"].FieldDefinition.FieldType == FieldType.Html)
                        {
                            workItem.Description += string.Format("<br/><a href=\"{0}\"><img src=\"{0}\" /></a>", workItem.Attachments[0].Uri.ToString());
                        }
                        else
                        {
                            workItem.Description += System.Environment.NewLine + workItem.Attachments[0].Uri.ToString();
                        }
                    }

                    if (checkbox_reproStep_AddImage.Checked && (workItem.Fields.Contains(fieldsReproStreps)))
                    {
                        if (workItem.Fields[fieldsReproStreps].FieldDefinition.FieldType == FieldType.Html)
                        {
                            workItem.Fields[fieldsReproStreps].Value += string.Format("<br/><a href=\"{0}\"><img src=\"{0}\" /></a>", workItem.Attachments[0].Uri.ToString());
                        }
                        else
                        {
                            workItem.Fields[fieldsReproStreps].Value += System.Environment.NewLine + workItem.Attachments[0].Uri.ToString();
                        }
                    }

                    workItem.Save();

                    this.SetLastValue();
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    string errrorMsg = "Validation Error in field\n";
                    foreach (Field field in validationErrors)
                    {
                        errrorMsg += field.Name + "\n";
                    }

                    MessageBox.Show(errrorMsg);
                }

                tfs.Dispose();

                // delete temps images
                System.IO.File.Delete(tempFile);
            }
            catch (Exception eError)
            {
                MessageBox.Show(eError.ToString());
            }
        }