Skip to content

Commit

Permalink
release 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
hhblaze committed Dec 9, 2020
1 parent 8955120 commit e470582
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 32 deletions.
9 changes: 5 additions & 4 deletions EntitySyncing.Net5/EntitySyncing.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions EntitySyncing.NetStandard20/EntitySyncing.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions EntitySyncingClient.Net5/EntitySyncingClient.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions EntitySyncingClient.NetStandard20/EntitySyncingClient.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 27 additions & 7 deletions SPEntitySyncing/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ public class Engine
{
internal DBreezeEngine DBEngine = null;

public Func<object, byte[]> Serialize = null;
public Func<byte[], Type, object> Deserialize = null;

/// <summary>
///
/// </summary>
/// <param name="dbEngine"></param>
/// <param name="logger">can be null</param>
/// <param name=""></param>
public Engine(DBreeze.DBreezeEngine dbEngine, ILogger logger)
/// <param name="logger"></param>
/// <param name="byteArraySerializer">can be null then DBreeze embedded serializer will be used</param>
/// <param name="byteArrayDeSerializer">can be null then DBreeze embedded deserializer will be used</param>
public Engine(DBreeze.DBreezeEngine dbEngine, ILogger logger, Func<object, byte[]> byteArraySerializer = null, Func<byte[], Type, object> byteArrayDeSerializer = null)
{
if (logger == null)
Logger.log = new LoggerWrapper();
Expand All @@ -38,11 +42,27 @@ public Engine(DBreeze.DBreezeEngine dbEngine, ILogger logger)
return;
}

if (DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator == null || DBreeze.Utils.CustomSerializator.ByteArraySerializator == null)
if((byteArraySerializer != null && byteArrayDeSerializer == null) || (byteArraySerializer != null && byteArrayDeSerializer == null))
throw new Exception("EntitySyncing.Engine.Init: please supply both ByteArrayDeSerializator and ByteArraySerializator");

if(byteArraySerializer == null && byteArrayDeSerializer == null)
{
//Trying to use DBreeze serializers
if (DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator == null || DBreeze.Utils.CustomSerializator.ByteArraySerializator == null)
{
throw new Exception("EntitySyncing.Engine.Init: please supply both ByteArrayDeSerializator and ByteArraySerializator or embed serializers to DBreeze");
}

this.Serialize = DBreeze.Utils.CustomSerializator.ByteArraySerializator;
this.Deserialize = DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator;
}
else
{
throw new Exception("EntitySyncing.Engine.Init: please supply for the DBreeze DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator && DBreeze.Utils.CustomSerializator.ByteArraySerializator");
this.Serialize = byteArraySerializer;
this.Deserialize = byteArrayDeSerializer;
}


DBEngine = dbEngine;
}

Expand Down Expand Up @@ -164,7 +184,7 @@ public byte[] SyncEntityStrategyV1<T>(HttpCapsule capsIn, EntitySyncingBaseV1<T>
//We must update server side and put into entityLog
//We don't return back this entity

newEntity = (T)DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator(row.SerializedObject, typeof(T));
newEntity = (T)Deserialize(row.SerializedObject, typeof(T));
//newEntity = row.SerializedObject.DeserializeProtobuf<T>();

((ISyncEntity)newEntity).Id = row.InternalId; //just for a case
Expand Down Expand Up @@ -204,7 +224,7 @@ public byte[] SyncEntityStrategyV1<T>(HttpCapsule capsIn, EntitySyncingBaseV1<T>

//Insert new
//newEntity = row.SerializedObject.DeserializeProtobuf<T>();
newEntity = (T)DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator(row.SerializedObject, typeof(T));
newEntity = (T)Deserialize(row.SerializedObject, typeof(T));


entitySync.ptrContent = null;
Expand Down
2 changes: 1 addition & 1 deletion SPEntitySyncing/SyncStrategyV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SyncStrategyV1<T>
/// <param name="table">Where must be stored index 200</param>
/// <param name="entity">entity.Id and entity.SyncTimestamp must be filled up</param>
/// <param name="ptrEntityContent">pointer to the entity content (16 bytes) gathered with DBreeze InsertDataBlockWithFixedAddress</param>
/// <param name="oldEntity">old instance of the entity from DB</param>
/// <param name="oldEntity">old instance of the entity from DB !!!MUST!!! be supplied when update or null when new entity</param>
public static void InsertIndex4Sync(DBreeze.Transactions.Transaction tran, string table, ISyncEntity entity, byte[] ptrEntityContent, ISyncEntity oldEntity)
{
if (oldEntity == null)
Expand Down
29 changes: 26 additions & 3 deletions SPEntitySyncingClient/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class Engine

internal DBreezeEngine DBEngine = null;

public Func<object, byte[]> Serialize = null;
public Func<byte[], Type, object> Deserialize = null;

/// <summary>
/// Url / payload
/// </summary>
Expand All @@ -59,7 +62,10 @@ public class Engine
/// <param name="resetWebSession"></param>
/// <param name="syncIsFinishing"></param>
/// <param name="logger">can be null</param>
public Engine(DBreeze.DBreezeEngine dbEngine, Func<string, byte[], Task<byte[]>> serverSender, Action resetWebSession, Action syncIsFinishing, ILogger logger)
/// <param name="byteArraySerializer">can be null then DBreeze embedded serializer will be used</param>
/// <param name="byteArrayDeSerializer">can be null then DBreeze embedded deserializer will be used</param>
public Engine(DBreeze.DBreezeEngine dbEngine, Func<string, byte[], Task<byte[]>> serverSender, Action resetWebSession, Action syncIsFinishing, ILogger logger,
Func<object, byte[]> byteArraySerializer = null, Func<byte[], Type, object> byteArrayDeSerializer = null)
{
if (logger == null)
Logger.log = new LoggerWrapper();
Expand All @@ -72,11 +78,28 @@ public Engine(DBreeze.DBreezeEngine dbEngine, Func<string, byte[], Task<byte[]>>
return;
}

if (DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator == null || DBreeze.Utils.CustomSerializator.ByteArraySerializator == null)

if ((byteArraySerializer != null && byteArrayDeSerializer == null) || (byteArraySerializer != null && byteArrayDeSerializer == null))
throw new Exception("EntitySyncing.Engine.Init: please supply both ByteArrayDeSerializator and ByteArraySerializator");

if (byteArraySerializer == null && byteArrayDeSerializer == null)
{
//Trying to use DBreeze serializers
if (DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator == null || DBreeze.Utils.CustomSerializator.ByteArraySerializator == null)
{
throw new Exception("EntitySyncing.Engine.Init: please supply both ByteArrayDeSerializator and ByteArraySerializator or embed serializers to DBreeze");
}

this.Serialize = DBreeze.Utils.CustomSerializator.ByteArraySerializator;
this.Deserialize = DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator;
}
else
{
throw new Exception("EntitySyncingClient.Engine.Init: please supply for the DBreeze DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator && DBreeze.Utils.CustomSerializator.ByteArraySerializator");
this.Serialize = byteArraySerializer;
this.Deserialize = byteArrayDeSerializer;
}


DBEngine = dbEngine;

_serverSender = serverSender;
Expand Down
14 changes: 7 additions & 7 deletions SPEntitySyncingClient/SyncStrategyV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SyncStrategyV1<T> : SyncStrategy<T>
/// <param name="table">Where must be stored index 200</param>
/// <param name="entity">entity.Id and entity.SyncTimestamp must be filled up</param>
/// <param name="ptrEntityContent">pointer to the entity content (16 bytes) gathered with DBreeze InsertDataBlockWithFixedAddress</param>
/// <param name="oldEntity">old instance of the entity from DB</param>
/// <param name="oldEntity">old instance of the entity from DB !!!MUST!!! be supplied when update or null when new entity</param>
public static void InsertIndex4Sync(DBreeze.Transactions.Transaction tran, string table, T entity, byte[] ptrEntityContent, T oldEntity)
{
ISyncEntity ent = ((ISyncEntity)entity);
Expand Down Expand Up @@ -150,15 +150,15 @@ public override bool UpdateLocalDatabase(ExchangeData exData) //(List<SyncOperat
((ISyncEntity)oldEntity).Id = opr.ExternalId; //Theoretically on this place can be called a user-function to get another ID type
((ISyncEntity)oldEntity).SyncTimestamp = ++now; //must be returned back, overriding SyncTimeStamp

_entitySync.OnInsertEntity(oldEntity, default(T), DBreeze.Utils.CustomSerializator.ByteArraySerializator(oldEntity), opr.InternalId);
_entitySync.OnInsertEntity(oldEntity, default(T), SyncEngine.Serialize(oldEntity), opr.InternalId);

InsertIndex4Sync(tran, _entitySync.entityTable, oldEntity, _entitySync.ptrContent, default(T));


//Setting value from the server for the existing ID (real entity that must belong to that id)
_entitySync.ptrContent = rowLocalEntity.Value;

_entitySync.OnInsertEntity((T)DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator(opr.SerializedObject, typeof(T)), default(T),
_entitySync.ptrContent = rowLocalEntity.Value;
_entitySync.OnInsertEntity((T)SyncEngine.Deserialize(opr.SerializedObject, typeof(T)), default(T),
opr.SerializedObject, 0);

reRunSync = true;
Expand All @@ -180,7 +180,7 @@ public override bool UpdateLocalDatabase(ExchangeData exData) //(List<SyncOperat
_entitySync.ptrContent = rowLocalEntity.Value;
localEntity = rowLocalEntity.GetDataBlockWithFixedAddress<T>();

entity = (T)DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator(opr.SerializedObject, typeof(T));
entity = (T)SyncEngine.Deserialize(opr.SerializedObject, typeof(T));

if (((ISyncEntity)localEntity).SyncTimestamp < opr.SyncTimestamp)
{
Expand All @@ -199,7 +199,7 @@ public override bool UpdateLocalDatabase(ExchangeData exData) //(List<SyncOperat
//Inserting new entity from server
_entitySync.ptrContent = null;
// entity = opr.SerializedObject.DeserializeProtobuf<T>();
entity = (T)DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator(opr.SerializedObject, typeof(T));
entity = (T)SyncEngine.Deserialize(opr.SerializedObject, typeof(T));

_entitySync.OnInsertEntity(entity, default(T), opr.SerializedObject, 0);
InsertIndex4Sync(tran, _entitySync.entityTable, entity, _entitySync.ptrContent, default(T));
Expand Down
2 changes: 1 addition & 1 deletion _Deployment/EntitySyncing.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>EntitySyncingServer</id>
<version>1.005.2020.1209</version>
<version>1.006.2020.1209</version>
<title>EntitySyncingServer</title>
<authors>[email protected]</authors>
<owners>https://tiesky.com</owners>
Expand Down
Binary file removed _Deployment/EntitySyncingClient.1.5.2020.1209.nupkg
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion _Deployment/EntitySyncingClient.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>EntitySyncingClient</id>
<version>1.005.2020.1209</version>
<version>1.006.2020.1209</version>
<title>EntitySyncingClient</title>
<authors>[email protected]</authors>
<owners>https://tiesky.com</owners>
Expand Down
Binary file removed _Deployment/EntitySyncingServer.1.5.2020.1209.nupkg
Binary file not shown.
Binary file not shown.

0 comments on commit e470582

Please sign in to comment.