Exemple #1
0
        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);
            }
        }
Exemple #2
0
        /// <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());
        }
Exemple #3
0
 private void CheckDetached(IChangeTrackable changeTrackable)
 {
     if (changeTrackable == null)
     {
         throw new ArgumentNullException("changeTrackable");
     }
     if (_changeables.Contains(changeTrackable.GetHashCode()))
     {
         throw new ArgumentException("Instance already attached!");
     }
 }
Exemple #4
0
        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);
        }
Exemple #5
0
 private bool IsDeleted(IChangeTrackable changeTrackable)
 {
     return(_deletedChangeables.Contains(changeTrackable.GetHashCode()));
 }
Exemple #6
0
 private bool IsChanged(IChangeTrackable changeTrackable)
 {
     return(_changedChangeables.ContainsKey(changeTrackable.GetHashCode()));
 }
Exemple #7
0
 private bool IsNew(IChangeTrackable changeTrackable)
 {
     return(_newChangeables.Contains(changeTrackable.GetHashCode()));
 }
Exemple #8
0
 private bool IsAttached(IChangeTrackable changeTrackable)
 {
     return(_changeables.Contains(changeTrackable.GetHashCode()));
 }