Beispiel #1
0
 public WizardWindow(WizardViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
 }
Beispiel #2
0
        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.
                var isNgFound        = true;
                var desktopDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                var workingDirectory = Directory.Exists(destinationDirectory)
                    ? destinationDirectory
                    : (Directory.Exists(desktopDirectory) ? desktopDirectory : null);
                if (!String.IsNullOrEmpty(workingDirectory))
                {
                    var ngVersionOutput = RunNgVersion(desktopDirectory);
                    isNgFound = ngVersionOutput.Contains(NgVersionSuccessFragment);
                }

                // Display the wizard to the user.
                var viewModel  = new WizardViewModel(projectName, isNgFound);
                var mainWindow = new WizardWindow(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;
            }
        }