Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Device batch feature update (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaiah Williams authored Jul 10, 2019
1 parent bd1b792 commit d84faf9
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 24 deletions.
7 changes: 6 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion build/PartnerCenter.NetCore.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>PartnerCenter.NetCore</id>
<version>1.5.1907.1</version>
<version>1.5.1907.2</version>
<authors>Microsoft Corporation</authors>
<owners>Microsoft</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
2 changes: 1 addition & 1 deletion build/PartnerCenter.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>PartnerCenter</id>
<version>1.5.1907.1</version>
<version>1.5.1907.2</version>
<authors>Microsoft Corporation</authors>
<owners>Microsoft</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
2 changes: 1 addition & 1 deletion docs/help/New-PartnerCustomerDeviceBatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## OUTPUTS
### System.String
### Microsoft.Store.PartnerCenter.PowerShell.Models.DevicesDeployment.PSBatchUploadDetails
## NOTES
Expand Down
54 changes: 45 additions & 9 deletions src/PowerShell/Commands/NewPartnerCustomerDeviceBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand Down Expand Up @@ -44,29 +48,61 @@ public class NewPartnerCustomerDeviceBatch : PartnerPSCmdlet
public override void ExecuteCmdlet()
{
DeviceBatchCreationRequest request;
string deviceBatch;
ResourceCollection<DeviceBatch> batches;
IEnumerable<Device> 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));
}
}
}
4 changes: 3 additions & 1 deletion src/PowerShell/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[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")]

69 changes: 69 additions & 0 deletions src/PowerShell/Models/DevicesDeployment/PSBatchUploadDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// -----------------------------------------------------------------------
// <copyright file="PSBatchUploadDetails.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace Microsoft.Store.PartnerCenter.PowerShell.Models.DevicesDeployment
{
using System;
using System.Linq;
using Common;
using PartnerCenter.Models.DevicesDeployment;

/// <summary>
/// Represents the result of devices batch upload.
/// </summary>
public sealed class PSBatchUploadDetails
{
/// <summary>
/// Initializes a new instance of the <see cref="PSBatchUploadDetails" /> class.
/// </summary>
public PSBatchUploadDetails()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="PSBatchUploadDetails" /> class.
/// </summary>
/// <param name="details">The details for this instance.</param>
public PSBatchUploadDetails(BatchUploadDetails details)
{
this.CopyFrom(details, CloneAdditionalOperations);
}

/// <summary>
/// Gets or sets the tracking ID of the batch of devices uploaded.
/// </summary>
public string BatchTrackingId { get; set; }

/// <summary>
/// Gets or sets the batch upload completed time.
/// </summary>
public DateTime CompletedTime { get; set; }

/// <summary>
/// Gets or sets the device upload status.
/// </summary>
public PSDeviceUploadDetails[] DevicesStatus { get; set; }

/// <summary>
/// Gets or sets the batch started time.
/// </summary>
public DateTime StartedTime { get; set; }

/// <summary>
/// Gets or sets the status.
/// </summary>
public DeviceUploadStatusType Status { get; set; }

/// <summary>
/// Additional operations to be performed when cloning an instance of <see cref="BatchUploadDetails"/> to an instance of <see cref="PSBatchUploadDetails" />.
/// </summary>
/// <param name="item">The item being cloned.</param>
private void CloneAdditionalOperations(BatchUploadDetails item)
{
DevicesStatus = item.DevicesStatus.Select(d => new PSDeviceUploadDetails(d)).ToArray();
}
}
}
10 changes: 4 additions & 6 deletions src/PowerShell/Models/DevicesDeployment/PSDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ public sealed class PSDevice
/// </summary>
public PSDevice()
{
Policies = new List<KeyValuePair<PolicyCategory, string>>();
}

/// <summary>
/// Initializes a new instance of the <see cref="PSDevice" /> class.
/// </summary>
/// <param name="device">The base PSDevice for this instance.</param>
public PSDevice(Device device)
/// <param name="item">The base item for this instance.</param>
public PSDevice(Device item)
{
Policies = new List<KeyValuePair<PolicyCategory, string>>();
this.CopyFrom(device, CloneAdditionalOperations);
this.CopyFrom(item, CloneAdditionalOperations);
}

/// <summary>
Expand Down Expand Up @@ -62,7 +60,7 @@ public PSDevice(Device device)
/// <summary>
/// Gets or sets the policies assigned.
/// </summary>
public List<KeyValuePair<PolicyCategory, string>> Policies { get; }
public List<KeyValuePair<PolicyCategory, string>> Policies { get; set; }

/// <summary>
/// Gets or sets the product key.
Expand Down
63 changes: 63 additions & 0 deletions src/PowerShell/Models/DevicesDeployment/PSDeviceUploadDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// -----------------------------------------------------------------------
// <copyright file="PSDeviceUploadDetails.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace Microsoft.Store.PartnerCenter.PowerShell.Models.DevicesDeployment
{
using Common;
using PartnerCenter.Models.DevicesDeployment;

/// <summary>
/// Represents the status of batch upload of devices.
/// </summary>
public sealed class PSDeviceUploadDetails
{
/// <summary>
/// Initializes a new instance of the <see cref="PSDeviceUploadDetails" /> class.
/// </summary>
public PSDeviceUploadDetails()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="PSDeviceUploadDetails" /> class.
/// </summary>
/// <param name="device">The base item for this instance.</param>
public PSDeviceUploadDetails(DeviceUploadDetails item)
{
this.CopyFrom(item);
}

/// <summary>
/// Gets or sets the device identifier.
/// </summary>
public string DeviceId { get; set; }

/// <summary>
/// Gets or sets the error code upon device upload failure.
/// </summary>
public string ErrorCode { get; set; }

/// <summary>
/// Gets or sets the error description upon device upload failure.
/// </summary>
public string ErrorDescription { get; set; }

/// <summary>
/// Gets or sets the product key.
/// </summary>
public string ProductKey { get; set; }

/// <summary>
/// Gets or sets the serial number.
/// </summary>
public string SerialNumber { get; set; }

/// <summary>
/// Gets or sets the device upload status.
/// </summary>
public DeviceUploadStatusType Status { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/PowerShell/PartnerCenter.NetCore.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/PowerShell/PartnerCenter.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
Expand Down
6 changes: 4 additions & 2 deletions src/PowerShell/PowerShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RepositoryUrl>https://github.com/Microsoft/Partner-Center-PowerShell.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Version>1.5.1907.1</Version>
<Version>1.5.1907.2</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,6 +25,8 @@
<None Remove="Commands\GetPartnerCustomerOrderProvisioningStatus.cs" />
<None Remove="Commands\GetPartnerValidationCode.cs" />
<None Remove="Factories\CancelRetryHandler.cs" />
<None Remove="Models\DevicesDeployment\PSBatchUploadDetails.cs" />
<None Remove="Models\DevicesDeployment\PSDeviceUploadDetails.cs" />
<None Remove="Models\Orders\PSOrderLineItemProvisioningStatus.cs" />
<None Remove="Models\ValidationCodes\PSValidationCode.cs" />
</ItemGroup>
Expand Down Expand Up @@ -65,7 +67,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="PartnerCenter.DotNet" Version="1.13.3" />
<PackageReference Include="PartnerCenter.DotNet" Version="1.13.3.2" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.5.0" />
</ItemGroup>
Expand Down

0 comments on commit d84faf9

Please sign in to comment.