Skip to content

Commit fea05f7

Browse files
v3 beta
1 parent d92e00b commit fea05f7

File tree

1,056 files changed

+67238
-2541
lines changed

Some content is hidden

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

1,056 files changed

+67238
-2541
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ src/Server/Coderr.Server.Web.Tests/applicationhost.config
3838
/src/Server/Coderr.Server.Web/wwwroot/dist/**
3939
/src/Server/Coderr.Server.Web/npm-shrinkwrap.json
4040
/src/Server/node_modules/**
41+
/src/Server/Coderr.Server.WebSite/ClientApp/.angular/

src/Server/Coderr.Server.Abstractions/Boot/ConfigurationContext.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ namespace Coderr.Server.Abstractions.Boot
88
{
99
public abstract class ConfigurationContext
1010
{
11+
protected ConfigurationContext(IServiceCollection services, Func<IServiceProvider> serviceProvider)
12+
{
13+
Services = services;
14+
ServiceProvider = serviceProvider;
15+
}
1116

1217
public Func<ClaimsPrincipal, IDbConnection> ConnectionFactory { get; set; }
13-
public IServiceCollection Services { get; set; }
14-
public Func<IServiceProvider> ServiceProvider { get; set; }
18+
public IServiceCollection Services { get; private set; }
19+
public Func<IServiceProvider> ServiceProvider { get; private set; }
1520
public IConfiguration Configuration { get; set; }
1621

1722
public abstract void RegisterMessageTypes(Assembly assembly);
23+
24+
public abstract ConfigurationContext Clone(IServiceCollection serviceCollection);
1825
}
1926
}

src/Server/Coderr.Server.Abstractions/Boot/IConfiguration.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Coderr.Server.Abstractions.Boot
44
{
55
public interface IConfiguration
66
{
7+
string this[string name] { get; }
78
IConfigurationSection GetSection(string name);
89
string GetConnectionString(string name);
910
IEnumerable<IConfigurationSection> GetChildren();
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Linq;
34
using System.Reflection;
5+
using System.Security.Cryptography.X509Certificates;
46
using Microsoft.Extensions.DependencyInjection;
57

68
namespace Coderr.Server.Abstractions.Boot
79
{
810
public static class RegisterExtensions
911
{
12+
1013
public static void RegisterContainerServices(this IServiceCollection serviceCollection, Assembly assembly)
1114
{
12-
var containerServices = assembly.GetTypes();
15+
var gotWrongAttribute = (
16+
from type in assembly.GetTypes()
17+
let attributes = type.GetCustomAttributes()
18+
where attributes.Count(x => x.GetType().FullName == "Griffin.Container.ContainerService") > 0
19+
select type).ToList();
20+
if (gotWrongAttribute.Count > 0)
21+
{
22+
throw new InvalidOperationException(
23+
$"Types \'{string.Join(",", gotWrongAttribute)}\' was decorated with the wrong attribute");
24+
}
25+
26+
var containerServices = assembly.GetTypes()
27+
.Where(x => x.GetCustomAttribute<ContainerServiceAttribute>() != null);
28+
1329
foreach (var containerService in containerServices)
1430
{
15-
var gotWrongAttribute = containerService
16-
.GetCustomAttributes()
17-
.Count(x => x.GetType().FullName == "Griffin.Container.ContainerService") == 1;
18-
if (gotWrongAttribute)
19-
{
20-
throw new InvalidOperationException(
21-
$"Type \'{containerService}\' was decorated with the wrong attribute");
22-
;
23-
}
31+
Debug.WriteLine(Assembly.GetCallingAssembly().GetName().Name + " registers " + containerService.FullName);
2432

2533
var attr = containerService.GetCustomAttribute<ContainerServiceAttribute>();
26-
if (attr == null)
27-
continue;
28-
2934
var interfaces = containerService.GetInterfaces();
35+
var lifetime = ConvertLifetime(attr);
3036

3137
// Hack so that the same instance is resolved for each interface
38+
bool isRegisteredAsSelf = false;
3239
if (interfaces.Length > 1 || attr.RegisterAsSelf)
33-
serviceCollection.RegisterService(attr, containerService, containerService);
40+
{
41+
serviceCollection.Add(new ServiceDescriptor(containerService, containerService, lifetime));
42+
isRegisteredAsSelf=true;
43+
}
44+
3445

3546
foreach (var @interface in interfaces)
3647
{
37-
serviceCollection.RegisterService(attr, @interface, containerService);
48+
var sd = isRegisteredAsSelf
49+
? new ServiceDescriptor(@interface, x => x.GetService(containerService), lifetime) // else we don't get the same instance in the scope.
50+
: new ServiceDescriptor(@interface, containerService, lifetime);
51+
serviceCollection.Add(sd);
3852
}
3953
}
4054
}
@@ -47,27 +61,33 @@ public static void RegisterMessageHandlers(this IServiceCollection serviceCollec
4761
.ToList();
4862
foreach (var type in types)
4963
{
64+
Debug.WriteLine(Assembly.GetCallingAssembly().GetName().Name + " registers " + type.FullName);
65+
5066
serviceCollection.AddScoped(type, type);
5167

5268
var ifs = type.GetInterfaces()
5369
.Where(x => x.Name.Contains("IMessageHandler") || x.Name.Contains("IQueryHandler"))
5470
.ToList();
5571
foreach (var @if in ifs)
5672
{
57-
serviceCollection.AddScoped(@if, type);
73+
serviceCollection.AddScoped(@if, x => x.GetService(type));
5874
}
5975
}
6076
}
6177

62-
private static void RegisterService(this IServiceCollection serviceCollection, ContainerServiceAttribute attr,
63-
Type service, Type implementation)
78+
private static ServiceLifetime ConvertLifetime(ContainerServiceAttribute attr)
6479
{
6580
if (attr.IsSingleInstance)
66-
serviceCollection.AddSingleton(service, implementation);
67-
else if (attr.IsTransient)
68-
serviceCollection.AddTransient(service, implementation);
69-
else
70-
serviceCollection.AddScoped(service, implementation);
81+
{
82+
return ServiceLifetime.Singleton;
83+
}
84+
85+
if (attr.IsTransient)
86+
{
87+
return ServiceLifetime.Transient;
88+
}
89+
90+
return ServiceLifetime.Scoped;
7191
}
7292
}
7393
}

src/Server/Coderr.Server.Abstractions/Coderr.Server.Abstractions.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<Configurations>Debug;Release;Premise</Configurations>
56
</PropertyGroup>
67

78
<ItemGroup>
89
<ProjectReference Include="..\Coderr.Server.Api\Coderr.Server.Api.csproj" />
910
</ItemGroup>
1011

1112
<ItemGroup>
12-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
13+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.22" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<Folder Include="Tags\" />
1318
</ItemGroup>
1419

1520

Original file line numberDiff line numberDiff line change
@@ -1,27 +1,54 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
2+
using System.Diagnostics;
43

54
namespace Coderr.Server.Abstractions
65
{
76
/// <summary>
8-
/// Wraps either the configuration file or the Docker environment variables.
7+
/// Wraps either the configuration file or the Docker environment variables.
98
/// </summary>
109
public class HostConfig
1110
{
1211
public static HostConfig Instance = new HostConfig();
1312

13+
private static bool _isTriggered;
14+
1415
public bool IsRunningInDocker { get; set; }
1516
public string ConnectionString { get; set; }
16-
public bool IsConfigured { get; set; }
17-
public string ConfigurationPassword { get; set; }
17+
18+
public bool IsDemo { get; set; } = Debugger.IsAttached;
19+
public bool IsConfigured { get; private set; }
20+
21+
/// <summary>
22+
/// Just to make it harder to take over an ongoing installation of Coderr on a public ip. Changed now and then.
23+
/// </summary>
24+
public string InstallationPassword { get; set; }
25+
26+
public event EventHandler Configured;
1827

1928
public override string ToString()
2029
{
2130
var tmp = IsRunningInDocker ? "[DOCKER] " : "[NATIVE] ";
22-
return IsConfigured
23-
? $"{tmp} running with {ConnectionString}"
24-
: $"{tmp} Will configure with password {ConfigurationPassword} and using {ConnectionString}";
31+
return $"{tmp} running with {ConnectionString}";
32+
}
33+
34+
/// <summary>
35+
/// Mark configuration as complete.
36+
/// </summary>
37+
public void MarkAsConfigured()
38+
{
39+
IsConfigured = true;
40+
}
41+
42+
/// <summary>
43+
/// Separate method since it must be run after everyone have subscribed on the event.
44+
/// </summary>
45+
public void TriggeredConfigured()
46+
{
47+
if (_isTriggered) return;
48+
49+
_isTriggered = true;
50+
IsConfigured = true;
51+
Configured?.Invoke(this, EventArgs.Empty);
2552
}
2653
}
27-
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System.Data;
2+
using System.Security.Claims;
23

34
namespace Coderr.Server.Abstractions
45
{
56
public interface IConnectionFactory
67
{
7-
IDbConnection OpenConnection();
8-
bool IsConfigured { get; set; }
8+
IDbConnection OpenConnection(ClaimsPrincipal principal);
9+
910
}
1011
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Data.Common;
2+
3+
namespace Coderr.Server.Abstractions
4+
{
5+
public interface IGotTransaction
6+
{
7+
DbTransaction Transaction { get; }
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using Coderr.Server.Abstractions.Boot;
3+
4+
namespace Coderr.Server.Abstractions
5+
{
6+
public class QueueConfig
7+
{
8+
public string ReportQueue { get; set; }
9+
public string InboundPartitions { get; set; }
10+
public string ReportEventQueue { get; set; }
11+
public string AppQueue { get; set; }
12+
13+
public void Configure(IConfiguration config)
14+
{
15+
if (config == null)
16+
{
17+
throw new ArgumentNullException(nameof(config));
18+
}
19+
20+
if (ServerConfig.Instance.IsLive)
21+
{
22+
ReportQueue = config.GetSection("MessageQueue")["ReportQueue"];
23+
ReportEventQueue = config.GetSection("MessageQueue")["ReportEventQueue"];
24+
AppQueue = config.GetSection("MessageQueue")["AppQueue"];
25+
InboundPartitions = config.GetSection("MessageQueue")["InboundPartitions"];
26+
}
27+
else
28+
{
29+
ReportQueue = "ErrorReports";
30+
ReportEventQueue = "ErrorReportEvents";
31+
AppQueue = "Messaging";
32+
InboundPartitions = "InboundPartitions";
33+
}
34+
}
35+
}
36+
}

src/Server/Coderr.Server.Abstractions/Reports/ReportConfig.cs

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public ReportConfig()
4949
/// </remarks>
5050
public int RetentionDays { get; set; }
5151

52+
/// <summary>
53+
/// Number of days to store incidents that have not received any new reports.
54+
/// </summary>
55+
public int RetentionDaysIncidents { get; set; }
56+
5257
string IConfigurationSection.SectionName => "ReportConfig";
5358

5459
IDictionary<string, string> IConfigurationSection.ToDictionary()
@@ -61,6 +66,8 @@ void IConfigurationSection.Load(IDictionary<string, string> settings)
6166
this.AssignProperties(settings);
6267
if (MaxReportJsonSize == 0)
6368
MaxReportJsonSize = 1000000;
69+
if (RetentionDaysIncidents == 0)
70+
RetentionDaysIncidents = 90;
6471
}
6572
}
6673
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
3+
namespace Coderr.Server.Abstractions
4+
{
5+
public class ServerConfig
6+
{
7+
public const string Premise = "Premise";
8+
public const string Live = "Live";
9+
10+
public static ServerConfig Instance = new ServerConfig();
11+
private ServerType _serverType;
12+
13+
public bool IsLive { get; private set; }
14+
15+
public bool UseSmtpHandler { get; set; }
16+
17+
public ServerType ServerType
18+
{
19+
get => _serverType;
20+
set
21+
{
22+
_serverType = value;
23+
IsLive = value == ServerType.Live;
24+
UseSmtpHandler = !IsLive;
25+
}
26+
}
27+
28+
public QueueConfig Queues { get; set; } = new QueueConfig();
29+
public bool IsCommercial { get; set; }
30+
31+
public bool IsModuleIgnored(Type type)
32+
{
33+
if (Instance.IsLive)
34+
{
35+
if (type.Assembly.GetName().Name.Contains($".{ServerConfig.Premise}"))
36+
return true;
37+
}
38+
else
39+
{
40+
if (type.Assembly.GetName().Name.Contains($".{ServerConfig.Live}"))
41+
return true;
42+
}
43+
44+
return false;
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Coderr.Server.Abstractions
4+
{
5+
[Flags]
6+
public enum ServerType
7+
{
8+
Community = 0,
9+
Premise = 1,
10+
PremisePlus = 3,
11+
Live = 4
12+
}
13+
}

0 commit comments

Comments
 (0)