|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Collections.ObjectModel; |
| 4 | +using System.Linq; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Windows.ApplicationModel; |
| 7 | + |
| 8 | +namespace PSADT.WindowsRuntime.Management.Deployment |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// Provides information about a package. |
| 12 | + /// </summary> |
| 13 | + public sealed class PackageInformation |
| 14 | + { |
| 15 | + /// <summary> |
| 16 | + /// |
| 17 | + /// </summary> |
| 18 | + /// <param name="package"></param> |
| 19 | + internal PackageInformation(Package package) |
| 20 | + { |
| 21 | + _package = package; |
| 22 | + Dependencies = new ReadOnlyCollection<PackageInformation>([.. package.Dependencies.Select(static d => new PackageInformation(d))]); |
| 23 | + } |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Gets the packages on which the current package depends. |
| 27 | + /// </summary> |
| 28 | + public IReadOnlyList<PackageInformation> Dependencies { get; } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Gets the package identity of the current package. |
| 32 | + /// </summary> |
| 33 | + public PackageId Id => _package.Id; |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// The CheckUpdateAvailabilityAsync method allows developers to check for updates to the main app package listed in the .appinstaller file. It allows the developer to determine if the updates are required due to .appinstaller policy. This method currently only works for applications installed via .appinstaller files. |
| 37 | + /// </summary> |
| 38 | + /// <returns>A PackageUpdateAvailabilityResult that indicates if an application has an update, and if the update is required.</returns> |
| 39 | + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "There's no async in PowerShell.")] |
| 40 | + public PackageUpdateAvailabilityResult CheckUpdateAvailability() |
| 41 | + { |
| 42 | + return CheckUpdateAvailabilityAsync().ConfigureAwait(false).GetAwaiter().GetResult(); |
| 43 | + } |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// The CheckUpdateAvailabilityAsync method allows developers to check for updates to the main app package listed in the .appinstaller file. It allows the developer to determine if the updates are required due to .appinstaller policy. This method currently only works for applications installed via .appinstaller files. |
| 47 | + /// </summary> |
| 48 | + /// <returns>A PackageUpdateAvailabilityResult that indicates if an application has an update, and if the update is required.</returns> |
| 49 | + public Task<PackageUpdateAvailabilityResult> CheckUpdateAvailabilityAsync() |
| 50 | + { |
| 51 | + return _package.CheckUpdateAvailabilityAsync().AsTask(); |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// The FindRelatedPackages method provides the dependencies and then dependents for a given package as a Package list. The list can be filtered by the type of dependency using the options parameter. |
| 56 | + /// </summary> |
| 57 | + /// <param name="options">The FindRelatedPackageOptions which defines the search options.</param> |
| 58 | + /// <returns>A read-only list of <see cref="PackageInformation"/> objects representing the related packages.</returns> |
| 59 | + public IReadOnlyList<PackageInformation> FindRelatedPackages(FindRelatedPackagesOptions options) |
| 60 | + { |
| 61 | + return new ReadOnlyCollection<PackageInformation>([.. _package.FindRelatedPackages(options).Select(static p => new PackageInformation(p))]); |
| 62 | + } |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Returns the .appinstaller XML file location. Use this method when you need to retrieve the .appinstaller XML file location for your app. For example, this is useful if your app needs to share a URI to its associated .appinstaller file. You can optionally add arguments to the URI. |
| 66 | + /// </summary> |
| 67 | + /// <returns>The .appinstaller XML file location.</returns> |
| 68 | + public AppInstallerInfo GetAppInstallerInfo() |
| 69 | + { |
| 70 | + return _package.GetAppInstallerInfo(); |
| 71 | + } |
| 72 | + |
| 73 | + /// <summary> |
| 74 | + /// Enumerates the packaged apps on the device and returns the list synchronously. Only apps included in the current package are returned. |
| 75 | + /// </summary> |
| 76 | + /// <returns>A list of AppListEntry objects that specify the packaged apps along with their display name, description, and logo.</returns> |
| 77 | + public IReadOnlyList<AppListEntryInformation> GetAppListEntries() |
| 78 | + { |
| 79 | + return new ReadOnlyCollection<AppListEntryInformation>([.. _package.GetAppListEntries().Select(static entry => new AppListEntryInformation(entry))]); |
| 80 | + } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Enumerates the packaged apps on the device and returns the list asynchronously. Only apps included in the current package are returned. |
| 84 | + /// </summary> |
| 85 | + /// <returns>A task that represents the asynchronous operation. The task result contains a list of AppListEntryInformation objects that specify the packaged apps along with their display name, description, and logo.</returns> |
| 86 | + public async Task<IReadOnlyList<AppListEntryInformation>> GetAppListEntriesAsync() |
| 87 | + { |
| 88 | + return new ReadOnlyCollection<AppListEntryInformation>([.. (await _package.GetAppListEntriesAsync().AsTask().ConfigureAwait(false)).Select(static entry => new AppListEntryInformation(entry))]); |
| 89 | + } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Gets the underlying <see cref="Package"/> object. |
| 93 | + /// </summary> |
| 94 | + private readonly Package _package; |
| 95 | + } |
| 96 | +} |
0 commit comments