/// <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> private void MenuItemCallback(object sender, EventArgs e) { TeamProjectPicker picker = new TeamProjectPicker(TeamProjectPickerMode.MultiProject, false); if (picker.ShowDialog() != DialogResult.OK) { return; } ProjectInfo[] projectsInfo = picker.SelectedProjects; TfsTeamProjectCollection tfsTeamProjecttollection = picker.SelectedTeamProjectCollection; DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2; Debug.Assert(dte2 != null, "dte2 != null"); if (projectsInfo.Length == 0) { // ReSharper disable once SuspiciousTypeConversion.Global IServiceProvider serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte2); VsShellUtilities.ShowMessageBox(serviceProvider, "At least one team project must be selected", "Tfs Permission Visualizer Error:", OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } string dgmlTempFilePath = System.IO.Path.GetTempFileName() + ".dgml"; CommonMessagePump msgPump = new CommonMessagePump { AllowCancel = false, EnableRealProgress = false, WaitTitle = "Building Permission graph...", WaitText = "Please wait while we are building security groups Permission graph." }; System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Run(() => { TfsPermissionGraphGenerator generator = new TfsPermissionGraphGenerator(); XDocument xDocument = generator.GenerateDependencyGraph(tfsTeamProjecttollection, projectsInfo); xDocument.Save(dgmlTempFilePath); }); // ReSharper disable once SuspiciousTypeConversion.Global // ReSharper disable once PossibleInvalidCastException CommonMessagePumpExitCode exitCode = msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle); dte2.ItemOperations.OpenFile(dgmlTempFilePath); }
static int Main(string[] args) { // C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe with "/rootsuffix Exp" // or // Start Project with -c https://dev.bittitan.com/tfs/BitTitan -p SendBus -f TfsPoking.dgml Options options = new Options(); Parser parser = new Parser(settings => { settings.CaseSensitive = false; settings.HelpWriter = Console.Error; settings.ParsingCulture = CultureInfo.InvariantCulture; }); bool result = parser.ParseArguments(args, options); if (!result) { ConsoleEntryPoint.Fail(); return(-1); } Uri collectionUri = new Uri(options.Collection); TfsTeamProjectCollection tfsTeamProjectCollection = new TfsTeamProjectCollection(collectionUri, CredentialCache.DefaultCredentials); tfsTeamProjectCollection.EnsureAuthenticated(); ICommonStructureService commonStructureService = tfsTeamProjectCollection.GetService <ICommonStructureService>(); IEnumerable <ProjectInfo> projectInfoList = commonStructureService.ListAllProjects(); if (options.Projects.Any()) { projectInfoList = projectInfoList.Where(pil => options.Projects.Contains(pil.Name)).ToArray(); } TfsPermissionGraphGenerator generator = new TfsPermissionGraphGenerator(); XDocument xDocument = generator.GenerateDependencyGraph(tfsTeamProjectCollection, projectInfoList); string dgmlTempFilePath = (String.IsNullOrEmpty(options.OutputFile)) ? "TfsPermissionVisualizer.dgml" : options.OutputFile; xDocument.Save(dgmlTempFilePath); return(0); }