コード例 #1
0
        /// <inheritdoc />
        public IEnumerable <TResource> BeforeDelete <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline)
            where TResource : class, IIdentifiable
        {
            GetHookResult <TResource> result = GetHook(ResourceHook.BeforeDelete, resources);

            if (result.Succeeded)
            {
                RelationshipAttribute[] relationships = result.Node.RelationshipsToNextLayer.Select(proxy => proxy.Attribute).ToArray();

                IEnumerable targetResources =
                    LoadDbValues(typeof(TResource), (IEnumerable <TResource>)result.Node.UniqueResources, ResourceHook.BeforeDelete, relationships) ??
                    result.Node.UniqueResources;

                var affected = new ResourceHashSet <TResource>(targetResources, result.Node.LeftsToNextLayer());

                IEnumerable <TResource> updated = result.Container.BeforeDelete(affected, pipeline);
                result.Node.UpdateUnique(updated);
                result.Node.Reassign(resources);
            }

            // If we're deleting an article, we're implicitly affected any owners related to it.
            // Here we're loading all relations onto the to-be-deleted article
            // if for that relation the BeforeImplicitUpdateHook is implemented,
            // and this hook is then executed
            foreach (KeyValuePair <Type, Dictionary <RelationshipAttribute, IEnumerable> > entry in result.Node.LeftsToNextLayerByRelationships())
            {
                Type rightType = entry.Key;
                Dictionary <RelationshipAttribute, IEnumerable> implicitTargets = entry.Value;
                FireForAffectedImplicits(rightType, implicitTargets, pipeline);
            }

            return(resources);
        }
コード例 #2
0
        /// <inheritdoc />
        public void AfterDelete <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline, bool succeeded)
            where TResource : class, IIdentifiable
        {
            GetHookResult <TResource> result = GetHook(ResourceHook.AfterDelete, resources);

            if (result.Succeeded)
            {
                result.Container.AfterDelete((HashSet <TResource>)result.Node.UniqueResources, pipeline, succeeded);
            }
        }
コード例 #3
0
        /// <inheritdoc />
        public void AfterUpdate <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline)
            where TResource : class, IIdentifiable
        {
            GetHookResult <TResource> result = GetHook(ResourceHook.AfterUpdate, resources);

            if (result.Succeeded)
            {
                result.Container.AfterUpdate((HashSet <TResource>)result.Node.UniqueResources, pipeline);
            }

            TraverseNodesInLayer(_nodeNavigator.CreateNextLayer(result.Node), ResourceHook.AfterUpdateRelationship,
                                 (nextContainer, nextNode) => FireAfterUpdateRelationship(nextContainer, nextNode, pipeline));
        }
コード例 #4
0
        /// <inheritdoc />
        public void AfterRead <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline)
            where TResource : class, IIdentifiable
        {
            GetHookResult <TResource> result = GetHook(ResourceHook.AfterRead, resources);

            if (result.Succeeded)
            {
                result.Container.AfterRead((HashSet <TResource>)result.Node.UniqueResources, pipeline);
            }

            TraverseNodesInLayer(_nodeNavigator.CreateNextLayer(result.Node), ResourceHook.AfterRead, (nextContainer, nextNode) =>
            {
                CallHook(nextContainer, ResourceHook.AfterRead, ArrayFactory.Create <object>(nextNode.UniqueResources, pipeline, true));
            });
        }
コード例 #5
0
        /// <inheritdoc />
        public IEnumerable <TResource> BeforeCreate <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline)
            where TResource : class, IIdentifiable
        {
            GetHookResult <TResource> result = GetHook(ResourceHook.BeforeCreate, resources);

            if (result.Succeeded)
            {
                var affected = new ResourceHashSet <TResource>((HashSet <TResource>)result.Node.UniqueResources, result.Node.LeftsToNextLayer());
                IEnumerable <TResource> updated = result.Container.BeforeCreate(affected, pipeline);
                result.Node.UpdateUnique(updated);
                result.Node.Reassign(resources);
            }

            FireNestedBeforeUpdateHooks(pipeline, _nodeNavigator.CreateNextLayer(result.Node));
            return(resources);
        }
コード例 #6
0
        /// <inheritdoc />
        public IEnumerable <TResource> BeforeUpdate <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline)
            where TResource : class, IIdentifiable
        {
            GetHookResult <TResource> result = GetHook(ResourceHook.BeforeUpdate, resources);

            if (result.Succeeded)
            {
                RelationshipAttribute[] relationships = result.Node.RelationshipsToNextLayer.Select(proxy => proxy.Attribute).ToArray();

                IEnumerable dbValues = LoadDbValues(typeof(TResource), (IEnumerable <TResource>)result.Node.UniqueResources, ResourceHook.BeforeUpdate,
                                                    relationships);

                var diff = new DiffableResourceHashSet <TResource>(result.Node.UniqueResources, dbValues, result.Node.LeftsToNextLayer(), _targetedFields);
                IEnumerable <TResource> updated = result.Container.BeforeUpdate(diff, pipeline);
                result.Node.UpdateUnique(updated);
                result.Node.Reassign(resources);
            }

            FireNestedBeforeUpdateHooks(pipeline, _nodeNavigator.CreateNextLayer(result.Node));
            return(resources);
        }
コード例 #7
0
        /// <inheritdoc />
        public IEnumerable <TResource> OnReturn <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline)
            where TResource : class, IIdentifiable
        {
            GetHookResult <TResource> result = GetHook(ResourceHook.OnReturn, resources);

            if (result.Succeeded)
            {
                IEnumerable <TResource> updated = result.Container.OnReturn((HashSet <TResource>)result.Node.UniqueResources, pipeline);
                ValidateHookResponse(updated);
                result.Node.UpdateUnique(updated);
                result.Node.Reassign(resources);
            }

            TraverseNodesInLayer(_nodeNavigator.CreateNextLayer(result.Node), ResourceHook.OnReturn, (nextContainer, nextNode) =>
            {
                IEnumerable filteredUniqueSet = CallHook(nextContainer, ResourceHook.OnReturn, ArrayFactory.Create <object>(nextNode.UniqueResources, pipeline));
                nextNode.UpdateUnique(filteredUniqueSet);
                nextNode.Reassign();
            });

            return(resources);
        }