Пример #1
0
        private IEnumerable <KeyValuePair <string, string> > GetMissingExtensions(IVsExtensionManager manager, DataStore store)
        {
            var installed    = manager.GetInstalledExtensions();
            var products     = ExtensionList.Products();
            var notInstalled = products.Where(product => !installed.Any(ins => ins.Header.Identifier == product.Key)).ToArray();

            return(notInstalled.Where(ext => !store.HasBeenInstalled(ext.Key)));
        }
Пример #2
0
        private async System.Threading.Tasks.Task Install()
        {
            var repository = (IVsExtensionRepository)GetService(typeof(SVsExtensionRepository));
            var manager    = (IVsExtensionManager)GetService(typeof(SVsExtensionManager));

            var installed = manager.GetInstalledExtensions();
            var products  = ExtensionList.Products();
            var missing   = products.Where(product => !installed.Any(ins => ins.Header.Identifier == product.Key));

            if (!missing.Any())
            {
                return;
            }

            var dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));

            var hwnd   = new IntPtr(dte.MainWindow.HWnd);
            var window = (Window)System.Windows.Interop.HwndSource.FromHwnd(hwnd).RootVisual;

            var dialog = new InstallerProgress(missing, $"Downloading extensions...");

            dialog.Owner = window;
            dialog.Show();

            await System.Threading.Tasks.Task.Run(() =>
            {
                foreach (var product in missing)
                {
                    if (!dialog.IsVisible)
                    {
                        break; // User cancelled the dialog
                    }
                    dialog.StartDownloading(product.Key);
                    dialog.SetMessage($"Installing {product.Value}...");
                    InstallExtension(repository, manager, product);
                    dialog.InstallComplete(product.Key);
                }
            });

            if (dialog.IsVisible)
            {
                dialog.Close();
                dialog = null;
                PromptForRestart();
            }
        }