Пример #1
0
 private void RaiseEvents([NotNull][ItemNotNull] IEnumerable <DiagramEventBase> events)
 {
     foreach (var @event in events)
     {
         DiagramChanged?.Invoke(@event);
     }
 }
Пример #2
0
 public void ClearDiagram()
 {
     lock (_diagramUpdateLockObject)
     {
         Diagram = Diagram.Clear();
         DiagramChanged?.Invoke(new DiagramClearedEvent(Diagram));
     }
 }
Пример #3
0
        public void AddNode(IDiagramNode node)
        {
            lock (_diagramUpdateLockObject)
            {
                if (Diagram.NodeExists(node.Id))
                {
                    return;
                }

                Diagram = Diagram.AddNode(node);
                DiagramChanged?.Invoke(new DiagramNodeAddedEvent(Diagram, node));
            }
        }
Пример #4
0
        public void AddConnector([NotNull] IDiagramConnector connector)
        {
            lock (_diagramUpdateLockObject)
            {
                if (Diagram.ConnectorExists(connector.Id))
                {
                    return;
                }

                Diagram = Diagram.AddConnector(connector);
                DiagramChanged?.Invoke(new DiagramConnectorAddedEvent(Diagram, connector));
            }
        }
Пример #5
0
        public void RemoveNode(ModelNodeId nodeId)
        {
            lock (_diagramUpdateLockObject)
            {
                if (!Diagram.NodeExists(nodeId))
                {
                    return;
                }

                var oldNode = Diagram.GetNode(nodeId);
                Diagram = Diagram.RemoveNode(nodeId);
                DiagramChanged?.Invoke(new DiagramNodeRemovedEvent(Diagram, oldNode));
            }
        }
Пример #6
0
        public void RemoveConnector(ModelRelationshipId connectorId)
        {
            lock (_diagramUpdateLockObject)
            {
                if (!Diagram.ConnectorExists(connectorId))
                {
                    return;
                }

                var oldConnector = Diagram.GetConnector(connectorId);
                Diagram = Diagram.RemoveConnector(connectorId);
                DiagramChanged?.Invoke(new DiagramConnectorRemovedEvent(Diagram, oldConnector));
            }
        }
Пример #7
0
        private void MutateWithLockThenRaiseEvents([NotNull] Func <DiagramEvent> diagramMutatorFunc)
        {
            DiagramEvent diagramEvent;

            lock (_diagramUpdateLockObject)
            {
                diagramEvent  = diagramMutatorFunc.Invoke();
                LatestDiagram = diagramEvent.NewDiagram;
            }

            DiagramChanged?.Invoke(diagramEvent);
            _diagramChangedEventStream.OnNext(diagramEvent);
            AfterDiagramChanged?.Invoke(diagramEvent);
        }
Пример #8
0
        public void UpdateDiagramNodeCenter(IDiagramNode diagramNode, Point2D newCenter)
        {
            lock (_diagramUpdateLockObject)
            {
                if (!Diagram.TryGetNode(diagramNode.Id, out var oldNode))
                {
                    return;
                }

                var newNode = oldNode.WithCenter(newCenter);
                Diagram = Diagram.UpdateNode(newNode);
                DiagramChanged?.Invoke(new DiagramNodePositionChangedEvent(Diagram, oldNode, newNode));
            }
        }
Пример #9
0
        public void UpdateDiagramNodeSize(IDiagramNode diagramNode, Size2D newSize)
        {
            lock (_diagramUpdateLockObject)
            {
                if (!Diagram.TryGetNode(diagramNode.Id, out var oldNode))
                {
                    return;
                }

                var newNode = oldNode.WithSize(newSize);
                Diagram = Diagram.UpdateNode(newNode);
                DiagramChanged?.Invoke(new DiagramNodeSizeChangedEvent(Diagram, oldNode, newNode));
            }
        }
Пример #10
0
        public void UpdateDiagramConnectorRoute(IDiagramConnector diagramConnector, Route newRoute)
        {
            lock (_diagramUpdateLockObject)
            {
                if (!Diagram.TryGetConnector(diagramConnector.Id, out var oldConnector))
                {
                    return;
                }

                var newConnector = oldConnector.WithRoute(newRoute);
                Diagram = Diagram.UpdateConnector(newConnector);
                DiagramChanged?.Invoke(new DiagramConnectorRouteChangedEvent(Diagram, oldConnector, newConnector));
            }
        }
Пример #11
0
        public void UpdateDiagramNodeModelNode(IDiagramNode diagramNode, IModelNode newModelNode)
        {
            lock (_diagramUpdateLockObject)
            {
                if (!Diagram.TryGetNode(diagramNode.Id, out IDiagramNode oldNode))
                {
                    return;
                }

                var newNode = oldNode.WithModelNode(newModelNode);
                Diagram = Diagram.UpdateNode(newNode);
                DiagramChanged?.Invoke(new DiagramNodeModelNodeChangedEvent(Diagram, oldNode, newNode));
            }
        }
Пример #12
0
 public void UpdateDiagramNodeCenter(IDiagramNode diagramNode, Point2D newCenter)
 {
     lock (_diagramUpdateLockObject)
     {
         Diagram
         .TryGetNode(diagramNode.Id)
         .Match(
             oldNode =>
         {
             var updatedNode = oldNode.WithCenter(newCenter);
             Diagram         = Diagram.UpdateNode(updatedNode);
             DiagramChanged?.Invoke(new DiagramNodePositionChangedEvent(Diagram, oldNode, updatedNode));
         },
             () => Debug.WriteLine($"Trying to move node {diagramNode} but it does not exist."));
     }
 }
Пример #13
0
 public void UpdateDiagramNodeSize(IDiagramNode diagramNode, Size2D newSize)
 {
     lock (_diagramUpdateLockObject)
     {
         Diagram
         .TryGetNode(diagramNode.Id)
         .Match(
             oldNode =>
         {
             var updatedNode = oldNode.WithSize(newSize);
             Diagram         = Diagram.UpdateNode(updatedNode);
             DiagramChanged?.Invoke(new DiagramNodeSizeChangedEvent(Diagram, oldNode, updatedNode));
         },
             () => throw new InvalidOperationException($"Node {diagramNode} does not exist."));
     }
 }
Пример #14
0
 public void UpdateConnectorRoute(ModelRelationshipId connectorId, Route newRoute)
 {
     lock (_diagramUpdateLockObject)
     {
         Diagram
         .TryGetConnector(connectorId)
         .Match(
             oldConnector =>
         {
             var newConnector = oldConnector.WithRoute(newRoute);
             Diagram          = Diagram.UpdateConnector(newConnector);
             DiagramChanged?.Invoke(new DiagramConnectorRouteChangedEvent(Diagram, oldConnector, newConnector));
         },
             () => throw new InvalidOperationException($"Connector {connectorId} does not exist."));
     }
 }
Пример #15
0
        private void MutateWithLockThenRaiseEvents([NotNull] Action <IDiagramMutator> diagramMutatorFunc)
        {
            DiagramEvent diagramEvent;

            lock (_diagramUpdateLockObject)
            {
                var diagramMutator = CreateDiagramMutator();
                diagramMutatorFunc.Invoke(diagramMutator);
                diagramEvent  = diagramMutator.GetDiagramEvent();
                LatestDiagram = diagramEvent.NewDiagram;
            }

            if (diagramEvent.IsEmpty)
            {
                return;
            }

            DiagramChanged?.Invoke(diagramEvent);
            _diagramChangedEventStream.OnNext(diagramEvent);
            AfterDiagramChanged?.Invoke(diagramEvent);
        }