private void Execute(object sender, EventArgs e) { string message = "This will reset Web Extension Pack and restart Visual Studio.\r\n\r\nDo you wish to continue?"; var answer = VsShellUtilities.ShowMessageBox( ServiceProvider, message, Vsix.Name, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); if (answer == (int)MessageBoxResult.OK) { var store = new DataStore(); if (store.Reset()) { IVsShell4 shell = (IVsShell4)ServiceProvider.GetService(typeof(SVsShell)); shell.Restart((uint)__VSRESTARTTYPE.RESTART_Normal); } else { var dte = (DTE2)ServiceProvider.GetService(typeof(DTE)); dte.StatusBar.Text = "An error occured. Please see output window for details."; } } }
private void InstallExtension(IVsExtensionRepository repository, IVsExtensionManager manager, KeyValuePair<string, string> product, DataStore store) { #if DEBUG System.Threading.Thread.Sleep(1000); return; #endif try { GalleryEntry entry = repository.CreateQuery<GalleryEntry>(includeTypeInQuery: false, includeSkuInQuery: true, searchSource: "ExtensionManagerUpdate") .Where(e => e.VsixID == product.Key) .AsEnumerable() .FirstOrDefault(); if (entry != null) { IInstallableExtension installable = repository.Download(entry); manager.Install(installable, false); store.PreviouslyInstalledExtensions.Add(entry.VsixID); } } catch (Exception ex) { Logger.Log(ex); } }
private async System.Threading.Tasks.Task Install() { var repository = (IVsExtensionRepository)GetService(typeof(SVsExtensionRepository)); var manager = (IVsExtensionManager)GetService(typeof(SVsExtensionManager)); var store = new DataStore(); var missing = GetMissingExtensions(manager, store); if (!missing.Any()) return; var allToBeInstalled = missing.ToArray(); 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 allToBeInstalled) { if (!dialog.IsVisible) break; // User canceled the dialog dialog.StartDownloading(product.Key); dialog.SetMessage($"Installing {product.Value}..."); InstallExtension(repository, manager, product, store); dialog.InstallComplete(product.Key); } store.Save(); }); if (dialog != null && dialog.IsVisible) { dialog.Close(); dialog = null; PromptForRestart(allToBeInstalled.Select(ext => ext.Value)); } }
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)); }