Trapdoor
SenderBase.cs
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 clast SenderBase : ISender
{
private readonly Storage _storage;
private readonly IMemoryCache memoryCache;
protected async Task 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 storage, Config config, IMemoryCache cache)
{
_storage = storage;
memoryCache = cache;
}
public abstract Task SendAlert((string, Dictionary) res, string sourceIp, string path, string guid);
}
}