Skip to content

Commit 1649f27

Browse files
committed
7.0.14 release
- [ENHANCEMENT] updated code to allow application pool to start if memcache is unavailable - [ENHANCEMENT] removed ApplicationLoaded flag from api as if there is no API config loaded on application startup then let an exception be thrown that is not caught - [ENHANCEMENT] updated ICacheConfig to allow API_MEMCACHED_ENABLED to be set in Code - [ENHANCEMENT] updated MemCacheD constructor to have the stats query within try catch Block - [ENHANCEMENT] updated ConsoleConfiguration.cs to remove ApplicationLoaded flag - [BUG FIX] updated ReadJSONSettings to return null if the version that is being looked for is not there
1 parent e834404 commit 1649f27

File tree

11 files changed

+99
-67
lines changed

11 files changed

+99
-67
lines changed

rls/packages/API.Library.7.0.14.nupkg

67.7 KB
Binary file not shown.

src/API.Library/API.Library.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
<PackageId>API.Library</PackageId>
1313
<Product>API Library</Product>
1414
<Copyright>Central Statistics Office, Ireland</Copyright>
15-
<Version>7.0.13</Version>
15+
<Version>7.0.14</Version>
1616
<Authors>Central Statistics Office, Ireland</Authors>
1717
<SignAssembly>False</SignAssembly>
1818
<RepositoryUrl>https://github.com/CSOIreland/Server-API-Library</RepositoryUrl>
1919
<PackageReleaseNotes>
20-
- [LIBRARY UPDATE] upgraded microsoft.data.sqlclient to 5.2.2
20+
- [ENHANCEMENT] updated code to allow application pool to start if memcache is unavailable
21+
- [ENHANCEMENT] removed ApplicationLoaded flag from api as if there is no API config loaded on application startup then let an exception be thrown that is not caught
22+
- [ENHANCEMENT] updated ICacheConfig to allow API_MEMCACHED_ENABLED to be set in Code
23+
- [ENHANCEMENT] updated MemCacheD constructor to have the stats query within try catch Block
24+
- [ENHANCEMENT] updated ConsoleConfiguration.cs to remove ApplicationLoaded flag
25+
- [BUG FIX] updated ReadJSONSettings to return null if the version that is being looked for is not there
2126
</PackageReleaseNotes>
2227
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
2328
<RestoreLockedMode>true</RestoreLockedMode>
@@ -36,6 +41,7 @@
3641
<None Remove="Entities\MemCacheD.cs~RFcba3198.TMP" />
3742
<None Remove="Entities\MethodReader.cs~RF8645ca5e.TMP" />
3843
<None Remove="log4net.config" />
44+
<None Remove="Middleware\ServiceConfiguration.cs~RF1c6e307d.TMP" />
3945
</ItemGroup>
4046

4147
<ItemGroup>

src/API.Library/Config/CacheConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public bool API_MEMCACHED_ENABLED
3737
{
3838
return _CacheSettingsDelegate.CurrentValue.API_MEMCACHED_ENABLED;
3939
}
40+
set{
41+
_CacheSettingsDelegate.CurrentValue.API_MEMCACHED_ENABLED = value;
42+
}
4043
}
4144

4245
public bool API_CACHE_TRACE_ENABLED

src/API.Library/Config/CommonConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public static IDictionary<string, string> ReadJSONSettings(decimal? inMemoryVers
8888
if (inMemoryVersion != Convert.ToDecimal(val.Value))
8989
{
9090
Log.Instance.Fatal("" + ConfigType + " : Configuration version not found for version " + inMemoryVersion);
91+
return null;
9192
}
9293
}
9394
if (dictionary.ContainsKey(val.Key))

src/API.Library/Console/ConsoleConfiguration.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,21 @@ public static IHost AddApiLibrary(IConfiguration configuration)
9797
ApiServicesHelper.ApiConfiguration = builder.Services.GetService<IApiConfiguration>();
9898
if (ApiServicesHelper.ApiConfiguration.Settings == null)
9999
{
100-
ApiServicesHelper.ApplicationLoaded = false;
100+
throw new Exception("API Settings failed to load");
101101
}
102102

103103
ApiServicesHelper.WebUtility = builder.Services.GetService<IWebUtility> ();
104104
ApiServicesHelper.ActiveDirectory = builder.Services.GetService<IActiveDirectory>();
105105

106-
if (ApiServicesHelper.APPConfig.enabled && ApiServicesHelper.ApplicationLoaded)
106+
if (ApiServicesHelper.APPConfig.enabled)
107107
{
108108
//load APP config here as if can't load application wont work
109109
ApiServicesHelper.AppConfiguration = builder.Services.GetService<IAppConfiguration>();
110+
111+
if (ApiServicesHelper.AppConfiguration.Settings == null)
112+
{
113+
throw new Exception("APP Settings failed to load");
114+
}
110115
}
111116

112117
Log.Instance.Info("All API setup completed");

src/API.Library/Entities/MemCacheD.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@ public MemCacheD()
3333
var port = ApiServicesHelper.Configuration.GetSection("enyimMemcached:Servers:0:Port").Value;
3434
var address = ApiServicesHelper.Configuration.GetSection("enyimMemcached:Servers:0:Address").Value;
3535

36-
ServerStats stats = ApiServicesHelper.MemcachedClient.Stats();
37-
3836
try
3937
{
38+
ServerStats stats = ApiServicesHelper.MemcachedClient.Stats();
4039
var upTime = stats.GetUptime(new IPEndPoint(IPAddress.Parse(address), int.Parse(port)));
4140
}
4241
catch (Exception ex)
4342
{
4443
Log.Instance.Fatal(ex);
4544
Log.Instance.Fatal("Memcache has not returned any stats data. Memcache may be unavailable");
46-
4745
}
4846
}
4947
}

src/API.Library/Entities/Tracing/DatabaseTrace/DatabaseTrace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static DataTable CreateDatabaseTraceDataTable()
2727
internal static void PopulateDatabaseTrace(string procedure, string procedureParams, DateTime startTime, decimal duration, string action, bool success)
2828
{
2929
//dont record tracing unless apiconfiguration has been loaded and their is a correlation id
30-
if (ApiServicesHelper.ApplicationLoaded && ApiServicesHelper.ApiConfiguration != null && APIMiddleware.correlationID.Value != null && APIMiddleware.databaseTraceDataTable.Value != null)
30+
if (ApiServicesHelper.ApiConfiguration != null && APIMiddleware.correlationID.Value != null && APIMiddleware.databaseTraceDataTable.Value != null)
3131
{
3232
try
3333
{

src/API.Library/Interfaces/ICacheConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public interface ICacheConfig
55
string API_MEMCACHED_SALSA { get; }
66
uint API_MEMCACHED_MAX_VALIDITY { get; }
77
uint API_MEMCACHED_MAX_SIZE { get; }
8-
bool API_MEMCACHED_ENABLED { get; }
8+
bool API_MEMCACHED_ENABLED { get; set; }
99
bool API_CACHE_TRACE_ENABLED { get; }
1010

1111
}

src/API.Library/Middleware/API.Middleware.cs

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,10 @@ public async Task InvokeAsync(HttpContext context)
2828
//set asynclocal value
2929
correlationID.Value = activity.RootId.ToString();
3030

31-
if (!ApiServicesHelper.ApplicationLoaded)
32-
{
33-
Log.Instance.Fatal("No API configuration loaded.");
34-
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
35-
await context.Response.WriteAsync("");
36-
}
37-
else
38-
{
39-
Trace trace = new Trace();
40-
41-
if (ApiServicesHelper.ApiConfiguration.API_TRACE_ENABLED)
31+
32+
Trace trace = new Trace();
33+
34+
if (ApiServicesHelper.ApiConfiguration.API_TRACE_ENABLED)
4235
{
4336
trace.TrcStartTime = DateTime.Now;
4437
trace.TrcCorrelationID = activity.RootId;
@@ -52,30 +45,27 @@ public async Task InvokeAsync(HttpContext context)
5245

5346
}
5447

55-
// Start the activity Stopwatch
56-
activity.Start();
48+
// Start the activity Stopwatch
49+
activity.Start();
5750

5851

59-
Log.Instance.Info("API Interface Opened");
52+
Log.Instance.Info("API Interface Opened");
6053

61-
// Thread a PerfomanceCollector
54+
// Thread a PerfomanceCollector
6255

63-
/// <summary>
56+
/// <summary>
6457
/// Flag to indicate if Performance is enabled
6558
/// </summary>
66-
bool API_PERFORMANCE_ENABLED = ApiServicesHelper.APIPerformanceSettings.API_PERFORMANCE_ENABLED;
59+
bool API_PERFORMANCE_ENABLED = ApiServicesHelper.APIPerformanceSettings.API_PERFORMANCE_ENABLED;
6760

68-
Log.Instance.Info("Performance Enabled: " + API_PERFORMANCE_ENABLED);
61+
Log.Instance.Info("Performance Enabled: " + API_PERFORMANCE_ENABLED);
6962

70-
//makes sure always disposed
71-
using var performanceCollector = new PerformanceCollector();
72-
using var cancelPerformance = new CancellationTokenSource();
73-
using var apiCancellationToken = new CancellationTokenSource();
63+
//makes sure always disposed
64+
using var performanceCollector = new PerformanceCollector();
65+
using var cancelPerformance = new CancellationTokenSource();
66+
using var apiCancellationToken = new CancellationTokenSource();
7467

75-
try
76-
{
77-
78-
68+
try{
7969
Thread performanceThread = new Thread(() =>
8070
{
8171
try
@@ -266,20 +256,13 @@ public async Task InvokeAsync(HttpContext context)
266256
await returnResponseAsync(context, "", apiCancellationToken, HttpStatusCode.BadRequest);
267257
break;
268258
}
269-
}
270-
catch (OperationCanceledException e)
271-
{
272-
//don't need to do anything here as operation has been cancelled
273-
}
274-
catch (Exception ex)
275-
{
276-
Log.Instance.Fatal(ex);
277-
await returnResponseAsync(context, "", apiCancellationToken, HttpStatusCode.InternalServerError);
278-
}
279-
finally
280-
{
281-
try
282-
{
259+
}catch (OperationCanceledException e){
260+
//don't need to do anything here as operation has been cancelled
261+
}catch (Exception ex){
262+
Log.Instance.Fatal(ex);
263+
await returnResponseAsync(context, "", apiCancellationToken, HttpStatusCode.InternalServerError);
264+
}finally{
265+
try{
283266

284267
if (context.Response.StatusCode != (int)HttpStatusCode.NotModified)
285268
{
@@ -339,15 +322,12 @@ public async Task InvokeAsync(HttpContext context)
339322
databaseTraceDataTable.Value.Dispose();
340323
databaseTraceDataTable.Value = null;
341324
}
342-
}
343-
catch (Exception ex)
344-
{
345-
Log.Instance.Error("Something went wrong after response sent");
346-
Log.Instance.Error(ex);
347-
}
348-
325+
}catch (Exception ex){
326+
Log.Instance.Error("Something went wrong after response sent");
327+
Log.Instance.Error(ex);
349328
}
350-
}
329+
330+
}
351331
}
352332
}
353333
}

src/API.Library/Middleware/ApiServicesHelper.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ namespace API
77
{
88
public class ApiServicesHelper
99
{
10-
/// <summary>
11-
/// indicator to indicate if the api config has loaded successfully
12-
/// </summary>
13-
public static bool ApplicationLoaded { get; set; } = true;
1410
public static IConfiguration Configuration { get; set; }
1511
public static ServiceProvider ServiceProvider { get; set; }
1612

0 commit comments

Comments
 (0)