public InstallExtensions ( IEnumerable |
||
extensionModels | IEnumerable |
|
Résultat | System.Threading.Tasks.Task |
public async Task InstallExtensions(IEnumerable<IExtensionModel> extensionModels)
{
bool hasInstalled = false;
int count = extensionModels.Count();
_progress = new InstallerProgress(count, $"Downloading and installing {count} extension(s)...");
_progress.Show();
await Task.Run(() =>
{
foreach (IExtensionModel model in extensionModels)
{
try
{
GalleryEntry entry = _repository.CreateQuery<GalleryEntry>(includeTypeInQuery: false, includeSkuInQuery: true, searchSource: "ExtensionManagerUpdate")
.Where(e => e.VsixID == model.ProductId)
.AsEnumerable()
.FirstOrDefault();
if (!_progress.IsVisible)
break;
if (entry != null)
{
IInstallableExtension installable = _repository.Download(entry);
if (!_progress.IsVisible)
break;
_manager.Install(installable, false);
hasInstalled = true;
var props = new Dictionary<string, string> { { "extension", model.Name } };
}
}
catch (Exception ex)
{
Logger.Log(ex);
}
}
});
if (_progress.IsVisible)
{
_progress.Close();
_progress = null;
}
if (hasInstalled)
PromptForRestart();
}
public async void OnActionItemClicked(IVsInfoBarUIElement infoBarUIElement, IVsInfoBarActionItem actionItem) { string context = actionItem.ActionContext; if (context == "install") { InstallerDialog dialog = new InstallerDialog(_suggestionResult.Extensions); dialog.NeverShowAgainForSolution = Settings.IsFileTypeIgnored(_suggestionResult.Matches); var dte = _serviceProvider.GetService(typeof(DTE)) as DTE2; var hwnd = new IntPtr(dte.MainWindow.HWnd); System.Windows.Window window = (System.Windows.Window)HwndSource.FromHwnd(hwnd).RootVisual; dialog.Owner = window; var result = dialog.ShowDialog(); Settings.IgnoreFileType(_suggestionResult.Matches, dialog.NeverShowAgainForSolution); if (!result.HasValue || !result.Value) { return; } ExtensionInstaller installer = new ExtensionInstaller(_serviceProvider, _repository, _manager); await installer.InstallExtensions(dialog.SelectedExtensions); } else if (context == "ignore") { Settings.IgnoreFileType(_suggestionResult.Matches, true); } }