Пример #1
0
        private IEnumerable <Relation> PopulateIncomingRelations(
            Node source,
            IRelatableEntity destination,
            IRelatableEntity relatableEntitySource,
            AbstractLookupHelper lookupHelper,
            AbstractMappingEngine masterMapper)
        {
            foreach (var relation in source.IncomingRelations)
            {
                if (relation.StartNode.Id == relation.EndNode.Id)
                {
                    throw new InvalidOperationException("Cannot relate nodes to themselves");
                }

                var startRelatedEntity = relation.StartNode.Id == (Guid)destination.Id.Value
                                           ? destination
                                           : GetEntityFromNodeRelation(relation.StartNode, lookupHelper, masterMapper);

                yield return(new Relation(new RelationType(relation.NodeRelationType.Alias),
                                          startRelatedEntity,
                                          relatableEntitySource,
                                          relation.Ordinal,
                                          relation.NodeRelationTags.Select(nodeRelationTag => new RelationMetaDatum(nodeRelationTag.Name, nodeRelationTag.Value)).ToArray()));
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a deep copy of an object and adds the copied children to the repository. Does not add the root duplicate to the repo, the caller should do this.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="original">The original.</param>
        /// <param name="newParent">The new parent.</param>
        /// <param name="relationType">Type of the relation.</param>
        /// <param name="ordinal">The ordinal.</param>
        /// <param name="unitOfWork">The unit of work.</param>
        /// <param name="metaData">The meta data.</param>
        /// <returns></returns>
        public static T CreateDeepCopyToNewParentInRepo <T>(this T original, IRelatableEntity newParent, AbstractRelationType relationType, int ordinal, IGroupUnit <IProviderTypeFilter> unitOfWork, params RelationMetaDatum[] metaData)
            where T : TypedEntity, new()
        {
            Mandate.ParameterNotNull(newParent, "newParent");
            Mandate.ParameterNotNull(relationType, "relationType");

            var copy = CreateCopyAndEnlistChildren(original, unitOfWork);

            // We've been given a new parent so add that to the copied item's relatinproxies
            copy.RelationProxies.EnlistParent(newParent, relationType, ordinal, metaData);

            return(copy);
        }
Пример #3
0
        private int CheckCountIncomingRelations(Node source, IRelatableEntity destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            var output = 0;

            foreach (var relation in source.IncomingRelations)
            {
                if (relation.StartNode.Id == relation.EndNode.Id)
                {
                    throw new InvalidOperationException("Cannot relate nodes to themselves");
                }

                output++;
            }
            return(output);
        }
Пример #4
0
        private static void AssertIdsOfRelationProxiesForEntity(IRelatableEntity singleItem, Uri idRoot)
        {
            var message = "For: " + singleItem.Id.ToFriendlyString() + " (" + singleItem.GetType() + ")";
            var rpc     = singleItem.RelationProxies;

            Assert.True(rpc.IsConnected, message);
            Assert.True(rpc.Any(), message);

            foreach (RelationProxy proxy in rpc)
            {
                Assert.False(proxy.Item.SourceId.IsNullValueOrEmpty());
                Assert.False(proxy.Item.DestinationId.IsNullValueOrEmpty());
                AssertEntityIdIsRooted(idRoot, proxy.Item.SourceId);
                AssertEntityIdIsRooted(idRoot, proxy.Item.DestinationId);
            }

            Assert.That(rpc.Count(), Is.EqualTo(rpc.AllChildRelations().Count() + rpc.AllParentRelations().Count()), message);
        }
Пример #5
0
        private void OldMapRelations <T>(T source, IRelatableEntity destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
            where T : Node
        {
            //destination.Relations.Clear();
            //destination.Relations.LazyLookAhead = (axis) =>
            //{
            //    switch (axis)
            //    {
            //        case HierarchyScope.Children:
            //        case HierarchyScope.Descendents:
            //        case HierarchyScope.DescendentsOrSelf:
            //            return CheckCountOutgoingRelations(source, destination, lookupHelper, masterMapper);
            //        case HierarchyScope.AllOrNone:
            //            return
            //                CheckCountIncomingRelations(source, destination, lookupHelper, masterMapper) +
            //                CheckCountOutgoingRelations(source, destination, lookupHelper, masterMapper);
            //        case HierarchyScope.Ancestors:
            //        case HierarchyScope.AncestorsOrSelf:
            //            return CheckCountIncomingRelations(source, destination, lookupHelper, masterMapper);
            //    }
            //    return 0;
            //};

            //destination.Relations.LazyLoadFactory = (relatableEntitySource, axis) =>
            //{
            //    switch (axis)
            //    {
            //        case HierarchyScope.Children:
            //        case HierarchyScope.Descendents:
            //        case HierarchyScope.DescendentsOrSelf:
            //            return PopulateOutgoingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper);
            //        case HierarchyScope.AllOrNone:
            //            return PopulateIncomingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper)
            //                .Concat(PopulateOutgoingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper));
            //        case HierarchyScope.Ancestors:
            //        case HierarchyScope.AncestorsOrSelf:
            //            return PopulateIncomingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper);
            //    }
            //    return Enumerable.Empty<Relation>();
            //};
        }
 /// <summary>
 /// Enlists an <see cref="IRelatableEntity"/> in a <see cref="RelationProxy"/> as a child of the <see cref="IRelatableEntity"/> which owns this collection.
 /// </summary>
 /// <param name="child">The child.</param>
 /// <param name="type">The type.</param>
 /// <param name="metaData">The meta data.</param>
 public void EnlistChild(IRelatableEntity child, AbstractRelationType type, params RelationMetaDatum[] metaData)
 {
     EnlistChild(child, type, 0, metaData);
 }
        /// <summary>
        /// Enlists an <see cref="IRelatableEntity"/> in a <see cref="RelationProxy"/> as a child of the <see cref="IRelatableEntity"/> which owns this collection.
        /// </summary>
        /// <param name="child">The child.</param>
        /// <param name="type">The type.</param>
        /// <param name="ordinal">The ordinal.</param>
        /// <param name="metaData">The meta data.</param>
        public void EnlistChild(IRelatableEntity child, AbstractRelationType type, int ordinal, params RelationMetaDatum[] metaData)
        {
            var newRelation = new Relation(type, _collectionOwner, child, ordinal, metaData);

            AddToChildrenWithLock(new RelationProxy(newRelation, RelationProxyStatus.ManuallyAdded));
        }
 public HiveEntityPostActionEventArgs(IRelatableEntity entity, AbstractScopedCache scopedCache)
 {
     Entity      = entity;
     ScopedCache = scopedCache;
 }
 /// <summary>
 /// Enlists an <see cref="IRelatableEntity"/> in a <see cref="RelationProxy"/> as a parent of the <see cref="IRelatableEntity"/> which owns this collection.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="type">The type.</param>
 /// <param name="metaData">The meta data.</param>
 public void EnlistParent(IRelatableEntity parent, AbstractRelationType type, params RelationMetaDatum[] metaData)
 {
     EnlistParent(parent, type, 0, metaData);
 }
Пример #10
0
 private void ExecuteInCancellableTask(IRelatableEntity entity, string preActionTaskTrigger, string postActionTaskTrigger, Action execution)
 {
     FrameworkContext.TaskManager.ExecuteInCancellableTask(this, entity, preActionTaskTrigger, postActionTaskTrigger, execution, x => new HiveEntityPreActionEventArgs(x, UnitScopedCache), x => new HiveEntityPostActionEventArgs(x, UnitScopedCache), FrameworkContext);
 }
Пример #11
0
 public static IEnumerable <IRelationById> GetChildRelations(this ICoreReadonlyRelationsRepository session, IRelatableEntity parent, RelationType relationType = null)
 {
     Mandate.ParameterNotNull(parent, "parent");
     return(session.GetChildRelations(parent.Id, relationType));
 }
Пример #12
0
 private void MapRelations <T>(T source, IRelatableEntity destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
     where T : Node
 {
     /* Temp: do nothing */
     return;
 }
Пример #13
0
 public static IEnumerable <IRelationById> GetParentRelations(this ICoreReadonlyRelationsRepository session, IRelatableEntity child, RelationType relationType = null)
 {
     Mandate.ParameterNotNull(child, "child");
     return(session.GetParentRelations(child.Id, relationType));
 }
 public HiveEntityPreActionEventArgs(IRelatableEntity entity, AbstractScopedCache scopedCache)
     : base(scopedCache)
 {
     Entity = entity;
 }
Пример #15
0
        private static void AssertIdsOfRelationProxiesForEntity(IRelatableEntity singleItem, Uri idRoot)
        {
            var message = "For: " + singleItem.Id.ToFriendlyString() + " (" + singleItem.GetType() + ")";
            var rpc = singleItem.RelationProxies;
            Assert.True(rpc.IsConnected, message);
            Assert.True(rpc.Any(), message);

            foreach (RelationProxy proxy in rpc)
            {
                Assert.False(proxy.Item.SourceId.IsNullValueOrEmpty());
                Assert.False(proxy.Item.DestinationId.IsNullValueOrEmpty());
                AssertEntityIdIsRooted(idRoot, proxy.Item.SourceId);
                AssertEntityIdIsRooted(idRoot, proxy.Item.DestinationId);
            }

            Assert.That(rpc.Count(), Is.EqualTo(rpc.AllChildRelations().Count() + rpc.AllParentRelations().Count()), message);
        }
Пример #16
0
 public static IEnumerable <IReadonlyRelation <IRelatableEntity, IRelatableEntity> > GetLazyRelations <T>(this ICoreReadonlyRepository <T> session, IRelatableEntity source, Direction direction, RelationType relationType = null)
     where T : class, IRelatableEntity
 {
     Mandate.ParameterNotNull(source, "source");
     return(GetLazyRelations(session, source.Id, direction, relationType));
 }
Пример #17
0
 public static IEnumerable <IRelationById> GetRelations(this ICoreReadonlyRelationsRepository session, IRelatableEntity source, Direction direction, RelationType relationType = null)
 {
     Mandate.ParameterNotNull(source, "source");
     return(GetRelations(session, source.Id, direction, relationType));
 }
Пример #18
0
 public static IEnumerable <IRelationById> GetParentFileRelations(this IEntityRepositoryGroup <IFileStore> unit, IRelatableEntity source)
 {
     Mandate.ParameterNotNull(source, "source");
     return(unit.GetParentRelations(source.Id, FixedRelationTypes.DefaultRelationType));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RelationProxyCollection"/> class.
 /// </summary>
 /// <param name="collectionOwner">The collection owner.</param>
 public RelationProxyCollection(IRelatableEntity collectionOwner)
 {
     _collectionOwner = collectionOwner;
 }
Пример #20
0
 public static void AddRelation(this ICoreRelationsRepository session, IRelatableEntity source, IRelatableEntity destination, AbstractRelationType relationType, int ordinal, params RelationMetaDatum[] metaData)
 {
     session.AddRelation(new Relation(relationType, source, destination, ordinal, metaData));
 }
        private static void MapRelations(Node enclosingNode, IRelatableEntity source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper)
        {
            /* Temporary: do nothing */

            return;
        }
Пример #22
0
 public static IEnumerable <IRelationById> GetAncestorRelations(this ICoreReadonlyRelationsRepository session, IRelatableEntity descendent, RelationType relationType = null)
 {
     Mandate.ParameterNotNull(descendent, "descendent");
     return(session.GetAncestorRelations(descendent.Id, relationType));
 }
 public HiveEntityPreActionEventArgs(IRelatableEntity entity, AbstractScopedCache scopedCache)
     : base(scopedCache)
 {
     Entity = entity;
 }
Пример #24
0
 public static IEnumerable <IRelationById> GetSiblingRelations(this ICoreReadonlyRelationsRepository session, IRelatableEntity sibling, RelationType relationType = null)
 {
     Mandate.ParameterNotNull(sibling, "sibling");
     return(GetSiblingRelations(session, sibling.Id, relationType));
 }
 public HiveEntityPostActionEventArgs(IRelatableEntity entity, AbstractScopedCache scopedCache)
 {
     Entity = entity;
     ScopedCache = scopedCache;
 }
Пример #26
0
 public static IEnumerable <IRelationById> GetDescendentRelations(this ICoreReadonlyRelationsRepository session, IRelatableEntity ancestor, RelationType relationType = null)
 {
     Mandate.ParameterNotNull(ancestor, "ancestor");
     return(session.GetDescendentRelations(ancestor.Id, relationType));
 }