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