public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary,
                               WizardRunKind runKind, object[] customParams)
        {
            string destinationDirectory = null;
            string solutionDirectory    = null;

            try
            {
                replacementsDictionary.TryGetValue("$safeprojectname$", out string projectName);
                replacementsDictionary.TryGetValue("$destinationdirectory$", out destinationDirectory);
                replacementsDictionary.TryGetValue("$solutiondirectory$", out solutionDirectory);

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

                // Display the wizard to the user.
                var viewModel  = new NgProjectWizardViewModel(projectName, this.isNgFound);
                var mainWindow = new NgProjectWizardWindow(viewModel);
                var accepted   = mainWindow.ShowDialog().GetValueOrDefault();

                this.skipNpmInstall = viewModel.SkipNpmInstall;
                // If package.json is included in the project, the npm package manager automatically starts installing packages after project creation.
                replacementsDictionary.Add("$includepackagejson$", this.skipNpmInstall ? String.Empty : includePackageJsonElement);

                this.addRouting = viewModel.AddRouting;

                if (!accepted)
                {
                    throw new WizardCancelledException("The wizard has been cancelled by the user.");
                }
            }
            catch
            {
                DateTime projectDirCreationTime = DateTime.MinValue;
                if (Directory.Exists(destinationDirectory))
                {
                    projectDirCreationTime = Directory.GetCreationTimeUtc(destinationDirectory);
                    Directory.Delete(destinationDirectory, true);
                }
                if (Directory.Exists(solutionDirectory))
                {
                    // The solution could exist before the template started.
                    // This is a poor man's method of deciding whether the solution dir was created at about the same time as the project dir.
                    var solutionDirCreationTime = Directory.GetCreationTimeUtc(solutionDirectory);
                    if (Math.Abs((projectDirCreationTime - solutionDirCreationTime).TotalSeconds) < 5)
                    {
                        Directory.Delete(solutionDirectory, true);
                    }
                }
                throw;
            }
        }
Example #2
0
 public NgProjectWizardWindow(NgProjectWizardViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
 }