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
56 changes: 53 additions & 3 deletions Code/Sif3Framework/Sif.Framework/Consumers/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public virtual TSingle Query(
}

TSingle obj = default(TSingle);

try
{
string url = new StringBuilder(EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate))
Expand Down Expand Up @@ -309,9 +309,44 @@ public virtual TSingle Query(
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.Query(uint?, uint?, string, string, RequestParameter[])">Query</see>
/// </summary>
public virtual TMultiple Query(
uint? navigationPage = null,
uint? navigationPageSize = null,
string zoneId = null,
string contextId = null,
params RequestParameter[] requestParameters)
{
if (!RegistrationService.Registered)
{
throw new InvalidOperationException("Consumer has not registered.");
}

string url = new StringBuilder(EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate))
.Append($"/{TypeName}s")
.Append(HttpUtils.MatrixParameters(zoneId, contextId))
.Append(GenerateQueryParameterString(requestParameters)).ToString();
string xml;

if (navigationPage.HasValue && navigationPageSize.HasValue)
{
xml = HttpUtils.GetRequest(url, RegistrationService.AuthorisationToken, navigationPage: (int)navigationPage, navigationPageSize: (int)navigationPageSize);
}
else
{
xml = HttpUtils.GetRequest(url, RegistrationService.AuthorisationToken);
}

return DeserialiseMultiple(xml);
}

/// <summary>
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.Query(out uint?, out uint?, uint?, uint?, string, string, RequestParameter[])">Query</see>
/// </summary>
public virtual TMultiple Query(
out uint? navigationCount,
out uint? navigationLastPage,
uint? navigationPage = null,
uint? navigationPageSize = null,
string zoneId = null,
string zoneId = null,
string contextId = null,
params RequestParameter[] requestParameters)
{
Expand All @@ -320,6 +355,9 @@ public virtual TMultiple Query(
throw new InvalidOperationException("Consumer has not registered.");
}

navigationCount = null;
navigationLastPage = null;

string url = new StringBuilder(EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate))
.Append($"/{TypeName}s")
.Append(HttpUtils.MatrixParameters(zoneId, contextId))
Expand All @@ -328,7 +366,9 @@ public virtual TMultiple Query(

if (navigationPage.HasValue && navigationPageSize.HasValue)
{
xml = HttpUtils.GetRequest(url, RegistrationService.AuthorisationToken, navigationPage: (int)navigationPage, navigationPageSize: (int)navigationPageSize);
xml = HttpUtils.GetRequestAndHeaders(url, RegistrationService.AuthorisationToken, out var responseHeaders, navigationPage: (int)navigationPage, navigationPageSize: (int)navigationPageSize);
navigationCount = GetResponseHeaderUInt(responseHeaders, ResponseParameterType.navigationCount);
navigationLastPage = GetResponseHeaderUInt(responseHeaders, ResponseParameterType.navigationLastPage);
}
else
{
Expand All @@ -338,6 +378,16 @@ public virtual TMultiple Query(
return DeserialiseMultiple(xml);
}

private static uint? GetResponseHeaderUInt(WebHeaderCollection responseHeaders, ResponseParameterType responseParameterType)
{
var responseHeaderValue = responseHeaders.Get(responseParameterType.ToDescription());
if (uint.TryParse(responseHeaderValue, out var responseHeaderValueUInt))
return string.IsNullOrWhiteSpace(responseHeaderValue)
? (uint?)null
: responseHeaderValueUInt;
return null;
}

/// <summary>
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.QueryByExample(TSingle, uint?, uint?, string, string, RequestParameter[])">QueryByExample</see>
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions Code/Sif3Framework/Sif.Framework/Consumers/IConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ TMultiple Query(
string contextId = null,
params RequestParameter[] requestParameters);

/// <summary>
/// Retrieve all objects.
/// <para>GET /StudentPersonals</para>
/// </summary>
/// <param name="navigationCount">Total number of of objects.</param>
/// <param name="navigationLastPage">Last page index.</param>
/// <param name="navigationPage">Current paging index.</param>
/// <param name="navigationPageSize">Page size.</param>
/// <param name="zoneId">Zone associated with the request.</param>
/// <param name="contextId">Zone context.</param>
/// <param name="requestParameters">Additional parameters associated with the request.</param>
/// <returns>Retrieved objects.</returns>
/// <exception cref="System.UnauthorizedAccessException">Request is unauthorised.</exception>
TMultiple Query(
out uint? navigationCount,
out uint? navigationLastPage,
uint? navigationPage = null,
uint? navigationPageSize = null,
string zoneId = null,
string contextId = null,
params RequestParameter[] requestParameters);

/// <summary>
/// Retrieve multiple objects using Query by Example.
/// <para>POST /StudentPersonals (methodOverride: GET)</para>
Expand Down