private int[] GetSelectedWorkItemIdentifiers() { Document activeDocument = dte.ActiveDocument; if ((activeDocument == null) || (documentService == null)) { return(new int[0]); } string activeDocumentName = activeDocument.FullName; IWorkItemTrackingDocument workItemTrackingDocument = documentService.FindDocument(activeDocumentName, null); var workItemDocument = workItemTrackingDocument as IWorkItemDocument; var resultsDocument = workItemTrackingDocument as IResultsDocument; if (resultsDocument != null) { return(resultsDocument.SelectedItemIds); } if ((workItemDocument != null) && (workItemDocument.Item != null)) { return(new [] { workItemDocument.Item.Id }); } return(new int[0]); }
/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// See the Initialize method to see how the menu item is associated to this function using /// the OleMenuCommandService service and the MenuCommand class. /// </summary> public static void MenuItemCallback(object sender, EventArgs e) { object _lockToken1 = new object(); object _lockToken2 = new object(); IWorkItemTrackingDocument doc = Utilities.docsrv2.FindDocument(Utilities.dte.ActiveDocument.FullName, _lockToken2); if (doc == null) { return; } int fldid; bool isSortable; var dataprov = (doc as IResultsDocument).ResultListDataProvider; dataprov.GetFieldInfo("field name", out fldid, out isSortable); var qdoc = (doc as IResultsDocument).QueryDocument;// as QueryDocument; /* * Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.PackageHelper.OpenQueryInOffice() * Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.QueryDocument * * Microsoft.TeamFoundation.OfficeIntegration.Client.DocumentLaunch * Microsoft.TeamFoundation.OfficeIntegration.Client.ExcelAddIn.CreateDocumentInternal() * Microsoft.TeamFoundation.OfficeIntegration.Client.ELeadWorkbook.CreateList() * / * * foreach (int i in (doc as IResultsDocument).SelectedItemIds) * { * string val = dataprov.GetFieldValue(dataprov.GetItemIndex(i), fldid); * /*IWorkItemDocument widoc = docsrv.GetWorkItem(tfscoll, i, _lockToken1); * if (widoc == null) continue; * * * widoc.Load(); * * wicoll.Add(widoc.Item.Id); * * widoc.Release(_lockToken1); * }*/ doc.Release(_lockToken2); //wistore.DestroyWorkItems(wicoll); }
public static void CopyChangesetComments(object sender, EventArgs e) { object _lockToken2 = new object(); if (DialogResult.No == MessageBox.Show("Are you sure you want to copy the Changeset comments?", Utilities.AppTitle, MessageBoxButtons.YesNo)) { return; } IWorkItemTrackingDocument doc2 = Utilities.docsrv2.FindDocument(Utilities.dte.ActiveDocument.FullName, _lockToken2); if (doc2 == null) { return; } try { foreach (int i in (doc2 as IResultsDocument).SelectedItemIds) { var wi = Utilities.wistore.GetWorkItem(i); if (wi.ExternalLinkCount == 0) { continue; } wi.Open(); foreach (var link in wi.Links.OfType <ExternalLink>()) { var ch = Utilities.vcsrv.ArtifactProvider.GetChangeset(new Uri(link.LinkedArtifactUri)); link.Comment = ch.Comment; } wi.Save(); } MessageBox.Show("Changesets added sucessfully.", Utilities.AppTitle); } catch (Exception ex) { Utilities.OutputCommandString(ex.ToString()); MessageBox.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message, Utilities.AppTitle); } doc2.Release(_lockToken2); }
/// <summary> /// This function is the callback used to execute a command when the a menu item is clicked. /// See the Initialize method to see how the menu item is associated to this function using /// the OleMenuCommandService service and the MenuCommand class. /// </summary> public void OnPlanWorkItem(object sender, EventArgs e) { Debug.WriteLine("WorkItemSearchReplace command invoked"); var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if (dteService == null) { Debug.WriteLine("[PlanWorkItemController] DTE Service is null."); return; } DocumentService documentService = Package.GetGlobalService(typeof(DocumentService)) as DocumentService; if (documentService == null) { Debug.WriteLine("[PlanWorkItemController] Document Service is null."); return; } string fullName = dteService.ActiveDocument.FullName; IWorkItemTrackingDocument activeDocument = documentService.FindDocument(fullName, null); if (activeDocument == null || !(activeDocument is IResultsDocument)) { Debug.WriteLine("[PlanWorkItemController] Active Document is null or doesn't implement IResultsDocument"); return; } int[] selectedItemIds = ((IResultsDocument)activeDocument).SelectedItemIds; if (selectedItemIds == null || selectedItemIds.Length == 0) { Debug.WriteLine("[PlanWorkItemController] Selected Work Items Ids is null or empty."); return; } this.OnPlanWorkItem(selectedItemIds); }
public static void DestroyWICallback(object sender, EventArgs e) { if (DialogResult.No == MessageBox.Show("Are you sure you want to destroy the WorkItems?", Utilities.AppTitle, MessageBoxButtons.YesNo)) { return; } var origCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { object _lockToken1 = new object(); object _lockToken2 = new object(); IWorkItemTrackingDocument doc2 = Utilities.docsrv2.FindDocument(Utilities.dte.ActiveDocument.FullName, _lockToken2); if (doc2 == null) { return; } var wicoll = new List <int>(); foreach (int i in (doc2 as IResultsDocument).SelectedItemIds) { IWorkItemDocument widoc = Utilities.docsrv2.GetWorkItem(Utilities.tfscoll, i, _lockToken1); if (widoc == null) { continue; } widoc.Load(); if (widoc.Item != null) { wicoll.Add(widoc.Item.Id); Utilities.OutputCommandString("Preparing for destroy: " + widoc.Item.Id + ", " + widoc.Item.Title); } else { Utilities.OutputCommandString("WorkItem cannot be destroyed: " + i); } widoc.Release(_lockToken1); } doc2.Release(_lockToken2); foreach (var result in Utilities.wistore.DestroyWorkItems(wicoll)) { Utilities.OutputCommandString("Exception destroying Work Item #" + result.Id + " :" + result.Exception.Message); } Cursor.Current = origCursor; if (wicoll.Count > 0) { MessageBox.Show("Destroyed " + wicoll.Count + " Work Items", Utilities.AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Cursor.Current = origCursor; Utilities.OutputCommandString(ex.ToString()); MessageBox.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message, Utilities.AppTitle, MessageBoxButtons.OK); } }
/// <summary> /// Menu callback event handler that activates the merge pane after selecting work items in Work Item Query view. /// See <see cref="MergeWIControl"/> /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> public static void MyWIExpMergeIDCallback(object sender, EventArgs e) { var origCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; IVsThreadedWaitDialog2 dlg = null; int icanceled; try { if (Utilities.paneMerge == null) { Cursor.Current = origCursor; MessageBox.Show("Failed to initialize " + Utilities.AppTitle + ": Pane was null.", Utilities.AppTitle); return; } var mfrm = Utilities.paneMerge.control; mfrm.SuppressEvents = true; mfrm.defServerName = "$/" + Utilities.vsTeamCtxMan.CurrentContext.TeamProjectName; mfrm.Initialize(); mfrm.ClearGrids(); IVsWindowFrame frame = Utilities.paneMerge.Frame as IVsWindowFrame; if (frame == null) { Cursor.Current = origCursor; MessageBox.Show("Failed to initialize " + Utilities.AppTitle + ": Frame was null.", Utilities.AppTitle); return; } // Bring the tool window to the front and give it focus ErrorHandler.ThrowOnFailure(frame.Show()); int idx = 0; int iddx = 0; bool nolinks = true; bool bcanceled = false; object _lockToken1 = new object(); object _lockToken2 = new object(); string sourcePath; dlg = Utilities.CreateThreadedWaitDialog("Collecting information about changesets", "Starting to process changesets...", "status", 100); dlg.UpdateProgress("Collecting information about changesets", "Starting to process changesets...", "status", 0, 100, true, out bcanceled); IWorkItemTrackingDocument doc2 = Utilities.docsrv2.FindDocument(Utilities.dte.ActiveDocument.FullName, _lockToken2); if (doc2 == null) { Cursor.Current = origCursor; return; } foreach (int i in (doc2 as IResultsDocument).SelectedItemIds) { IWorkItemDocument widoc = Utilities.docsrv2.GetWorkItem(Utilities.tfscoll, i, _lockToken1); if (widoc == null) { continue; } if (!widoc.IsLoaded) { widoc.Load(); } iddx = 0; while (!widoc.IsLoaded && ++iddx < 10) { Thread.Sleep(1000); if (widoc.ItemState == WorkItemState.Error) { Utilities.OutputCommandString(widoc.Exception != null ? widoc.Exception.ToString() : "WorkItem cannot be loaded " + i); iddx = i; break; } } if (iddx == 10) { Utilities.OutputCommandString("WorkItem cannot be loaded " + i + ". Please open it manually and then try to load again."); iddx = i; break; } iddx = 0; foreach (Link lnk in widoc.Item.Links.Cast <Link>().Where(x => x.ArtifactLinkType.Name == "Fixed in Changeset")) { Changeset ch = Utilities.vcsrv.ArtifactProvider.GetChangeset(new Uri((lnk as ExternalLink).LinkedArtifactUri)); if (ch.Changes == null || ch.Changes.Length == 0) { continue; } string change = ch.Changes.Take(5).Select(x => x.ChangeType.ToString()).Aggregate((x, y) => x + "," + y); if (ch.Changes.Length > 5) { change += "..."; } string[] relbranches = MergeFactory.QueryBranchObjectOwnership(ch.ChangesetId); if (relbranches.Length == 0) { sourcePath = "$/" + Utilities.vsTeamCtxMan.CurrentContext.TeamProjectName; } else { sourcePath = relbranches[0]; } //} ListViewItem itm = mfrm.AddNewGridItem(widoc.Item.Id.ToString(), ch.ChangesetId.ToString(), ch.CreationDate.ToShortDateString(), ch.Owner, sourcePath, change, ch.Comment, new ListViewItemTag(ch.ChangesetId, widoc.Item.Id, sourcePath, ch.CreationDate)); Utilities.OutputCommandString("Adding Changeset: " + itm.Name + " => " + sourcePath); nolinks = false; dlg.UpdateProgress("Collecting information about changesets", "Processing changeset: " + ch.ChangesetId, "status", idx++, 100, false, out bcanceled); if (bcanceled) { widoc.Release(_lockToken1); doc2.Release(_lockToken2); mfrm.SortItems(); mfrm.SuppressEvents = false; Cursor.Current = origCursor; return; } if (idx == 100) { idx = 0; } } widoc.Release(_lockToken1); } doc2.Release(_lockToken2); mfrm.SortItems(); mfrm.UpdateRelatedBranchesCombo(); mfrm.SuppressEvents = false; Cursor.Current = origCursor; dlg.EndWaitDialog(out icanceled); if (iddx > 0) { MessageBox.Show("WorkItem cannot be loaded " + iddx + ". Please open it manually and then try to load again.", Utilities.AppTitle); } else if (nolinks) { MessageBox.Show("No linked Changesets where found in selected Work Items.", Utilities.AppTitle); } } catch (Exception ex) { Cursor.Current = origCursor; if (dlg != null) { dlg.EndWaitDialog(out icanceled); } Utilities.OutputCommandString(ex.ToString()); MessageBox.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message, Utilities.AppTitle, MessageBoxButtons.OK); } return; }