Пример #1
0
        protected virtual async Task <bool> CallCommand(string argument, string cwd)
        {
            ProcessStartInfo start = new ProcessStartInfo
            {
                WorkingDirectory       = cwd,
                UseShellExecute        = false,
                WindowStyle            = ProcessWindowStyle.Hidden,
                CreateNoWindow         = true,
                FileName               = "cmd.exe",
                Arguments              = argument,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                StandardErrorEncoding  = Encoding.UTF8,
                StandardOutputEncoding = Encoding.UTF8,
            };

            ModifyPathVariable(start);

            try
            {
                using (var p = System.Diagnostics.Process.Start(start))
                {
                    var error = await p.StandardError.ReadToEndAsync();

                    var output = await p.StandardOutput.ReadToEndAsync();

                    p.WaitForExit();

                    Logger.Log(output, true);

                    if (p.ExitCode == 0)
                    {
                        VSPackage.UpdateStatus("Package installed");
                    }
                    else
                    {
                        VSPackage.UpdateStatus("An error installing package. See output window for details");
                        Logger.Log(error, true);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                VSPackage.UpdateStatus("An error installing package. See output window for details");
                Logger.Log(ex, true);
                return(false);
            }
        }
Пример #2
0
        public override async Task <bool> InstallPackage(Project project, string packageName, string version)
        {
            var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
            var installer      = componentModel.GetService <IVsPackageInstaller>();

            return(await System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    installer.InstallPackage(null, project, packageName, (Version)null, false);
                    VSPackage.UpdateStatus("Package installed");
                    return true;
                }
                catch (Exception ex)
                {
                    VSPackage.UpdateStatus("An error installing package. See output window for details");
                    Logger.Log(ex);
                    return false;
                }
            }));
        }
Пример #3
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            Project project = _project ?? ProjectHelpers.GetSelectedProject();

            if (project == null)
            {
                return;
            }

            InstallDialog dialog = new InstallDialog(ServiceProvider, new Bower(), new Npm(), new Jspm());
            var           result = dialog.ShowDialog();

            if (!dialog.DialogResult.HasValue || !dialog.DialogResult.Value)
            {
                return;
            }

            VSPackage.UpdateStatus($"Installing {dialog.Package} package from {dialog.Provider.Name}...");

            dialog.Provider.InstallPackage(project, dialog.Package, dialog.Version);
        }