Exemplo n.º 1
0
        public void ApplyChangeFromServer(ISyncEntity proxy)
        {
            Entity entity = null;

            foreach (var e in List)
            {
                if (e.ID == proxy.ID)
                {
                    entity = e;
                    break;
                }
            }

            if (entity != null)
            {
                if (proxy.IsDeleted)
                {
                    Delete(entity);
                }
                else
                {
                    Update(proxy, entity);
                }
            }
            else
            {
                Create(proxy);
            }
        }
Exemplo n.º 2
0
        public void SetClientEntitySynced(ISyncEntity entity, DateTime server_last_sync_date)
        {
            Entity e = null;
            foreach (var e_tmp in List)
            {
                if (e_tmp.ID == entity.ID)
                {
                    e = e_tmp;
                    break;
                }
            }

            if (e == null)
                return;

            if (e.IsDeleted)
            {
                List.Remove(e);
            }
                //check if entity was not modified localy while sending to server
            else if (e.ClientModifyDate == entity.ClientModifyDate)
            {
                e.ServerSyncDate = server_last_sync_date;
                e.IsModified = false;
            }
        }
Exemplo n.º 3
0
        public void SetClientEntitySynced(ISyncEntity entity, DateTime server_last_sync_date)
        {
            Entity e = null;

            foreach (var e_tmp in List)
            {
                if (e_tmp.ID == entity.ID)
                {
                    e = e_tmp;
                    break;
                }
            }

            if (e == null)
            {
                return;
            }

            if (e.IsDeleted)
            {
                List.Remove(e);
            }
            //check if entity was not modified localy while sending to server
            else if (e.ClientModifyDate == entity.ClientModifyDate)
            {
                e.ServerSyncDate = server_last_sync_date;
                e.IsModified     = false;
            }
        }
Exemplo n.º 4
0
        public void ApplyChangeFromServer(ISyncEntity proxy)
        {
            Entity entity = null;
            foreach (var e in List)
            {
                if (e.ID == proxy.ID)
                {
                    entity = e;
                    break;
                }
            }

            if (entity != null)
            {
                if (proxy.IsDeleted)
                {
                    Delete(entity);
                }
                else
                {
                    Update(proxy, entity);
                }
            }
            else
            {
                Create(proxy);
            }
        }
Exemplo n.º 5
0
        private void Update(ISyncEntity proxy, Entity entity)
        {
            if (entity.ClientModifyDate < proxy.ClientModifyDate)
            {
                entity.ClientModifyDate = proxy.ClientModifyDate;
                entity.ServerSyncDate   = proxy.ServerSyncDate;

                entity.Data = ((IEntity)proxy).Data;
            }
        }
Exemplo n.º 6
0
        private void Update(Entity entity, ISyncEntity proxy)
        {
            if (!entity.IsDeleted && entity.ClientModifyDate < proxy.ClientModifyDate)
            {
                entity.ClientModifyDate = proxy.ClientModifyDate;
                entity.ServerSyncDate   = DateTime.UtcNow;

                entity.Data = ((IEntity)proxy).Data;
            }
        }
Exemplo n.º 7
0
        private void Update(Entity entity, ISyncEntity proxy)
        {
            if (!entity.IsDeleted && entity.ClientModifyDate < proxy.ClientModifyDate)
            {
                entity.ClientModifyDate = proxy.ClientModifyDate;
                entity.ServerSyncDate = DateTime.UtcNow;

                entity.Data = ((IEntity)proxy).Data;
            }
        }
Exemplo n.º 8
0
        private Entity Create(ISyncEntity proxy)
        {
            var entity = new Entity(proxy.ID);
            entity.ClientModifyDate = proxy.ClientModifyDate;
            entity.ServerSyncDate = DateTime.UtcNow;

            entity.Data = ((IEntity)proxy).Data;

            List.Add(entity.ID, entity);
            return entity;
        }
Exemplo n.º 9
0
        private void Create(ISyncEntity proxy)
        {
            var entity = new Entity(proxy.ID);

            entity.ClientModifyDate = proxy.ClientModifyDate;
            entity.ServerSyncDate   = proxy.ServerSyncDate;

            entity.Data = ((IEntity)proxy).Data;

            List.Add(entity);
        }
Exemplo n.º 10
0
        private Entity Create(ISyncEntity proxy)
        {
            var entity = new Entity(proxy.ID);

            entity.ClientModifyDate = proxy.ClientModifyDate;
            entity.ServerSyncDate   = DateTime.UtcNow;

            entity.Data = ((IEntity)proxy).Data;

            List.Add(entity.ID, entity);
            return(entity);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Fills up index 200. Creation of transaction, synchronization of the table and transaction commit is outside of this function.
        /// Entity desired ID and SyncTimestamp must be specified
        /// </summary>
        /// <param name="tran"></param>
        /// <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 !!!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);

            if (oldEntity == null)
            {
                tran.Insert <byte[], byte[]>(table, 200.ToIndex(ent.Id), ptrEntityContent);
            }

            //Adding to value one byte indicating that this is a new entity
            tran.Insert <byte[], byte[]>(table, 201.ToIndex(ent.SyncTimestamp, ent.Id), (oldEntity == null) ? new byte[] { 1 } : null);
        }
Exemplo n.º 12
0
        public DateTime SendChangedToServer(ISyncEntity entity)
        {
            // Create server proxy from client entity
            var proxy = new ServerEntity()
            {
                ID = entity.ID,
                ClientModifyDate = entity.ClientModifyDate,
                IsDeleted        = entity.IsDeleted,
                Data             = ((Client.IEntity)entity).Data
            };

            return(Server.ServerImpl.Instance.SendChangedToServer(proxy));
        }
Exemplo n.º 13
0
        public DateTime SendChangedToServer(ISyncEntity entity)
        {
            // Create server proxy from client entity
            var proxy = new ServerEntity()
                {
                    ID = entity.ID,
                    ClientModifyDate = entity.ClientModifyDate,
                    IsDeleted = entity.IsDeleted,
                    Data = ((Client.IEntity)entity).Data
                };

            return Server.ServerImpl.Instance.SendChangedToServer(proxy);
        }
Exemplo n.º 14
0
            public void Synchronize()
            {
                EntityTypeEnum entityType = EntityTypeEnum.Hierarchy;

                var type = $@"teste.Sync{entityType.ToString()}";

                var coco = System.Reflection.Assembly.GetExecutingAssembly().FullName;
                var tata = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

                Entity = (ISyncEntity)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(type);
                var teste = GetInstance(type);


                Entity.SynchronizeAll();
            }
Exemplo n.º 15
0
 public DateTime SendChangedToServer(ISyncEntity proxy)
 {
     Entity entity = null;
     if (List.ContainsKey(proxy.ID))
     {
         entity = List[proxy.ID];
         if (proxy.IsDeleted)
             Delete(entity, proxy);
         else
             Update(entity, proxy);
     }
     else
     {
         entity = Create(proxy);
     }
     return entity.ServerSyncDate;
 }
Exemplo n.º 16
0
        public DateTime SendChangedToServer(ISyncEntity proxy)
        {
            Entity entity = null;

            if (List.ContainsKey(proxy.ID))
            {
                entity = List[proxy.ID];
                if (proxy.IsDeleted)
                {
                    Delete(entity, proxy);
                }
                else
                {
                    Update(entity, proxy);
                }
            }
            else
            {
                entity = Create(proxy);
            }
            return(entity.ServerSyncDate);
        }
Exemplo n.º 17
0
 private void Delete(Entity entity, ISyncEntity proxy)
 {
     entity.ClientModifyDate = proxy.ClientModifyDate;
     entity.ServerSyncDate = DateTime.UtcNow;
     entity.IsDeleted = true;
 }
Exemplo n.º 18
0
 private void Delete(Entity entity, ISyncEntity proxy)
 {
     entity.ClientModifyDate = proxy.ClientModifyDate;
     entity.ServerSyncDate   = DateTime.UtcNow;
     entity.IsDeleted        = true;
 }
Exemplo n.º 19
0
        private void Update(ISyncEntity proxy, Entity entity)
        {
            if (entity.ClientModifyDate < proxy.ClientModifyDate)
            {
                entity.ClientModifyDate = proxy.ClientModifyDate;
                entity.ServerSyncDate = proxy.ServerSyncDate;

                entity.Data = ((IEntity)proxy).Data;
            }
        }
Exemplo n.º 20
0
        private void Create(ISyncEntity proxy)
        {
            var entity = new Entity(proxy.ID);
            entity.ClientModifyDate = proxy.ClientModifyDate;
            entity.ServerSyncDate = proxy.ServerSyncDate;

            entity.Data = ((IEntity)proxy).Data;

            List.Add(entity);
        }
Exemplo n.º 21
0
	/// <summary>
	/// Unregisters the entity.
	/// </summary>
	/// <param name="entity">Entity.</param>
	public void 			UnregisterEntity(ISyncEntity entity)
	{
		m_dEntity.Remove(entity);
	}
Exemplo n.º 22
0
        /// <summary>
        /// Fills up index 200. Creation of transaction, synchronization of the table and transaction commit is outside of this function.
        /// Entity desired ID and SyncTimestamp must be specified
        /// </summary>
        /// <param name="tran"></param>
        /// <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 !!!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)
            {
                tran.Insert <byte[], byte[]>(table, 200.ToIndex(entity.Id), ptrEntityContent);
            }

            tran.Insert <byte[], byte[]>(table, 201.ToIndex(entity.SyncTimestamp, entity.Id), null);
        }
Exemplo n.º 23
0
	/// <summary>
	/// Registers the AO.
	/// </summary>
	/// <param name="aoi">Aoi.</param>
	public virtual void 	RegisterEntity(ISyncEntity entity)
	{
		// ref the aoi object
		m_dEntity.Add(entity);
	}