Ejemplo n.º 1
0
        private void PerformDataOperation(StateChange <TEntityA, TEntityB> stateChange)
        {
            TimedAction(() =>
            {
                Log.Debug($"Performing Data Operation ({stateChange.Operation}) on Entity: {stateChange}");

                switch (stateChange.Operation)
                {
                case OperationEnum.Insert:
                    stateChange.TargetKey = DataTarget.Insert(stateChange.SourceItem);
                    Log.Debug(
                        $"INSERT: SourceKey = '{stateChange.SourceKey}', TargetKey = '{stateChange.TargetKey}'");
                    ExecuteNestedTasks?.Invoke(stateChange.SourceKey, stateChange.TargetKey, stateChange.SourceItem,
                                               stateChange.TargetItem, stateChange);
                    break;

                case OperationEnum.Update:
                    stateChange.TargetKey = DataTarget.Update(stateChange.SourceItem, stateChange.TargetItem);
                    Log.Debug(
                        $"UPDATE: SourceKey = '{stateChange.SourceKey}', TargetKey = '{stateChange.TargetKey}'");
                    ExecuteNestedTasks?.Invoke(stateChange.SourceKey, stateChange.TargetKey, stateChange.SourceItem,
                                               stateChange.TargetItem, stateChange);
                    break;

                case OperationEnum.Delete:
                    Log.Debug(
                        $"DELETE: SourceKey = '{stateChange.SourceKey}', TargetKey = '{stateChange.TargetKey}'");
                    ExecuteNestedTasks?.Invoke(stateChange.SourceKey, stateChange.TargetKey, stateChange.SourceItem,
                                               stateChange.TargetItem, stateChange);
                    DataTarget.Delete(stateChange.TargetItem);
                    stateChange.TargetKey = null;
                    break;

                case OperationEnum.None:
                    break;
                }
            }, nameof(PerformDataOperation));
        }