private void RaiseEvents([NotNull][ItemNotNull] IEnumerable <DiagramEventBase> events) { foreach (var @event in events) { DiagramChanged?.Invoke(@event); } }
public void ClearDiagram() { lock (_diagramUpdateLockObject) { Diagram = Diagram.Clear(); DiagramChanged?.Invoke(new DiagramClearedEvent(Diagram)); } }
public void AddNode(IDiagramNode node) { lock (_diagramUpdateLockObject) { if (Diagram.NodeExists(node.Id)) { return; } Diagram = Diagram.AddNode(node); DiagramChanged?.Invoke(new DiagramNodeAddedEvent(Diagram, node)); } }
public void AddConnector([NotNull] IDiagramConnector connector) { lock (_diagramUpdateLockObject) { if (Diagram.ConnectorExists(connector.Id)) { return; } Diagram = Diagram.AddConnector(connector); DiagramChanged?.Invoke(new DiagramConnectorAddedEvent(Diagram, connector)); } }
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)); } }
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)); } }
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); }
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)); } }
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)); } }
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)); } }
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)); } }
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.")); } }
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.")); } }
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.")); } }
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); }