Skip to content

Commit 686dc44

Browse files
committed
7.0.10 release
- [ENHANCEMENT] refactored configuration insert to deployupdate table - [ENHANCEMENT] removed scoped ADO as never used - [ENHANCEMENT]refactored to use a using statement > using var performanceCollector = new PerformanceCollector(); > using var cancelPerformance = new CancellationTokenSource(); > using var apiCancellationToken = new CancellationTokenSource();
1 parent ce546e6 commit 686dc44

File tree

10 files changed

+76
-73
lines changed

10 files changed

+76
-73
lines changed

rls/packages/API.Library.7.0.10.nupkg

67.3 KB
Binary file not shown.

rls/packages/API.Library.7.0.9.nupkg

67.1 KB
Binary file not shown.

src/API.Library/API.Library.csproj

Lines changed: 7 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.8</Version>
15+
<Version>7.0.10</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-
- [ENHANCEMENT] added referrer and content length to api trace
20+
- [ENHANCEMENT] refactored configuration insert to deployupdate table
21+
- [ENHANCEMENT] removed scoped ADO as never used
22+
- [ENHANCEMENT]refactored to use a using statement
23+
> using var performanceCollector = new PerformanceCollector();
24+
> using var cancelPerformance = new CancellationTokenSource();
25+
> using var apiCancellationToken = new CancellationTokenSource();
2126
</PackageReleaseNotes>
2227
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
2328
<RestoreLockedMode>true</RestoreLockedMode>

src/API.Library/Config/ApiConfiguration.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,31 @@ private IDictionary<string, string> ReadDBAppSettings(IADO ado)
173173
{
174174
new ADO_inputParams() { name = "@app_settings_version", value = inMemoryVersion ?? (object)System.DBNull.Value },
175175
};
176+
177+
var dictionary = new Dictionary<string, string>();
178+
179+
176180
try
177181
{
178182
// No transaction required
179183
output = ado.ExecuteReaderProcedure("Api_Settings_Read", paramList);
180184

185+
foreach (var c in output.data[0])
186+
{
187+
if (dictionary.ContainsKey(c.API_KEY))
188+
{
189+
Log.Instance.Fatal("Duplicate API Config Key detected : " + c.API_KEY);
190+
}
191+
else
192+
{
193+
dictionary.Add(c.API_KEY, c.API_VALUE);
194+
}
195+
}
196+
197+
var tVersion = output.data[1];
198+
inMemoryVersion = tVersion[0].max_version_number;
199+
200+
CommonConfig.deployUpdate(inMemoryVersion, "API");
181201
}
182202
catch (Exception ex)
183203
{
@@ -186,26 +206,6 @@ private IDictionary<string, string> ReadDBAppSettings(IADO ado)
186206
//version number not found in database
187207
throw ex;
188208
}
189-
190-
var dictionary = new Dictionary<string, string>();
191-
192-
foreach (var c in output.data[0])
193-
{
194-
if (dictionary.ContainsKey(c.API_KEY))
195-
{
196-
Log.Instance.Fatal("Duplicate API Config Key detected : " + c.API_KEY);
197-
}
198-
else
199-
{
200-
dictionary.Add(c.API_KEY, c.API_VALUE);
201-
}
202-
}
203-
204-
var tVersion = output.data[1];
205-
inMemoryVersion = tVersion[0].max_version_number;
206-
207-
CommonConfig.deployUpdate(ado, inMemoryVersion, "API");
208-
209209
return dictionary;
210210
}
211211
}

src/API.Library/Config/AppConfiguration.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,39 +133,41 @@ private IDictionary<string, string> ReadDBAppSettings(IADO ado)
133133
{
134134
new ADO_inputParams() { name = "@app_settings_version", value = inMemoryVersion ?? (object)System.DBNull.Value },
135135
};
136+
137+
var dictionary = new Dictionary<string, string>();
138+
139+
136140
try
137141
{
138142
// No transaction required
139143
output = ado.ExecuteReaderProcedure("App_Settings_Read", paramList);
144+
145+
foreach (var c in output.data[0])
146+
{
147+
if (dictionary.ContainsKey(c.APP_KEY))
148+
{
149+
Log.Instance.Fatal("Duplicate APP Config Key detected : " + c.APP_KEY);
150+
}
151+
else
152+
{
153+
dictionary.Add(c.APP_KEY, c.APP_VALUE);
154+
}
155+
}
156+
157+
var tVersion = output.data[1];
158+
inMemoryVersion = tVersion[0].max_version_number;
159+
160+
CommonConfig.deployUpdate( inMemoryVersion, "APP");
140161

141162
}
142163
catch (Exception ex)
143164
{
144-
ado.CloseConnection();
165+
ado.Dispose();
145166
Log.Instance.Fatal(ex.ToString());
146167
//version number not found in database
147168
throw ex;
148169
}
149170

150-
var dictionary = new Dictionary<string, string>();
151-
152-
153-
foreach (var c in output.data[0])
154-
{
155-
if (dictionary.ContainsKey(c.APP_KEY))
156-
{
157-
Log.Instance.Fatal("Duplicate APP Config Key detected : " + c.APP_KEY);
158-
}
159-
else
160-
{
161-
dictionary.Add(c.APP_KEY, c.APP_VALUE);
162-
}
163-
}
164-
165-
var tVersion = output.data[1];
166-
inMemoryVersion = tVersion[0].max_version_number;
167-
168-
CommonConfig.deployUpdate(ado, inMemoryVersion, "APP");
169171

170172
return dictionary;
171173
}

src/API.Library/Config/CommonConfig.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,35 +104,34 @@ public static IDictionary<string, string> ReadJSONSettings(decimal? inMemoryVers
104104
}
105105

106106

107-
public static void deployUpdate(IADO ado, decimal? inMemoryVersion, string configType)
107+
public static void deployUpdate( decimal? inMemoryVersion, string configType)
108108
{
109+
110+
109111
var inputParamList = new List<ADO_inputParams>()
110-
{
111-
new ADO_inputParams() {name= "@app_settings_version", value = inMemoryVersion},
112-
new ADO_inputParams() {name= "@config_setting_type", value = configType}
113-
};
112+
{
113+
new ADO_inputParams() {name= "@app_settings_version", value = inMemoryVersion},
114+
new ADO_inputParams() {name= "@config_setting_type", value = configType}
115+
};
114116

115117
var retParam = new ADO_returnParam();
116118
retParam.name = "return";
117119
retParam.value = 0;
118-
120+
IADO ado = new ADO();
119121
try
120122
{
121-
ado.StartTransaction();
122123
ado.ExecuteNonQueryProcedure("App_Setting_Deploy_Update", inputParamList, ref retParam);
123-
ado.CommitTransaction();
124124
}
125125
catch (Exception ex)
126126
{
127-
ado.RollbackTransaction();
128127
//log the audit insert failed but no need to raise error.
129128
Log.Instance.Fatal("failed to insert into App_Setting_Deploy_Update : version - " + inMemoryVersion + " , config_setting_type - "+ configType + "");
130129
Log.Instance.Fatal(ex.ToString());
131130
}
132131
finally
133132
{
134133
//now close the connection
135-
ado.CloseConnection(true);
134+
ado.Dispose();
136135
}
137136
}
138137

src/API.Library/Entities/Tracing/Trace/Trace_ADO.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace API
1+
using Microsoft.IdentityModel.Tokens;
2+
3+
namespace API
24
{
35
/// <summary>
46
/// ADO classes for Trace
@@ -29,10 +31,12 @@ internal static void Create(Trace trace)
2931
new ADO_inputParams() {name= "@TrcStatusCode",value=trace.TrcStatusCode},
3032
new ADO_inputParams() {name= "@TrcMachineName",value=trace.TrcMachineName},
3133
new ADO_inputParams() {name= "@TrcRequestVerb", value = trace.TrcRequestVerb},
32-
new ADO_inputParams() {name= "@TrcCorrelationID", value = trace.TrcCorrelationID},
33-
new ADO_inputParams() {name= "@TrcContentLength", value = trace.TrcContentLength}
34+
new ADO_inputParams() {name= "@TrcCorrelationID", value = trace.TrcCorrelationID}
3435
};
3536

37+
if (trace.TrcContentLength != null)
38+
inputParamList.Add(new ADO_inputParams() { name = "@TrcContentLength", value = trace.TrcContentLength });
39+
3640
if (!string.IsNullOrEmpty(trace.TrcUseragent))
3741
inputParamList.Add(new ADO_inputParams() { name = "@TrcUseragent", value = trace.TrcUseragent });
3842

src/API.Library/Entities/Utility.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using Microsoft.AspNetCore.Http;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
32
using System.Diagnostics;
4-
using System.Globalization;
53
using System.IO.Compression;
64
using System.Net;
7-
using System.Net.Sockets;
85
using System.Security.Cryptography;
96
using System.Text;
10-
using System.Text.RegularExpressions;
117

128
namespace API
139
{

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Http;
2+
using Microsoft.Extensions.DependencyInjection;
23
using System.Data;
34
using System.Diagnostics;
45
using System.Net;
@@ -7,17 +8,16 @@ namespace API
78
{
89
public class APIMiddleware : Common
910
{
10-
1111
private readonly RequestDelegate _next;
1212
public static AsyncLocal<DataTable> cacheTraceDataTable = new AsyncLocal<DataTable>();
1313
public static AsyncLocal<DataTable> databaseTraceDataTable = new AsyncLocal<DataTable>();
1414
public static AsyncLocal<string> correlationID = new AsyncLocal<string>();
1515

16-
public APIMiddleware(RequestDelegate next) : base()
16+
public APIMiddleware(RequestDelegate next) : base()
1717
{
1818
_next = next;
19-
}
20-
19+
}
20+
2121
public async Task InvokeAsync(HttpContext context)
2222
{
2323
// Initiate the activity
@@ -67,14 +67,10 @@ public async Task InvokeAsync(HttpContext context)
6767

6868
Log.Instance.Info("Performance Enabled: " + API_PERFORMANCE_ENABLED);
6969

70-
71-
PerformanceCollector performanceCollector = new PerformanceCollector();
72-
73-
var cancelPerformance = new CancellationTokenSource();
74-
75-
76-
77-
CancellationTokenSource apiCancellationToken = new CancellationTokenSource();
70+
//makes sure always disposed
71+
using var performanceCollector = new PerformanceCollector();
72+
using var cancelPerformance = new CancellationTokenSource();
73+
using var apiCancellationToken = new CancellationTokenSource();
7874

7975
try
8076
{

src/API.Library/Middleware/ServiceConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static IServiceCollection AddApiLibrary(this IServiceCollection service,
5151
service.AddSingleton<IAPIPerformanceConfiguration, APIPerformanceConfiguration>();
5252
service.AddSingleton<IDatabaseTracingConfiguration, DatabaseTracingConfiguration>();
5353

54-
service.AddScoped<IADO, ADO>();
54+
// service.AddScoped<IADO, ADO>();
5555

5656
var sp = service.BuildServiceProvider();
5757
var ADOSettings = sp.GetService<IOptions<ADOSettings>>();
@@ -93,6 +93,7 @@ public static IServiceCollection AddApiLibrary(this IServiceCollection service,
9393
//load APP config here as if can't load application wont work
9494
ApiServicesHelper.AppConfiguration = sp.GetRequiredService<IAppConfiguration>();
9595
}
96+
9697
bool isStateless = Convert.ToBoolean(ApiServicesHelper.ApiConfiguration.Settings["API_STATELESS"]);
9798
if (!isStateless)
9899
{

0 commit comments

Comments
 (0)