From d84faf9fa2259351ea93002e40c16e4985cc0a4d Mon Sep 17 00:00:00 2001 From: Isaiah Williams Date: Wed, 10 Jul 2019 16:01:12 -0500 Subject: [PATCH] Device batch feature update (#137) --- ChangeLog.md | 7 +- build/PartnerCenter.NetCore.nuspec | 2 +- build/PartnerCenter.nuspec | 2 +- docs/help/New-PartnerCustomerDeviceBatch.md | 2 +- .../Commands/NewPartnerCustomerDeviceBatch.cs | 54 ++++++++++++--- src/PowerShell/GlobalSuppressions.cs | 4 +- .../DevicesDeployment/PSBatchUploadDetails.cs | 69 +++++++++++++++++++ .../Models/DevicesDeployment/PSDevice.cs | 10 ++- .../PSDeviceUploadDetails.cs | 63 +++++++++++++++++ src/PowerShell/PartnerCenter.NetCore.psd1 | 2 +- src/PowerShell/PartnerCenter.psd1 | 2 +- src/PowerShell/PowerShell.csproj | 6 +- 12 files changed, 199 insertions(+), 24 deletions(-) create mode 100644 src/PowerShell/Models/DevicesDeployment/PSBatchUploadDetails.cs create mode 100644 src/PowerShell/Models/DevicesDeployment/PSDeviceUploadDetails.cs diff --git a/ChangeLog.md b/ChangeLog.md index 75cbf657..ba14de98 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,10 +20,15 @@ # Change Log +## 1.5.1907.2 + +* Devices + * Modified the output for the [New-PartnerCustomerDeviceBatch](https://docs.microsoft.com/powershell/module/partnercenter/New-PartnerCustomerAgreement) command. + ## 1.5.1907.1 * Agreements - * Removed the *UserId* parameter from the [New-PartnerCustomerAgreement](https://docs.microsoft.com/powershell/module/partnercenter/set-partnercustomersubscription) command + * Removed the *UserId* parameter from the [New-PartnerCustomerAgreement](https://docs.microsoft.com/powershell/module/partnercenter/New-PartnerCustomerAgreement) command * Devices * Addressed an issue preventing the successful creation of a device batch diff --git a/build/PartnerCenter.NetCore.nuspec b/build/PartnerCenter.NetCore.nuspec index b1f2d053..3d2d873b 100644 --- a/build/PartnerCenter.NetCore.nuspec +++ b/build/PartnerCenter.NetCore.nuspec @@ -2,7 +2,7 @@ PartnerCenter.NetCore - 1.5.1907.1 + 1.5.1907.2 Microsoft Corporation Microsoft false diff --git a/build/PartnerCenter.nuspec b/build/PartnerCenter.nuspec index 326cefa2..79629cc5 100644 --- a/build/PartnerCenter.nuspec +++ b/build/PartnerCenter.nuspec @@ -2,7 +2,7 @@ PartnerCenter - 1.5.1907.1 + 1.5.1907.2 Microsoft Corporation Microsoft false diff --git a/docs/help/New-PartnerCustomerDeviceBatch.md b/docs/help/New-PartnerCustomerDeviceBatch.md index 2e062c18..c2e45457 100644 --- a/docs/help/New-PartnerCustomerDeviceBatch.md +++ b/docs/help/New-PartnerCustomerDeviceBatch.md @@ -123,7 +123,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## OUTPUTS -### System.String +### Microsoft.Store.PartnerCenter.PowerShell.Models.DevicesDeployment.PSBatchUploadDetails ## NOTES diff --git a/src/PowerShell/Commands/NewPartnerCustomerDeviceBatch.cs b/src/PowerShell/Commands/NewPartnerCustomerDeviceBatch.cs index 3e11faea..c1e64cb1 100644 --- a/src/PowerShell/Commands/NewPartnerCustomerDeviceBatch.cs +++ b/src/PowerShell/Commands/NewPartnerCustomerDeviceBatch.cs @@ -6,15 +6,19 @@ namespace Microsoft.Store.PartnerCenter.PowerShell.Commands { + using System; + using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Management.Automation; using System.Text.RegularExpressions; + using System.Threading; using Models.DevicesDeployment; + using PartnerCenter.Models; using PartnerCenter.Models.DevicesDeployment; using Properties; - [Cmdlet(VerbsCommon.New, "PartnerCustomerDeviceBatch", SupportsShouldProcess = true), OutputType(typeof(string))] + [Cmdlet(VerbsCommon.New, "PartnerCustomerDeviceBatch", SupportsShouldProcess = true), OutputType(typeof(PSBatchUploadDetails))] public class NewPartnerCustomerDeviceBatch : PartnerPSCmdlet { /// @@ -44,29 +48,61 @@ public class NewPartnerCustomerDeviceBatch : PartnerPSCmdlet public override void ExecuteCmdlet() { DeviceBatchCreationRequest request; - string deviceBatch; + ResourceCollection batches; + IEnumerable devices; + BatchUploadDetails status; + string location; if (!ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.NewPartnerCustomerDeviceBatchWhatIf, BatchId))) { return; } - request = new DeviceBatchCreationRequest + batches = Partner.Customers[CustomerId].DeviceBatches.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + + devices = Devices.Select(d => new Device + { + HardwareHash = d.HardwareHash, + ModelName = d.ModelName, + OemManufacturerName = d.OemManufacturerName, + Policies = d.Policies, + ProductKey = d.ProductKey, + SerialNumber = d.SerialNumber + }); + + if (batches.Items.SingleOrDefault(b => b.Id.Equals(BatchId, StringComparison.InvariantCultureIgnoreCase)) != null) { - BatchId = BatchId, - Devices = Devices.Select(d => new Device + location = Partner.Customers[CustomerId].DeviceBatches[BatchId].Devices.CreateAsync(Devices.Select(d => new Device { HardwareHash = d.HardwareHash, ModelName = d.ModelName, OemManufacturerName = d.OemManufacturerName, + Policies = d.Policies, ProductKey = d.ProductKey, SerialNumber = d.SerialNumber - }) - }; + })).GetAwaiter().GetResult(); + } + else + { + request = new DeviceBatchCreationRequest + { + BatchId = BatchId, + Devices = devices + }; - deviceBatch = Partner.Customers[CustomerId].DeviceBatches.CreateAsync(request).GetAwaiter().GetResult(); + location = Partner.Customers[CustomerId].DeviceBatches.CreateAsync(request).GetAwaiter().GetResult(); + } + + status = Partner.Customers[CustomerId].BatchUploadStatus.ById(location.Split('/')[4]).GetAsync().GetAwaiter().GetResult(); + + while (status.Status == DeviceUploadStatusType.Processing || status.Status == DeviceUploadStatusType.Queued) + { + Thread.Sleep(5000); + + status = Partner.Customers[CustomerId].BatchUploadStatus.ById(location.Split('/')[4]).GetAsync().GetAwaiter().GetResult(); + } - WriteObject(deviceBatch); + WriteObject(new PSBatchUploadDetails(status)); } } } \ No newline at end of file diff --git a/src/PowerShell/GlobalSuppressions.cs b/src/PowerShell/GlobalSuppressions.cs index 9643ee09..00e814d6 100644 --- a/src/PowerShell/GlobalSuppressions.cs +++ b/src/PowerShell/GlobalSuppressions.cs @@ -12,6 +12,8 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Property used as part of a PowerShell cmdlet", Scope = "member", Target = "~P:Microsoft.Store.PartnerCenter.PowerShell.Commands.GetPartnerCustomerUserLicense.LicenseGroup")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Property used as part of a PowerShell cmdlet", Scope = "member", Target = "~P:Microsoft.Store.PartnerCenter.PowerShell.Commands.NewPartnerCustomerDeviceBatch.Devices")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Property used as part of a PowerShell cmdlet", Scope = "member", Target = "~P:Microsoft.Store.PartnerCenter.PowerShell.Commands.NewPartnerCustomerApplicationConsent.ApplicationGrants")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Property used as part of a PowerShell cmdlet", Scope = "member", Target = "~P:Microsoft.Store.PartnerCenter.PowerShell.Models.DevicesDeployment.PSBatchUploadDetails.DevicesStatus")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Property used as part of a PowerShell cmdlet", Scope = "member", Target = "~P:Microsoft.Store.PartnerCenter.PowerShell.Commands.NewPartnerCustomerOrderLineItem.ProvisioningContext")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Property used as part of a PowerShell cmdlet", Scope = "member", Target = "~P:Microsoft.Store.PartnerCenter.PowerShell.Commands.NewPartnerCustomerCartLineItem.ProvisioningContext")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Property used as part of a PowerShell cmdlet", Scope = "member", Target = "~P:Microsoft.Store.PartnerCenter.PowerShell.Commands.GetPartnerProductInventory.Variables")] \ No newline at end of file +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Property used as part of a PowerShell cmdlet", Scope = "member", Target = "~P:Microsoft.Store.PartnerCenter.PowerShell.Commands.GetPartnerProductInventory.Variables")] + diff --git a/src/PowerShell/Models/DevicesDeployment/PSBatchUploadDetails.cs b/src/PowerShell/Models/DevicesDeployment/PSBatchUploadDetails.cs new file mode 100644 index 00000000..e9038c51 --- /dev/null +++ b/src/PowerShell/Models/DevicesDeployment/PSBatchUploadDetails.cs @@ -0,0 +1,69 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.PowerShell.Models.DevicesDeployment +{ + using System; + using System.Linq; + using Common; + using PartnerCenter.Models.DevicesDeployment; + + /// + /// Represents the result of devices batch upload. + /// + public sealed class PSBatchUploadDetails + { + /// + /// Initializes a new instance of the class. + /// + public PSBatchUploadDetails() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The details for this instance. + public PSBatchUploadDetails(BatchUploadDetails details) + { + this.CopyFrom(details, CloneAdditionalOperations); + } + + /// + /// Gets or sets the tracking ID of the batch of devices uploaded. + /// + public string BatchTrackingId { get; set; } + + /// + /// Gets or sets the batch upload completed time. + /// + public DateTime CompletedTime { get; set; } + + /// + /// Gets or sets the device upload status. + /// + public PSDeviceUploadDetails[] DevicesStatus { get; set; } + + /// + /// Gets or sets the batch started time. + /// + public DateTime StartedTime { get; set; } + + /// + /// Gets or sets the status. + /// + public DeviceUploadStatusType Status { get; set; } + + /// + /// Additional operations to be performed when cloning an instance of to an instance of . + /// + /// The item being cloned. + private void CloneAdditionalOperations(BatchUploadDetails item) + { + DevicesStatus = item.DevicesStatus.Select(d => new PSDeviceUploadDetails(d)).ToArray(); + } + } +} \ No newline at end of file diff --git a/src/PowerShell/Models/DevicesDeployment/PSDevice.cs b/src/PowerShell/Models/DevicesDeployment/PSDevice.cs index 941ac261..b947f1bb 100644 --- a/src/PowerShell/Models/DevicesDeployment/PSDevice.cs +++ b/src/PowerShell/Models/DevicesDeployment/PSDevice.cs @@ -21,17 +21,15 @@ public sealed class PSDevice /// public PSDevice() { - Policies = new List>(); } /// /// Initializes a new instance of the class. /// - /// The base PSDevice for this instance. - public PSDevice(Device device) + /// The base item for this instance. + public PSDevice(Device item) { - Policies = new List>(); - this.CopyFrom(device, CloneAdditionalOperations); + this.CopyFrom(item, CloneAdditionalOperations); } /// @@ -62,7 +60,7 @@ public PSDevice(Device device) /// /// Gets or sets the policies assigned. /// - public List> Policies { get; } + public List> Policies { get; set; } /// /// Gets or sets the product key. diff --git a/src/PowerShell/Models/DevicesDeployment/PSDeviceUploadDetails.cs b/src/PowerShell/Models/DevicesDeployment/PSDeviceUploadDetails.cs new file mode 100644 index 00000000..41f34a65 --- /dev/null +++ b/src/PowerShell/Models/DevicesDeployment/PSDeviceUploadDetails.cs @@ -0,0 +1,63 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ----------------------------------------------------------------------- + +namespace Microsoft.Store.PartnerCenter.PowerShell.Models.DevicesDeployment +{ + using Common; + using PartnerCenter.Models.DevicesDeployment; + + /// + /// Represents the status of batch upload of devices. + /// + public sealed class PSDeviceUploadDetails + { + /// + /// Initializes a new instance of the class. + /// + public PSDeviceUploadDetails() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The base item for this instance. + public PSDeviceUploadDetails(DeviceUploadDetails item) + { + this.CopyFrom(item); + } + + /// + /// Gets or sets the device identifier. + /// + public string DeviceId { get; set; } + + /// + /// Gets or sets the error code upon device upload failure. + /// + public string ErrorCode { get; set; } + + /// + /// Gets or sets the error description upon device upload failure. + /// + public string ErrorDescription { get; set; } + + /// + /// Gets or sets the product key. + /// + public string ProductKey { get; set; } + + /// + /// Gets or sets the serial number. + /// + public string SerialNumber { get; set; } + + /// + /// Gets or sets the device upload status. + /// + public DeviceUploadStatusType Status { get; set; } + } +} \ No newline at end of file diff --git a/src/PowerShell/PartnerCenter.NetCore.psd1 b/src/PowerShell/PartnerCenter.NetCore.psd1 index 47572623..2d269ce8 100644 --- a/src/PowerShell/PartnerCenter.NetCore.psd1 +++ b/src/PowerShell/PartnerCenter.NetCore.psd1 @@ -11,7 +11,7 @@ RootModule = 'Microsoft.Store.PartnerCenter.PowerShell.dll' # Version number of this module. - ModuleVersion = '1.5.1907.1' + ModuleVersion = '1.5.1907.2' # Supported PSEditions CompatiblePSEditions = 'Core', 'Desktop' diff --git a/src/PowerShell/PartnerCenter.psd1 b/src/PowerShell/PartnerCenter.psd1 index b7b08b1a..b581e389 100644 --- a/src/PowerShell/PartnerCenter.psd1 +++ b/src/PowerShell/PartnerCenter.psd1 @@ -11,7 +11,7 @@ RootModule = 'Microsoft.Store.PartnerCenter.PowerShell.dll' # Version number of this module. - ModuleVersion = '1.5.1907.1' + ModuleVersion = '1.5.1907.2' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/src/PowerShell/PowerShell.csproj b/src/PowerShell/PowerShell.csproj index bab0621c..758ac6b2 100644 --- a/src/PowerShell/PowerShell.csproj +++ b/src/PowerShell/PowerShell.csproj @@ -14,7 +14,7 @@ https://github.com/Microsoft/Partner-Center-PowerShell.git git true - 1.5.1907.1 + 1.5.1907.2 @@ -25,6 +25,8 @@ + + @@ -65,7 +67,7 @@ - +