public async Task Execute(IEnumerable <CommitContext> context, Next <IEnumerable <CommitContext> > next)
        {
            bool AddOrRemove(CommitContext commitContext) => commitContext.ActionType != ActionType.Update;

            bool UpdateHasChanges(CommitContext commitContext) => commitContext.ActionType == ActionType.Update &&
            _tracking.HasChanges(commitContext.Entity);

            var toCommit = context
                           .Where(x => AddOrRemove(x) || UpdateHasChanges(x)).ToList();


            await next(toCommit);


            foreach (var item in toCommit)
            {
                switch (item.ActionType)
                {
                case ActionType.Add:
                    _tracking.TrackInstance(item.Entity);
                    break;

                case ActionType.Update:
                    _tracking.Reset(item.Entity);
                    break;

                case ActionType.Delete:
                    _tracking.CeaseTracking(item.Entity);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <LoadContext> > Execute(QueryContext context,
                                                               Next <QueryContext, IEnumerable <LoadContext> > next)
        {
            var items = (await next(context)).ToList();

            foreach (var item in items)
            {
                if (item.LoadedFromCache)
                {
                    continue;
                }

                _tracking.TrackInstance(item.Entity);
            }

            return(items);
        }
Beispiel #3
0
        public async Task Execute(IEnumerable <T> context, Next <IEnumerable <T> > next)
        {
            var items = context.ToList();

            await next(items);

            foreach (var item in items)
            {
                if (item.LoadedFromCache)
                {
                    continue;
                }
                if (item.Entity == null)
                {
                    continue;
                }
                _tracking.TrackInstance(item.Entity);
            }
        }
Beispiel #4
0
        public virtual void Attach <T>(T instance) where T : class
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
            //allows for attaching exiting objects to this session!
            //(issue could arise with the rev)
            var value = _idAccessor.GetId(instance);
            var key   = _idManager.GetFromId(typeof(T), value);
            var entry = new SessionEntry()
            {
                Action   = ActionType.Update,
                Instance = _tracking.TrackInstance(instance),
                Key      = key
            };


            _sessionCache.Attach(entry);
        }