예제 #1
0
        private EntityChange FindExisting(EntityChange entity)
        {
            var command = _entitySerialiazer.FindExisting(_datastore, entity);
            var result  = _datastore.ExecuteReader(command, _entitySerialiazer).FirstOrDefault();

            return(result);
        }
예제 #2
0
        protected bool Equals(EntityChange other)
        {
            if (other == null)
            {
                return(false);
            }

            return(string.Equals(EntityName, other.EntityName) &&
                   Fields.IsEquals(other.Fields));
        }
예제 #3
0
        public static EntityChange Create(IEntityInfo entityInfo, IEntity entity)
        {
            var result = new EntityChange(entityInfo);

            foreach (var field in entityInfo.Fields)
            {
                var entityField = new EntityField(field.FieldName, field.GetEntityValue(entity), field);
                result.Fields.Add(entityField);
            }
            return(result);
        }
예제 #4
0
        public bool IsSameEntity(EntityChange entityChange)
        {
            if (entityChange == null)
            {
                return(false);
            }

            var primary      = GetPrimaryField();
            var otherPrimary = entityChange.GetPrimaryField();

            return(primary.GetFieldValue().Equals(otherPrimary.GetFieldValue()));
        }
예제 #5
0
        private EntityChange FindDeleted(EntityChange entity)
        {
            if (_entityTombstoneSerialiazer == null)
            {
                return(null);
            }

            var command = _entityTombstoneSerialiazer.FindExisting(_datastore, entity);
            var result  = _datastore.ExecuteReader(command, _entityTombstoneSerialiazer).FirstOrDefault();

            return(result);
        }
예제 #6
0
        private void ApplyUpdateWhenExistInLocal(IEntityConflict entityConflict, EntityChange existing, ISyncableEntity entity,
                                                 EntityChange row)
        {
            if (HasChangedOnBothSide(existing, entity))
            {
                entityConflict.OnApplyUpdateExistingUpdatedToo(existing, row);
                return;
            }

            try
            {
                row.ApplyUpdate(_datastore, _entitySerialiazer);
            }
            catch
            {
                entityConflict.OnApplyUpdate(existing, row);
            }
        }
예제 #7
0
        private void ApplyInsertWhenNoExistInLocal(IEntityConflict entityConflict, EntityChange row)
        {
            var deleted = FindDeleted(row);

            if (deleted != null)
            {
                entityConflict.OnApplyInsertDeletedOnRemote(row);
                return;
            }

            try
            {
                row.ApplyInsert(_datastore, _entitySerialiazer);
            }
            catch
            {
                entityConflict.OnApplyInsert(null, row);
            }
        }
예제 #8
0
        private void ApplyDeletetWhenExistInLocal(IEntityConflict entityConflict, EntityChange existing, ISyncableEntity entity,
                                                  EntityChange row)
        {
            if (HasInsertedOnTarget(existing, entity))
            {
                entityConflict.OnApplyDeleteExistingInserted(existing);
                return;
            }

            if (HasChangedOnBothSide(existing, entity))
            {
                entityConflict.OnApplyDeleteExistingUpdated(existing);
                return;
            }

            try
            {
                row.ApplyDelete(_datastore, EntityName, _entitySerialiazer);
            }
            catch
            {
                entityConflict.OnApplyDelete(existing, row);
            }
        }
예제 #9
0
 private bool HasChangedOnBothSide(EntityChange existing, ISyncableEntity entity)
 {
     return(existing.HasChangedInSession(entity.UpdateTrackingColumn, _syncSession) ||
            existing.HasChangedInSession(entity.LastSyncTrackingColumn, _syncSession));
 }
예제 #10
0
 private bool HasInsertedOnTarget(EntityChange existing, ISyncableEntity entity)
 {
     return(existing.HasChangedInSession(entity.CreationTrackingColumn, _syncSession));
 }
예제 #11
0
 private bool IsNotUpdated(EntityChange entityChange)
 {
     return(Update.FirstOrDefault(_ => _.IsSameEntity(entityChange)) == null);
 }