-
Notifications
You must be signed in to change notification settings - Fork 5
/
MailAlerter.cs
47 lines (38 loc) · 1.31 KB
/
MailAlerter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using CK.Core;
using System;
using System.Threading.Tasks;
namespace CK.Monitoring.Handlers;
/// <summary>
/// Stupid handler implementation.
/// </summary>
public class MailAlerter : IGrandOutputHandler
{
MailAlerterConfiguration _c;
// Just fo test... See HostingTests.finding_MailAlerter_handler_by_conventions_Async().
public static string? LastMailSent;
public MailAlerter( MailAlerterConfiguration c )
{
_c = c;
}
public ValueTask<bool> ActivateAsync( IActivityMonitor m ) => ValueTask.FromResult( _c.CheckValidity( m ) );
public ValueTask<bool> ApplyConfigurationAsync( IActivityMonitor m, IHandlerConfiguration c )
{
if( c is MailAlerterConfiguration newC && newC.Email == _c.Email )
{
_c = newC;
return ValueTask.FromResult( true );
}
return ValueTask.FromResult( false );
}
public ValueTask DeactivateAsync( IActivityMonitor m ) => default;
public ValueTask HandleAsync( IActivityMonitor m, InputLogEntry logEvent )
{
if( logEvent.Tags.IsSupersetOf( CK.Monitoring.MailAlerter.SendMail ) )
{
LastMailSent = logEvent.Text;
// Do send mail...
}
return default;
}
public ValueTask OnTimerAsync( IActivityMonitor m, TimeSpan timerSpan ) => default;
}