Пример #1
0
        /// <summary>
        /// The user has made changes in the view.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void OnViewChanged(object sender, GraphChangedEventArgs e)
        {
            List <ChangeProperty.Property> changes = new List <ChangeProperty.Property>();

            changes.Add(new ChangeProperty.Property(model, nameof(model.Arcs), e.Arcs));
            changes.Add(new ChangeProperty.Property(model, nameof(model.Nodes), e.Nodes));
            // todo - update InitialState as well? This function is currently
            // not used a a callback for initial state being changed, but it
            // might make sense to update it anyway...

            // Check for multiple nodes or arcs with the same name.
            IEnumerable <IGrouping <string, StateNode> > duplicateNodes = e.Nodes.GroupBy(n => n.Name).Where(g => g.Count() > 1);

            if (duplicateNodes.Any())
            {
                throw new Exception($"Unable to apply changes - duplicate node name found: {duplicateNodes.First().Key}");
            }
            IEnumerable <IGrouping <string, RuleAction> > duplicateArcs = e.Arcs.GroupBy(n => n.Name).Where(g => g.Count() > 1);

            if (duplicateArcs.Any())
            {
                throw new Exception($"Unable to apply changes - duplicate arc name found: {duplicateArcs.First().Key}");
            }

            ChangeProperty command = new ChangeProperty(changes);

            presenter.CommandHistory.Add(command);
        }
Пример #2
0
        private void DisplayedGraphChanged(object sender, GraphChangedEventArgs args)
        {
            if (_suspendNotifications)
            {
                return;
            }

            var graph = Graph;

            Contract.Assert(graph != null);

            _suspendNotifications = true;

            if (args.OldEdges != null)
            {
                args.OldEdges.ForEach(e =>
                {
                    var toRemove = _edges.Single(e.Equals);
                    RemoveEdge(toRemove);
                });
            }
            if (args.OldVertices != null)
            {
                args.OldVertices.ForEach(e =>
                {
                    var toRemove = _vertices.Single(e.Equals);
                    RemoveVertex(toRemove);
                });
            }
            if (args.NewVertices != null)
            {
                args.NewVertices.ForEach(AddVertex);
            }
            if (args.NewEdges != null)
            {
                args.NewEdges.ForEach(AddEdge);
            }

            _suspendNotifications = false;
        }