Skip to content

Commit 07d2585

Browse files
committed
Remove most static settings factory references
1 parent 0e19378 commit 07d2585

29 files changed

+165
-67
lines changed

src/InEngine.Core/AbstractCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace InEngine.Core
1212
{
13-
abstract public class AbstractCommand : IJob, IWrite, IHasCommandLifeCycle
13+
abstract public class AbstractCommand : IJob, IWrite, IHasCommandLifeCycle, IHasMailSettings
1414
{
1515
protected ILog Log { get; set; }
1616
public CommandLifeCycle CommandLifeCycle { get; set; }
@@ -20,6 +20,7 @@ abstract public class AbstractCommand : IJob, IWrite, IHasCommandLifeCycle
2020
public string SchedulerGroup { get; set; }
2121
public string ScheduleId { get; set; }
2222
public int SecondsBeforeTimeout { get; set; }
23+
public MailSettings MailSettings { get; set; }
2324

2425
protected AbstractCommand()
2526
{
@@ -29,7 +30,7 @@ protected AbstractCommand()
2930
SchedulerGroup = GetType().AssemblyQualifiedName;
3031
Write = new Write();
3132
CommandLifeCycle = new CommandLifeCycle() {
32-
MailSettings = InEngineSettings.Make().Mail
33+
MailSettings = MailSettings
3334
};
3435
SecondsBeforeTimeout = 300;
3536
}
@@ -89,7 +90,6 @@ public virtual void Execute(IJobExecutionContext context)
8990
property.SetValue(this, x.Value);
9091
});
9192
}
92-
9393
RunWithLifeCycle();
9494
}
9595
#endregion

src/InEngine.Core/Commands/Exec.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public class Exec : AbstractCommand
2121

2222
public override void Run()
2323
{
24-
var settings = InEngineSettings.Make();
2524
if (ExecWhitelist == null)
26-
ExecWhitelist = settings.ExecWhitelist;
25+
ExecWhitelist = InEngineSettings.Make().ExecWhitelist;
2726
if (!ExecWhitelist.ContainsKey(Executable))
2827
throw new CommandFailedException("Executable is not whitelisted.");
2928
var fileName = ExecWhitelist[Executable];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace InEngine.Core.IO
2+
{
3+
public interface IHasMailSettings
4+
{
5+
MailSettings MailSettings { get; set; }
6+
}
7+
}

src/InEngine.Core/LifeCycle/CommandLifeCycle.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ public void FirePostActions(AbstractCommand command)
8787
try
8888
{
8989
if (ShouldEmailOutput)
90-
new IO.Mail() {
90+
new Mail() {
9191
Host = MailSettings.Host,
9292
Port = MailSettings.Port,
9393
Username = MailSettings.Username,
9494
Password = MailSettings.Password,
95-
}
96-
.Send(MailSettings.From, EmailOutputToAddress, emailSubject, commandOutput);
95+
}.Send(MailSettings.From, EmailOutputToAddress, emailSubject, commandOutput);
9796
}
9897
catch (Exception exception)
9998
{

src/InEngine.Core/Queuing/Clients/FileClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading;
66
using Common.Logging;
77
using InEngine.Core.Exceptions;
8+
using InEngine.Core.IO;
89
using InEngine.Core.Queuing.Message;
910

1011
namespace InEngine.Core.Queuing.Clients
@@ -13,6 +14,7 @@ public class FileClient : IQueueClient
1314
{
1415
static Mutex consumeLock = new Mutex();
1516
public static FileClientSettings ClientSettings { get; set; }
17+
public MailSettings MailSettings { get; set; }
1618

1719
public ILog Log { get; set; } = LogManager.GetLogger<FileClient>();
1820
public int Id { get; set; } = 0;

src/InEngine.Core/Queuing/Clients/RabbitMQClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using Common.Logging;
66
using InEngine.Core.Exceptions;
7+
using InEngine.Core.IO;
78
using InEngine.Core.Queuing.Message;
89
using RabbitMQ.Client;
910
using RabbitMQ.Client.Events;
@@ -13,6 +14,7 @@ namespace InEngine.Core.Queuing.Clients
1314
public class RabbitMQClient : IQueueClient, IDisposable
1415
{
1516
public static RabbitMQClientSettings ClientSettings { get; set; }
17+
public MailSettings MailSettings { get; set; }
1618

1719
public ILog Log { get; set; } = LogManager.GetLogger<SyncClient>();
1820
public int Id { get; set; } = 0;

src/InEngine.Core/Queuing/Clients/RedisClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Common.Logging;
77
using InEngine.Core.Exceptions;
8+
using InEngine.Core.IO;
89
using InEngine.Core.Queuing.Message;
910
using StackExchange.Redis;
1011

@@ -13,6 +14,7 @@ namespace InEngine.Core.Queuing.Clients
1314
public class RedisClient : IQueueClient
1415
{
1516
public static RedisClientSettings ClientSettings { get; set; }
17+
public MailSettings MailSettings { get; set; }
1618

1719
public ILog Log { get; set; } = LogManager.GetLogger<RedisClient>();
1820
public int Id { get; set; } = 0;

src/InEngine.Core/Queuing/Clients/SyncClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
using System.Collections.Generic;
33
using System.Threading;
44
using Common.Logging;
5+
using InEngine.Core.IO;
56
using InEngine.Core.Queuing.Message;
67

78
namespace InEngine.Core.Queuing.Clients
89
{
910
public class SyncClient : IQueueClient
1011
{
12+
public MailSettings MailSettings { get; set; }
13+
1114
public ILog Log { get; set; } = LogManager.GetLogger<SyncClient>();
1215
public int Id { get; set; } = 0;
1316
public string QueueBaseName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

src/InEngine.Core/Queuing/Commands/Consume.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace InEngine.Core.Queuing.Commands
77
{
8-
public class Consume : AbstractCommand
8+
public class Consume : AbstractCommand, IHasQueueSettings
99
{
1010
[Option("all", HelpText = "Consume all the messages in the primary or secondary queue.")]
1111
public bool ShouldConsumeAll { get; set; }
@@ -16,9 +16,11 @@ public class Consume : AbstractCommand
1616
[Option("secondary", DefaultValue = false, HelpText = "Consume from the secondary queue.")]
1717
public bool UseSecondaryQueue { get; set; }
1818

19+
public QueueSettings QueueSettings { get; set; }
20+
1921
public override void Run()
2022
{
21-
var queue = QueueAdapter.Make(UseSecondaryQueue);
23+
var queue = QueueAdapter.Make(UseSecondaryQueue, QueueSettings, MailSettings);
2224
ICommandEnvelope commandEnvelope;
2325
while (ShouldConsumeAll)
2426
try

src/InEngine.Core/Queuing/Commands/Flush.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace InEngine.Core.Queuing.Commands
55
{
6-
public class Flush : AbstractCommand
6+
public class Flush : AbstractCommand, IHasQueueSettings
77
{
88
[Option("pending", HelpText = "Clear the pending queue.")]
99
public bool PendingQueue { get; set; }
@@ -17,11 +17,13 @@ public class Flush : AbstractCommand
1717
[Option("secondary", HelpText = "Clear secondary queues. Primary queues are cleared by default.")]
1818
public bool UseSecondaryQueue { get; set; }
1919

20+
public QueueSettings QueueSettings { get; set; }
21+
2022
public override void Run()
2123
{
2224
if (PendingQueue == false && FailedQueue == false && InProgressQueue == false)
2325
throw new CommandFailedException("Must specify at least one queue to clear. Use -h to see available options.");
24-
var queue = QueueAdapter.Make(UseSecondaryQueue);
26+
var queue = QueueAdapter.Make(UseSecondaryQueue, QueueSettings, MailSettings);
2527
if (PendingQueue)
2628
Info($"Pending: {queue.ClearPendingQueue().ToString()}");
2729
if (InProgressQueue)

0 commit comments

Comments
 (0)