Changeset 11249 for trunk/sources/HeuristicLab.Core/3.3/Collections
- Timestamp:
- 07/31/14 10:03:24 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs
r11248 r11249 71 71 private void AfterDeserialization() { 72 72 foreach (var vertex in vertices) { 73 vertex.ArcAdded += OnVertexArcAdded;74 vertex.ArcRemoved += OnVertexArcRemoved;73 vertex.ArcAdded += Vertex_ArcAdded; 74 vertex.ArcRemoved += Vertex_ArcRemoved; 75 75 } 76 76 … … 91 91 vertices.Add(vertex); 92 92 // register event handlers 93 vertex.ArcAdded += OnVertexArcAdded;94 vertex.ArcRemoved += OnVertexArcRemoved;95 OnVertedAdded(this, EventArgs.Empty);93 vertex.ArcAdded += Vertex_ArcAdded; 94 vertex.ArcRemoved += Vertex_ArcRemoved; 95 OnVertedAdded(this, new EventArgs<IVertex>(vertex)); 96 96 } 97 97 … … 103 103 RemoveArc(arc); 104 104 // deregister event handlers 105 vertex.ArcAdded -= OnVertexArcAdded;106 vertex.ArcRemoved -= OnVertexArcRemoved;107 OnVertexRemoved(this, EventArgs.Empty); // do not pass the removed vertex in the event as we don't need it anymore105 vertex.ArcAdded -= Vertex_ArcAdded; 106 vertex.ArcRemoved -= Vertex_ArcRemoved; 107 OnVertexRemoved(this, new EventArgs<IVertex>(vertex)); 108 108 } 109 109 … … 120 120 target.AddArc(arc); 121 121 arcs.Add(arc); 122 OnArcAdded(this, EventArgs.Empty);123 122 } 124 123 … … 129 128 source.RemoveArc(arc); 130 129 target.RemoveArc(arc); 131 OnArcRemoved(this, EventArgs.Empty);132 130 } 133 131 134 protected virtual void OnVertexArcAdded(object sender, EventArgs<IArc> args) { 132 protected virtual void Vertex_ArcAdded(object sender, EventArgs<IArc> args) { 133 // the ArcAdded event is fired by a vertex when an arc from/to another vertex is added to its list of connections 134 // because the arc is added in both directions by both the source and the target, this event will get fired twice here 135 135 var arc = args.Value; 136 // the ArcAdded event is fired by a vertex when an arc from/to another vertex is added to its list of connections 137 // because the arc is added in both directions by both the source and the target, this event will get fired twice 138 // here, we only want to add the arc once, so if its already contained, we return without complaining 139 if (arcs.Contains(arc)) return; 140 arcs.Add(arc); 136 if (arcs.Add(arc)) OnArcAdded(this, new EventArgs<IArc>(arc)); 141 137 } 142 138 143 protected virtual void OnVertexArcRemoved(object sender, EventArgs<IArc> args) {139 protected virtual void Vertex_ArcRemoved(object sender, EventArgs<IArc> args) { 144 140 var arc = args.Value; 145 if (!arcs.Contains(arc)) return; // the same rationale as above 146 arcs.Remove(arc); 141 if (arcs.Remove(arc)) OnArcRemoved(this, new EventArgs<IArc>(arc)); 147 142 } 148 143 149 144 // events 150 145 public event EventHandler VertexAdded; 151 protected virtual void OnVertedAdded(object sender, EventArgs args) {146 protected virtual void OnVertedAdded(object sender, EventArgs<IVertex> args) { 152 147 var added = VertexAdded; 153 148 if (added != null) … … 156 151 157 152 public event EventHandler VertexRemoved; 158 protected virtual void OnVertexRemoved(object sender, EventArgs args) {153 protected virtual void OnVertexRemoved(object sender, EventArgs<IVertex> args) { 159 154 var removed = VertexRemoved; 160 155 if (removed != null) … … 163 158 164 159 public event EventHandler ArcAdded; 165 protected virtual void OnArcAdded(object sender, EventArgs args) {160 protected virtual void OnArcAdded(object sender, EventArgs<IArc> args) { 166 161 var added = ArcAdded; 167 162 if (added != null) … … 170 165 171 166 public event EventHandler ArcRemoved; 172 protected virtual void OnArcRemoved(object sender, EventArgs args) {167 protected virtual void OnArcRemoved(object sender, EventArgs<IArc> args) { 173 168 var removed = ArcRemoved; 174 169 if (removed != null)
Note: See TracChangeset
for help on using the changeset viewer.