Skip to content

Commit e78495e

Browse files
committed
Corrected config management changes.
1 parent 0a922bf commit e78495e

File tree

16 files changed

+71
-39
lines changed

16 files changed

+71
-39
lines changed

src/Server/Coderr.Server.App/Configuration/CoderrConfigSection.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace codeRR.Server.App.Configuration
99
/// </summary>
1010
public sealed class codeRRConfigSection : IConfigurationSection
1111
{
12+
public codeRRConfigSection()
13+
{
14+
ActivateTracking = true;
15+
}
16+
1217
/// <summary>
1318
/// Allow us to track exceptions in OTE.
1419
/// </summary>

src/Server/Coderr.Server.App/Core/Accounts/CommandHandlers/RegisterAccountHandler.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,19 @@ private async Task SendAccountInfo(IMessageContext context, string userName)
9090
var account = await _repository.GetByUserNameAsync(userName);
9191

9292
var config = _configStore.Load<BaseConfiguration>();
93+
var email = config.SupportEmail;
9394
//TODO: HTML email
9495
var msg = new EmailMessage
9596
{
96-
TextBody = @"Hello!
97+
TextBody = $@"Hello!
9798
98-
Someone (you?) tried to create an account with the same information as your account.
99+
Someone (you?) tried to create an account with the same login as your account.
99100
100101
If it was you, you can request a new password from the login page. Otherwise,
101-
contact us so that we can investigate: help@coderrapp.com
102+
contact us so that we can investigate: {email}
102103
103-
Cheerio,
104-
codeRR Team",
104+
Regards,
105+
Support team",
105106
Subject = "codeRR registration"
106107
};
107108
msg.Recipients = new[] { new EmailAddress(account.Email) };

src/Server/Coderr.Server.App/Core/Reports/Config/ReportConfig.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ namespace codeRR.Server.App.Core.Reports.Config
99
/// </summary>
1010
public class ReportConfig : IConfigurationSection
1111
{
12+
/// <summary>
13+
/// Creates a new instance of <see cref="ReportConfig" />
14+
/// </summary>
15+
/// <remarks>
16+
/// <para>
17+
/// Sets default of MaxReportJsonSize to 2000000, MaxReportsPerIncident to 500 and RetentionDays to 90.
18+
/// </para>
19+
/// </remarks>
20+
public ReportConfig()
21+
{
22+
MaxReportJsonSize = 2000000;
23+
MaxReportsPerIncident = 500;
24+
RetentionDays = 90;
25+
}
26+
1227
/// <summary>
1328
/// Maximum number of bytes that a uncompressed JSON report can be
1429
/// </summary>

src/Server/Coderr.Server.App/Modules/Versions/Events/AttachVersionTagToIncident.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public AttachVersionTagToIncident(IVersionRepository repository, ConfigurationSt
3131
private string GetVersionAssemblyName(int applicationId)
3232
{
3333
var config = _configStore.Load<ApplicationVersionConfig>();
34-
return config == null ? null : config.GetAssemblyName(applicationId);
34+
return config.GetAssemblyName(applicationId);
3535
}
3636

3737

src/Server/Coderr.Server.Infrastructure/Configuration/Database/DatabaseStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public override T Load<T>()
5252
items[name] = value;
5353
}
5454

55-
// all config classes should have defaults.
55+
// all configuration classes should have defaults.
5656
if (items.Count == 0)
5757
return new T();
5858

src/Server/Coderr.Server.PluginApi/Config/ConfigurationStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Coderr.Server.PluginApi.Config
44
{
55
/// <summary>
6-
/// Used to modify config settings.
6+
/// Used to modify configuration settings.
77
/// </summary>
88
/// <remarks>
99
/// <para>

src/Server/Coderr.Server.Web/App_Start/Services/ServiceRunner.cs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ public class ServiceRunner : IDisposable
3636
private readonly CompositionRoot _compositionRoot = new CompositionRoot();
3737
private readonly ILog _log = LogManager.GetLogger(typeof(ServiceRunner));
3838
private readonly PluginManager _pluginManager = new PluginManager();
39+
private readonly CancellationTokenSource _shutdownToken = new CancellationTokenSource();
3940
private ApplicationServiceManager _appManager;
4041
private BackgroundJobManager _backgroundJobManager;
4142
private PluginConfiguration _pluginConfiguration;
42-
private readonly CancellationTokenSource _shutdownToken = new CancellationTokenSource();
43+
private AdoNetMessageQueueProvider _queueProvider;
44+
45+
public ServiceRunner()
46+
{
47+
_queueProvider = CreateQueueProvider();
48+
}
4349

4450
public IContainer Container => CompositionRoot.Container;
4551

@@ -61,22 +67,19 @@ public void Start(IAppBuilder app)
6167
{
6268
LetPluginsRegisterServices(registrar);
6369

64-
registrar.RegisterService<IMessageBus>(
65-
x => new SingleInstanceMessageBus(x.Resolve<IMessageQueueProvider>().Open("Messaging")),
66-
Lifetime.Singleton);
70+
registrar.RegisterService<IMessageBus>(x =>
71+
{
72+
var queue = x.Resolve<IMessageQueueProvider>().Open("Messaging");
73+
var bus = new SingleInstanceMessageBus(queue);
74+
return bus;
75+
}, Lifetime.Singleton);
6776
registrar.RegisterConcrete<ScopedQueryBus>();
6877
registrar.RegisterService(CreateMessageInvoker, Lifetime.Scoped);
6978

70-
registrar.RegisterService(x=> CreateQueueListener(x, "Messaging", "Messaging"), Lifetime.Singleton);
79+
registrar.RegisterService(x => CreateQueueListener(x, "Messaging", "Messaging"), Lifetime.Singleton);
7180
registrar.RegisterService(x => CreateQueueListener(x, "Reports", "Messaging"), Lifetime.Singleton);
7281
registrar.RegisterService(x => CreateQueueListener(x, "Feedback", "Messaging"), Lifetime.Singleton);
73-
registrar.RegisterService<IMessageQueueProvider>(x =>
74-
{
75-
Func<IDbConnection> dbFactory = () => DbConnectionFactory.Open(Startup.ConnectionStringName, true);
76-
var serializer = new MessagingSerializer(typeof(AdoNetMessageDto));
77-
var provider = new AdoNetMessageQueueProvider(dbFactory, serializer);
78-
return provider;
79-
}, Lifetime.Singleton);
82+
registrar.RegisterInstance<IMessageQueueProvider>(_queueProvider);
8083

8184
// let us guard it since it runs events in the background.
8285
//var service = registrar.Registrations.First(x => x.Implements(typeof(IMessageBus)));
@@ -136,7 +139,7 @@ private void BuildServices()
136139

137140
private IMessageInvoker CreateMessageInvoker(IServiceLocator x)
138141
{
139-
var scope = new GriffinContainerScopeAdapter((IChildContainer) x);
142+
var scope = new GriffinContainerScopeAdapter((IChildContainer)x);
140143
var invoker = new MessageInvoker(scope);
141144
invoker.HandlerMissing += (sender, args) =>
142145
{
@@ -147,7 +150,7 @@ private IMessageInvoker CreateMessageInvoker(IServiceLocator x)
147150
}
148151
catch (Exception ex)
149152
{
150-
Err.Report(ex, new {args.Message});
153+
Err.Report(ex, new { args.Message });
151154
}
152155
};
153156
invoker.HandlerInvoked += (sender, args) =>
@@ -168,7 +171,8 @@ private IMessageInvoker CreateMessageInvoker(IServiceLocator x)
168171
return invoker;
169172
}
170173

171-
private QueueListener CreateQueueListener(IServiceLocator locator, string inboundQueueName, string outboundQueueName)
174+
private QueueListener CreateQueueListener(IServiceLocator locator, string inboundQueueName,
175+
string outboundQueueName)
172176
{
173177
var provider = locator.Resolve<IMessageQueueProvider>();
174178
var inboundQueue = provider.Open(inboundQueueName);
@@ -182,7 +186,7 @@ private QueueListener CreateQueueListener(IServiceLocator locator, string inboun
182186
};
183187
listener.PoisonMessageDetected += (sender, args) =>
184188
{
185-
Err.Report(args.Exception, new {args.Message});
189+
Err.Report(args.Exception, new { args.Message });
186190
_log.Error(inboundQueueName + " Poison message: " + args.Message.Body, args.Exception);
187191
};
188192
listener.ScopeCreated += (sender, args) =>
@@ -201,9 +205,12 @@ private QueueListener CreateQueueListener(IServiceLocator locator, string inboun
201205
return listener;
202206
}
203207

204-
private void Logga(LogLevel level, string queuenameormessagename, string message)
208+
private AdoNetMessageQueueProvider CreateQueueProvider()
205209
{
206-
210+
Func<IDbConnection> dbFactory = () => DbConnectionFactory.Open(Startup.ConnectionStringName, true);
211+
var serializer = new MessagingSerializer(typeof(AdoNetMessageDto));
212+
var provider = new AdoNetMessageQueueProvider(dbFactory, serializer);
213+
return provider;
207214
}
208215

209216
private void LetPluginsRegisterServices(ContainerRegistrar registrar)
@@ -212,6 +219,10 @@ private void LetPluginsRegisterServices(ContainerRegistrar registrar)
212219
_pluginManager.ConfigurePlugins(_pluginConfiguration);
213220
}
214221

222+
private void Logga(LogLevel level, string queuenameormessagename, string message)
223+
{
224+
}
225+
215226

216227
private void OnBackgroundJobScopeClosing(object sender, ScopeClosingEventArgs e)
217228
{
@@ -229,7 +240,7 @@ private void OnBackgroundJobScopeClosing(object sender, ScopeClosingEventArgs e)
229240

230241
private void OnJobFailed(object sender, BackgroundJobFailedEventArgs e)
231242
{
232-
Err.Report(e.Exception, new{JobType = e.Job?.GetType().FullName});
243+
Err.Report(e.Exception, new { JobType = e.Job?.GetType().FullName });
233244
_log.Error("Failed to execute " + e.Job, e.Exception);
234245
}
235246

src/Server/Coderr.Server.Web/Areas/Admin/Controllers/ApplicationController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public async Task<ActionResult> Versions(ApplicationVersionViewModel model)
105105
return View(model);
106106

107107
//null if this is the first time we run
108-
var config = _configStore.Load<ApplicationVersionConfig>() ?? new ApplicationVersionConfig();
108+
var config = _configStore.Load<ApplicationVersionConfig>();
109109
config.AddOrUpdate(model.ApplicationId, model.SelectedAssembly);
110110
_configStore.Store(config);
111111

src/Server/Coderr.Server.Web/Areas/Admin/Controllers/HomeController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ActionResult Basics()
2222
{
2323
var model = new BasicsViewModel();
2424
var config = _configStore.Load<BaseConfiguration>();
25-
if (config != null)
25+
if (config.BaseUrl != null)
2626
{
2727
model.BaseUrl = config.BaseUrl.ToString();
2828
model.SupportEmail = config.SupportEmail;
@@ -65,7 +65,7 @@ public ActionResult Errors()
6565
{
6666
var model = new ErrorTrackingViewModel();
6767
var config = _configStore.Load<codeRRConfigSection>();
68-
if (config != null)
68+
if (!string.IsNullOrEmpty(model.ContactEmail))
6969
{
7070
model.ContactEmail = config.ContactEmail;
7171
}

src/Server/Coderr.Server.Web/Areas/Admin/Controllers/MessagingController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public ActionResult Email()
2020
{
2121
var model = new EmailViewModel();
2222
var settings = _configStore.Load<DotNetSmtpSettings>();
23-
if (settings == null || string.IsNullOrEmpty(settings.SmtpHost))
23+
if (string.IsNullOrEmpty(settings.SmtpHost))
2424
return View(model);
2525

2626
model.AccountName = settings.AccountName;

0 commit comments

Comments
 (0)