예제 #1
0
        private void ProcessLinks()
        {
            Console.Write("\n\nProcessing Links:\n\n");


            foreach (var resultWorkItem in WizardInfo.ResultWorkItems)
            {
                if (resultWorkItem is SkippedSourceWorkItem)
                {
                    string category = WizardInfo.WorkItemGenerator.WorkItemTypeToCategoryMapping[WizardInfo.WorkItemGenerator.SelectedWorkItemTypeName];
                    int    tfsId    = WizardInfo.LinksManager.WorkItemCategoryToIdMappings[category][resultWorkItem.SourceId].TfsId;

                    AddWorkItemInTestSuites(tfsId, resultWorkItem.TestSuites);
                    continue;
                }

                var workItemStatus = new WorkItemMigrationStatus();
                workItemStatus.SourceId     = resultWorkItem.SourceId;
                workItemStatus.SessionId    = WizardInfo.LinksManager.SessionId;
                workItemStatus.WorkItemType = WizardInfo.WorkItemGenerator.SelectedWorkItemTypeName;

                PassedSourceWorkItem passedWorkItem = resultWorkItem as PassedSourceWorkItem;

                if (passedWorkItem != null)
                {
                    workItemStatus.Status = Status.Passed;
                    workItemStatus.TfsId  = passedWorkItem.TFSId;
                }
                else
                {
                    var failedWorkItem = resultWorkItem as FailedSourceWorkItem;
                    if (failedWorkItem != null)
                    {
                        workItemStatus.Status  = Status.Failed;
                        workItemStatus.TfsId   = -1;
                        workItemStatus.Message = failedWorkItem.Error;
                    }
                }
                if (!string.IsNullOrEmpty(workItemStatus.SourceId))
                {
                    WizardInfo.LinksManager.UpdateIdMapping(workItemStatus.SourceId, workItemStatus);
                }

                if (passedWorkItem != null)
                {
                    foreach (Link link in passedWorkItem.Links)
                    {
                        WizardInfo.LinksManager.AddLink(link);
                    }
                    foreach (string testSuite in passedWorkItem.TestSuites)
                    {
                        WizardInfo.WorkItemGenerator.AddWorkItemToTestSuite(passedWorkItem.TFSId, testSuite);
                    }
                }
            }
            WizardInfo.LinksManager.Save();
            WizardInfo.LinksManager.PublishReport();
        }
        private bool PostMigrationEvent(ISourceWorkItem sourceWorkItem)
        {
            // If this action is cancelled then update the message and return Stopped State
            if (m_worker.CancellationPending)
            {
                Message = Resources.UserInterruptionText;
                return(false);
            }

            if (sourceWorkItem is SkippedSourceWorkItem)
            {
                return(true);
            }

            // updating the counters
            UpdateCounters(sourceWorkItem.GetType());

            PassedSourceWorkItem passedWorkItem = sourceWorkItem as PassedSourceWorkItem;

            if (passedWorkItem != null)
            {
                AddWorkItemInTestSuites(passedWorkItem.TFSId, passedWorkItem.TestSuites);
            }

            if (m_wizardInfo.IsLinking)
            {
                var workItemStatus = new WorkItemMigrationStatus();
                workItemStatus.SourceId     = sourceWorkItem.SourceId;
                workItemStatus.SessionId    = m_wizardInfo.LinksManager.SessionId;
                workItemStatus.WorkItemType = m_wizardInfo.WorkItemGenerator.SelectedWorkItemTypeName;

                if (passedWorkItem != null)
                {
                    workItemStatus.Status = WorkItemMigrator.Status.Passed;
                    workItemStatus.TfsId  = passedWorkItem.TFSId;
                }
                else
                {
                    var failedWorkItem = sourceWorkItem as FailedSourceWorkItem;
                    if (failedWorkItem != null)
                    {
                        workItemStatus.Status  = WorkItemMigrator.Status.Failed;
                        workItemStatus.TfsId   = -1;
                        workItemStatus.Message = failedWorkItem.Error;
                    }
                }
                if (!string.IsNullOrEmpty(workItemStatus.SourceId))
                {
                    m_wizardInfo.LinksManager.UpdateIdMapping(workItemStatus.SourceId, workItemStatus);
                }
            }

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Updates ID Mapping Dictionary with one new entry
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="id"></param>
        public void UpdateIdMapping(string sourceId, WorkItemMigrationStatus status)
        {
            string category = m_wizardInfo.WorkItemGenerator.WorkItemTypeToCategoryMapping[m_wizardInfo.WorkItemGenerator.SelectedWorkItemTypeName];

            if (!WorkItemCategoryToIdMappings.ContainsKey(category))
            {
                WorkItemCategoryToIdMappings.Add(category, new Dictionary <string, WorkItemMigrationStatus>());
            }
            if (!WorkItemCategoryToIdMappings[category].ContainsKey(sourceId))
            {
                WorkItemCategoryToIdMappings[category].Add(sourceId, status);
            }
        }
예제 #4
0
        /// <summary>
        /// Load Links and ID Mapping from Links file
        /// </summary>
        private void LoadLinksAndIDMapping()
        {
            LoadLinkingFileFromTask();

            // First time there will not be any links file
            if (!File.Exists(LinksFilePath))
            {
                return;
            }

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(LinksFilePath);

            // get the root Node of the xml Document
            XmlElement root = (XmlElement)xmlDocument.LastChild;

            var deletedWITs = new List <WorkItemMigrationStatus>();

            // Traverse each child node of the root node
            foreach (XmlElement node in root.ChildNodes)
            {
                switch (node.Name)
                {
                case SessionIdElementName:
                    SessionId = int.Parse(node.InnerXml);
                    if (SessionId > 0)
                    {
                        SessionId++;
                    }
                    else
                    {
                        SessionId = 1;
                    }
                    break;

                // If this is ID Mapping Node
                case IDMappingXMLElementName:
                    foreach (XmlElement workItemTypeNode in node.ChildNodes)
                    {
                        string workItemType     = workItemTypeNode.Attributes[NameXMLElementName].Value;
                        string workItemCategory = m_wizardInfo.WorkItemGenerator.WorkItemTypeToCategoryMapping[workItemType];
                        WorkItemCategoryToIdMappings.Add(workItemCategory, new Dictionary <string, WorkItemMigrationStatus>());
                        foreach (XmlElement idMappingNode in workItemTypeNode.ChildNodes)
                        {
                            string sourceId = idMappingNode.Attributes[SourceIDXMLElementName].Value;

                            WorkItemMigrationStatus status = new WorkItemMigrationStatus();
                            status.WorkItemType = workItemType;
                            status.TfsId        = int.Parse(idMappingNode.Attributes[TFSIDXMLElementName].Value);
                            status.SourceId     = sourceId;
                            status.Message      = idMappingNode.Attributes[MessageXMLElementName].Value;
                            status.Status       = (Status)Enum.Parse(typeof(Status), idMappingNode.Attributes[StatusXMLElementName].Value, true);
                            status.SessionId    = int.Parse(idMappingNode.Attributes[SessionIdElementName].Value);

                            if (m_wizardInfo.WorkItemGenerator.IsWitExists(status.TfsId))
                            {
                                WorkItemCategoryToIdMappings[workItemCategory].Add(sourceId, status);
                            }
                            else
                            {
                                deletedWITs.Add(status);
                            }
                        }
                    }
                    break;

                case LinksXMLElementName:
                    foreach (XmlElement workItemTypeNode in node.ChildNodes)
                    {
                        string workItemType = workItemTypeNode.Attributes[NameXMLElementName].Value;
                        foreach (XmlElement linkCategoryNode in workItemTypeNode.ChildNodes)
                        {
                            foreach (XmlElement linkIDGroupNode in linkCategoryNode.ChildNodes)
                            {
                                int id = int.Parse(linkIDGroupNode.Attributes[IDXMLElementName].Value);
                                foreach (XmlElement linkNode in linkIDGroupNode.ChildNodes)
                                {
                                    Link link = new Link();
                                    link.StartWorkItemTfsTypeName = linkNode.Attributes[StartWorkItemTypeXMLElementName].Value;
                                    link.StartWorkItemSourceId    = linkNode.Attributes[StartWorkItemSourceIDXMLElementName].Value;
                                    link.StartWorkItemTfsId       = int.Parse(linkNode.Attributes[StartWorkItemTFSIdXMLElementName].Value);
                                    link.LinkTypeName             = linkNode.Attributes[LinkTypeXMLElementName].Value;
                                    link.EndWorkItemTfsTypeName   = linkNode.Attributes[EndWorkItemTfsTypeXMLElementName].Value;
                                    link.EndWorkItemSourceId      = linkNode.Attributes[EndWorkItemSourceIdXMLElementName].Value;
                                    link.EndWorkItemTfsId         = int.Parse(linkNode.Attributes[EndWorkItemTFSIdXMLElementName].Value);
                                    link.IsExistInTfs             = bool.Parse(linkNode.Attributes[IsExistsInTFSXMLElementName].Value);
                                    link.Message = linkNode.Attributes[MessageXMLElementName].Value;
                                    link.StartWorkItemCategory = linkNode.Attributes[StartWorkItemCategoryElementName].Value;
                                    link.EndWorkItemCategory   = linkNode.Attributes[EndWorkItemCategoryElementName].Value;
                                    int sessionId;
                                    int.TryParse(linkNode.Attributes[SessionIdElementName].Value, out sessionId);
                                    link.SessionId = sessionId;
                                    m_links.Add(link);
                                }
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            RemoveLinksofDeletedWITs(deletedWITs);
        }