Skip to content

Commit 1469e47

Browse files
authored
Merge pull request #1 from nsip/develop
Implement payload compression and Changes Since
2 parents bec992e + 2d1c036 commit 1469e47

64 files changed

Lines changed: 1354 additions & 284 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Code/Sif3Framework/Sif.Framework.EnvironmentProvider/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Systemic Pty Ltd")]
1212
[assembly: AssemblyProduct("Sif.Framework.EnvironmentProvider")]
13-
[assembly: AssemblyCopyright("Copyright © Systemic Pty Ltd 2016")]
13+
[assembly: AssemblyCopyright("Copyright © Systemic Pty Ltd 2017")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("3.0.0.0")]
35-
[assembly: AssemblyFileVersion("3.0.0.0")]
34+
[assembly: AssemblyVersion("3.1.0.0")]
35+
[assembly: AssemblyFileVersion("3.1.0.0")]

Code/Sif3Framework/Sif.Framework.Tests/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Systemic Pty Ltd")]
1212
[assembly: AssemblyProduct("Sif.Framework.Test")]
13-
[assembly: AssemblyCopyright("Copyright © Systemic Pty Ltd 2016")]
13+
[assembly: AssemblyCopyright("Copyright © Systemic Pty Ltd 2017")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("3.0.0.0")]
36-
[assembly: AssemblyFileVersion("3.0.0.0")]
35+
[assembly: AssemblyVersion("3.1.0.0")]
36+
[assembly: AssemblyFileVersion("3.1.0.0")]

Code/Sif3Framework/Sif.Framework/Consumers/Consumer.cs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Systemic Pty Ltd
2+
* Copyright 2017 Systemic Pty Ltd
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616

1717
using log4net;
18+
using Sif.Framework.Extensions;
1819
using Sif.Framework.Model.DataModels;
1920
using Sif.Framework.Model.Query;
2021
using Sif.Framework.Model.Responses;
@@ -181,6 +182,23 @@ public void Unregister(bool? deleteOnUnregister = null)
181182
registrationService.Unregister(deleteOnUnregister);
182183
}
183184

185+
/// <summary>
186+
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.GetChangesSinceMarker(string, string)">GetChangesSinceMarker</see>
187+
/// </summary>
188+
public string GetChangesSinceMarker(string zone = null, string context = null)
189+
{
190+
191+
if (!RegistrationService.Registered)
192+
{
193+
throw new InvalidOperationException("Consumer has not registered.");
194+
}
195+
196+
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context);
197+
WebHeaderCollection responseHeaders = HttpUtils.HeadRequest(url, RegistrationService.AuthorisationToken);
198+
199+
return responseHeaders[HttpUtils.RequestHeader.changesSinceMarker.ToDescription()];
200+
}
201+
184202
/// <summary>
185203
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.Create(TSingle, string, string)">Create</see>
186204
/// </summary>
@@ -298,7 +316,7 @@ public virtual TMultiple Query(uint? navigationPage = null, uint? navigationPage
298316
}
299317

300318
/// <summary>
301-
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.QueryByExample(TSingle, uint?, uint?, string, string)">Query</see>
319+
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.QueryByExample(TSingle, uint?, uint?, string, string)">QueryByExample</see>
302320
/// </summary>
303321
public virtual TMultiple QueryByExample(TSingle obj, uint? navigationPage = null, uint? navigationPageSize = null, string zone = null, string context = null)
304322
{
@@ -319,7 +337,7 @@ public virtual TMultiple QueryByExample(TSingle obj, uint? navigationPage = null
319337
}
320338

321339
/// <summary>
322-
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.QueryByServicePath(IEnumerable{EqualCondition}, uint?, uint?, string, string)">Query</see>
340+
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.QueryByServicePath(IEnumerable{EqualCondition}, uint?, uint?, string, string)">QueryByServicePath</see>
323341
/// </summary>
324342
public virtual TMultiple QueryByServicePath(IEnumerable<EqualCondition> conditions, uint? navigationPage = null, uint? navigationPageSize = null, string zone = null, string context = null)
325343
{
@@ -357,6 +375,36 @@ public virtual TMultiple QueryByServicePath(IEnumerable<EqualCondition> conditio
357375
return DeserialiseMultiple(xml);
358376
}
359377

378+
/// <summary>
379+
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.QueryChangesSince(string, out string, uint?, uint?, string, string)">QueryChangesSince</see>
380+
/// </summary>
381+
public TMultiple QueryChangesSince(string changesSinceMarker, out string nextChangesSinceMarker, uint? navigationPage = null, uint? navigationPageSize = null, string zone = null, string context = null)
382+
{
383+
384+
if (!RegistrationService.Registered)
385+
{
386+
throw new InvalidOperationException("Consumer has not registered.");
387+
}
388+
389+
string changesSinceParameter = (changesSinceMarker == null ? string.Empty : "?changesSinceMarker=" + changesSinceMarker);
390+
string url = EnvironmentUtils.ParseServiceUrl(EnvironmentTemplate) + "/" + TypeName + "s" + HttpUtils.MatrixParameters(zone, context) + changesSinceParameter;
391+
WebHeaderCollection responseHeaders;
392+
string xml;
393+
394+
if (navigationPage.HasValue && navigationPageSize.HasValue)
395+
{
396+
xml = HttpUtils.GetRequestAndHeaders(url, RegistrationService.AuthorisationToken, out responseHeaders, (int)navigationPage, (int)navigationPageSize);
397+
}
398+
else
399+
{
400+
xml = HttpUtils.GetRequestAndHeaders(url, RegistrationService.AuthorisationToken, out responseHeaders);
401+
}
402+
403+
nextChangesSinceMarker = responseHeaders[HttpUtils.RequestHeader.changesSinceMarker.ToDescription()];
404+
405+
return DeserialiseMultiple(xml);
406+
}
407+
360408
/// <summary>
361409
/// <see cref="IConsumer{TSingle,TMultiple,TPrimaryKey}.Update(TSingle, string, string)">Update</see>
362410
/// </summary>

Code/Sif3Framework/Sif.Framework/Consumers/IConsumer.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Systemic Pty Ltd
2+
* Copyright 2017 Systemic Pty Ltd
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,15 @@ public interface IConsumer<TSingle, TMultiple, TPrimaryKey> : IPayloadSerialisab
4444
/// <param name="deleteOnUnregister">True to remove session data on unregister; false to leave session data.</param>
4545
void Unregister(bool? deleteOnUnregister = null);
4646

47+
/// <summary>
48+
/// Retrieve the current Changes Since marker.
49+
/// <para>HEAD /StudentPersonals</para>
50+
/// </summary>
51+
/// <param name="zone">Zone associated with the request.</param>
52+
/// <param name="context">Zone context.</param>
53+
/// <returns>Changes Since marker.</returns>
54+
string GetChangesSinceMarker(string zone = null, string context = null);
55+
4756
/// <summary>
4857
/// Create a single object.
4958
/// <para>POST /StudentPersonals/StudentPersonal</para>
@@ -111,6 +120,19 @@ public interface IConsumer<TSingle, TMultiple, TPrimaryKey> : IPayloadSerialisab
111120
/// <returns>Retrieved objects.</returns>
112121
TMultiple QueryByServicePath(IEnumerable<EqualCondition> conditions, uint? navigationPage = null, uint? navigationPageSize = null, string zone = null, string context = null);
113122

123+
/// <summary>
124+
/// Retrieve multiple objects based on the Changes Since marker.
125+
/// <para>GET /StudentPersonals</para>
126+
/// </summary>
127+
/// <param name="changesSinceMarker">Changes Since marker.</param>
128+
/// <param name="nextChangesSinceMarker">Next Changes Since marker.</param>
129+
/// <param name="navigationPage">Current paging index.</param>
130+
/// <param name="navigationPageSize">Page size.</param>
131+
/// <param name="zone">Zone associated with the request.</param>
132+
/// <param name="context">Zone context.</param>
133+
/// <returns>Retrieved objects.</returns>
134+
TMultiple QueryChangesSince(string changesSinceMarker, out string nextChangesSinceMarker, uint? navigationPage = null, uint? navigationPageSize = null, string zone = null, string context = null);
135+
114136
/// <summary>
115137
/// Update a single object.
116138
/// <para>PUT /StudentPersonals/{id}</para>

Code/Sif3Framework/Sif.Framework/Extensions/Extension.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Systemic Pty Ltd
2+
* Copyright 2017 Systemic Pty Ltd
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,9 @@
1515
*/
1616

1717
using Sif.Framework.WebApi;
18+
using Sif.Framework.WebApi.ActionResults;
1819
using System;
20+
using System.Collections.Generic;
1921
using System.ComponentModel;
2022
using System.Linq;
2123
using System.Web.Http;
@@ -29,6 +31,40 @@ namespace Sif.Framework.Extensions
2931
static class Extension
3032
{
3133

34+
/// <summary>
35+
/// Extension to add a custom header to an action result.
36+
/// </summary>
37+
/// <param name="actionResult">Action result.</param>
38+
/// <param name="headerName">Name of the header.</param>
39+
/// <param name="headerValue">Value associated with the header.</param>
40+
/// <returns>Action result with a custom header.</returns>
41+
public static IHttpActionResult AddHeader(this IHttpActionResult actionResult, string headerName, string headerValue)
42+
{
43+
return AddHeader(actionResult, headerName, new[] { headerValue });
44+
}
45+
46+
/// <summary>
47+
/// Extension to add a custom header to an action result.
48+
/// </summary>
49+
/// <param name="actionResult">Action result.</param>
50+
/// <param name="headerName">Name of the header.</param>
51+
/// <param name="headerValues">Values associated with the header.</param>
52+
/// <returns>Action result with a custom header.</returns>
53+
public static IHttpActionResult AddHeader(this IHttpActionResult actionResult, string headerName, ICollection<string> headerValues)
54+
{
55+
return new CustomHeaderResult(actionResult, headerName, headerValues);
56+
}
57+
58+
/// <summary>
59+
/// Extension to clear the content of an action result but the leave the content length.
60+
/// </summary>
61+
/// <param name="actionResult">Action result.</param>
62+
/// <returns>Action result with empty content.</returns>
63+
public static IHttpActionResult ClearContent(this IHttpActionResult actionResult)
64+
{
65+
return new EmptyContentResult(actionResult);
66+
}
67+
3268
/// <summary>
3369
/// Extension of types to check whether one is assignable from a generic type.
3470
/// </summary>

Code/Sif3Framework/Sif.Framework/Model/Settings/ConfigFileBasedFrameworkSettings.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Systemic Pty Ltd
2+
* Copyright 2016 Systemic Pty Ltd
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,14 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
using log4net;
1817
using Sif.Framework.Model.Infrastructure;
19-
using Sif.Framework.Utils;
2018
using System;
21-
using System.Collections.Generic;
2219
using System.Configuration;
23-
using System.Linq;
24-
using System.Reflection;
2520

2621
namespace Sif.Framework.Model.Settings
2722
{
@@ -31,7 +26,6 @@ namespace Sif.Framework.Model.Settings
3126
/// </summary>
3227
abstract class ConfigFileBasedFrameworkSettings : IFrameworkSettings
3328
{
34-
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
3529
private Configuration configuration;
3630

3731
/// <summary>
@@ -171,6 +165,19 @@ public string AuthenticationMethod
171165

172166
}
173167

168+
/// <summary>
169+
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.CompressPayload"/>
170+
/// </summary>
171+
public bool CompressPayload
172+
{
173+
174+
get
175+
{
176+
return GetBooleanSetting(SettingsPrefix + ".payload.compress", false);
177+
}
178+
179+
}
180+
174181
/// <summary>
175182
/// <see cref="Sif.Framework.Model.Settings.IFrameworkSettings.ConsumerName"/>
176183
/// </summary>

Code/Sif3Framework/Sif.Framework/Model/Settings/IFrameworkSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Systemic Pty Ltd
2+
* Copyright 2016 Systemic Pty Ltd
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,11 @@ public interface IFrameworkSettings
3535
/// </summary>
3636
string AuthenticationMethod { get; }
3737

38+
/// <summary>
39+
/// Compress payload flag if it exists; false otherwise.
40+
/// </summary>
41+
bool CompressPayload { get; }
42+
3843
/// <summary>
3944
/// Consumer name if it exists; null otherwise.
4045
/// </summary>

Code/Sif3Framework/Sif.Framework/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
88
[assembly: AssemblyTitle("Sif.Framework")]
9-
[assembly: AssemblyDescription("Core library of the SIF 3 Framework.")]
9+
[assembly: AssemblyDescription("Core library of the SIF3 Framework based on SIF Infrastructure 3.2.")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Systemic Pty Ltd")]
1212
[assembly: AssemblyProduct("Sif.Framework")]
13-
[assembly: AssemblyCopyright("Copyright © Systemic Pty Ltd 2016")]
13+
[assembly: AssemblyCopyright("Copyright © Systemic Pty Ltd 2017")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,8 +32,8 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("3.0.0.0")]
36-
[assembly: AssemblyFileVersion("3.0.0.0")]
35+
[assembly: AssemblyVersion("3.1.0.0")]
36+
[assembly: AssemblyFileVersion("3.1.0.0")]
3737

3838
// Configure log4net using the .config file
3939
[assembly: log4net.Config.XmlConfigurator(Watch = true)]

Code/Sif3Framework/Sif.Framework/Providers/IProvider.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Systemic Pty Ltd
2+
* Copyright 2017 Systemic Pty Ltd
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,10 +97,11 @@ interface IProvider<TSingle, TMultiple, TPrimaryKey>
9797
/// <para>500 - Failure, internal service error</para>
9898
/// </summary>
9999
/// <param name="obj">Example object to base the query on.</param>
100+
/// <param name="changesSinceMarker">Changes Since marker.</param>
100101
/// <param name="zone">Zone associated with the request.</param>
101102
/// <param name="context">Zone context.</param>
102103
/// <returns>All objects, objects that match the properties of the example object or no objects (TMultiple).</returns>
103-
IHttpActionResult Get(TSingle obj, string[] zone = null, string[] context = null);
104+
IHttpActionResult Get(TSingle obj, string changesSinceMarker = null, string[] zone = null, string[] context = null);
104105

105106
/// <summary>
106107
/// Retrieve multiple objects using Service Paths.
@@ -196,6 +197,23 @@ interface IProvider<TSingle, TMultiple, TPrimaryKey>
196197
/// <returns>Response containing status of each object deleted (deleteResponseType).</returns>
197198
IHttpActionResult Delete(deleteRequestType deleteRequest, string[] zone = null, string[] context = null);
198199

200+
/// <summary>
201+
/// Retrieve the message headers associated with a call to retrieve all objects.
202+
/// <para>HEAD api/{controller}</para>
203+
/// <para/>
204+
/// <para>200 - Success, ok</para>
205+
/// <para>204 - Success, no content</para>
206+
/// <para>400 - Failue, bad request</para>
207+
/// <para>401 - Failure, unauthorised</para>
208+
/// <para>403 - Failure, forbidden</para>
209+
/// <para>413 - Failure, response too large</para>
210+
/// <para>500 - Failure, internal service error</para>
211+
/// </summary>
212+
/// <param name="zone">Zone associated with the request.</param>
213+
/// <param name="context">Zone context.</param>
214+
/// <returns>No objects, just message header information (void).</returns>
215+
IHttpActionResult Head(string[] zone = null, string[] context = null);
216+
199217
}
200218

201219
}

0 commit comments

Comments
 (0)