private EntityChange FindExisting(EntityChange entity) { var command = _entitySerialiazer.FindExisting(_datastore, entity); var result = _datastore.ExecuteReader(command, _entitySerialiazer).FirstOrDefault(); return(result); }
protected bool Equals(EntityChange other) { if (other == null) { return(false); } return(string.Equals(EntityName, other.EntityName) && Fields.IsEquals(other.Fields)); }
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); }
public bool IsSameEntity(EntityChange entityChange) { if (entityChange == null) { return(false); } var primary = GetPrimaryField(); var otherPrimary = entityChange.GetPrimaryField(); return(primary.GetFieldValue().Equals(otherPrimary.GetFieldValue())); }
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); }
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); } }
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); } }
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); } }
private bool HasChangedOnBothSide(EntityChange existing, ISyncableEntity entity) { return(existing.HasChangedInSession(entity.UpdateTrackingColumn, _syncSession) || existing.HasChangedInSession(entity.LastSyncTrackingColumn, _syncSession)); }
private bool HasInsertedOnTarget(EntityChange existing, ISyncableEntity entity) { return(existing.HasChangedInSession(entity.CreationTrackingColumn, _syncSession)); }
private bool IsNotUpdated(EntityChange entityChange) { return(Update.FirstOrDefault(_ => _.IsSameEntity(entityChange)) == null); }