/// <summary> /// Returns the data instance that should be edited based on the given edit state and data /// type. /// </summary> private static Data.IData GetEditedData(IQueryableEntity entity, DataEditState editState, Type dataType) { var accessor = new DataAccessor(dataType); switch (editState) { case DataEditState.Current: return entity.Current(accessor); case DataEditState.Previous: return entity.Previous(accessor); } throw new InvalidOperationException("Unknown edit state"); }
/// <summary> /// Sets the editing state for the given data type in the given entity to the given value. /// </summary> private void SetEditState(IQueryableEntity entity, Type dataType, DataEditState value) { int entityId = ((IEntity)entity).UniqueId; HashSet<int> hashSet; if (_previous.TryGetValue(entityId, out hashSet) == false) { hashSet = new HashSet<int>(); _previous[entityId] = hashSet; } int dataId = new DataAccessor(dataType).Id; switch (value) { case DataEditState.Current: hashSet.Remove(dataId); break; case DataEditState.Previous: hashSet.Add(dataId); break; } }
/// <summary> /// Returns the data header that should be shown above the data type. /// </summary> private static string GetDataHeader(Type dataType, IQueryableEntity queryableEntity, DataEditState editState) { StringBuilder result = new StringBuilder(); result.Append(dataType.Name); if (queryableEntity is IEntity) { result.Append(editState == DataEditState.Current ? " (current)" : " (previous)"); IEntity entity = (IEntity)queryableEntity; DataAccessor accessor = new DataAccessor(dataType); if (entity.WasAdded(accessor)) { result.Append(" (added)"); } if (entity.WasModified(accessor)) { result.Append(" (modified)"); } if (entity.WasRemoved(accessor)) { result.Append(" (removed)"); } } return result.ToString(); }