-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathStorage.cs
67 lines (60 loc) · 1.49 KB
/
Storage.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
namespace Trapdoor
{
[DynamoDBTable("TRAPDOOR_LOG")]
public class SessionLog
{
[DynamoDBHashKey] public string Id { get; set; }
[DynamoDBProperty] public byte[] Data { get; set; }
}
public class Storage<T> : DynamoDBContext
{
public Storage(IAmazonDynamoDB client) : base(client)
{
}
public async Task<List<T>> GetByHash(string hash)
{
try
{
var res = await QueryAsync<T>(hash).GetRemainingAsync();
return res;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
public async Task<T> Get(string hash, string range)
{
try
{
var res = await LoadAsync<T>(hash, range);
return res;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw;
}
}
public async Task<T> Store(T dto)
{
try
{
await SaveAsync(dto);
return dto;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw;
}
}
}
}