Now that we have defined the bases contracts necessary for synchronization, we can define some base classes that implement those contracts, the main idea behind these base classes is to, later on, add the possibility to inject configurations with .net dependency injection.

Let’s start with the delta implementation

https://github.com/egarim/SyncFramework/blob/main/src/BIT.Data.Sync/Delta.cs

/// <summary>
    /// An implementation of the IDelta interface, this class is primary used for serialization and transportation purpose 
    /// </summary>
    public class Delta : IDelta
    {
        public Delta()
        {
        }
        public static Guid GenerateComb()
        {
            return Provider.PostgreSql.Create();
           
        }
        public Delta(string identity, byte[] operation, bool processed = false)
        {

            Identity = identity;
            Operation = operation;
            Processed = processed;
        }
        public Delta(IDelta Delta)
        {

            Identity = Delta.Identity;
            Index = Delta.Index;
            Operation = Delta.Operation;
          

        }
        public Delta(string identity, Guid index, byte[] operation, bool processed = false)
        {

            Identity = identity;
            Index = index;
            Operation = operation;
            Processed = processed;
        }
        public virtual DateTime Date { get; set; }
        public virtual string Identity { get; set; }

        public virtual Guid Index { get; set; }

        public virtual byte[] Operation { get; set; }
        public virtual bool Processed { get; set; }
        public virtual double Epoch { get; set; }

    }

Now the delta store

https://github.com/egarim/SyncFramework/blob/main/src/BIT.Data.Sync/DeltaStoreBase.cs

   public abstract class DeltaStoreBase : IDeltaStore
   {

       protected DeltaStoreBase()
       {

       }
       protected DeltaStoreSettings _deltaStoreSettings;

       public string Identity { get; private set; }

       public DeltaStoreBase(DeltaStoreSettings deltaStoreSettings)
       {
           this._deltaStoreSettings = deltaStoreSettings;
           Setup();
       }
       protected virtual void Setup()
       {

       }
       public abstract Task SaveDeltasAsync(IEnumerable<IDelta> deltas, CancellationToken cancellationToken = default);

       public abstract Task<IEnumerable<IDelta>> GetDeltasFromOtherNodes(Guid startindex, string identity, CancellationToken cancellationToken = default);
       //public abstract Task<IEnumerable<IDelta>> GetDeltasToSendAsync(Guid startindex, CancellationToken cancellationToken = default);
       public abstract Task<Guid> GetLastProcessedDeltaAsync(CancellationToken cancellationToken = default);
       public abstract Task SetLastProcessedDeltaAsync(Guid Index, CancellationToken cancellationToken = default);

       public abstract Task<IEnumerable<IDelta>> GetDeltasAsync(Guid startindex, CancellationToken cancellationToken = default);

       public void SetIdentity(string Identity)
       {
           this.Identity = Identity;
       }

       public abstract Task<Guid> GetLastPushedDeltaAsync(CancellationToken cancellationToken = default);
       public abstract Task SetLastPushedDeltaAsync(Guid Index, CancellationToken cancellationToken = default);

       public abstract Task<int> GetDeltaCountAsync(Guid startindex, CancellationToken cancellationToken=default);
       public abstract Task PurgeDeltasAsync(CancellationToken cancellationToken);
   }

and finally, the delta processor

https://github.com/egarim/SyncFramework/blob/main/src/BIT.Data.Sync/DeltaProcessorBase.cs

public abstract class DeltaProcessorBase : IDeltaProcessor
{
    protected DeltaStoreSettings _deltaStoreSettings;
    public DeltaProcessorBase(DeltaStoreSettings deltaStoreSettings)
    {
        _deltaStoreSettings = deltaStoreSettings;
    }

    public abstract Task ProcessDeltasAsync(IEnumerable<IDelta> Deltas, CancellationToken cancellationToken);

}

That’s it for this post, see you on the next post “Planning the first implementation”