-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDeltaStoreBase.cs
68 lines (55 loc) · 2.86 KB
/
DeltaStoreBase.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
68
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using BIT.Data.Sync.EventArgs;
namespace BIT.Data.Sync
{
public abstract class DeltaStoreBase : IDeltaStore, IDeltaStoreWithEvents
{
protected ISequenceService sequenceService;
public event EventHandler<SavingDeltaEventArgs> SavingDelta;
public event EventHandler<SavedDeltaEventArgs> SavedDelta;
protected virtual void OnSavingDelta(SavingDeltaEventArgs e)
{
SavingDelta?.Invoke(this, e);
}
protected virtual void OnSavedDelta(SavedDeltaEventArgs e)
{
SavedDelta?.Invoke(this, e);
}
public ISequenceService SequenceService => sequenceService;
public DeltaStoreBase(ISequenceService sequenceService)
{
this.sequenceService = sequenceService;
}
protected virtual string GuardStartIndex(string startIndex)
{
if (startIndex == null)
{
return "";
}
else
{
return startIndex;
}
}
protected virtual async Task SetDeltaIndex(IDelta delta)
{
delta.Index = await sequenceService.GenerateNextSequenceAsync();
}
public abstract Task SaveDeltasAsync(IEnumerable<IDelta> deltas, CancellationToken cancellationToken = default);
public abstract Task<IEnumerable<IDelta>> GetDeltasFromOtherNodes(string startIndex, string identity, CancellationToken cancellationToken = default);
public abstract Task<string> GetLastProcessedDeltaAsync(string identity, CancellationToken cancellationToken = default);
public abstract Task SetLastProcessedDeltaAsync(string Index, string identity, CancellationToken cancellationToken = default);
public abstract Task<IEnumerable<IDelta>> GetDeltasAsync(string startIndex, CancellationToken cancellationToken = default);
public abstract Task<IEnumerable<IDelta>> GetDeltasByIdentityAsync(string startIndex, string identity, CancellationToken cancellationToken = default);
public abstract Task<string> GetLastPushedDeltaAsync(string identity, CancellationToken cancellationToken = default);
public abstract Task SetLastPushedDeltaAsync(string Index, string identity, CancellationToken cancellationToken = default);
public abstract Task<int> GetDeltaCountAsync(string startIndex, string identity, CancellationToken cancellationToken=default);
public abstract Task PurgeDeltasAsync(string identity, CancellationToken cancellationToken=default);
public abstract Task ResetDeltasStatusAsync(string identity, CancellationToken cancellationToken=default);
public abstract Task<IDelta> GetDeltaAsync(string deltaId, CancellationToken cancellationToken);
}
}