Skip to content

Commit

Permalink
Update the Funtional Service Provider to use the correct matrix param…
Browse files Browse the repository at this point in the history
…eters.
  • Loading branch information
rafidzal committed Mar 29, 2017
1 parent 684394e commit 8b95d14
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 84 deletions.
47 changes: 12 additions & 35 deletions Code/Sif3Framework/Sif.Framework/Consumers/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,6 @@ public Consumer(string applicationKey, string instanceId = null, string userToke
registrationService = new RegistrationService(SettingsManager.ConsumerSettings, SessionsManager.ConsumerSessionService);
}

/// <summary>
/// Build up a string of Matrix Parameters based upon the passed parameters.
/// </summary>
/// <param name="zone">Zone associated with a request.</param>
/// <param name="context">Zone context.</param>
/// <returns>String of Matrix Parameters.</returns>
private string MatrixParameters(string zone = null, string context = null)
{
string matrixParameters = "";

if (!string.IsNullOrWhiteSpace(zone))
{
matrixParameters += ";zoneId=" + zone.Trim();
}

if (!string.IsNullOrWhiteSpace(context))
{
matrixParameters += ";contextId=" + context.Trim();
}

return matrixParameters;
}

/// <summary>
/// <see cref="IPayloadSerialisable{TSingle,TMultiple}.SerialiseSingle(TSingle)">SerialiseSingle</see>
/// </summary>
Expand Down Expand Up @@ -192,7 +169,7 @@ public string GetChangesSinceMarker(string zone = null, string context = null)
throw new InvalidOperationException("Consumer has not registered.");
}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context);
WebHeaderCollection responseHeaders = HttpUtils.HeadRequest(url, RegistrationService.AuthorisationToken);

return responseHeaders[HttpUtils.RequestHeader.changesSinceMarker.ToDescription()];
Expand All @@ -209,7 +186,7 @@ public virtual TSingle Create(TSingle obj, string zone = null, string context =
throw new InvalidOperationException("Consumer has not registered.");
}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + "/" + TypeName + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + "/" + TypeName + HttpUtils.MatrixParameters(zone, context);
string body = SerialiseSingle(obj);
string xml = HttpUtils.PostRequest(url, RegistrationService.AuthorisationToken, body);
if (log.IsDebugEnabled) log.Debug("XML from POST request ...");
Expand All @@ -229,7 +206,7 @@ public virtual MultipleCreateResponse Create(TMultiple obj, string zone = null,
throw new InvalidOperationException("Consumer has not registered.");
}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context);
string body = SerialiseMultiple(obj);
string xml = HttpUtils.PostRequest(url, RegistrationService.AuthorisationToken, body);
if (log.IsDebugEnabled) log.Debug("XML from POST request ...");
Expand All @@ -255,7 +232,7 @@ public virtual TSingle Query(TPrimaryKey refId, string zone = null, string conte

try
{
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + "/" + refId + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + "/" + refId + HttpUtils.MatrixParameters(zone, context);
string xml = HttpUtils.GetRequest(url, RegistrationService.AuthorisationToken);
if (log.IsDebugEnabled) log.Debug("XML from GET request ...");
if (log.IsDebugEnabled) log.Debug(xml);
Expand Down Expand Up @@ -299,7 +276,7 @@ public virtual TMultiple Query(uint? navigationPage = null, uint? navigationPage
throw new InvalidOperationException("Consumer has not registered.");
}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context);
string xml;

if (navigationPage.HasValue && navigationPageSize.HasValue)
Expand All @@ -325,7 +302,7 @@ public virtual TMultiple QueryByExample(TSingle obj, uint? navigationPage = null
throw new InvalidOperationException("Consumer has not registered.");
}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context);
string body = SerialiseSingle(obj);
// TODO: Update PostRequest to accept paging parameters.
string xml = HttpUtils.PostRequest(url, RegistrationService.AuthorisationToken, body, "GET");
Expand Down Expand Up @@ -358,7 +335,7 @@ public virtual TMultiple QueryByServicePath(IEnumerable<EqualCondition> conditio

}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + servicePath + "/" + TypeName + "s" + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + servicePath + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context);
if (log.IsDebugEnabled) log.Debug("Service Path URL is " + url);
string xml;

Expand Down Expand Up @@ -386,7 +363,7 @@ public TMultiple QueryChangesSince(string changesSinceMarker, out string nextCha
}

string changesSinceParameter = (changesSinceMarker == null ? string.Empty : "?changesSinceMarker=" + changesSinceMarker);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + MatrixParameters(zone, context) + changesSinceParameter;
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context) + changesSinceParameter;
WebHeaderCollection responseHeaders;
string xml;

Expand Down Expand Up @@ -415,7 +392,7 @@ public virtual void Update(TSingle obj, string zone = null, string context = nul
throw new InvalidOperationException("Consumer has not registered.");
}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + "/" + obj.RefId + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + "/" + obj.RefId + HttpUtils.MatrixParameters(zone, context);
string body = SerialiseSingle(obj);
string xml = HttpUtils.PutRequest(url, RegistrationService.AuthorisationToken, body);
if (log.IsDebugEnabled) log.Debug("XML from PUT request ...");
Expand All @@ -433,7 +410,7 @@ public virtual MultipleUpdateResponse Update(TMultiple obj, string zone = null,
throw new InvalidOperationException("Consumer has not registered.");
}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context);
string body = SerialiseMultiple(obj);
string xml = HttpUtils.PutRequest(url, RegistrationService.AuthorisationToken, body);
if (log.IsDebugEnabled) log.Debug("XML from PUT request ...");
Expand All @@ -455,7 +432,7 @@ public virtual void Delete(TPrimaryKey refId, string zone = null, string context
throw new InvalidOperationException("Consumer has not registered.");
}

string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + "/" + refId + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + "/" + refId + HttpUtils.MatrixParameters(zone, context);
string xml = HttpUtils.DeleteRequest(url, RegistrationService.AuthorisationToken);
if (log.IsDebugEnabled) log.Debug("XML from DELETE request ...");
if (log.IsDebugEnabled) log.Debug(xml);
Expand All @@ -481,7 +458,7 @@ public virtual MultipleDeleteResponse Delete(IEnumerable<TPrimaryKey> refIds, st
}

deleteRequestType request = new deleteRequestType { deletes = deleteIds.ToArray() };
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + MatrixParameters(zone, context);
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context);
string body = SerialiserFactory.GetXmlSerialiser<deleteRequestType>().Serialise(request);
string xml = HttpUtils.PutRequest(url, RegistrationService.AuthorisationToken, body, "DELETE");
if (log.IsDebugEnabled) log.Debug("XML from PUT (DELETE) request ...");
Expand Down
Loading

0 comments on commit 8b95d14

Please sign in to comment.