public TeamFoundationServerWorkItemQueryProvider(IWorkItemStore workItemStore,
                                                  IWiqlQueryBuilder queryBuilder, IWorkItemMapper workItemMapper)
 {
     WorkItemStore    = workItemStore;
     WiqlQueryBuilder = queryBuilder;
     WorkItemMapper   = workItemMapper;
 }
 public RelativesAwareTeamFoundationServerWorkItemQueryProvider(
     IWorkItemStore workItemStore,
     IWiqlQueryBuilder queryBuilder,
     IWorkItemMapper workItemMapper,
     IFieldMapper fieldMapper)
     : base(workItemStore, queryBuilder, workItemMapper)
 {
     _fieldMapper = fieldMapper;
 }
Exemple #3
0
        public override void Given()
        {
            var workItems = new List <IWorkItem>
            {
                new MockWorkItem("SimpleMockWorkItem", new Dictionary <string, object>
                {
                    { "ID", 1 },
                    { "IntField", 2 }
                }),
                new MockWorkItem("SimpleMockWorkItem", new Dictionary <string, object>
                {
                    { "ID", 2 },
                    { "IntField", 4 }
                })
                ,
                new MockWorkItem("SimpleMockWorkItem", new Dictionary <string, object>
                {
                    { "ID", 3 },
                    { "IntField", 3 }
                })
                ,
                new MockWorkItem("SimpleMockWorkItem", new Dictionary <string, object>
                {
                    { "ID", 4 },
                    { "IntField", 4 }
                })
                ,
                new MockWorkItem("SimpleMockWorkItem", new Dictionary <string, object>
                {
                    { "ID", 5 },
                    { "IntField", 5 }
                })
            };

            var links = new[] {
                new MockWorkItemLinkInfo(0, 3),
                new MockWorkItemLinkInfo(3, 1),
                new MockWorkItemLinkInfo(3, 2),
                new MockWorkItemLinkInfo(0, 4),
                new MockWorkItemLinkInfo(0, 5)
            };

            WorkItemStore = new MockWorkItemStore(workItems, links);
            FieldMapper   = new CachingFieldMapper(new FieldMapper());

            var propertyInspector = new PropertyInspector(PropertyReflector);
            var mapperStrategies  = new IWorkItemMapperStrategy[]
            {
                new AttributeMapperStrategy(propertyInspector,
                                            new TypeParser()),
                new WorkItemLinksMapperStrategy(propertyInspector, WorkItemStore)
            };

            Builder = new WiqlQueryBuilder(new WiqlTranslator(FieldMapper), new PartialEvaluator(), new QueryRewriter());
            Mapper  = new WorkItemMapper(mapperStrategies);
        }
 public virtual void Map(
     Type targetWorkItemType,
     IDictionary <IWorkItem, IIdentifiable <int?> > workItemMappings,
     IWorkItemMapper workItemMapper)
 {
     foreach (var workItemMapping in workItemMappings)
     {
         Map(targetWorkItemType, workItemMapping.Key, workItemMapping.Value, workItemMapper);
     }
 }
 protected virtual void Map(
     Type targetWorkItemType,
     IWorkItem sourceWorkItem,
     IIdentifiable targetWorkItem,
     IWorkItemMapper workItemMapper)
 {
     Map(
         targetWorkItemType,
         new[] { new KeyValuePair <IWorkItem, IIdentifiable>(sourceWorkItem, targetWorkItem) },
         workItemMapper);
 }
 protected virtual void Map(
     Type targetWorkItemType,
     IWorkItem sourceWorkItem,
     IIdentifiable <int?> targetWorkItem,
     IWorkItemMapper workItemMapper)
 {
     Map(targetWorkItemType, new Dictionary <IWorkItem, IIdentifiable <int?> >(Comparer.WorkItem)
     {
         { sourceWorkItem, targetWorkItem }
     }, workItemMapper);
 }
Exemple #7
0
        public override void Given()
        {
            var propertyInspector = new PropertyInspector(new PropertyReflector());
            var mappingStrategies = new IWorkItemMapperStrategy[]
            {
                new AttributeMapperStrategy(propertyInspector),
                new WorkItemLinksMapperStrategy(propertyInspector, WorkItemStore)
            };

            WorkItemMapper = new WorkItemMapper(mappingStrategies);
        }
Exemple #8
0
        public override void Map <T>(IDictionary <IWorkItem, T> workItemMappings, IWorkItemMapper workItemMapper)
        {
            var targetWorkItemType = typeof(T);

            foreach (var workItemMapping in workItemMappings)
            {
                var sourceWorkItem = workItemMapping.Key;
                var targetWorkItem = workItemMapping.Value;

                MapImpl(targetWorkItemType, sourceWorkItem, targetWorkItem);
            }
        }
 protected virtual void Map <T>(IWorkItem sourceWorkItem, T targetWorkItem, IWorkItemMapper workItemMapper)
     where T : IIdentifiable <int?>, new()
 {
     Map(typeof(T), sourceWorkItem, targetWorkItem, workItemMapper);
 }
 public virtual void Map <T>(IDictionary <IWorkItem, T> workItemMappings, IWorkItemMapper workItemMapper)
     where T : IIdentifiable <int?>, new()
 {
     Map(typeof(T), workItemMappings.ToDictionary(k => k.Key, e => (IIdentifiable <int?>)e.Value, Comparer.WorkItem), workItemMapper);
 }
Exemple #11
0
 public MapperTeamFoundationServerWorkItemQueryProvider(IWorkItemStore workItemStore,
                                                        IWiqlQueryBuilder queryBuilder, IWorkItemMapper workItemMapper) : base(workItemStore, queryBuilder)
 {
     WorkItemMapper = workItemMapper;
 }
 protected virtual void Map <T>(IWorkItem sourceWorkItem, T targetWorkItem, IWorkItemMapper workItemMapper)
 {
     Map(typeof(T), sourceWorkItem, (IIdentifiable)targetWorkItem, workItemMapper);
 }
Exemple #13
0
        public override void Map(Type targetWorkItemType, IEnumerable <KeyValuePair <IWorkItem, IIdentifiable> > workItemMappings, IWorkItemMapper workItemMapper)
        {
            var accessor = TypeAccessor.Create(targetWorkItemType, true);

            foreach (var workItemMapping in workItemMappings)
            {
                var sourceWorkItem = workItemMapping.Key;
                var targetWorkItem = workItemMapping.Value;

                MapImpl(targetWorkItemType, sourceWorkItem, accessor, targetWorkItem);
            }
        }
        public override void Map(
            Type targetWorkItemType,
            IEnumerable <KeyValuePair <IWorkItem, IIdentifiable> > workItemMappings,
            IWorkItemMapper workItemMapper)
        {
            var linksLookup = BuildLinksRelationships(targetWorkItemType, workItemMappings);

            // REVIEW: We don't have any cycle detection, this avoids causing stack overflows in those cases
            workItemMapper = new WorkItemMapper(workItemMapper.MapperStrategies.Except(new[] { this }));

            // If there were no items added to the lookup, don't bother querying VSO
            if (!linksLookup.Any())
            {
                return;
            }

            // Load all the items
            var workItems = Store.Query(linksLookup.SelectMany(p => p.Value).Distinct())
                            .ToDictionary(k => k.Id, e => e);

            var idToMapTargetLookup = workItemMappings.ToDictionary(k => k.Key.Id, e => e);
            var accessor            = TypeAccessor.Create(targetWorkItemType, true);


            // REVIEW: The recursion of links can cause mapping multiple times on the same values
            // For example, a common ancestor
            var previouslyMapped = new Dictionary <Tuple <int, RuntimeTypeHandle>, IIdentifiable>();

            // Enumerate through items requiring a VSO lookup and map the objects
            // There are n-passes to map, where n=number of link types
            foreach (var item in linksLookup)
            {
                var sourceWorkItem = idToMapTargetLookup[item.Key.Item1].Key;
                var targetWorkItem = idToMapTargetLookup[item.Key.Item1].Value;

#if DEBUG && TRACE
                Trace.TraceInformation("{0}: Mapping {1} on {2}", GetType().Name, item.Key.Item2, sourceWorkItem.Id);
#endif

                foreach (var property in
                         PropertiesOnWorkItemCache(
                             _inspector,
                             sourceWorkItem,
                             targetWorkItemType,
                             typeof(WorkItemLinkAttribute)))
                {
                    var def = PropertyInfoLinkTypeCache(_inspector, property);
                    if (def != null)
                    {
                        var        propertyType = def.WorkItemType;
                        var        linkType     = def.LinkName;
                        var        key          = new Tuple <int, string>(sourceWorkItem.Id, linkType);
                        List <int> linkIds;

                        if (!linksLookup.TryGetValue(key, out linkIds))
                        {
                            // Could not find any IDs for the given ID/LinkType
                            continue;
                        }


                        var wi = linkIds
                                 // Only get the new items that need to be mapped
                                 .Where(p => !previouslyMapped.ContainsKey(new Tuple <int, RuntimeTypeHandle>(p, propertyType.TypeHandle)))
                                 .Select(
                            s =>
                        {
                            IWorkItem val;
                            workItems.TryGetValue(s, out val);
                            return(val);
                        }).Where(p => p != null)
                                 .ToList();

                        var createdItems = workItemMapper.Create(propertyType, wi).ToList();

                        // Add the newly created items to the cache
                        // This allows for lazy creation of common parents
                        foreach (var createdItem in createdItems)
                        {
                            var key2 = new Tuple <int, RuntimeTypeHandle>(createdItem.Id, propertyType.TypeHandle);
                            previouslyMapped[key2] = createdItem;
                        }

                        var existing = linkIds
                                       // Only get the new items that need to be mapped
                                       .Where(
                            p =>
                            previouslyMapped.ContainsKey(
                                new Tuple <int, RuntimeTypeHandle>(p, propertyType.TypeHandle)))
                                       .Select(s => previouslyMapped[new Tuple <int, RuntimeTypeHandle>(s, propertyType.TypeHandle)]);

                        var allItems = createdItems.Union(existing).ToList();

                        // REVIEW: These steps are required as the type defined for the link may be different than targetWorkItemType
                        // ReSharper disable SuggestVarOrType_SimpleTypes
                        IList results = (IList)typeof(List <>)
                                        // ReSharper restore SuggestVarOrType_SimpleTypes
                                        .MakeGenericType(propertyType)
                                        .GetConstructor(new[] { typeof(int) })
                                        .Invoke(new object[] { allItems.Count });
                        foreach (var link in allItems)
                        {
                            results.Add(link);
                        }

                        accessor[targetWorkItem, property.Name] = results;
                    }
                }
            }
        }
Exemple #15
0
        public override void Map(Type targeWorkItemType, IEnumerable <KeyValuePair <IWorkItem, IIdentifiable> > workItemMappings, IWorkItemMapper workItemMapper)
        {
            var workingSet = workItemMappings.ToDictionary(kvp => kvp.Key, kvp => kvp.Value, new WorkItemKeyComparer());

            if (!workingSet.Any())
            {
                return;
            }

            var validIdentityProperties = GetWorkItemIdentityFieldNameToIdentityPropertyMap(targeWorkItemType, _inspector);

            if (!validIdentityProperties.Any())
            {
                return;
            }
            var accessor = TypeAccessor.Create(targeWorkItemType, true);
            var validIdentityFieldsWithWorkItems = GetWorkItemsWithIdentityFieldValues(workingSet.Keys.ToList(), validIdentityProperties.Keys.ToList());
            var identitySearchTerms   = GetIdentitySearchTerms(validIdentityFieldsWithWorkItems).ToList();
            var identitySearchResults = GetIdentityMap(_identityManagementService, identitySearchTerms);

            foreach (var workItem in validIdentityFieldsWithWorkItems)
            {
                var targetObject = workingSet[workItem.WorkItem];
                foreach (var sourceField in workItem.ValidFields)
                {
                    var targetProperty = validIdentityProperties[sourceField.Name];
                    var mappedValue    = identitySearchResults[sourceField.Value];
                    if (!string.IsNullOrEmpty(mappedValue))
                    {
                        accessor[targetObject, targetProperty.Name] = mappedValue;
                    }
                }
            }
        }
Exemple #16
0
        public override void Map(Type targetWorkItemType, IDictionary <IWorkItem, IIdentifiable <int?> > workItemMappings, IWorkItemMapper workItemMapper)
        {
            foreach (var workItemMapping in workItemMappings)
            {
                var sourceWorkItem = workItemMapping.Key;
                var targetWorkItem = workItemMapping.Value;

                MapImpl(targetWorkItemType, sourceWorkItem, targetWorkItem);
            }
        }
        public override void Map(Type targeWorkItemType, IEnumerable <KeyValuePair <IWorkItem, IIdentifiable> > workItemMappings, IWorkItemMapper workItemMapper)
        {
            var workingSet    = workItemMappings.ToList();
            var parentIdField = targeWorkItemType.GetProperty("ParentId");

            if (!workingSet.Any() || parentIdField == null)
            {
                return;
            }

            var workItems          = workingSet.Select(wi => wi.Key).ToList();
            var ids                = workItems.Select(wi => wi.Id);
            var asOf               = workItems.Max(wi => wi.ChangedDate);
            var childToParentLinks =
                _workItemStore.QueryLinks(string.Format(ParentLinkQueryFormat, string.Join(",", ids), asOf))
                .Where(link => link.LinkTypeId != SelfReferenceLinkId);
            var childToParentDictionary = childToParentLinks.ToDictionary(link => link.SourceId, link => link.TargetId);

            foreach (var workItemMapping in workingSet)
            {
                var childId = workItemMapping.Key.Id;
                if (childToParentDictionary.ContainsKey(childId))
                {
                    parentIdField.SetValue(workItemMapping.Value, childToParentDictionary[childId]);
                }
            }
        }
 public virtual void Map(Type targetWorkItemType, IEnumerable <KeyValuePair <IWorkItem, IIdentifiable> > workItemMappings, IWorkItemMapper workItemMapper)
 {
     foreach (var workItemMapping in workItemMappings)
     {
         Map(targetWorkItemType, workItemMapping.Key, workItemMapping.Value, workItemMapper);
     }
 }
Exemple #19
0
        /// <summary>
        /// Maps the specified target work item type.
        /// </summary>
        /// <param name="targetWorkItemType">Type of the targe work item.</param>
        /// <param name="workItemMappings">The work item mappings.</param>
        /// <param name="workItemMapper">The work item mapper.</param>
        public override void Map(Type targetWorkItemType, IDictionary <IWorkItem, IIdentifiable <int?> > workItemMappings, IWorkItemMapper workItemMapper)
        {
            if (!workItemMappings.Any())
            {
                return;
            }

            var validIdentityProperties = GetWorkItemIdentityFieldNameToIdentityPropertyMap(targetWorkItemType, _inspector);

            if (!validIdentityProperties.Any())
            {
                return;
            }

            var validIdentityFieldsWithWorkItems = GetWorkItemsWithIdentityFieldValues(workItemMappings.Keys, validIdentityProperties.Keys);
            var identitySearchTerms   = GetIdentitySearchTerms(validIdentityFieldsWithWorkItems);
            var identitySearchResults = MapIdentityValues(identitySearchTerms);

            foreach (var workItem in validIdentityFieldsWithWorkItems)
            {
                var targetObject = workItemMappings[workItem.WorkItem];
                foreach (var sourceField in workItem.ValidFields)
                {
                    var targetProperties = validIdentityProperties[sourceField.Name];
                    var mappedValue      = identitySearchResults[sourceField.Value];

                    foreach (var targetProperty in targetProperties)
                    {
                        AssignFieldValue(targetWorkItemType, workItem.WorkItem, targetObject, targetProperty,
                                         sourceField.Name, true, sourceField.Value, mappedValue);
                    }
                }
            }
        }
 public virtual void Map <T>(
     IEnumerable <KeyValuePair <IWorkItem, T> > workItemMappings,
     IWorkItemMapper workItemMapper) where T : IIdentifiable, new()
 {
     Map(typeof(T), workItemMappings.Select(s => new KeyValuePair <IWorkItem, IIdentifiable>(s.Key, s.Value)), workItemMapper);
 }