Skip to content

Commit 1044211

Browse files
authored
Merge pull request #70 from mo-esmp/fix/coding-style
Fix/coding style
2 parents 6151fa7 + dc2a641 commit 1044211

File tree

13 files changed

+106
-140
lines changed

13 files changed

+106
-140
lines changed

samples/SampleWebApp/Startup.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Microsoft.AspNetCore.Authentication.JwtBearer;
21
using Microsoft.AspNetCore.Builder;
32
using Microsoft.AspNetCore.Hosting;
43
using Microsoft.AspNetCore.Identity;
@@ -107,27 +106,27 @@ private void AddAuthentication(IServiceCollection services)
107106
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
108107
.AddEntityFrameworkStores<ApplicationDbContext>();
109108

110-
services
111-
.AddAuthentication(options =>
112-
{
113-
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
114-
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
115-
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
116-
})
117-
.AddJwtBearer(options =>
118-
{
119-
options.TokenValidationParameters =
120-
new TokenValidationParameters
121-
{
122-
ValidateIssuer = false,
123-
ValidateAudience = true,
124-
ValidateLifetime = true,
125-
ValidateIssuerSigningKey = true,
126-
ValidIssuer = Configuration["Jwt:Issuer"],
127-
ValidAudience = Configuration["Jwt:Audience"],
128-
IssuerSigningKey = JwtKeyGenerator.Generate(Configuration["Jwt:SecretKey"])
129-
};
130-
});
109+
//services
110+
// .AddAuthentication(options =>
111+
// {
112+
// options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
113+
// options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
114+
// options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
115+
// })
116+
// .AddJwtBearer(options =>
117+
// {
118+
// options.TokenValidationParameters =
119+
// new TokenValidationParameters
120+
// {
121+
// ValidateIssuer = false,
122+
// ValidateAudience = true,
123+
// ValidateLifetime = true,
124+
// ValidateIssuerSigningKey = true,
125+
// ValidIssuer = Configuration["Jwt:Issuer"],
126+
// ValidAudience = Configuration["Jwt:Audience"],
127+
// IssuerSigningKey = JwtKeyGenerator.Generate(Configuration["Jwt:SecretKey"])
128+
// };
129+
// });
131130
}
132131
}
133132
}

samples/SampleWebApp/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737
]
3838
},
39-
39+
4040
"Serilog2": {
4141
"Using": [ "Serilog.Sinks.MSSqlServer" ],
4242
"MinimumLevel": "Debug",

src/Serilog.Ui.Core/AggregateDataProvider.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,22 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55

6-
namespace Serilog.Ui.Core.Services
6+
namespace Serilog.Ui.Core
77
{
88
/// <summary>
9-
/// Aggregates multiple <see cref="IDataProvider"/> into one instance.
9+
/// Aggregates multiple <see cref="IDataProvider"/> into one instance.
1010
/// </summary>
1111
public class AggregateDataProvider : IDataProvider
1212
{
13-
/// <summary>
14-
/// <inheritdoc cref="IDataProvider.Name"/>
15-
/// NOTE We assume only one Aggregate provider, so the name is static.
16-
/// </summary>
17-
public string Name => nameof(AggregateDataProvider);
18-
19-
private IDataProvider _dataProvider;
20-
21-
/// <summary>
22-
/// If there is only one data provider, this is it.
23-
/// If there are multiple, this is the current data provider.
24-
/// </summary>
25-
public IDataProvider DataProvider => _dataProvider;
26-
13+
private IDataProvider _selectedDataProvider;
2714
private readonly Dictionary<string, IDataProvider> _dataProviders = new Dictionary<string, IDataProvider>();
28-
15+
2916
public AggregateDataProvider(IEnumerable<IDataProvider> dataProviders)
3017
{
31-
if (dataProviders == null) throw new ArgumentNullException(nameof(dataProviders));
18+
if (dataProviders == null)
19+
throw new ArgumentNullException(nameof(dataProviders));
3220

33-
foreach (var grouped in dataProviders
34-
.GroupBy(c => c.Name, e => e, (k, e) => e.ToList()))
21+
foreach (var grouped in dataProviders.GroupBy(dp => dp.Name, p => p, (k, e) => e.ToList()))
3522
{
3623
var name = grouped[0].Name;
3724

@@ -41,8 +28,9 @@ public AggregateDataProvider(IEnumerable<IDataProvider> dataProviders)
4128
}
4229
else
4330
{
44-
// When providers with the same name are registered, we ensure uniqueness by generating a key
45-
// I.e. ["MSSQL.dbo.logs", "MSSQL.dbo.logs"] => ["MSSQL.dbo.logs[0]", "MSSQL.dbo.logs[1]"]
31+
// When providers with the same name are registered, we ensure uniqueness by
32+
// generating a key I.e. ["MSSQL.dbo.logs", "MSSQL.dbo.logs"] =>
33+
// ["MSSQL.dbo.logs[0]", "MSSQL.dbo.logs[1]"]
4634
for (var i = 0; i < grouped.Count; i++)
4735
{
4836
var dataProvider = grouped[i];
@@ -51,22 +39,34 @@ public AggregateDataProvider(IEnumerable<IDataProvider> dataProviders)
5139
}
5240
}
5341

54-
_dataProvider = _dataProviders.First(c => true).Value;
42+
_selectedDataProvider = _dataProviders.First(c => true).Value;
5543
}
5644

57-
public void SwitchToProvider(string key)
58-
=> _dataProvider = _dataProviders[key];
45+
/// <summary>
46+
/// <inheritdoc cref="IDataProvider.Name"/> NOTE We assume only one Aggregate provider, so
47+
/// the name is static.
48+
/// </summary>
49+
public string Name => nameof(AggregateDataProvider);
5950

60-
public IEnumerable<string> Keys => _dataProviders.Keys;
51+
/// <summary>
52+
/// If there is only one data provider, this is it. If there are multiple, this is the
53+
/// current data provider.
54+
/// </summary>
55+
public IDataProvider SelectedDataProvider => _selectedDataProvider;
6156

62-
#region Delegating members of IDataProvider
57+
public void SwitchToProvider(string key) => _selectedDataProvider = _dataProviders[key];
6358

64-
public async Task<(IEnumerable<LogModel>, int)> FetchDataAsync(int page, int count, string level = null, string searchCriteria = null, DateTime? startDate = null, DateTime? endDate = null)
59+
public IEnumerable<string> Keys => _dataProviders.Keys;
60+
61+
public async Task<(IEnumerable<LogModel>, int)> FetchDataAsync(
62+
int page,
63+
int count,
64+
string level = null,
65+
string searchCriteria = null,
66+
DateTime? startDate = null,
67+
DateTime? endDate = null)
6568
{
66-
return await DataProvider.FetchDataAsync(page, count, level, searchCriteria, startDate, endDate);
69+
return await SelectedDataProvider.FetchDataAsync(page, count, level, searchCriteria, startDate, endDate);
6770
}
68-
69-
#endregion
70-
7171
}
7272
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
namespace Serilog.Ui.Core.Extensions
1+
namespace Serilog.Ui.Core
22
{
33
public static class RelationalDbOptionsExtensions
44
{
55
public static string ToDataProviderName(this RelationalDbOptions options, string providerName)
66
=> string.Join(".", providerName, options.Schema, options.TableName);
77
}
8-
}
8+
}

src/Serilog.Ui.ElasticSearchProvider/ElasticSearchDbDataProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ namespace Serilog.Ui.ElasticSearchProvider
1010
{
1111
public class ElasticSearchDbDataProvider : IDataProvider
1212
{
13-
public string Name => string.Join(".", "ES", _options.IndexName);
14-
1513
private readonly IElasticClient _client;
1614
private readonly ElasticSearchDbOptions _options;
17-
15+
1816
public ElasticSearchDbDataProvider(IElasticClient client, ElasticSearchDbOptions options)
1917
{
2018
_client = client ?? throw new ArgumentNullException(nameof(client));
@@ -32,6 +30,8 @@ public ElasticSearchDbDataProvider(IElasticClient client, ElasticSearchDbOptions
3230
return GetLogsAsync(page - 1, count, level, searchCriteria, startDate, endDate);
3331
}
3432

33+
public string Name => string.Join(".", "ES", _options.IndexName);
34+
3535
private async Task<(IEnumerable<LogModel>, int)> GetLogsAsync(
3636
int page,
3737
int count,

src/Serilog.Ui.MongoDbProvider/Extensions/SerilogUiOptionBuilderExtensions.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
namespace Serilog.Ui.MongoDbProvider
99
{
1010
/// <summary>
11-
/// MongoDB data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
11+
/// MongoDB data provider specific extension methods for <see cref="SerilogUiOptionsBuilder"/>.
1212
/// </summary>
1313
public static class SerilogUiOptionBuilderExtensions
1414
{
1515
/// <summary>
16-
/// Configures the SerilogUi to connect to a MongoDB database.
16+
/// Configures the SerilogUi to connect to a MongoDB database.
1717
/// </summary>
1818
/// <param name="optionsBuilder">The options builder.</param>
1919
/// <param name="connectionString">The connection string.</param>
@@ -34,7 +34,8 @@ string collectionName
3434

3535
var databaseName = MongoUrl.Create(connectionString).DatabaseName;
3636

37-
if (string.IsNullOrWhiteSpace(databaseName)) throw new ArgumentException(nameof(MongoUrl.DatabaseName));
37+
if (string.IsNullOrWhiteSpace(databaseName))
38+
throw new ArgumentException(nameof(MongoUrl.DatabaseName));
3839

3940
var mongoProvider = new MongoDbOptions
4041
{
@@ -45,8 +46,8 @@ string collectionName
4546

4647
var builder = ((ISerilogUiOptionsBuilder)optionsBuilder);
4748

48-
// TODO Fixup MongoDb to allow multiple registrations.
49-
// Think about multiple ES clients (singletons) used in data providers (scoped)
49+
// TODO Fixup MongoDb to allow multiple registrations. Think about multiple ES clients
50+
// (singletons) used in data providers (scoped)
5051
if (builder.Services.Any(c => c.ImplementationType == typeof(MongoDbDataProvider)))
5152
throw new NotSupportedException($"Adding multiple registrations of '{typeof(MongoDbDataProvider).FullName}' is not (yet) supported.");
5253

@@ -56,7 +57,7 @@ string collectionName
5657
}
5758

5859
/// <summary>
59-
/// Configures the SerilogUi to connect to a MongoDB database.
60+
/// Configures the SerilogUi to connect to a MongoDB database.
6061
/// </summary>
6162
/// <param name="optionsBuilder">The options builder.</param>
6263
/// <param name="connectionString">The connection string.</param>
@@ -90,8 +91,8 @@ string collectionName
9091

9192
var builder = ((ISerilogUiOptionsBuilder)optionsBuilder);
9293

93-
// TODO Fixup MongoDb to allow multiple registrations.
94-
// Think about multiple ES clients (singletons) used in data providers (scoped)
94+
// TODO Fixup MongoDb to allow multiple registrations. Think about multiple ES clients
95+
// (singletons) used in data providers (scoped)
9596
if (builder.Services.Any(c => c.ImplementationType == typeof(MongoDbDataProvider)))
9697
throw new NotSupportedException($"Adding multiple registrations of '{typeof(MongoDbDataProvider).FullName}' is not (yet) supported.");
9798

src/Serilog.Ui.MongoDbProvider/MongoDbDataProvider.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ namespace Serilog.Ui.MongoDbProvider
99
{
1010
public class MongoDbDataProvider : IDataProvider
1111
{
12-
13-
public string Name => string.Join(".", "MongoDb", _options.DatabaseName, _options.CollectionName);
14-
1512
private readonly IMongoCollection<MongoDbLogModel> _collection;
1613
private readonly MongoDbOptions _options;
1714

@@ -41,6 +38,8 @@ public MongoDbDataProvider(IMongoClient client, MongoDbOptions options)
4138
return (logsTask, logCountTask);
4239
}
4340

41+
public string Name => string.Join(".", "MongoDb", _options.DatabaseName, _options.CollectionName);
42+
4443
private async Task<IEnumerable<LogModel>> GetLogsAsync(
4544
int page,
4645
int count,
@@ -80,7 +79,11 @@ await _collection.Indexes.CreateOneAsync(
8079
}
8180
}
8281

83-
private async Task<int> CountLogsAsync(string level, string searchCriteria, DateTime? startDate, DateTime? endDate)
82+
private async Task<int> CountLogsAsync(
83+
string level,
84+
string searchCriteria,
85+
DateTime? startDate,
86+
DateTime? endDate)
8487
{
8588
var builder = Builders<MongoDbLogModel>.Filter.Empty;
8689
GenerateWhereClause(ref builder, level, searchCriteria, startDate, endDate);

src/Serilog.Ui.MsSqlServerProvider/SqlServerDataProvider.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
using System.Data;
77
using System.Text;
88
using System.Threading.Tasks;
9-
using Serilog.Ui.Core.Extensions;
109

1110
namespace Serilog.Ui.MsSqlServerProvider
1211
{
1312
public class SqlServerDataProvider : IDataProvider
1413
{
15-
public string Name => _options.ToDataProviderName("MsSQL");
16-
1714
private readonly RelationalDbOptions _options;
18-
15+
1916
public SqlServerDataProvider(RelationalDbOptions options)
2017
{
2118
_options = options ?? throw new ArgumentNullException(nameof(options));
@@ -38,6 +35,8 @@ public SqlServerDataProvider(RelationalDbOptions options)
3835
return (await logsTask, await logCountTask);
3936
}
4037

38+
public string Name => _options.ToDataProviderName("MsSQL");
39+
4140
private async Task<IEnumerable<LogModel>> GetLogsAsync(
4241
int page,
4342
int count,

src/Serilog.Ui.MySqlProvider/MySqlDataProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
using System.Collections.Generic;
66
using System.Text;
77
using System.Threading.Tasks;
8-
using Serilog.Ui.Core.Extensions;
98

109
namespace Serilog.Ui.MySqlProvider
1110
{
1211
public class MySqlDataProvider : IDataProvider
1312
{
14-
public string Name => _options.ToDataProviderName("MySQL");
15-
1613
private readonly RelationalDbOptions _options;
1714

1815
public MySqlDataProvider(RelationalDbOptions options)
@@ -37,6 +34,8 @@ public MySqlDataProvider(RelationalDbOptions options)
3734
return (await logsTask, await logCountTask);
3835
}
3936

37+
public string Name => _options.ToDataProviderName("MySQL");
38+
4039
private async Task<IEnumerable<LogModel>> GetLogsAsync(
4140
int page,
4241
int count,

0 commit comments

Comments
 (0)