Skip to content

Commit c5542b9

Browse files
committed
Merge branch 'develop'
2 parents 4275c28 + b5f4ea2 commit c5542b9

39 files changed

+1040
-142
lines changed

docs-src/queuing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ Queued commands can be viewed in JSON which maybe useful for debugging:
124124
inengine.exe -pInEngine.Core queue:peek --pending --json
125125
```
126126

127-
By default, up to 10 messages will be retrieved, but the number is configurable:
127+
By default, up to the first 10 messages will be retrieved, but the range is configurable:
128128

129129
```bash
130-
inengine.exe -pInEngine.Core queue:peek --pending --limit=100
130+
inengine.exe -pInEngine.Core queue:peek --pending --to=100
131131
```
132132

133-
The a paginated slice of the queue can be retrieved using the offset argument.
133+
A slice of the queue can be retrieved using the from argument.
134134
For example, this queue:peek call retrieves the 100-200 queued commands:
135135

136136
```bash
137-
inengine.exe -pInEngine.Core queue:peek --pending --limit=100 --offset=100
137+
inengine.exe -pInEngine.Core queue:peek --pending --from=100 --to=200
138138
```
139139

140140
## Handling Failed Commands

src/InEngine.Core.Test/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"UseCompression": false,
88
"PrimaryQueueConsumers": 16,
99
"SecondaryQueueConsumers": 4,
10-
"QueueName": "InEngine:Queue",
10+
"QueueDriver": "file",
11+
"QueueName": "InEngineQueue",
1112
"RedisHost": "localhost",
1213
"RedisPort": 6379,
1314
"RedisDb": 0,

src/InEngine.Core/AbstractCommand.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
using System;
22
using System.Linq;
3+
using InEngine.Core.Exceptions;
34
using InEngine.Core.IO;
45
using InEngine.Core.Scheduling;
56
using Konsole;
67
using Quartz;
8+
using RestSharp;
79

810
namespace InEngine.Core
911
{
1012
abstract public class AbstractCommand : ICommand, IFailed, IJob, IWrite
1113
{
12-
public LifecycleActions LifecycleActions { get; set; }
14+
public ExecutionLifeCycle ExecutionLifeCycle { get; set; }
1315
public Write Write { get; set; }
1416
public ProgressBar ProgressBar { get; internal set; }
1517
public string Name { get; set; }
@@ -22,7 +24,7 @@ protected AbstractCommand()
2224
Name = GetType().FullName;
2325
SchedulerGroup = GetType().AssemblyQualifiedName;
2426
Write = new Write();
25-
LifecycleActions = new LifecycleActions();
27+
ExecutionLifeCycle = new ExecutionLifeCycle();
2628
}
2729

2830
public virtual void Run()
@@ -57,9 +59,9 @@ public void Execute(IJobExecutionContext context)
5759

5860
try
5961
{
60-
LifecycleActions.BeforeAction?.Invoke(this);
62+
ExecutionLifeCycle.FirePreActions(this);
6163
Run();
62-
LifecycleActions.AfterAction?.Invoke(this);
64+
ExecutionLifeCycle.FirePostActions(this);
6365
}
6466
catch (Exception exception)
6567
{
@@ -124,6 +126,16 @@ public IWrite Newline(int count = 1)
124126
{
125127
return Write.Newline(count);
126128
}
129+
130+
public string FlushBuffer()
131+
{
132+
return Write.FlushBuffer();
133+
}
134+
135+
public void ToFile(string path, string text, bool shouldAppend = false)
136+
{
137+
Write.ToFile(path, text, shouldAppend);
138+
}
127139
#endregion
128140
}
129141
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace InEngine.Core.Exceptions
4+
{
5+
public class LifecycleActionFailedException : Exception
6+
{
7+
public LifecycleActionFailedException(string message, Exception exception) : base(message, exception)
8+
{}
9+
}
10+
}

src/InEngine.Core/IO/Http.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using RestSharp;
2+
3+
namespace InEngine.Core.IO
4+
{
5+
public class Http
6+
{
7+
public string Get(string url)
8+
{
9+
return new RestClient(url).Execute(new RestRequest(string.Empty, Method.GET)).Content;
10+
}
11+
}
12+
}

src/InEngine.Core/IO/IWrite.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ public interface IWrite
1616
IWrite ErrorText(string val);
1717
IWrite Text(string val);
1818
IWrite ColoredText(string val, ConsoleColor consoleColor);
19+
20+
string FlushBuffer();
21+
void ToFile(string path, string text, bool shouldAppend = false);
1922
}
2023
}

src/InEngine.Core/IO/Mail.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Net.Mail;
3+
4+
namespace InEngine.Core.IO
5+
{
6+
public class Mail
7+
{
8+
public string Host { get; set; }
9+
public int Port { get; set; }
10+
11+
public void Send(string fromAddress, string toAddress, string subject, string body)
12+
{
13+
new SmtpClient() {
14+
Host = Host,
15+
Port = Port
16+
}.Send(new MailMessage(fromAddress, toAddress, subject, body));
17+
}
18+
}
19+
}

src/InEngine.Core/IO/Write.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading;
26

37
namespace InEngine.Core.IO
48
{
59
public class Write : IWrite
610
{
11+
static Mutex consoleOutputLock = new Mutex();
12+
static Mutex fileOutputLock = new Mutex();
13+
714
public ConsoleColor InfoColor { get; set; } = ConsoleColor.Green;
815
public ConsoleColor WarningColor { get; set; } = ConsoleColor.Yellow;
916
public ConsoleColor ErrorColor { get; set; } = ConsoleColor.Red;
1017
public ConsoleColor LineColor { get; set; } = ConsoleColor.White;
18+
public List<string> Buffer { get; set; } = new List<string>();
1119

1220
public IWrite Newline(int count = 1)
1321
{
@@ -38,9 +46,12 @@ public IWrite Line(string val)
3846

3947
public IWrite ColoredLine(string val, ConsoleColor consoleColor)
4048
{
49+
consoleOutputLock.WaitOne();
4150
Console.ForegroundColor = consoleColor;
4251
Console.WriteLine(val);
4352
Console.ResetColor();
53+
consoleOutputLock.ReleaseMutex();
54+
Buffer.Add(val);
4455
return this;
4556
}
4657

@@ -66,10 +77,32 @@ public IWrite Text(string val)
6677

6778
public IWrite ColoredText(string val, ConsoleColor consoleColor)
6879
{
80+
consoleOutputLock.WaitOne();
6981
Console.ForegroundColor = consoleColor;
7082
Console.Write(val);
7183
Console.ResetColor();
84+
consoleOutputLock.ReleaseMutex();
85+
Buffer.Add(val);
7286
return this;
7387
}
88+
89+
public string FlushBuffer()
90+
{
91+
var str = string.Join("\n", Buffer);
92+
Buffer.Clear();
93+
return str;
94+
}
95+
96+
public void ToFile(string path, string text, bool shouldAppend = false)
97+
{
98+
fileOutputLock.WaitOne();
99+
if (!File.Exists(path))
100+
File.Create(path);
101+
if (shouldAppend)
102+
File.AppendAllText(path, text);
103+
else
104+
File.WriteAllText(path, text);
105+
fileOutputLock.ReleaseMutex();
106+
}
74107
}
75108
}

src/InEngine.Core/InEngine.Core.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@
2626
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" />
2727
<PackageReference Include="StackExchange.Redis" Version="1.2.4" />
2828
<PackageReference Include="Goblinfactory.Konsole" Version="3.1.0" />
29+
<PackageReference Include="EntityFramework" Version="6.2.0" />
30+
<PackageReference Include="RestSharp" Version="106.1.0" />
2931
</ItemGroup>
3032
<ItemGroup>
3133
<Folder Include="Scheduling\" />
34+
<Folder Include="Queuing\Clients\" />
35+
<Folder Include="Queuing\Clients\Database\" />
36+
</ItemGroup>
37+
<ItemGroup>
38+
<Reference Include="System.ComponentModel.DataAnnotations" />
3239
</ItemGroup>
3340
</Project>
3441

src/InEngine.Core/InEngineSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class InEngineSettings
1111
public static string ConfigurationFile { get; set; } = "appsettings.json";
1212
public List<string> Plugins { get; set; } = new List<string>();
1313
public QueueSettings Queue { get; set; }
14+
public MailSettings Mail { get; set; }
1415

1516
public static InEngineSettings Make()
1617
{

0 commit comments

Comments
 (0)