예제 #1
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary,
                               WizardRunKind runKind, object[] customParams)
        {
            replacementsDictionary.TryGetValue("$solutiondirectory$", out string solutionDirectory);

            var settings = new NgItemWizardViewModel.NgItemWizardSettings();

            // Test if @angular/cli is installed globally.
            this.isNgFound     = NgWizardHelper.IsNgFound(solutionDirectory);
            settings.IsNgFound = this.isNgFound;

            var dte            = (DTE)automationObject;
            var activeProjects = (Array)dte.ActiveSolutionProjects;

            if (activeProjects.Length > 0)
            {
                var project = (Project)activeProjects.GetValue(0);

                // The NuGet package needs netstandard2.0. We don't support ASP.NET Core 1.x projects.
                settings.IsAspNetCore2 = NgWizardHelper.IsAspNetCore2(project);
                // Look for an existing .angular-cli.json indicating there has been already an Angular CLI app created.
                settings.IsAngularCliJsonFound = NgWizardHelper.FindFileInRootDir(project, NgWizardHelper.AngularCliJsonFileName);
                // Test if a package.json exists.
                settings.IsOldPackageJsonFound = NgWizardHelper.FindFileInRootDir(project, NgWizardHelper.PackageJsonFileName, out string packageJsonFilePath);
                // Test if an entry for "@angular/core" exists in package.json.
                settings.IsNpmAngularFound = NgWizardHelper.IsNpmAngularFound(packageJsonFilePath);

                // Automatic installation is disabled if .gitignore or package.json or tsconfig.json or Startup.cs is opened in an editor window.
                settings.IsGitignoreOpened    = NgWizardHelper.IsFileOpened(project, NgWizardHelper.GitignoreFileName);
                settings.IsPackageJsonOpened  = NgWizardHelper.IsFileOpened(project, NgWizardHelper.PackageJsonFileName);
                settings.IsStartupCsOpened    = NgWizardHelper.IsFileOpened(project, NgWizardHelper.StartupCsFileName);
                settings.IsTsconfigJsonOpened = NgWizardHelper.IsFileOpened(project, NgWizardHelper.TsconfigJsonFileName);
            }

            // Display the wizard to the user.
            var viewModel  = new NgItemWizardViewModel(settings);
            var mainWindow = new NgItemWizardWindow(viewModel);
            var accepted   = mainWindow.ShowDialog().GetValueOrDefault();

            this.installAutomatically = viewModel.InstallAutomatically;

            if (!accepted)
            {
                throw new WizardCancelledException("The wizard has been cancelled by the user.");
            }
        }
 public NgItemWizardWindow(NgItemWizardViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
 }