Пример #1
0
        public ModelEvent AddRelationship(
            ModelNodeId sourceId,
            ModelNodeId targetId,
            ModelRelationshipStereotype stereotype,
            object payload = null)
        {
            if (payload != null && _payloadToModelRelationshipMap.ContainsKey(payload))
            {
                throw new Exception($"The model already contains a relationship with payload: {payload}");
            }

            var relationship = CreateRelationship(sourceId, targetId, stereotype, payload);

            if (!IsRelationshipValid(relationship))
            {
                throw new ArgumentException($"{relationship} is invalid.");
            }

            var itemEvents = new List <ModelItemEventBase>();

            var(newGraph, newPayloadToModelRelationshipMap) = AddRelationshipCore(
                relationship,
                _graph,
                _payloadToModelRelationshipMap,
                itemEvents);

            var newModel = CreateInstance(newGraph, _payloadToModelNodeMap, newPayloadToModelRelationshipMap);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #2
0
        public ModelEvent AddNode(
            string name,
            ModelNodeStereotype stereotype,
            object payload           = null,
            ModelNodeId?parentNodeId = null)
        {
            if (payload != null && _payloadToModelNodeMap.ContainsKey(payload))
            {
                throw new Exception($"The model already contains a node with payload: {payload}");
            }

            var itemEvents = new List <ModelItemEventBase>();

            var newNode = CreateNode(name, stereotype, payload);

            var(newGraph, newPayloadToModelNodeMap) = AddNodeCore(newNode, _graph, _payloadToModelNodeMap, itemEvents);

            var newPayloadToModelRelationshipMap = _payloadToModelRelationshipMap;

            if (parentNodeId.HasValue)
            {
                var containsRelationship = CreateRelationship(parentNodeId.Value, newNode.Id, ModelRelationshipStereotype.Containment, payload: null);
                (newGraph, newPayloadToModelRelationshipMap) = AddRelationshipCore(
                    containsRelationship,
                    newGraph,
                    newPayloadToModelRelationshipMap,
                    itemEvents);
            }

            var newModel = CreateInstance(newGraph, newPayloadToModelNodeMap, newPayloadToModelRelationshipMap);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #3
0
        public ModelEvent Clear()
        {
            var newModel = Create();

            // Shall we raise node and relationship removed events ?
            return(ModelEvent.Create(newModel));
        }
Пример #4
0
        public ModelEvent RemoveRelationship(ModelRelationshipId relationshipId)
        {
            var itemEvents = new List <ModelItemEventBase>();
            var newGraph   = RemoveRelationshipCore(relationshipId, _graph, itemEvents);

            var newModel = CreateInstance(newGraph);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #5
0
        public ModelEvent RemoveRelationship(ModelRelationshipId relationshipId)
        {
            var itemEvents = new List <ModelItemEventBase>();

            var(newGraph, newPayloadToModelRelationshipMap) = RemoveRelationshipCore(relationshipId, _graph, _payloadToModelRelationshipMap, itemEvents);

            var newModel = CreateInstance(newGraph, _payloadToModelNodeMap, newPayloadToModelRelationshipMap);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #6
0
        public ModelEvent UpdateNode(IModelNode updatedNode)
        {
            var itemEvents = new List <ModelItemEventBase>();

            var(newGraph, newPayloadToModelNodeMap) = UpdateNodeCore(updatedNode, _graph, _payloadToModelNodeMap, itemEvents);

            var newModel = CreateInstance(newGraph, newPayloadToModelNodeMap, _payloadToModelRelationshipMap);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #7
0
        public ModelEvent Clear()
        {
            var itemEvents = Relationships.Select(i => new ModelRelationshipRemovedEvent(i))
                             .OfType <ModelItemEventBase>()
                             .Concat(Nodes.Select(i => new ModelNodeRemovedEvent(i)));

            var newModel = Create(
                _sequenceProvider,
                _modelRuleProviders,
                _nodePayloadEqualityComparer,
                _relationshipPayloadEqualityComparer);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #8
0
        public ModelEvent RemoveNode(ModelNodeId nodeId)
        {
            var itemEvents = new List <ModelItemEventBase>();
            var newGraph   = _graph;

            foreach (var relationship in GetRelationships(nodeId))
            {
                newGraph = RemoveRelationshipCore(relationship.Id, newGraph, itemEvents);
            }

            newGraph = RemoveNodeCore(nodeId, newGraph, itemEvents);

            var newModel = CreateInstance(newGraph);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #9
0
        public ModelEvent RemoveNode(ModelNodeId nodeId)
        {
            var itemEvents = new List <ModelItemEventBase>();
            var newGraph   = _graph;

            var newPayloadToModelRelationshipMap = _payloadToModelRelationshipMap;

            foreach (var relationship in GetRelationships(nodeId))
            {
                (newGraph, newPayloadToModelRelationshipMap) = RemoveRelationshipCore(relationship.Id, newGraph, newPayloadToModelRelationshipMap, itemEvents);
            }

            ImmutableDictionary <object, IModelNode> newPayloadToModelNodeMap;

            (newGraph, newPayloadToModelNodeMap) = RemoveNodeCore(nodeId, newGraph, _payloadToModelNodeMap, itemEvents);

            var newModel = CreateInstance(newGraph, newPayloadToModelNodeMap, newPayloadToModelRelationshipMap);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #10
0
        public ModelEvent AddRelationship(
            ModelNodeId sourceId,
            ModelNodeId targetId,
            ModelRelationshipStereotype stereotype,
            object payload = null)
        {
            var relationship = CreateRelationship(sourceId, targetId, stereotype, payload);

            if (!IsRelationshipValid(relationship))
            {
                throw new ArgumentException($"{relationship} is invalid.");
            }

            var itemEvents = new List <ModelItemEventBase>();
            var newGraph   = AddRelationshipCore(relationship, _graph, itemEvents);

            var newModel = CreateInstance(newGraph);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Пример #11
0
        public ModelEvent AddNode(
            string name,
            ModelNodeStereotype stereotype,
            object payload           = null,
            ModelNodeId?parentNodeId = null)
        {
            var itemEvents = new List <ModelItemEventBase>();

            var newNode  = CreateNode(name, stereotype, payload);
            var newGraph = AddNodeCore(newNode, _graph, itemEvents);

            if (parentNodeId.HasValue)
            {
                var containsRelationship = CreateRelationship(parentNodeId.Value, newNode.Id, ModelRelationshipStereotype.Containment, payload: null);
                newGraph = AddRelationshipCore(containsRelationship, newGraph, itemEvents);
            }

            var newModel = CreateInstance(newGraph);

            return(ModelEvent.Create(newModel, itemEvents));
        }