Ejemplo n.º 1
0
        private (IModelGraph, ImmutableDictionary <object, IModelNode>) UpdateNodeCore(
            [NotNull] IModelNode updatedNode,
            [NotNull] IModelGraph modelGraph,
            [NotNull] ImmutableDictionary <object, IModelNode> payloadToModelNodeMap,
            [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
        {
            var oldNode = GetNode(updatedNode.Id);

            itemEvents.Add(new ModelNodeUpdatedEvent(oldNode, updatedNode));

            if (oldNode.Payload != null)
            {
                payloadToModelNodeMap = payloadToModelNodeMap.Remove(oldNode.Payload);
            }

            if (updatedNode.Payload != null)
            {
                payloadToModelNodeMap = payloadToModelNodeMap.Add(updatedNode.Payload, updatedNode);
            }

            return(
                modelGraph.UpdateVertex(updatedNode),
                payloadToModelNodeMap
                );
        }
Ejemplo n.º 2
0
 private static IModelGraph AddRelationshipCore(
     [NotNull] IModelRelationship relationship,
     [NotNull] IModelGraph modelGraph,
     [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
 {
     itemEvents.Add(new ModelRelationshipAddedEvent(relationship));
     return(modelGraph.AddEdge(relationship));
 }
Ejemplo n.º 3
0
 private static IModelGraph AddNodeCore(
     [NotNull] IModelNode newNode,
     [NotNull] IModelGraph modelGraph,
     [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
 {
     itemEvents.Add(new ModelNodeAddedEvent(newNode));
     return(modelGraph.AddVertex(newNode));
 }
Ejemplo n.º 4
0
        private IModelGraph RemoveRelationshipCore(
            ModelRelationshipId relationshipId,
            [NotNull] IModelGraph modelGraph,
            [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
        {
            var oldRelationship = GetRelationship(relationshipId);

            itemEvents.Add(new ModelRelationshipRemovedEvent(oldRelationship));
            return(modelGraph.RemoveEdge(relationshipId));
        }
Ejemplo n.º 5
0
        private IModelGraph RemoveNodeCore(
            ModelNodeId nodeId,
            [NotNull] IModelGraph modelGraph,
            [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
        {
            var oldNode = GetNode(nodeId);

            itemEvents.Add(new ModelNodeRemovedEvent(oldNode));
            return(modelGraph.RemoveVertex(nodeId));
        }
Ejemplo n.º 6
0
 private IModel CreateInstance(
     IModelGraph graph,
     [NotNull] ImmutableDictionary <object, IModelNode> payloadToModelNodeMap,
     [NotNull] ImmutableDictionary <object, IModelRelationship> payloadToModelRelationshipMap)
 => new Model(
     graph,
     payloadToModelNodeMap,
     payloadToModelRelationshipMap,
     _sequenceProvider,
     _modelRuleProviders,
     _nodePayloadEqualityComparer,
     _relationshipPayloadEqualityComparer);
Ejemplo n.º 7
0
        private static (IModelGraph, ImmutableDictionary <object, IModelRelationship> payloadToModelRelationshipMap) AddRelationshipCore(
            [NotNull] IModelRelationship relationship,
            [NotNull] IModelGraph modelGraph,
            [NotNull] ImmutableDictionary <object, IModelRelationship> payloadToModelRelationshipMap,
            [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
        {
            itemEvents.Add(new ModelRelationshipAddedEvent(relationship));

            return(
                modelGraph.AddEdge(relationship),
                relationship.Payload == null
                    ? payloadToModelRelationshipMap
                    : payloadToModelRelationshipMap.Add(relationship.Payload, relationship)
                );
        }
Ejemplo n.º 8
0
        private static (IModelGraph, ImmutableDictionary <object, IModelNode>) AddNodeCore(
            [NotNull] IModelNode newNode,
            [NotNull] IModelGraph modelGraph,
            [NotNull] ImmutableDictionary <object, IModelNode> payloadToModelNodeMap,
            [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
        {
            itemEvents.Add(new ModelNodeAddedEvent(newNode));

            return(
                modelGraph.AddVertex(newNode),
                newNode.Payload == null
                    ? payloadToModelNodeMap
                    : payloadToModelNodeMap.Add(newNode.Payload, newNode)
                );
        }
Ejemplo n.º 9
0
        private (IModelGraph, ImmutableDictionary <object, IModelRelationship>) RemoveRelationshipCore(
            ModelRelationshipId relationshipId,
            [NotNull] IModelGraph modelGraph,
            [NotNull] ImmutableDictionary <object, IModelRelationship> payloadToModelRelationshipMap,
            [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
        {
            var oldRelationship = GetRelationship(relationshipId);

            itemEvents.Add(new ModelRelationshipRemovedEvent(oldRelationship));

            return(
                modelGraph.RemoveEdge(relationshipId),
                oldRelationship.Payload == null
                    ? payloadToModelRelationshipMap
                    : payloadToModelRelationshipMap.Remove(oldRelationship.Payload)
                );
        }
Ejemplo n.º 10
0
        private (IModelGraph, ImmutableDictionary <object, IModelNode>) RemoveNodeCore(
            ModelNodeId nodeId,
            [NotNull] IModelGraph modelGraph,
            [NotNull] ImmutableDictionary <object, IModelNode> payloadToModelNodeMap,
            [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
        {
            var oldNode = GetNode(nodeId);

            itemEvents.Add(new ModelNodeRemovedEvent(oldNode));

            return(
                modelGraph.RemoveVertex(nodeId),
                oldNode.Payload == null
                    ? payloadToModelNodeMap
                    : payloadToModelNodeMap.Remove(oldNode.Payload)
                );
        }
Ejemplo n.º 11
0
 private Model(
     IModelGraph graph,
     [NotNull] ImmutableDictionary <object, IModelNode> payloadToModelNodeMap,
     [NotNull] ImmutableDictionary <object, IModelRelationship> payloadToModelRelationshipMap,
     [NotNull] ISequenceProvider sequenceProvider,
     [CanBeNull] IEnumerable <IModelRuleProvider> modelRuleProviders,
     [CanBeNull] IEqualityComparer <object> nodePayloadEqualityComparer,
     [CanBeNull] IEqualityComparer <object> relationshipPayloadEqualityComparer)
 {
     _graph = graph;
     _payloadToModelNodeMap         = payloadToModelNodeMap;
     _payloadToModelRelationshipMap = payloadToModelRelationshipMap;
     _sequenceProvider                    = sequenceProvider;
     _modelRuleProviders                  = modelRuleProviders;
     _nodePayloadEqualityComparer         = nodePayloadEqualityComparer;
     _relationshipPayloadEqualityComparer = relationshipPayloadEqualityComparer;
 }
Ejemplo n.º 12
0
 private static IModel CreateInstance(IModelGraph graph) => new Model(graph);
Ejemplo n.º 13
0
 private Model(IModelGraph graph)
 {
     _graph = graph;
 }
Ejemplo n.º 14
0
 private Model(IModelGraph graph, [NotNull] params IModelRuleProvider[] modelRuleProviders)
 {
     _graph = graph;
     _modelRuleProviders = modelRuleProviders;
 }
Ejemplo n.º 15
0
 private IModel CreateInstance(IModelGraph graph) => new Model(graph, _modelRuleProviders);