Skip to content

Commit

Permalink
Improve IpAddresses.GetUnassignedAsync
Browse files Browse the repository at this point in the history
Resolves #369
  • Loading branch information
Jericho committed Aug 11, 2021
1 parent cfbdf81 commit f1181a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
20 changes: 20 additions & 0 deletions Source/StrongGrid/Extensions/Public.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,5 +1125,25 @@ public static Task<Segment> UpdateAsync(this ISegments segments, string segmentI
if (filterConditions.HasValue && filterConditions.Value != null && filterConditions.Value.Any()) filters.Add(new KeyValuePair<SearchLogicalOperator, IEnumerable<SearchCriteria<ContactsFilterField>>>(SearchLogicalOperator.And, filterConditions.Value));
return segments.UpdateAsync(segmentId, name, filters, cancellationToken);
}

/// <summary>
/// Retrieve unassigned IP addresses.
/// </summary>
/// <param name="ipAddresses">The IP addresses resource.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>
/// An array of <see cref="IpAddress">Ip addresses</see>.
/// </returns>
public static async Task<IpAddress[]> GetUnassignedAsync(this IIpAddresses ipAddresses, CancellationToken cancellationToken = default)
{
var allIpAddresses = await ipAddresses.GetAllAsync(cancellationToken: cancellationToken).ConfigureAwait(false);

var unassignedIpAddresses = allIpAddresses.Records
.Where(ip => ip.Pools == null || !ip.Pools.Any())
.ToArray();

return unassignedIpAddresses;
}

}
}
9 changes: 0 additions & 9 deletions Source/StrongGrid/Resources/IIpAddresses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ public interface IIpAddresses
/// </returns>
Task<IpAddress[]> GetAssignedAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve unassigned IP addresses.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>
/// An array of <see cref="IpAddress">Ip addresses</see>.
/// </returns>
Task<IpAddress[]> GetUnassignedAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve all IP addresses that are currently warming up.
/// </summary>
Expand Down
18 changes: 0 additions & 18 deletions Source/StrongGrid/Resources/IpAddresses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,6 @@ public Task<IpAddress[]> GetAssignedAsync(CancellationToken cancellationToken =
.AsObject<IpAddress[]>();
}

/// <summary>
/// Retrieve unassigned IP addresses.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>
/// An array of <see cref="IpAddress">Ip addresses</see>.
/// </returns>
public async Task<IpAddress[]> GetUnassignedAsync(CancellationToken cancellationToken = default)
{
var allIpAddresses = await this.GetAllAsync(cancellationToken: cancellationToken).ConfigureAwait(false);

var unassignedIpAddresses = allIpAddresses.Records
.Where(ip => ip.Subusers == null || !ip.Subusers.Any())
.ToArray();

return unassignedIpAddresses;
}

/// <summary>
/// Retrieve all IP addresess that are currently warming up.
/// </summary>
Expand Down

0 comments on commit f1181a8

Please sign in to comment.