private void AddTFSItemToolStripMenuItem_Click(object sender, EventArgs e) { frmRecalculateHours oRec = new frmRecalculateHours { Location = Cursor.Position }; oRec.openType = frmRecalculateHours.OpenType.TFS; if (oRec.ShowDialog() == DialogResult.OK) { if (int.TryParse(oRec.dHours.ToString(), out int iId)) { WorkItemRegister oWi = null; foreach (var oDataSource in oDataSources.Where(x => x.Type == Datasourcetype.TFS)) { if (oWi == null) { oWi = WorkItemMapper.GetHistoricalWorkitemsByIDs(oDataSource.ServerUrl, oDataSource.ProjectName, oDataSource.User, new int[] { iId }).FirstOrDefault(); if (oWi != null) { lvwHistory.Items.Add(WorkItemHoursToLVWItem(lvwHistory.SelectedItems[0].Group, WorkItemToWIHours(oWi, null, oDataSource, 0))); } } } } else { MessageBox.Show("Coulnd't parse the TFS ID, please try again with an integer"); } } }
private void LoadTFSCSV() { frmLoginSendHaxCom oLogin = new frmLoginSendHaxCom { LoginURL = TimeKeeperBaseURL }; oLogin.openMode = frmLoginSendHaxCom.OpenMode.Search; oLogin.optDays.Enabled = false; oLogin.optSel.Enabled = false; if (oLogin.ShowDialog() == DialogResult.OK) { List <WorkItemsDay> oItems = new List <WorkItemsDay>(); List <CsvReg> regs = getHaxComTFSTime(oLogin.PHPSession, dtpFrom.Value, DateTime.Today, oLogin.chkAll.Checked, (oLogin.CHKBug.Checked || oLogin.chkPBI.Checked || oLogin.chkOther.Checked), oLogin.chkMeeting.Checked, oLogin.chkPrjtLess.Checked, oLogin.chkNonBillable.Checked, oLogin.chkCapitalized.Checked); var oDataSource = oDataSources.First(x => x.Type == Datasourcetype.TFS); var outlookDataSource = oDataSources.FirstOrDefault(x => x.Type == Datasourcetype.Outlook); //gets rest of TFS data using the TFS IDS var tfsItems = WorkItemMapper.GetHistoricalWorkitemsByIDs(oDataSource.ServerUrl, oDataSource.ProjectName, oDataSource.User, regs.Select(x => x.TFSId).Distinct()); //assembles the listview foreach (DateTime dDate in regs.Select(x => x.Date).Distinct()) { var oTemp = new WorkItemsDay(dDate); foreach (CsvReg oReg in regs.Where(x => x.Date == dDate)) { if (oReg.TFSId == 0) //meetings { var oWI = new WorkItemHours(); oWI.HaxComID = oReg.EntryID; oWI.ID = "meeting"; oWI.ProjectId = 0; oWI.ClientId = 166; oWI.SubClientId = 5; oWI.Function = 41; //dev meeting oWI.Description = oReg.Title; oWI.Title = oReg.Title; oWI.FromDatasource = outlookDataSource; oWI.BillingType = BillingType.Capitalized; oWI.HaxComHours = oReg.Hours; oTemp.WorkItems.Add(oWI); } else { var oTFSI = tfsItems.FirstOrDefault(x => x.ID == oReg.TFSId.ToString()); if (oTFSI != null) { string sType = oTFSI.Type.ToUpperInvariant(); if (oLogin.chkAll.Checked || (sType == "BUG" && oLogin.CHKBug.Checked) || (sType == "USER STORY" && oLogin.chkPBI.Checked) || (sType != "BUG" && sType != "PRODUCT BACKLOG ITEM" && oLogin.chkOther.Checked)) { oTemp.WorkItems.Add(WorkItemToWIHours(oTFSI, oReg.EntryID, oDataSource, oReg.Hours)); } } } } oItems.Add(oTemp); } UpdateListview(oItems, false); } }
private void LoadNewItems() { List <WorkItemsDay> oItems = new List <WorkItemsDay>(); WorkItemsDay oTemp; foreach (DataSource oDataSource in oDataSources) { switch (oDataSource.Type) { case Datasourcetype.Outlook: Outlook oDS = new Outlook(); var oMeetings = oDS.GetAllCalendarItems(dtpFrom.Value, new DateTimeOffset[] { }); foreach (DateTime oDate in oMeetings.Select(x => x.Date.Date).Distinct()) { oTemp = oItems.FirstOrDefault(x => x.Date == oDate); if (oTemp == null) { oTemp = new WorkItemsDay(oDate); oItems.Add(oTemp); } oTemp.WorkItems.AddRange( oMeetings.Where(x => x.Date.Date == oDate) .Select(x => new WorkItemHours() { FixedHours = true, Hours = TimeSpan.FromHours((double)x.DurationInHours), HaxComHours = x.DurationInHours, Title = x.Name, ID = "meeting", TfsId = 0, FromDatasource = oDataSource, ProjectId = 0, ClientId = 166, SubClientId = 5, Function = 41, // meeting BillingType = BillingType.Capitalized, Description = x.Name, })); } break; case Datasourcetype.TFS: var oTFSItems = WorkItemMapper.GetHistoricalWorkitemsByUser(oDataSource.ServerUrl, oDataSource.ProjectName, oDataSource.User, dtpFrom.Value, oDataSource); foreach (DateTime oDate in oTFSItems.Select(x => x.Date.Date).Distinct()) { oTemp = oItems.FirstOrDefault(x => x.Date == oDate); if (oTemp == null) { oTemp = new WorkItemsDay(oDate); oItems.Add(oTemp); } oTemp.WorkItems.AddRange(oTFSItems.Where(x => x.Date.Date == oDate).Select(x => x.WorkItems).FirstOrDefault()); } break; } } UpdateListview(oItems, true); }
/// <exception cref="NotSupportedException"><paramref name="workItemType"/> is not assignable to <see cref="IWorkItem"/>.</exception> protected override IEnumerable ExecuteRawQuery(Type workItemType, string queryString) { var workItems = WorkItemStore.Query(queryString); if (typeof(IIdentifiable).IsAssignableFrom(workItemType)) { return(WorkItemMapper.Create(workItemType, workItems)); } throw new NotSupportedException($"Unsupported type for performing relatives aware queries: {workItemType.Name}. To perform relatives aware queries the types involved must inherit from IIdentifiable."); }
public void SetupData() { var propertyInspector = new PropertyInspector(new PropertyReflector()); var typeParser = new TypeParser(); var mappingStrategies = new IWorkItemMapperStrategy[] { new AttributeMapperStrategy(propertyInspector, typeParser) }; _mapper = new WorkItemMapper(mappingStrategies); var generator = new WorkItemGenerator <MockWorkItem>(() => new MockWorkItem("Baz"), new[] { "Revisions", "Item" }); _items = generator.Generate(); }
private IEnumerable GetRelatives(IEnumerable <IIdentifiable> source, RelativesExpression relativesExpression, Type itemType, DateTime asOf) { var results = Activator .CreateInstance(typeof(List <>) .MakeGenericType(itemType)) as IList; var ids = source.Select(item => item.Id); if (!ids.Any()) { return(results); } var workItemLinks = WorkItemStore.QueryLinks(GetQueryStringForRelativesOf(ids, relativesExpression.AncestorType, relativesExpression.DescendentType, relativesExpression.Direction, asOf)); var map = new Dictionary <int, List <int> >(); workItemLinks.Where(link => link.SourceId == 0).ToList().ForEach(link => map.Add(link.TargetId, new List <int>())); foreach (var ancestorId in map.Keys) { map[ancestorId].AddRange(GetTransitiveLinks(ancestorId, workItemLinks).Select(child => child.TargetId)); } ids = ids.Union(workItemLinks.Select(link => link.SourceId)).Union(workItemLinks.Select(link => link.TargetId)).Where(id => id != 0); var workItems = HydrateAndFilterItems(ids, relativesExpression.AncestorType, relativesExpression.DescendentType, asOf); foreach (var ancestorId in map.Keys) { var id = ancestorId; // Get the ancestor from the list of hydrated work items var ancestorWorkItem = workItems.Single(item => item.Id == ancestorId); // Filter the work items to just those IDs that are in the map for this ancestor. // NOTE: Please note that the strategy is to start with the hydrated work items and filter to // those in the map, and NOT to lookup every work item in the map. The latter strategy would // break because the map also contains the IDs of Task Groups that have been filtered out. // This way we start with work items that we already know exist. var descendentWorkItems = workItems.Where(wi => map[id].Contains(wi.Id)); var ancestor = WorkItemMapper.Create(relativesExpression.AncestorType, new[] { ancestorWorkItem }).Cast <object>().Single(); var descendents = WorkItemMapper.Create(relativesExpression.DescendentType, descendentWorkItems); var properTypedDescendents = GenerateListOfType(descendents, itemType); var result = Activator.CreateInstance(itemType, ancestor, properTypedDescendents); results.Add(result); } return(results); }
public void SetupData() { var generator = new WorkItemLinkGenerator(() => new MockWorkItem("Baz"), new[] { "Revisions", "Item" }); _items = generator.Generate(); var propertyInspector = new PropertyInspector(new PropertyReflector()); var typeParser = new TypeParser(); var mappingStrategies = new IWorkItemMapperStrategy[] { new AttributeMapperStrategy(propertyInspector, typeParser), new WorkItemLinksMapperStrategy(propertyInspector, new MockWorkItemStore(_items)), }; Mapper = new WorkItemMapper(mappingStrategies); MappingItems = _items.Take(500).ToList(); }
public void SetupData() { var propertyInspector = new PropertyInspector(new PropertyReflector()); var mappingStrategies = new IWorkItemMapperStrategy[] { new AttributeMapperStrategy(propertyInspector) }; _mapper = new WorkItemMapper(mappingStrategies); var wis = new MockWorkItemStore(); var generator = new WorkItemGenerator <MockWorkItem>(() => wis.Create(), new[] { "Revisions", "Item" }); _items = generator.Generate(1); wis.Add(_items); _item = new[] { _items.First() }; _type = typeof(MockModel); }
public override void Given() { var workItemStore = new MockWorkItemStore(WorkItemStoreWorkItems, WorkItemStoreWorkItemLinks); var fieldMapper = new CachingFieldMapper(new FieldMapper()); var propertyReflector = new PropertyReflector(); var propertyInspector = new PropertyInspector(propertyReflector); var builder = new WiqlQueryBuilder(new RelativesAwareWiqlTranslator(fieldMapper), new PartialEvaluator(), new RelativesAwareQueryRewriter()); var mapperStrategies = new IWorkItemMapperStrategy[] { new AttributeMapperStrategy(propertyInspector, new TypeParser()), new WorkItemLinksMapperStrategy(propertyInspector, workItemStore), new ParentIdMapperStrategy(workItemStore) }; var mapper = new WorkItemMapper(mapperStrategies); var queryProvider = new RelativesAwareTeamFoundationServerWorkItemQueryProvider(workItemStore, builder, mapper, fieldMapper); Query = new Query <SimpleMockModel>(queryProvider, builder); }
public override void Given() { var workItemStore = CreateWorkItemStore(); var fieldMapper = CreateFieldMapper(); var propertyInspector = CreatePropertyInspector(); var mapperStrategies = new IWorkItemMapperStrategy[] { new AttributeMapperStrategy(propertyInspector), new WorkItemLinksMapperStrategy(propertyInspector, workItemStore) }; var builder = new WiqlQueryBuilder(new WiqlTranslator(fieldMapper), new PartialEvaluator(), new QueryRewriter()); var mapper = new WorkItemMapper(mapperStrategies); var queryProvider = new MapperTeamFoundationServerWorkItemQueryProvider(workItemStore, builder, mapper); Query = new Query <T>(queryProvider, builder); }
public void SetupData() { var wis = new MockWorkItemStore(); var generator = new WorkItemLinkGenerator <MockWorkItem>( () => wis.Create(), wis.WorkItemLinkTypes[CoreLinkTypeReferenceNames.Hierarchy], (e, s, t) => new MockRelatedLink(e, s, t), new[] { "Revisions", "Item" }); wis.Add(generator.Generate()); var propertyInspector = new PropertyInspector(new PropertyReflector()); var mappingStrategies = new IWorkItemMapperStrategy[] { new AttributeMapperStrategy(propertyInspector), new WorkItemLinksMapperStrategy(propertyInspector, wis), }; _mapper = new WorkItemMapper(mappingStrategies); // Try to map 10% of what came back var mapCount = (int)(generator.Items.Count * 0.1); _items = generator.Items.Take(mapCount).ToList(); }
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; } } } }
protected virtual IEnumerable ExecuteRawQuery(Type workItemType, string queryString) { var workItems = WorkItemStore.Query(queryString); return(WorkItemMapper.Create(workItemType, workItems)); }
public override void Given() { ParentIdStrategy = new ParentIdMapperStrategy(WorkItemStore); Instance = new WorkItemMapper(new[] { ParentIdStrategy }); }