Skip to content

Commit 6eb39ea

Browse files
authored
Package Management: Is Provisioned API spec (#4484)
* IsProvisioned spec * Fixed typo. Fixed sample * Fixed sample. Fixed table
1 parent 4eb59c3 commit 6eb39ea

File tree

1 file changed

+97
-1
lines changed

1 file changed

+97
-1
lines changed

specs/packagemanager/PackageManagement.md

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ but with additional functionality, improved developer experience and performance
2020
- [3.9. PackageRuntimeManager](#39-packageruntimemanager)
2121
- [3.10. PackageVolume Repair](#310-packagevolume-repair)
2222
- [3.11. Usability](#311-usability)
23+
- [3.12 Is\*Provisioned()](#312-isprovisioned)
2324
- [4. Examples](#4-examples)
2425
- [4.1. AddPackageAsync()](#41-addpackageasync)
2526
- [4.2. AddPackageByUriAsync()](#42-addpackagebyuriasync)
@@ -29,6 +30,7 @@ but with additional functionality, improved developer experience and performance
2930
- [4.6. PackageRuntimeManager.AddPackageSet()](#46-packageruntimemanageraddpackageset)
3031
- [4.7. PackageRuntimeManager.RemovePackageset()](#47-packageruntimemanagerremovepackageset)
3132
- [4.8. PackageVolume.Repair()](#48-packagevolumerepair)
33+
- [4.9. IsPackageProvisioned()](#49-ispackageprovisioned)
3234
- [5. Remarks](#5-remarks)
3335
- [5.1. Platform Support](#51-platform-support)
3436
- [6. API Details](#6-api-details)
@@ -125,6 +127,7 @@ The following table shows the supported permutations of verbs and targets:
125127
|Remove | X | X | WAS | OS/WAS | X | X | OS/WAS | WAS |
126128
|Repair | X | X | WAS | WAS | X | X | WAS | WAS |
127129
|Reset | X | X | WAS | WAS | X | X | WAS | WAS |
130+
|IsProvisioned | X | X | OS/WAS | X | X | X | WAS | WAS |
128131
|Provision | X | X | OS/WAS | X | X | X | WAS | WAS |
129132
|Deprovision | X | X | OS/WAS | X | X | X | WAS | WAS |
130133

@@ -333,7 +336,7 @@ package management APIs in Windows (e.g. Windows.Management.Deployment.PackageMa
333336
requested package is installed.
334337
* Many `PackageManager` operations accept a target package as a file but require it expressed as a
335338
`Uri`. `PackageDeploymentManager` provides overrides also accepting it as a `String`.
336-
* `PackageManager.RemovePackageByFullNameAsyn(p)` fails if the specified package isn't found.
339+
* `PackageManager.RemovePackageByFullNameAsync(p)` fails if the specified package isn't found.
337340
`PackageDeploymentManager` succeeds as the requested package is not present at the end of the
338341
operation.
339342
* This follows the core deployment principle "'Tis not the journey that matters but the
@@ -344,6 +347,12 @@ package management APIs in Windows (e.g. Windows.Management.Deployment.PackageMa
344347
not PackageFamilyName. `PackageDeploymentManager` provides a richer API accepting additional
345348
identifiers.
346349

350+
## 3.12 Is*Provisioned()
351+
352+
Is\*Provisioned\*() methods determine if the target is provisioned.
353+
354+
These methods require administrative privileges.
355+
347356
# 4. Examples
348357

349358
## 4.1. AddPackageAsync()
@@ -635,6 +644,78 @@ void CheckAndFixPackageVolume(string packageStorePath)
635644
}
636645
```
637646

647+
## 4.9. IsPackageProvisioned()
648+
649+
Fabrikam app installing Contoso's Muffin and Waffle packages for all users if necessary, and with explicit user confirmation before the installation.
650+
651+
```c#
652+
void Install()
653+
{
654+
// We want to check what's provisioned by PackageFamilyName. If something's
655+
// not provisioned we'll also need MinVersion and PackageUri to Stage and
656+
// Provision. But checking if a family is provisioned only supports some
657+
// URI schemes (notably, not the one we need for our staging work). So we'll
658+
// define the PackageSet with the families we want checked and if something's
659+
// not provisioned we'll add the additional properties needed.
660+
661+
var packageSet = new PackageSet() {
662+
Items = { new PackageSetItem() { PackageFamilyName = "contoso.muffin_1234567890abc" },
663+
{ new PackageSetItem() { PackageFamilyName = "contoso.waffle_1234567890abc" }
664+
}
665+
};
666+
667+
var packageDeploymentManager = PackageDeploymentManager.GetDefault();
668+
if (packageDeploymentManager.IsPackageSetProvisioned(packageSet))
669+
{
670+
return;
671+
}
672+
673+
bool ok = PromptUserForConfirmation();
674+
if (!ok)
675+
{
676+
return;
677+
}
678+
679+
packageSet.Items()[0].MinVersion(ToVersion(1, 2, 3, 4));
680+
packageSet.Items()[0].PackageUri(new Uri("c:\\contoso\\muffin-1.2.3.4.msix"));
681+
packageSet.Items()[1].MinVersion(ToVersion(2, 4, 6, 8));
682+
packageSet.Items()[1].PackageUri(new Uri("https://contoso.com/waffle-2.4.6.8.msix"));
683+
684+
var stageOptions = new StagePackageOptions();
685+
var deploymentResult = await packageDeploymentManager.StagePackageSetReadyAsync(packageSet, options);
686+
if (deplymentResult.Status == PackageDeploymentStatus.CompletedSuccess)
687+
{
688+
Console.WriteLine("Staged");
689+
}
690+
else
691+
{
692+
Console.WriteLine("Error:{} ExtendedError:{} {}",
693+
deploymentResult.Error.HResult, deploymentResult.ExtendedError.HResult, deploymentResult.ErrorText);
694+
return;
695+
}
696+
697+
var options = new ProvisionPackageOptions();
698+
var deploymentResult = await packageDeploymentManager.ProvisionPackageSetReadyAsync(packageSet, options);
699+
if (deplymentResult.Status == PackageDeploymentStatus.CompletedSuccess)
700+
{
701+
Console.WriteLine("Provisioned");
702+
}
703+
else
704+
{
705+
Console.WriteLine("Error:{} ExtendedError:{} {}",
706+
deploymentResult.Error.HResult, deploymentResult.ExtendedError.HResult, deploymentResult.ErrorText);
707+
}
708+
}
709+
710+
PackageVersion ToVersion(uint major, uint minor, uint build, uint revision) =>
711+
new PackageVersion {
712+
Major = checked((ushort)major),
713+
Minor = checked((ushort)minor),
714+
Build = checked((ushort)build),
715+
Revision = checked((ushort)revision)
716+
};
717+
```
718+
638719
# 5. Remarks
639720

640721
## 5.1. Platform Support
@@ -1050,6 +1131,21 @@ namespace Microsoft.Windows.Management.Deployment
10501131
Windows.Foundation.IAsyncOperationWithProgress<PackageDeploymentResult, PackageDeploymentProgress>
10511132
RepairPackageSetAsync(PackageSet packageSet);
10521133

1134+
//-------------------------------------------------------------
1135+
// IsProvisioned
1136+
1137+
// Return true if the package(s) are provisioned
1138+
1139+
[contract(PackageDeploymentContract, 2)]
1140+
Boolean IsPackageProvisioned(String package);
1141+
1142+
[contract(PackageDeploymentContract, 2)]
1143+
Boolean IsPackageProvisionedByUri(Windows.Foundation.Uri packageUri);
1144+
1145+
/// @note packageSet[Item].PackageUri is optional
1146+
[contract(PackageDeploymentContract, 2)]
1147+
Boolean IsPackageSetProvisioned(PackageSet packageSet);
1148+
10531149
//-------------------------------------------------------------
10541150
// Provision packages
10551151

0 commit comments

Comments
 (0)