public IEnumerable <InstalledPackage> GetAllInstalledPackages() { IReadOnlyDictionary <string, string?>?keyValues = _keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix); var installedPackages = new Dictionary <string, InstalledPackage>(); // Collect the package from the package migration plans foreach (PackageMigrationPlan plan in _packageMigrationPlans) { if (!installedPackages.TryGetValue(plan.PackageName, out InstalledPackage? installedPackage)) { installedPackage = new InstalledPackage { PackageName = plan.PackageName }; installedPackages.Add(plan.PackageName, installedPackage); } var currentPlans = installedPackage.PackageMigrationPlans.ToList(); if (keyValues is null || keyValues.TryGetValue(Constants.Conventions.Migrations.KeyValuePrefix + plan.Name, out var currentState)) { currentState = null; } currentPlans.Add(new InstalledPackageMigrationPlans { CurrentMigrationId = currentState, FinalMigrationId = plan.FinalState }); installedPackage.PackageMigrationPlans = currentPlans; } // Collect and merge the packages from the manifests foreach (PackageManifest package in _manifestParser.GetManifests()) { if (package.PackageName is null) { continue; } if (!installedPackages.TryGetValue(package.PackageName, out InstalledPackage? installedPackage)) { installedPackage = new InstalledPackage { PackageName = package.PackageName }; installedPackages.Add(package.PackageName, installedPackage); } installedPackage.PackageView = package.PackageView; } // Return all packages with a name in the package.manifest or package migrations return(installedPackages.Values); }
/// <summary> /// Runs all migration plans for a package name if any are pending. /// </summary> /// <param name="packageName"></param> /// <returns></returns> public IEnumerable <ExecutedMigrationPlan> RunPackageMigrationsIfPending(string packageName) { IReadOnlyDictionary <string, string?>?keyValues = _keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix); IReadOnlyList <string> pendingMigrations = _pendingPackageMigrations.GetPendingPackageMigrations(keyValues); IEnumerable <string> packagePlans = _packageMigrationPlans.Values .Where(x => x.PackageName.InvariantEquals(packageName)) .Where(x => pendingMigrations.Contains(x.Name)) .Select(x => x.Name); return(RunPackagePlans(packagePlans)); }
public IEnumerable <InstalledPackage> GetAllInstalledPackages() { IReadOnlyDictionary <string, string> keyValues = _keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix); var installedPackages = new Dictionary <string, InstalledPackage>(); // Collect the package from the package migration plans foreach (PackageMigrationPlan plan in _packageMigrationPlans) { if (!installedPackages.TryGetValue(plan.PackageName, out InstalledPackage installedPackage)) { installedPackage = new InstalledPackage { PackageName = plan.PackageName }; installedPackages.Add(plan.PackageName, installedPackage); } var currentPlans = installedPackage.PackageMigrationPlans.ToList(); keyValues.TryGetValue(Constants.Conventions.Migrations.KeyValuePrefix + plan.Name, out var currentState); currentPlans.Add(new InstalledPackageMigrationPlans { CurrentMigrationId = currentState, FinalMigrationId = plan.FinalState }); installedPackage.PackageMigrationPlans = currentPlans; } // Collect and merge the packages from the manifests foreach (PackageManifest package in _manifestParser.GetManifests()) { if (!installedPackages.TryGetValue(package.PackageName, out InstalledPackage installedPackage)) { installedPackage = new InstalledPackage { PackageName = package.PackageName }; installedPackages.Add(package.PackageName, installedPackage); } installedPackage.PackageView = package.PackageView; } // Filter the packages listed here. i.e. only packages that have migrations or views. // Else whats the point in showing them? return(installedPackages .Values .Where(x => !x.PackageView.IsNullOrWhiteSpace() || x.PackageMigrationPlans.Any())); }