private void InternalAcceptChanges(IChangeTrackable changeTrackable) { if (changeTrackable == null) { return; } var type = changeTrackable.GetType(); foreach (var propertyManagerInfo in _propertyManager.GetInfos(type)) { AcceptChangeableValue(propertyManagerInfo, changeTrackable); } var hashCode = changeTrackable.GetHashCode(); if (IsNew(changeTrackable)) { _repository.Add(changeTrackable); _newChangeables.Remove(hashCode); } else if (IsChanged(changeTrackable)) { _repository.Update(changeTrackable); _changedChangeables.Remove(hashCode); } }
/// <summary> /// Attaches the specified changeTrackable. /// </summary> /// <param name="changeTrackable">The changeTrackable.</param> private void InternalAttach(IChangeTrackable changeTrackable) { if ((changeTrackable == null) || IsAttached(changeTrackable)) { return; } foreach (var changeablePropertyInfo in _propertyManager.GetInfos(changeTrackable)) { AttachChangeableValue(changeablePropertyInfo, changeTrackable); } changeTrackable.PropertyChanged += ChangeablePropertyChanged; _changeables.Add(changeTrackable.GetHashCode()); _newChangeables.Add(changeTrackable.GetHashCode()); }
private void CheckDetached(IChangeTrackable changeTrackable) { if (changeTrackable == null) { throw new ArgumentNullException("changeTrackable"); } if (_changeables.Contains(changeTrackable.GetHashCode())) { throw new ArgumentException("Instance already attached!"); } }
private void InternalRollback(IChangeTrackable changeTrackable) { if (ChangeableState(changeTrackable) != ChangeState.Changed) { return; } var type = changeTrackable.GetType(); foreach (var keyValuePair in _changedChangeables[changeTrackable.GetHashCode()].AllChanges) { _propertyManager.GetInfo(type, keyValuePair.Key).SetValue(changeTrackable, RollbackValidObject(keyValuePair.Value.OldValue)); } InternalAcceptChanges(changeTrackable); }
private bool IsDeleted(IChangeTrackable changeTrackable) { return(_deletedChangeables.Contains(changeTrackable.GetHashCode())); }
private bool IsChanged(IChangeTrackable changeTrackable) { return(_changedChangeables.ContainsKey(changeTrackable.GetHashCode())); }
private bool IsNew(IChangeTrackable changeTrackable) { return(_newChangeables.Contains(changeTrackable.GetHashCode())); }
private bool IsAttached(IChangeTrackable changeTrackable) { return(_changeables.Contains(changeTrackable.GetHashCode())); }