private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!TryGetFilePath(out var filePath))
            {
                return;
            }

            var manifest = Manifest.FromFile(filePath);

            manifest.MarkSelected(_es.GetInstalledExtensions());

            var dialog = ImportWindow.Open(manifest.Extensions, Purpose.Import);

            if (dialog.DialogResult == true && dialog.SelectedExtension.Any())
            {
                var installSystemWide = dialog.InstallSystemWide;
                var toInstall         = dialog.SelectedExtension.Select(ext => ext.ID).ToList();

                var repository = ServiceProvider.GetService(typeof(SVsExtensionRepository)) as IVsExtensionRepository;
                Assumes.Present(repository);

                IEnumerable <GalleryEntry> marketplaceEntries = repository.GetVSGalleryExtensions <GalleryEntry>(toInstall, 1033, false).Where(x => x.DownloadUrl != null);
                var tempDir = PrepareTempDir();

                var dte = ServiceProvider.GetService(typeof(DTE)) as DTE;
                Assumes.Present(dte);

                dte.StatusBar.Text = "Downloading extensions...";

                HasRootSuffix(out var rootSuffix);
                ThreadHelper.JoinableTaskFactory.Run(() => DownloadExtensionsAsync(installSystemWide, marketplaceEntries, tempDir, dte, rootSuffix));
            }
        }
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var dte = ServiceProvider.GetService(typeof(DTE)) as DTE;

            Assumes.Present(dte);

            if (string.IsNullOrEmpty(dte.Solution?.FileName))
            {
                ShowMessageBox("The solution must be saved in order to manage solution extensions.");
                return;
            }

            var fileName = Path.ChangeExtension(dte.Solution.FileName, ".vsext");

            try
            {
                var extensions = _es.GetInstalledExtensions().ToList();

                if (File.Exists(fileName))
                {
                    var manifest = Manifest.FromFile(fileName);
                    extensions = extensions.Union(manifest.Extensions).ToList();

                    foreach (Extension ext in extensions)
                    {
                        ext.Selected = manifest.Extensions.Contains(ext);
                    }
                }
                else
                {
                    foreach (Extension ext in extensions)
                    {
                        ext.Selected = false;
                    }
                }

                var dialog = ImportWindow.Open(extensions, Purpose.List);

                if (dialog.DialogResult == true)
                {
                    var manifest = new Manifest(dialog.SelectedExtension);
                    var json     = JsonConvert.SerializeObject(manifest, Formatting.Indented);

                    File.WriteAllText(fileName, json);

                    // Add the file to the solution items folder if it's new or if it's not there already.
                    Project solItems = GetOrCreateSolutionItems((DTE2)dte);
                    solItems.ProjectItems.AddFromFile(fileName);

                    VsShellUtilities.OpenDocument(ServiceProvider, fileName);
                }
            }
            catch (Exception ex)
            {
                ShowMessageBox(ex.Message);
            }
        }
Пример #3
0
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!TryGetFilePath(out string filePath))
            {
                return;
            }

            var manifest = Manifest.FromFile(filePath);

            manifest.MarkSelected(_es.GetInstalledExtensions());

            var dialog = ImportWindow.Open(manifest.Extensions, Purpose.Install);

            if (dialog.DialogResult == true && dialog.SelectedExtension.Any())
            {
                var toInstall = dialog.SelectedExtension.Select(ext => ext.ID).ToList();

                var repository = ServiceProvider.GetService(typeof(SVsExtensionRepository)) as IVsExtensionRepository;
                Assumes.Present(repository);

                IEnumerable <GalleryEntry> marketplaceEntries = repository.GetVSGalleryExtensions <GalleryEntry>(toInstall, 1033, false);
                string tempDir = PrepareTempDir();

                var dte = ServiceProvider.GetService(typeof(DTE)) as DTE;
                Assumes.Present(dte);

                dte.StatusBar.Text = "Downloading extensions...";

                HasRootSuffix(out string rootSuffix);

                ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
                {
                    await DownloadExtensionAsync(marketplaceEntries, tempDir);

                    InvokeVsixInstaller(tempDir, rootSuffix);

                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    dte.StatusBar.Text = "Extensions downloaded. Starting VSIX Installer...";
                });
            }
        }