public async Task <IPackageCatalog> GetRepositoryCatalogAsync(bool forceDownload, IProgress <string> progress) { // This should really be thread-safe but await can't be inside a lock so // we'll just have to hope and pray this doesn't happen concurrently. Worst // case is we'll end up with two retrievals, one of which will be binned, // which isn't the end of the world. _sRepoCatalog = null; if (null == _sRepoCatalog || _sRepoCatalog.ResultsCount == 0 || forceDownload) { Exception ex = null; using (var commander = CreateNpmCommander()) { EventHandler <NpmExceptionEventArgs> exHandler = (sender, args) => { LogException(sender, args); ex = args.Exception; }; commander.ErrorLogged += LogError; commander.ExceptionLogged += exHandler; _sRepoCatalog = await commander.GetCatalogAsync(forceDownload, progress); commander.ErrorLogged -= LogError; commander.ExceptionLogged -= exHandler; } if (null != ex) { OnOutputLogged(ex.ToString()); throw ex; } } return(_sRepoCatalog); }
public PackageRepository(IPackageCatalog packageCatalog, IStorage <IList <UWPApplication> > storage) { _storage = storage ?? throw new ArgumentNullException(nameof(storage), "StorageRepository requires an initialized storage interface"); _packageCatalog = packageCatalog ?? throw new ArgumentNullException(nameof(packageCatalog), "PackageRepository expects an interface to be able to subscribe to package events"); _packageCatalog.PackageInstalling += OnPackageInstalling; _packageCatalog.PackageUninstalling += OnPackageUninstalling; }
private async void LoadCatalog(bool forceRefresh) { IsLoadingCatalog = true; CatalogControlVisibility = Visibility.Collapsed; LoadingCatalogControlVisibility = Visibility.Visible; LoadingCatalogMessage = SR.GetString(SR.CatalogLoadingDefault); LastRefreshedMessage = LastRefreshedMessageProvider.RefreshInProgress; var controller = _npmController; controller.ErrorLogged += _executeViewModel.commander_ErrorLogged; controller.ExceptionLogged += _executeViewModel.commander_ExceptionLogged; controller.OutputLogged += _executeViewModel.commander_OutputLogged; _executeViewModel.SetCancellableSafe(false); try { _allPackages = await controller.GetRepositoryCatalogAsync( forceRefresh, new Progress <string>(msg => LoadingCatalogProgressMessage = msg) ); IsCatalogEmpty = false; } catch (NpmNotFoundException) { LastRefreshedMessage = LastRefreshedMessageProvider.NpmNotFound; } catch (NpmCatalogEmptyException) { IsCatalogEmpty = true; LastRefreshedMessage = new LastRefreshedMessageProvider(_allPackages.LastRefreshed); } catch (Exception ex) { if (IsCriticalException(ex)) { throw; } LastRefreshedMessage = LastRefreshedMessageProvider.RefreshFailed; IsCatalogEmpty = true; } finally { IsLoadingCatalog = false; controller.ErrorLogged -= _executeViewModel.commander_ErrorLogged; controller.ExceptionLogged -= _executeViewModel.commander_ExceptionLogged; controller.OutputLogged -= _executeViewModel.commander_OutputLogged; _executeViewModel.SetCancellableSafe(true); // The catalog refresh operation spawns many long-lived Gen 2 objects, // so the garbage collector will take a while to get to them otherwise. GC.Collect(); } // Reset the filter text, otherwise the results will be outdated. FilterText = string.Empty; // We want to show the catalog regardless of whether an exception was thrown so that the user has the chance to refresh it. LoadingCatalogControlVisibility = Visibility.Collapsed; StartFilter(); }
public async Task<IPackageCatalog> GetRepositoryCatalogAsync(bool forceDownload, IProgress<string> progress) { // This should really be thread-safe but await can't be inside a lock so // we'll just have to hope and pray this doesn't happen concurrently. Worst // case is we'll end up with two retrievals, one of which will be binned, // which isn't the end of the world. _sRepoCatalog = null; if (null == _sRepoCatalog || _sRepoCatalog.ResultsCount == 0 || forceDownload) { Exception ex = null; using (var commander = CreateNpmCommander()) { EventHandler<NpmExceptionEventArgs> exHandler = (sender, args) => { LogException(sender, args); ex = args.Exception; }; commander.ErrorLogged += LogError; commander.ExceptionLogged += exHandler; _sRepoCatalog = await commander.GetCatalogAsync(forceDownload, progress); commander.ErrorLogged -= LogError; commander.ExceptionLogged -= exHandler; } if (null != ex) { OnOutputLogged(ex.ToString()); throw ex; } } return _sRepoCatalog; }
private async void LoadCatalog(bool forceRefresh) { IsLoadingCatalog = true; CatalogControlVisibility = Visibility.Collapsed; LoadingCatalogControlVisibility = Visibility.Visible; LoadingCatalogMessage = SR.GetString(SR.CatalogLoadingDefault); LastRefreshedMessage = LastRefreshedMessageProvider.RefreshInProgress; var controller = _npmController; controller.ErrorLogged += _executeViewModel.commander_ErrorLogged; controller.ExceptionLogged += _executeViewModel.commander_ExceptionLogged; controller.OutputLogged += _executeViewModel.commander_OutputLogged; _executeViewModel.SetCancellableSafe(false); try { _allPackages = await controller.GetRepositoryCatalogAsync( forceRefresh, new Progress<string>(msg => LoadingCatalogProgressMessage = msg) ); IsCatalogEmpty = false; } catch (NpmNotFoundException) { LastRefreshedMessage = LastRefreshedMessageProvider.NpmNotFound; } catch (NpmCatalogEmptyException) { IsCatalogEmpty = true; LastRefreshedMessage = new LastRefreshedMessageProvider(_allPackages.LastRefreshed); } catch (Exception ex) { if (IsCriticalException(ex)) { throw; } LastRefreshedMessage = LastRefreshedMessageProvider.RefreshFailed; IsCatalogEmpty = true; } finally { IsLoadingCatalog = false; controller.ErrorLogged -= _executeViewModel.commander_ErrorLogged; controller.ExceptionLogged -= _executeViewModel.commander_ExceptionLogged; controller.OutputLogged -= _executeViewModel.commander_OutputLogged; _executeViewModel.SetCancellableSafe(true); // The catalog refresh operation spawns many long-lived Gen 2 objects, // so the garbage collector will take a while to get to them otherwise. GC.Collect(); } // Reset the filter text, otherwise the results will be outdated. FilterText = string.Empty; // We want to show the catalog regardless of whether an exception was thrown so that the user has the chance to refresh it. LoadingCatalogControlVisibility = Visibility.Collapsed; StartFilter(); }
public PackageRepository(IPackageCatalog packageCatalog) { _packageCatalog = packageCatalog ?? throw new ArgumentNullException(nameof(packageCatalog), "PackageRepository expects an interface to be able to subscribe to package events"); _packageCatalog.PackageInstalling += OnPackageInstalling; _packageCatalog.PackageUninstalling += OnPackageUninstalling; }