private async void Execute(object sender, EventArgs e) { try { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = (DTE2)await package.GetServiceAsync(typeof(DTE)); Assumes.Present(dte); foreach (string projectPath in await GetSelectedProjectPathsAsync(dte)) { var viewModel = new DeploymentDialogViewModel(_services, projectPath); var view = new DeploymentDialogView(viewModel); var deployWindow = new DeploymentWindow { Content = view }; deployWindow.ShowModal(); //* Actions to take after modal closes: if (viewModel.DeploymentInProgress) // don't open tool window if modal was closed via "X" button { DisplayOutputToolWindow(); } } } catch (Exception ex) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); // TODO: decide what to do if we encounter an error at this stage // (log or message box? etc.) VsShellUtilities.ShowMessageBox( package, ex.ToString(), "Unable to push to Tanzu Application Service", OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST ); } }
private async void Execute(object sender, EventArgs e) { try { // Ensure project file access happens on the main thread await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = (DTE2)await _package.GetServiceAsync(typeof(DTE)); Assumes.Present(dte); var activeProjects = (Array)dte.ActiveSolutionProjects; foreach (Project proj in activeProjects) { string projectDirectory = Path.GetDirectoryName(proj.FullName); string tfm = proj.Properties.Item("TargetFrameworkMoniker").Value.ToString(); if (tfm.StartsWith(".NETFramework") && !File.Exists(Path.Combine(projectDirectory, "Web.config"))) { string msg = $"This project appears to target .NET Framework; pushing it to Tanzu Application Service requires a 'Web.config' file at it's base directory, but none was found in {projectDirectory}"; _dialogService.DisplayErrorDialog("Unable to push to Tanzu Application Service", msg); } else { var viewModel = new DeploymentDialogViewModel(_services, proj.Name, projectDirectory, tfm); var view = new DeploymentDialogView(viewModel, new ThemeService()); view.ShowDialog(); // * Actions to take after modal closes: if (viewModel.DeploymentInProgress) // don't open tool window if modal was closed via "X" button { viewModel.OutputView.Show(); } } } } catch (Exception ex) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _dialogService.DisplayErrorDialog("Unable to push to Tanzu Application Service", ex.Message); } }