-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSenderBase.cs
48 lines (42 loc) · 1.39 KB
/
SenderBase.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
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
namespace Trapdoor
{
public abstract class SenderBase : ISender
{
private readonly Storage<SessionLog> _storage;
private readonly IMemoryCache memoryCache;
protected async Task<List<string>> GetLogs(string id)
{
string type = this.GetType().Name;
return (await _storage.GetByHash($"{type}#{id}"))
.Select(x => Compression.Unzip(x.Data)).Distinct().ToList();
}
public async Task StoreLogs(string id, string data)
{
string type = this.GetType().Name;
try
{
await _storage.Store(new SessionLog()
{
Id = $"{type}#{id}",
Data = Compression.Zip(data)
});
}
catch (Exception e)
{
Console.WriteLine($"Error storing logs : {e.Message}");
}
}
protected SenderBase(Storage<SessionLog> storage, Config config, IMemoryCache cache)
{
_storage = storage;
memoryCache = cache;
}
public abstract Task<string> SendAlert((string, Dictionary<string, dynamic>) res, string sourceIp, string path, string guid);
}
}