diff --git a/EntitySyncing.Net5/EntitySyncing.xml b/EntitySyncing.Net5/EntitySyncing.xml index d2caa10..4bd103c 100644 --- a/EntitySyncing.Net5/EntitySyncing.xml +++ b/EntitySyncing.Net5/EntitySyncing.xml @@ -4,13 +4,14 @@ EntitySyncing - + - can be null - + + can be null then DBreeze embedded serializer will be used + can be null then DBreeze embedded deserializer will be used @@ -72,7 +73,7 @@ Where must be stored index 200 entity.Id and entity.SyncTimestamp must be filled up pointer to the entity content (16 bytes) gathered with DBreeze InsertDataBlockWithFixedAddress - old instance of the entity from DB + old instance of the entity from DB !!!MUST!!! be supplied when update or null when new entity diff --git a/EntitySyncing.NetStandard20/EntitySyncing.xml b/EntitySyncing.NetStandard20/EntitySyncing.xml index d2caa10..4bd103c 100644 --- a/EntitySyncing.NetStandard20/EntitySyncing.xml +++ b/EntitySyncing.NetStandard20/EntitySyncing.xml @@ -4,13 +4,14 @@ EntitySyncing - + - can be null - + + can be null then DBreeze embedded serializer will be used + can be null then DBreeze embedded deserializer will be used @@ -72,7 +73,7 @@ Where must be stored index 200 entity.Id and entity.SyncTimestamp must be filled up pointer to the entity content (16 bytes) gathered with DBreeze InsertDataBlockWithFixedAddress - old instance of the entity from DB + old instance of the entity from DB !!!MUST!!! be supplied when update or null when new entity diff --git a/EntitySyncingClient.Net5/EntitySyncingClient.xml b/EntitySyncingClient.Net5/EntitySyncingClient.xml index f8c6b6e..6fcfd86 100644 --- a/EntitySyncingClient.Net5/EntitySyncingClient.xml +++ b/EntitySyncingClient.Net5/EntitySyncingClient.xml @@ -24,7 +24,7 @@ Url / payload - + @@ -33,6 +33,8 @@ can be null + can be null then DBreeze embedded serializer will be used + can be null then DBreeze embedded deserializer will be used @@ -117,7 +119,7 @@ Where must be stored index 200 entity.Id and entity.SyncTimestamp must be filled up pointer to the entity content (16 bytes) gathered with DBreeze InsertDataBlockWithFixedAddress - old instance of the entity from DB + old instance of the entity from DB !!!MUST!!! be supplied when update or null when new entity diff --git a/EntitySyncingClient.NetStandard20/EntitySyncingClient.xml b/EntitySyncingClient.NetStandard20/EntitySyncingClient.xml index f8c6b6e..6fcfd86 100644 --- a/EntitySyncingClient.NetStandard20/EntitySyncingClient.xml +++ b/EntitySyncingClient.NetStandard20/EntitySyncingClient.xml @@ -24,7 +24,7 @@ Url / payload - + @@ -33,6 +33,8 @@ can be null + can be null then DBreeze embedded serializer will be used + can be null then DBreeze embedded deserializer will be used @@ -117,7 +119,7 @@ Where must be stored index 200 entity.Id and entity.SyncTimestamp must be filled up pointer to the entity content (16 bytes) gathered with DBreeze InsertDataBlockWithFixedAddress - old instance of the entity from DB + old instance of the entity from DB !!!MUST!!! be supplied when update or null when new entity diff --git a/SPEntitySyncing/Engine.cs b/SPEntitySyncing/Engine.cs index cc15f5d..e251374 100644 --- a/SPEntitySyncing/Engine.cs +++ b/SPEntitySyncing/Engine.cs @@ -19,13 +19,17 @@ public class Engine { internal DBreezeEngine DBEngine = null; + public Func Serialize = null; + public Func Deserialize = null; + /// /// /// /// - /// can be null - /// - public Engine(DBreeze.DBreezeEngine dbEngine, ILogger logger) + /// + /// can be null then DBreeze embedded serializer will be used + /// can be null then DBreeze embedded deserializer will be used + public Engine(DBreeze.DBreezeEngine dbEngine, ILogger logger, Func byteArraySerializer = null, Func byteArrayDeSerializer = null) { if (logger == null) Logger.log = new LoggerWrapper(); @@ -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; } @@ -164,7 +184,7 @@ public byte[] SyncEntityStrategyV1(HttpCapsule capsIn, EntitySyncingBaseV1 //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(); ((ISyncEntity)newEntity).Id = row.InternalId; //just for a case @@ -204,7 +224,7 @@ public byte[] SyncEntityStrategyV1(HttpCapsule capsIn, EntitySyncingBaseV1 //Insert new //newEntity = row.SerializedObject.DeserializeProtobuf(); - newEntity = (T)DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator(row.SerializedObject, typeof(T)); + newEntity = (T)Deserialize(row.SerializedObject, typeof(T)); entitySync.ptrContent = null; diff --git a/SPEntitySyncing/SyncStrategyV1.cs b/SPEntitySyncing/SyncStrategyV1.cs index 0e2d7d6..0558771 100644 --- a/SPEntitySyncing/SyncStrategyV1.cs +++ b/SPEntitySyncing/SyncStrategyV1.cs @@ -19,7 +19,7 @@ public class SyncStrategyV1 /// Where must be stored index 200 /// entity.Id and entity.SyncTimestamp must be filled up /// pointer to the entity content (16 bytes) gathered with DBreeze InsertDataBlockWithFixedAddress - /// old instance of the entity from DB + /// old instance of the entity from DB !!!MUST!!! be supplied when update or null when new entity public static void InsertIndex4Sync(DBreeze.Transactions.Transaction tran, string table, ISyncEntity entity, byte[] ptrEntityContent, ISyncEntity oldEntity) { if (oldEntity == null) diff --git a/SPEntitySyncingClient/Engine.cs b/SPEntitySyncingClient/Engine.cs index ec0a102..43ec41a 100644 --- a/SPEntitySyncingClient/Engine.cs +++ b/SPEntitySyncingClient/Engine.cs @@ -39,6 +39,9 @@ public class Engine internal DBreezeEngine DBEngine = null; + public Func Serialize = null; + public Func Deserialize = null; + /// /// Url / payload /// @@ -59,7 +62,10 @@ public class Engine /// /// /// can be null - public Engine(DBreeze.DBreezeEngine dbEngine, Func> serverSender, Action resetWebSession, Action syncIsFinishing, ILogger logger) + /// can be null then DBreeze embedded serializer will be used + /// can be null then DBreeze embedded deserializer will be used + public Engine(DBreeze.DBreezeEngine dbEngine, Func> serverSender, Action resetWebSession, Action syncIsFinishing, ILogger logger, + Func byteArraySerializer = null, Func byteArrayDeSerializer = null) { if (logger == null) Logger.log = new LoggerWrapper(); @@ -72,11 +78,28 @@ public Engine(DBreeze.DBreezeEngine dbEngine, Func> 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; diff --git a/SPEntitySyncingClient/SyncStrategyV1.cs b/SPEntitySyncingClient/SyncStrategyV1.cs index fe25496..45f4406 100644 --- a/SPEntitySyncingClient/SyncStrategyV1.cs +++ b/SPEntitySyncingClient/SyncStrategyV1.cs @@ -29,7 +29,7 @@ public class SyncStrategyV1 : SyncStrategy /// Where must be stored index 200 /// entity.Id and entity.SyncTimestamp must be filled up /// pointer to the entity content (16 bytes) gathered with DBreeze InsertDataBlockWithFixedAddress - /// old instance of the entity from DB + /// old instance of the entity from DB !!!MUST!!! be supplied when update or null when new entity public static void InsertIndex4Sync(DBreeze.Transactions.Transaction tran, string table, T entity, byte[] ptrEntityContent, T oldEntity) { ISyncEntity ent = ((ISyncEntity)entity); @@ -150,15 +150,15 @@ public override bool UpdateLocalDatabase(ExchangeData exData) //(List(); - entity = (T)DBreeze.Utils.CustomSerializator.ByteArrayDeSerializator(opr.SerializedObject, typeof(T)); + entity = (T)SyncEngine.Deserialize(opr.SerializedObject, typeof(T)); if (((ISyncEntity)localEntity).SyncTimestamp < opr.SyncTimestamp) { @@ -199,7 +199,7 @@ public override bool UpdateLocalDatabase(ExchangeData exData) //(List(); - 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)); diff --git a/_Deployment/EntitySyncing.nuspec b/_Deployment/EntitySyncing.nuspec index 30a7988..ebe2026 100644 --- a/_Deployment/EntitySyncing.nuspec +++ b/_Deployment/EntitySyncing.nuspec @@ -2,7 +2,7 @@ EntitySyncingServer - 1.005.2020.1209 + 1.006.2020.1209 EntitySyncingServer hhblaze@gmail.com https://tiesky.com diff --git a/_Deployment/EntitySyncingClient.1.5.2020.1209.nupkg b/_Deployment/EntitySyncingClient.1.5.2020.1209.nupkg deleted file mode 100644 index 96d6b49..0000000 Binary files a/_Deployment/EntitySyncingClient.1.5.2020.1209.nupkg and /dev/null differ diff --git a/_Deployment/EntitySyncingClient.1.6.2020.1209.nupkg b/_Deployment/EntitySyncingClient.1.6.2020.1209.nupkg new file mode 100644 index 0000000..ef47b21 Binary files /dev/null and b/_Deployment/EntitySyncingClient.1.6.2020.1209.nupkg differ diff --git a/_Deployment/EntitySyncingClient.nuspec b/_Deployment/EntitySyncingClient.nuspec index 939f699..3c8aacb 100644 --- a/_Deployment/EntitySyncingClient.nuspec +++ b/_Deployment/EntitySyncingClient.nuspec @@ -2,7 +2,7 @@ EntitySyncingClient - 1.005.2020.1209 + 1.006.2020.1209 EntitySyncingClient hhblaze@gmail.com https://tiesky.com diff --git a/_Deployment/EntitySyncingServer.1.5.2020.1209.nupkg b/_Deployment/EntitySyncingServer.1.5.2020.1209.nupkg deleted file mode 100644 index 7a503e0..0000000 Binary files a/_Deployment/EntitySyncingServer.1.5.2020.1209.nupkg and /dev/null differ diff --git a/_Deployment/EntitySyncingServer.1.6.2020.1209.nupkg b/_Deployment/EntitySyncingServer.1.6.2020.1209.nupkg new file mode 100644 index 0000000..9865274 Binary files /dev/null and b/_Deployment/EntitySyncingServer.1.6.2020.1209.nupkg differ