Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 85 additions & 13 deletions src/Applications/wrapper/v1.0/Cmdlets/GetMgApplicationDelta.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,57 @@
namespace Microsoft.Graph.PowerShell.Applications
{
[GraphRoute("GET", "/applications/delta()")]
[Cmdlet(VerbsCommon.Get, "MgApplicationDelta")]
[Cmdlet(VerbsCommon.Get, "MgApplicationDelta", DefaultParameterSetName = "DeltaSync")]
[OutputType(typeof(global::Microsoft.Graph.PowerShell.Applications.Client.Applications.Delta.DeltaGetResponse))]
public class GetMgApplicationDeltaCommand : GraphClientCmdlet
{





[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public string? Filter { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
[Alias("Select")]
public string[]? Property { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
[Alias("Expand")]
public string[]? ExpandProperty { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
[Alias("OrderBy")]
public string[]? Sort { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public string? Search { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public int Top { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public int Skip { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public SwitchParameter Count { get; set; }

// Resumes a previous sync from the link that run published. Universal: every delta
// request builder accepts a raw URL, whereas a token argument exists on only a few.
[Parameter(Mandatory = true, ParameterSetName = "Resume")]
public string DeltaLink { get; set; } = string.Empty;

// Follows @odata.nextLink through the change set. Without it only the first page returns,
// plus a warning when more pages exist.
[Parameter(Mandatory = false)]
public SwitchParameter All { get; set; }

// Receives the @odata.deltaLink that terminates the change set, for the next sync round.
// A named variable is how this SDK already returns a scalar alongside a pipeline
// (-CountVariable on the published list cmdlets).
[Parameter(Mandatory = false)]
[Alias("DLV")]
public string? DeltaLinkVariable { get; set; }



Expand All @@ -59,11 +74,21 @@ protected override void ProcessRecord()
var requestAdapter = GetRequestAdapter();
var client = new ApiClient(requestAdapter);

// Cleared before the request so a failed or interrupted run cannot leave the previous
// run's link readable, which would silently resume from the wrong point.
if (this.IsParameterBound(nameof(DeltaLinkVariable)))
SessionState.PSVariable.Set(DeltaLinkVariable, null);

global::Microsoft.Graph.PowerShell.Applications.Client.Applications.Delta.DeltaGetResponse? result;
try
{
result = client.Applications.Delta.GetAsDeltaGetResponseAsync(requestConfiguration =>
result = ParameterSetName == "Resume"
? client.Applications.Delta.WithUrl(DeltaLink).GetAsDeltaGetResponseAsync(requestConfiguration =>
{

AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult()
: client.Applications.Delta.GetAsDeltaGetResponseAsync(requestConfiguration =>
{
if (this.IsParameterBound(nameof(Filter)))
requestConfiguration.QueryParameters.Filter = Filter;
Expand Down Expand Up @@ -91,14 +116,61 @@ protected override void ProcessRecord()

AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult();

var fetched = 0;
while (true)
{
if (result?.Value is { } items)
{
WriteObject(items, enumerateCollection: true);
fetched += items.Count;
}

var nextLink = result?.OdataNextLink;
var deltaLink = result?.OdataDeltaLink;

// A response cannot be both continued and terminated; treating one as
// authoritative would silently drop pages or resume from a partial set.
if (!string.IsNullOrEmpty(nextLink) && !string.IsNullOrEmpty(deltaLink))
{
ThrowTerminatingError(new ErrorRecord(
new InvalidOperationException("The response carries both @odata.nextLink and @odata.deltaLink, which is not a valid delta response."),
"InvalidDeltaResponse", ErrorCategory.InvalidData, targetObject: null));
return;
}

if (!string.IsNullOrEmpty(deltaLink))
{
if (this.IsParameterBound(nameof(DeltaLinkVariable)))
SessionState.PSVariable.Set(DeltaLinkVariable, deltaLink);
break;
}

// No link of either kind: the change set ends here and there is nothing to
// publish for a next round.
if (string.IsNullOrEmpty(nextLink)) break;

if (!All.IsPresent)
{
WriteWarning("More results are available. Use -All to return all pages.");
break;
}

if (Stopping) break;
if (this.IsParameterBound(nameof(Top)) && fetched >= Top) break;

result = client.Applications.Delta.WithUrl(nextLink).GetAsDeltaGetResponseAsync(requestConfiguration =>
{

AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult();
}
}
catch (Exception ex) when (ex is not PipelineStoppedException)
{
ThrowGraphRequestFailed(ex, null);
return;
}

WriteObject(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,57 @@
namespace Microsoft.Graph.PowerShell.Applications
{
[GraphRoute("GET", "/servicePrincipals/delta()")]
[Cmdlet(VerbsCommon.Get, "MgServicePrincipalDelta")]
[Cmdlet(VerbsCommon.Get, "MgServicePrincipalDelta", DefaultParameterSetName = "DeltaSync")]
[OutputType(typeof(global::Microsoft.Graph.PowerShell.Applications.Client.ServicePrincipals.Delta.DeltaGetResponse))]
public class GetMgServicePrincipalDeltaCommand : GraphClientCmdlet
{





[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public string? Filter { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
[Alias("Select")]
public string[]? Property { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
[Alias("Expand")]
public string[]? ExpandProperty { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
[Alias("OrderBy")]
public string[]? Sort { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public string? Search { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public int Top { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public int Skip { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = "DeltaSync")]
public SwitchParameter Count { get; set; }

// Resumes a previous sync from the link that run published. Universal: every delta
// request builder accepts a raw URL, whereas a token argument exists on only a few.
[Parameter(Mandatory = true, ParameterSetName = "Resume")]
public string DeltaLink { get; set; } = string.Empty;

// Follows @odata.nextLink through the change set. Without it only the first page returns,
// plus a warning when more pages exist.
[Parameter(Mandatory = false)]
public SwitchParameter All { get; set; }

// Receives the @odata.deltaLink that terminates the change set, for the next sync round.
// A named variable is how this SDK already returns a scalar alongside a pipeline
// (-CountVariable on the published list cmdlets).
[Parameter(Mandatory = false)]
[Alias("DLV")]
public string? DeltaLinkVariable { get; set; }



Expand All @@ -59,11 +74,21 @@ protected override void ProcessRecord()
var requestAdapter = GetRequestAdapter();
var client = new ApiClient(requestAdapter);

// Cleared before the request so a failed or interrupted run cannot leave the previous
// run's link readable, which would silently resume from the wrong point.
if (this.IsParameterBound(nameof(DeltaLinkVariable)))
SessionState.PSVariable.Set(DeltaLinkVariable, null);

global::Microsoft.Graph.PowerShell.Applications.Client.ServicePrincipals.Delta.DeltaGetResponse? result;
try
{
result = client.ServicePrincipals.Delta.GetAsDeltaGetResponseAsync(requestConfiguration =>
result = ParameterSetName == "Resume"
? client.ServicePrincipals.Delta.WithUrl(DeltaLink).GetAsDeltaGetResponseAsync(requestConfiguration =>
{

AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult()
: client.ServicePrincipals.Delta.GetAsDeltaGetResponseAsync(requestConfiguration =>
{
if (this.IsParameterBound(nameof(Filter)))
requestConfiguration.QueryParameters.Filter = Filter;
Expand Down Expand Up @@ -91,14 +116,61 @@ protected override void ProcessRecord()

AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult();

var fetched = 0;
while (true)
{
if (result?.Value is { } items)
{
WriteObject(items, enumerateCollection: true);
fetched += items.Count;
}

var nextLink = result?.OdataNextLink;
var deltaLink = result?.OdataDeltaLink;

// A response cannot be both continued and terminated; treating one as
// authoritative would silently drop pages or resume from a partial set.
if (!string.IsNullOrEmpty(nextLink) && !string.IsNullOrEmpty(deltaLink))
{
ThrowTerminatingError(new ErrorRecord(
new InvalidOperationException("The response carries both @odata.nextLink and @odata.deltaLink, which is not a valid delta response."),
"InvalidDeltaResponse", ErrorCategory.InvalidData, targetObject: null));
return;
}

if (!string.IsNullOrEmpty(deltaLink))
{
if (this.IsParameterBound(nameof(DeltaLinkVariable)))
SessionState.PSVariable.Set(DeltaLinkVariable, deltaLink);
break;
}

// No link of either kind: the change set ends here and there is nothing to
// publish for a next round.
if (string.IsNullOrEmpty(nextLink)) break;

if (!All.IsPresent)
{
WriteWarning("More results are available. Use -All to return all pages.");
break;
}

if (Stopping) break;
if (this.IsParameterBound(nameof(Top)) && fetched >= Top) break;

result = client.ServicePrincipals.Delta.WithUrl(nextLink).GetAsDeltaGetResponseAsync(requestConfiguration =>
{

AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult();
}
}
catch (Exception ex) when (ex is not PipelineStoppedException)
{
ThrowGraphRequestFailed(ex, null);
return;
}

WriteObject(result);
}
}
}
Loading
Loading