using StabilityMatrix.Core.Models.FileInterfaces; using StabilityMatrix.Core.Models.Progress; namespace StabilityMatrix.Core.Models.Packages.Extensions; /// /// Interface for a package extension manager. /// public interface IPackageExtensionManager { /// /// Default manifests for this extension manager. /// IEnumerable DefaultManifests { get; } /// /// Get manifests given an installed package. /// By default returns . /// IEnumerable GetManifests(InstalledPackage installedPackage) { return DefaultManifests; } /// /// Get extensions from the provided manifest. /// Task> GetManifestExtensionsAsync( ExtensionManifest manifest, CancellationToken cancellationToken = default ); /// /// Get extensions from all provided manifests. /// async Task> GetManifestExtensionsAsync( IEnumerable manifests, CancellationToken cancellationToken = default ) { var extensions = Enumerable.Empty(); foreach (var manifest in manifests) { cancellationToken.ThrowIfCancellationRequested(); extensions = extensions.Concat( await GetManifestExtensionsAsync(manifest, cancellationToken).ConfigureAwait(false) ); } return extensions; } /// /// Get unique extensions from all provided manifests. As a mapping of their reference. /// async Task> GetManifestExtensionsMapAsync( IEnumerable manifests, CancellationToken cancellationToken = default ) { var result = new Dictionary(); foreach ( var extension in await GetManifestExtensionsAsync(manifests, cancellationToken) .ConfigureAwait(false) ) { cancellationToken.ThrowIfCancellationRequested(); var key = extension.Reference.ToString(); if (!result.TryAdd(key, extension)) { // Replace result[key] = extension; } } return result; } /// /// Get all installed extensions for the provided package. /// Task> GetInstalledExtensionsAsync( InstalledPackage installedPackage, CancellationToken cancellationToken = default ); /// /// Like , but does not check version. /// Task> GetInstalledExtensionsLiteAsync( InstalledPackage installedPackage, CancellationToken cancellationToken = default ); /// /// Get updated info (version) for an installed extension. /// Task GetInstalledExtensionInfoAsync( InstalledPackageExtension installedExtension ); /// /// Install an extension to the provided package. /// Task InstallExtensionAsync( PackageExtension extension, InstalledPackage installedPackage, PackageExtensionVersion? version = null, IProgress? progress = null, CancellationToken cancellationToken = default ); /// /// Update an installed extension to the provided version. /// If no version is provided, the latest version will be used. /// Task UpdateExtensionAsync( InstalledPackageExtension installedExtension, InstalledPackage installedPackage, PackageExtensionVersion? version = null, IProgress? progress = null, CancellationToken cancellationToken = default ); /// /// Uninstall an installed extension. /// Task UninstallExtensionAsync( InstalledPackageExtension installedExtension, InstalledPackage installedPackage, IProgress? progress = null, CancellationToken cancellationToken = default ); }