public void Handle(ProfileAddedMessage message)
        {
            var tfsProfile = _profile.Settings as TfsPluginProfile;

            if (!tfsProfile.WorkItemsEnabled)
            {
                return;
            }

            var projectsMapping = new ProjectsMappingHistoryElement()
            {
                Key            = tfsProfile.ProjectsMapping[0].Key,
                Value          = tfsProfile.ProjectsMapping[0].Value,
                WorkItemsRange = new CreatedWorkItemsRange()
                {
                    Min = int.Parse(tfsProfile.StartWorkItem), Max = -1
                },
                IsCurrent     = true,
                ImportedTypes = tfsProfile.EntityMapping.Select(
                    x => new ImportedType {
                    StartID = int.Parse(tfsProfile.StartWorkItem), Type = x.First, IsFirstSync = false
                }).ToList()
            };

            var projectsMappingHistory = new ProjectsMappingHistory();

            projectsMappingHistory.Add(projectsMapping);

            _profile.Get <ProjectsMappingHistory>().ReplaceWith(projectsMappingHistory);
        }
Exemple #2
0
        public void Handle(ProfileUpdatedMessage message)
        {
            var tfsProfile = _profile.Settings as TfsPluginProfile;

            var projectsMappingHistory = _profile.Get <ProjectsMappingHistory>().FirstOrDefault();

            if (projectsMappingHistory == null)
            {
                return;
            }

            var currentElement = projectsMappingHistory.Current;
            var importedTypes  = new List <ImportedType>(currentElement.ImportedTypes);

            foreach (var mapping in tfsProfile.EntityMapping)
            {
                if (currentElement.ImportedTypes.Exists(x => x.Type == mapping.First))
                {
                    continue;
                }

                importedTypes.Add(new ImportedType {
                    StartID = int.Parse(tfsProfile.StartWorkItem), Type = mapping.First, IsFirstSync = true
                });
            }

            if (currentElement.IsEquals(tfsProfile.ProjectsMapping[0]))
            {
                if (importedTypes.Count != currentElement.ImportedTypes.Count)
                {
                    currentElement.ImportedTypes = importedTypes;
                    _profile.Get <ProjectsMappingHistory>().ReplaceWith(projectsMappingHistory);
                }

                return;
            }

            currentElement.IsCurrent = false;

            importedTypes = importedTypes.Select(x => x.Clone()).ToList();

            importedTypes.ForEach(importedType =>
            {
                if (!importedType.IsFirstSync)
                {
                    importedType.StartID = currentElement.WorkItemsRange.Max + 1;
                }
            });

            var projectsMapping = new ProjectsMappingHistoryElement()
            {
                Key            = tfsProfile.ProjectsMapping[0].Key,
                Value          = tfsProfile.ProjectsMapping[0].Value,
                WorkItemsRange = new CreatedWorkItemsRange()
                {
                    Min = currentElement.WorkItemsRange.Max + 1, Max = -1
                },
                IsCurrent     = true,
                ImportedTypes = importedTypes
            };

            projectsMappingHistory.Add(projectsMapping);

            _profile.Get <ProjectsMappingHistory>().ReplaceWith(projectsMappingHistory);
        }