// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; using System.Collections.Generic; using System.Linq; using NuGet; namespace ICSharpCode.PackageManagement { public class UpdatedPackagesViewModel : PackagesViewModel { IPackageManagementService packageManagementService; UpdatedPackages updatedPackages; string errorMessage = String.Empty; public UpdatedPackagesViewModel( IPackageManagementService packageManagementService, IMessageReporter messageReporter, ITaskFactory taskFactory) : this( packageManagementService, messageReporter, new LicenseAcceptanceService(), taskFactory) { } public UpdatedPackagesViewModel( IPackageManagementService packageManagementService, IMessageReporter messageReporter, ILicenseAcceptanceService licenseAcceptanceService, ITaskFactory taskFactory) : base( packageManagementService, new UpdatedPackageViewModelFactory(packageManagementService, licenseAcceptanceService, messageReporter), taskFactory) { this.packageManagementService = packageManagementService; } protected override void UpdateRepositoryBeforeReadPackagesTaskStarts() { try { updatedPackages = new UpdatedPackages(packageManagementService); } catch (Exception ex) { errorMessage = ex.Message; } } protected override IQueryable GetAllPackages() { if (updatedPackages == null) { ThrowSavedException(); } return GetUpdatedPackages(); } void ThrowSavedException() { throw new ApplicationException(errorMessage); } IQueryable GetUpdatedPackages() { return updatedPackages.GetUpdatedPackages().AsQueryable(); } } }