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));
}
}