/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private async void ExecuteAsync(object sender, EventArgs e) { // ThreadHelper.ThrowIfNotOnUIThread(); //string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName); //string title = "GeneratorCommand"; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); var host = await ServiceProvider.GetServiceAsync(typeof(SDTE)) as DTE; if (host.SelectedItems.MultiSelect) { VsShellUtilities.ShowMessageBox( this.package, "Multiple selected items are currently not supported.", "Information", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); MessageBox.Show("Multiple selected items are currently not supported", "Information"); return; } var selectedItem = host.SelectedItems.Item(1); if (selectedItem == null) { return; } var selectedProject = selectedItem.Project; var projectPath = selectedProject.Properties.Item("FullPath").Value.ToString(); ////TODO: test purposes only //var componentModel = (IComponentModel)ServiceProvider.GetServiceAsync(typeof(SComponentModel)).Result; //var workspace = componentModel.GetService<Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>(); //var project = workspace.CurrentSolution.Projects.First(c => c.Name == selectedProject.Name); await Task.Run(() => { var logger = new OutputLogger(); var generatorPath = Path.Combine(Path.GetDirectoryName(projectPath), "Project.gen.json"); var generator = GeneratorSerializer.Instance.Load(generatorPath); generator.SetExecutionContext(new ProjectModel(selectedProject)); generator.SetLogger(logger); try { generator.Execute(); } catch (Exception ex) { logger.Error(ex); MessageBox.Show("Generator execution completed with errors. See output window for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); // Show a message box to prove we were here //VsShellUtilities.ShowMessageBox( // this.package, // message, // title, // OLEMSGICON.OLEMSGICON_INFO, // OLEMSGBUTTON.OLEMSGBUTTON_OK, // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); }