Пример #1
0
 private void StartRequiredPackageInstallations(OutputWindowWriter outputWindowWriter)
 {
     try
     {
         // Initialize the progress bar.
         StatusBar.Progress(ref progressRef, 1, "", 0, 0);
         outputWindowWriter.Show();
         for (int index = 0; index < npmPackages.Count; index++)
         {
             var package = npmPackages[index];
             UpdateStatusMessage("Installing required NPM package '" + package.Id + "'...");
             package.InstallGlobally(
                 (sender, args) =>
             {
                 if (!string.IsNullOrEmpty(args.Data))
                 {
                     string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                     outputWindowWriter.WriteLine(s);
                 }
             },
                 (sender, args) =>
             {
                 if (!string.IsNullOrEmpty(args.Data))
                 {
                     string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                     outputWindowWriter.WriteLine(s);
                 }
             });     //Installs global npm package if missing
             StatusBar.Progress(ref progressRef, 1, "", Convert.ToUInt32(index),
                                Convert.ToUInt32(npmPackages.Count));
         }
     }
     catch (ProcessException pe)
     {
         MessageBox.Show("An error has occurred during a NPM package installation - " + pe.Message,
                         "An error has occurred during a NPM package installation.",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error,
                         MessageBoxDefaultButton.Button1,
                         MessageBoxOptions.DefaultDesktopOnly,
                         false);
         throw new WizardBackoutException("An error has occurred during a NPM package installation.");
     }
     catch (TimeoutException te)
     {
         MessageBox.Show("An NPM install has timed out - " + te.Message,
                         "An error has occurred during a NPM package installation.",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error,
                         MessageBoxDefaultButton.Button1,
                         MessageBoxOptions.DefaultDesktopOnly,
                         false);
         throw new WizardBackoutException("An error has occurred during a NPM package installation.");
     }
     catch (Exception e)
     {
         MessageBox.Show("An error has occurred during a NPM package installation." + e.Message,
                         "An error has occurred during a NPM package installation.",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error,
                         MessageBoxDefaultButton.Button1,
                         MessageBoxOptions.DefaultDesktopOnly,
                         false);
         throw new WizardBackoutException("An error has occurred during a NPM package installation.");
     }
 }
Пример #2
0
        public void ProjectFinishedGenerating(Project project)
        {
            //
            var outputWindowPane = _dte.Windows.Item(OutputWindowGuid); //Output window pane
            var _outputWindow    = new OutputWindowWriter(ServiceStackVSPackageCmdSetGuid, "ServiceStackVS");

            outputWindowPane.Visible = true;
            string projectPath = project.FullName.Substring(0,
                                                            project.FullName.LastIndexOf("\\", System.StringComparison.Ordinal));

            System.Threading.Tasks.Task.Run(() =>
            {
                StartRequiredPackageInstallations(_outputWindow);
                try
                {
                    if (!NodePackageUtils.HasBowerOnPath())
                    {
                        string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                        string npmFolder     = Path.Combine(appDataFolder, "npm");
                        npmFolder.AddToPathEnvironmentVariable();
                    }
                    UpdateStatusMessage("Downloading bower depedencies...");
                    NodePackageUtils.RunBowerInstall(projectPath, (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            _outputWindow.WriteLine(s);
                        }
                    }, (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            _outputWindow.WriteLine(s);
                        }
                    });
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Bower install failed: " + exception.Message,
                                    "An error has occurred during a Bower install.",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1,
                                    MessageBoxOptions.DefaultDesktopOnly,
                                    false);
                }
            }).Wait();

            UpdateStatusMessage("Downloading NPM depedencies...");
            System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    UpdateStatusMessage("Clearing NPM cache...");
                    NodePackageUtils.NpmClearCache(projectPath);
                    UpdateStatusMessage("Running NPM install...");
                    NodePackageUtils.RunNpmInstall(projectPath,
                                                   (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            _outputWindow.WriteLine(s);
                        }
                    },
                                                   (sender, args) =>
                    {
                        if (!string.IsNullOrEmpty(args.Data))
                        {
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            _outputWindow.WriteLine(s);
                        }
                    }, 600);
                    _outputWindow.WriteLine("NPM Install complete");
                    UpdateStatusMessage("Ready");
                    StatusBar.Clear();
                }
                catch (Exception exception)
                {
                    _outputWindow.WriteLine("An error has occurred during an NPM install");
                    _outputWindow.WriteLine("NPM install failed: " + exception.Message);
                }
            });
        }