public async void AssociateIt(int selectedWorkItemId, object mm) { await ParentSection.RefreshAsync(); IPendingChangesExt pendingChangesExt = ParentSection.GetService <IPendingChangesExt>(); var model = pendingChangesExt.GetType().GetField("m_workItemsSection", BindingFlags.NonPublic | BindingFlags.Instance); var modelType = model.FieldType; var workItemSection = model.GetValue(pendingChangesExt); var selectedWil = workItemSection.GetType().GetProperty("SelectedWorkItems").GetValue(workItemSection) as ObservableCollection <WorkItemValueProvider>; var availablWil = workItemSection.GetType().GetProperty("WorkItemsListProvider").GetValue(workItemSection) as WorkItemsListProvider; try { while (!availablWil.WorkItems.Where(x => x.Id == selectedWorkItemId).Any()) { await System.Threading.Tasks.Task.Delay(25); } selectedWil.Clear(); selectedWil.Add(availablWil.WorkItems.Where(x => x.Id == selectedWorkItemId).First()); EnvDTE80.DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2; dte2.ExecuteCommand("TeamFoundationContextMenus.WorkItemActionLink.TfsContextPendingChangesPageWorkItemActionLinkAssociate"); selectedWil.Clear(); } catch (Exception ex) { ParentSection.ShowNotification(ex.ToString(), NotificationType.Error); } }
private void AddWorkItem(bool associate = false) { try { var item = this.workItemList.SelectedItem; if (item == null) { return; } var propertyId = item.GetType().GetProperty("Id"); if (propertyId == null) { return; } int selectedWorkItemId = (int)propertyId.GetValue(item); IPendingChangesExt pendingChangesExt = ParentSection.GetService <IPendingChangesExt>(); var workItemSection = pendingChangesExt.GetType().GetField("m_workItemsSection", BindingFlags.NonPublic | BindingFlags.Instance); var modelType = workItemSection.FieldType; var model = workItemSection.GetValue(pendingChangesExt); var m = modelType.GetMethod("AddWorkItemById", BindingFlags.NonPublic | BindingFlags.Instance); m.Invoke(model, new object[] { selectedWorkItemId }); if (associate) { AssociateIt(selectedWorkItemId, model); } var workItem = ParentSection.RecentWorkItems.FirstOrDefault(wi => wi.Id == selectedWorkItemId); if (workItem != null) { ParentSection.RecentWorkItems.Remove(workItem); } } catch (Exception ex) { ParentSection.ShowNotification(ex.ToString(), NotificationType.Error); } }
private void OnAddWorkItem(object sender, RoutedEventArgs e) { try { var item = this.workItemList.SelectedItem; if (item == null) { return; } var selectedWorkItem = item as AssociatedWorkItemInfo; if (selectedWorkItem == null) { return; } int selectedWorkItemId = selectedWorkItem.Id; var pc = ParentSection.GetService <IPendingChangesExt>(); var model = pc.GetType().GetField("m_workItemsSection", BindingFlags.NonPublic | BindingFlags.Instance); var t = model.FieldType; var mm = model.GetValue(pc); var m = t.GetMethod("AddWorkItemById", BindingFlags.NonPublic | BindingFlags.Instance); m.Invoke(mm, new object[] { selectedWorkItemId }); var workItem = ParentSection.RecentWorkItems.FirstOrDefault(wi => wi.Id == selectedWorkItemId); if (workItem != null) { ParentSection.RecentWorkItems.Remove(workItem); } } catch (Exception ex) { ParentSection.ShowNotification(ex.ToString(), NotificationType.Error); } }