/// <inheritdoc /> public IEnumerable <TResource> BeforeDelete <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.BeforeDelete, resources, out var container, out var node)) { var relationships = node.RelationshipsToNextLayer.Select(p => p.Attribute).ToArray(); var targetResources = LoadDbValues(typeof(TResource), (IEnumerable <TResource>)node.UniqueResources, ResourceHook.BeforeDelete, relationships) ?? node.UniqueResources; var affected = new ResourceHashSet <TResource>(targetResources, node.LeftsToNextLayer()); IEnumerable <TResource> updated = container.BeforeDelete(affected, pipeline); node.UpdateUnique(updated); node.Reassign(_resourceFactory, 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 (var entry in node.LeftsToNextLayerByRelationships()) { var rightType = entry.Key; var implicitTargets = entry.Value; FireForAffectedImplicits(rightType, implicitTargets, pipeline); } return(resources); }
/// <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); }
/// <inheritdoc /> public IEnumerable <TResource> BeforeCreate <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.BeforeCreate, resources, out var container, out var node)) { var affected = new ResourceHashSet <TResource>((HashSet <TResource>)node.UniqueResources, node.LeftsToNextLayer()); IEnumerable <TResource> updated = container.BeforeCreate(affected, pipeline); node.UpdateUnique(updated); node.Reassign(_resourceFactory, resources); } FireNestedBeforeUpdateHooks(pipeline, _traversalHelper.CreateNextLayer(node)); return(resources); }
/// <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); }
public void ResourceHashSet_GetByRelationships() { // Arrange ResourceHashSet <Dummy> resources = new ResourceHashSet <Dummy>(_allResources, _relationships); // Act Dictionary <RelationshipAttribute, HashSet <Dummy> > toOnes = resources.GetByRelationship <ToOne>(); Dictionary <RelationshipAttribute, HashSet <Dummy> > toManies = resources.GetByRelationship <ToMany>(); Dictionary <RelationshipAttribute, HashSet <Dummy> > notTargeted = resources.GetByRelationship <NotTargeted>(); Dictionary <RelationshipAttribute, HashSet <Dummy> > allRelationships = resources.AffectedRelationships; // Assert AssertRelationshipDictionaryGetters(allRelationships, toOnes, toManies, notTargeted); var allResourcesWithAffectedRelationships = allRelationships.SelectMany(kvp => kvp.Value).ToList(); _noRelationshipsResources.ToList().ForEach(e => { Assert.DoesNotContain(e, allResourcesWithAffectedRelationships); }); }