Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/OperatorBase.cs @ 2474

Last change on this file since 2474 was 2474, checked in by swagner, 14 years ago

Implemented generic EventArgs (#796)

File size: 24.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Xml;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Common;
28
29namespace HeuristicLab.Core {
30  /// <summary>
31  /// The base class for all operators.
32  /// </summary>
33  public abstract class OperatorBase : ConstrainedItemBase, IOperator {
34
35    [Storable]
36    private string myName;
37    /// <summary>
38    /// Gets or sets the name of the operator.
39    /// </summary>
40    /// <remarks>Calls <see cref="OnNameChanged"/> in the setter.</remarks>
41    public string Name {
42      get { return myName; }
43      set {
44        if (myName != value) {
45          myName = value;
46          OnNameChanged();
47        }
48      }
49    }
50    /// <summary>
51    /// Gets the description of the current operator.
52    /// </summary>
53    /// <remarks>Returns "No operator description available" if the method is not overriden.</remarks>
54    public virtual string Description {
55      get { return "No operator description available."; }
56    }
57    /// <summary>
58    /// Flag whether the current instance has been canceled.
59    /// </summary>
60    protected bool myCanceled;
61    /// <inheritdoc/>
62    public bool Canceled {
63      get { return myCanceled; }
64    }
65
66    [Storable]
67    private bool myBreakpoint;
68    /// <inheritdoc/>
69    /// <remarks>Calls <see cref="OnBreakpointChanged"/> in the setter.</remarks>
70    public bool Breakpoint {
71      get { return myBreakpoint; }
72      set {
73        if (value != myBreakpoint) {
74          myBreakpoint = value;
75          OnBreakpointChanged();
76        }
77      }
78    }
79
80    [Storable]
81    private List<IOperator> mySubOperators;
82    /// <summary>
83    /// Gets a list of all suboperators.
84    /// <note type="caution"> Returns the suboperators read-only!</note>
85    /// </summary>
86    public virtual IList<IOperator> SubOperators {
87      get { return mySubOperators.AsReadOnly(); }
88    }
89
90    [Storable]
91    private Dictionary<string, IVariableInfo> myVariableInfos;
92    /// <inheritdoc/>
93    public virtual ICollection<IVariableInfo> VariableInfos {
94      get { return myVariableInfos.Values; }
95    }
96   
97    private Dictionary<string, IVariable> myVariables;
98    /// <inheritdoc/>   
99    public virtual ICollection<IVariable> Variables {
100      get { return myVariables.Values; }
101    }
102
103    [Storable(Name="Variables")]
104    private List<IVariable> VariablePersistence {
105      get { return new List<IVariable>(myVariables.Values); }
106      set {
107        myVariables.Clear();
108        foreach (IVariable var in value) {
109          AddVariable(var);
110        }
111      }
112    }
113
114    /// <summary>
115    /// Initializes a new instance of <see cref="OperatorBase"/> setting the breakpoint flag and
116    /// the canceled flag to <c>false</c> and the name of the operator to the type name.
117    /// </summary>
118    protected OperatorBase() {
119      myName = this.GetType().Name;
120      myCanceled = false;
121      myBreakpoint = false;
122      mySubOperators = new List<IOperator>();
123      myVariableInfos = new Dictionary<string, IVariableInfo>();
124      myVariables = new Dictionary<string, IVariable>();
125    }
126
127    /// <summary>
128    /// Clones the current instance (deep clone).
129    /// </summary>
130    /// <remarks>Clones also sub operators, variables and variable infos.</remarks>
131    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
132    /// <returns>The cloned object as <see cref="OperatorBase"/>.</returns>
133    public override object Clone(IDictionary<Guid, object> clonedObjects) {
134      OperatorBase clone = (OperatorBase)base.Clone(clonedObjects);
135      clone.myName = Name;
136      clone.mySubOperators.Clear();
137      for (int i = 0; i < SubOperators.Count; i++)
138        clone.AddSubOperator((IOperator)Auxiliary.Clone(SubOperators[i], clonedObjects));
139      clone.myVariableInfos.Clear();
140      foreach (IVariableInfo variableInfo in myVariableInfos.Values)
141        clone.AddVariableInfo((IVariableInfo)Auxiliary.Clone(variableInfo, clonedObjects));
142      clone.myVariables.Clear();
143      foreach (IVariable variable in myVariables.Values)
144        clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects));
145      return clone;
146    }
147
148    /// <summary>
149    /// Creates a new instance of <see cref="OperatorBaseView"/> to represent the current operator
150    /// visually.
151    /// </summary>
152    /// <returns>The created view as <see cref="OperatorBaseView"/>.</returns>
153    public override IView CreateView() {
154      return new OperatorBaseView(this);
155    }
156
157    #region SubOperator Methods
158    /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator)"/>
159    /// <param name="subOperator">The sub operator to add.</param>
160    /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
161    public virtual void AddSubOperator(IOperator subOperator) {
162      mySubOperators.Add(subOperator);
163      OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);
164    }
165    /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator)"/>
166    /// <param name="subOperator">The sub operator to add.</param>
167    /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
168    public virtual bool TryAddSubOperator(IOperator subOperator) {
169      mySubOperators.Add(subOperator);
170      if (IsValid()) {
171        OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);
172        return true;
173      } else {
174        mySubOperators.RemoveAt(mySubOperators.Count - 1);
175        return false;
176      }
177    }
178    /// <inheritdoc cref="HeuristicLab.Core.IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator,
179    /// out System.Collections.Generic.ICollection&lt;HeuristicLab.Core.IConstraint&gt;)"/>
180    /// <param name="subOperator">The sub operator to add.</param>
181    /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
182    public virtual bool TryAddSubOperator(IOperator subOperator, out ICollection<IConstraint> violatedConstraints) {
183      mySubOperators.Add(subOperator);
184      if (IsValid(out violatedConstraints)) {
185        OnSubOperatorAdded(subOperator, mySubOperators.Count - 1);
186        return true;
187      } else {
188        mySubOperators.RemoveAt(mySubOperators.Count - 1);
189        return false;
190      }
191    }
192    /// <inheritdoc cref="HeuristicLab.Core.IOperator.AddSubOperator(HeuristicLab.Core.IOperator, int)"/>
193    /// <param name="subOperator">The sub operator to add.</param>
194    /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
195    public virtual void AddSubOperator(IOperator subOperator, int index) {
196      mySubOperators.Insert(index, subOperator);
197      OnSubOperatorAdded(subOperator, index);
198    }
199    /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int)"/>
200    /// <param name="subOperator">The sub operator to add.</param>
201    /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
202    public virtual bool TryAddSubOperator(IOperator subOperator, int index) {
203      mySubOperators.Insert(index, subOperator);
204      if (IsValid()) {
205        OnSubOperatorAdded(subOperator, index);
206        return true;
207      } else {
208        mySubOperators.RemoveAt(index);
209        return false;
210      }
211    }
212    /// <inheritdoc cref="IOperator.TryAddSubOperator(HeuristicLab.Core.IOperator, int, out
213    /// System.Collections.Generic.ICollection&lt;HeuristicLab.Core.IConstraint&gt;)"/>
214    /// <param name="subOperator">The sub operator to add.</param>
215    /// <remarks>Calls <see cref="OnSubOperatorAdded"/>.</remarks>
216    public virtual bool TryAddSubOperator(IOperator subOperator, int index, out ICollection<IConstraint> violatedConstraints) {
217      mySubOperators.Insert(index, subOperator);
218      if (IsValid(out violatedConstraints)) {
219        OnSubOperatorAdded(subOperator, index);
220        return true;
221      } else {
222        mySubOperators.RemoveAt(index);
223        return false;
224      }
225    }
226    /// <inheritdoc/>
227    /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>
228    public virtual void RemoveSubOperator(int index) {
229      IOperator op = mySubOperators[index];
230      mySubOperators.RemoveAt(index);
231      OnSubOperatorRemoved(op, index);
232    }
233    /// <inheritdoc/>
234    /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>
235    public virtual bool TryRemoveSubOperator(int index) {
236      IOperator op = mySubOperators[index];
237      mySubOperators.RemoveAt(index);
238      if (IsValid()) {
239        OnSubOperatorRemoved(op, index);
240        return true;
241      } else {
242        mySubOperators.Insert(index, op);
243        return false;
244      }
245    }
246    /// <inheritdoc/>
247    /// <remarks>Calls <see cref="OnSubOperatorRemoved"/>.</remarks>
248    public virtual bool TryRemoveSubOperator(int index, out ICollection<IConstraint> violatedConstraints) {
249      IOperator op = mySubOperators[index];
250      mySubOperators.RemoveAt(index);
251      if (IsValid(out violatedConstraints)) {
252        OnSubOperatorRemoved(op, index);
253        return true;
254      } else {
255        mySubOperators.Insert(index, op);
256        return false;
257      }
258    }
259    #endregion
260
261    #region VariableInfo Methods
262    /// <inheritdoc/>
263    public virtual IVariableInfo GetVariableInfo(string formalName) {
264      IVariableInfo info;
265      if (myVariableInfos.TryGetValue(formalName, out info))
266        return info;
267      else
268        return null;
269    }
270    /// <inheritdoc/>
271    /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>
272    public virtual void AddVariableInfo(IVariableInfo variableInfo) {
273      myVariableInfos.Add(variableInfo.FormalName, variableInfo);
274      OnVariableInfoAdded(variableInfo);
275    }
276    /// <inheritdoc/>
277    /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>
278    public virtual bool TryAddVariableInfo(IVariableInfo variableInfo) {
279      myVariableInfos.Add(variableInfo.FormalName, variableInfo);
280      if (IsValid()) {
281        OnVariableInfoAdded(variableInfo);
282        return true;
283      } else {
284        myVariableInfos.Remove(variableInfo.FormalName);
285        return false;
286      }
287    }
288    /// <inheritdoc/>
289    /// <remarks>Calls <see cref="OnVariableInfoAdded"/>.</remarks>
290    public virtual bool TryAddVariableInfo(IVariableInfo variableInfo, out ICollection<IConstraint> violatedConstraints) {
291      myVariableInfos.Add(variableInfo.FormalName, variableInfo);
292      if (IsValid(out violatedConstraints)) {
293        OnVariableInfoAdded(variableInfo);
294        return true;
295      } else {
296        myVariableInfos.Remove(variableInfo.FormalName);
297        return false;
298      }
299    }
300    /// <inheritdoc/>
301    /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>
302    public virtual void RemoveVariableInfo(string formalName) {
303      IVariableInfo variableInfo;
304      if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {
305        myVariableInfos.Remove(formalName);
306        OnVariableInfoRemoved(variableInfo);
307      }
308    }
309    /// <inheritdoc/>
310    /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>
311    public virtual bool TryRemoveVariableInfo(string formalName) {
312      IVariableInfo variableInfo;
313      if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {
314        myVariableInfos.Remove(formalName);
315        if (IsValid()) {
316          OnVariableInfoRemoved(variableInfo);
317          return true;
318        } else {
319          myVariableInfos.Add(formalName, variableInfo);
320          return false;
321        }
322      }
323      return true;
324    }
325    /// <inheritdoc/>
326    /// <remarks>Calls <see cref="OnVariableInfoRemoved"/>.</remarks>
327    public virtual bool TryRemoveVariableInfo(string formalName, out ICollection<IConstraint> violatedConstraints) {
328      IVariableInfo variableInfo;
329      if (myVariableInfos.TryGetValue(formalName, out variableInfo)) {
330        myVariableInfos.Remove(formalName);
331        if (IsValid(out violatedConstraints)) {
332          OnVariableInfoRemoved(variableInfo);
333          return true;
334        } else {
335          myVariableInfos.Add(formalName, variableInfo);
336          return false;
337        }
338      }
339      violatedConstraints = new List<IConstraint>();
340      return true;
341    }
342    #endregion
343
344    #region Variable Methods
345    /// <inheritdoc/>
346    public virtual IVariable GetVariable(string name) {
347      IVariable variable;
348      if (myVariables.TryGetValue(name, out variable))
349        return variable;
350      else
351        return null;
352    }
353    /// <inheritdoc/>
354    /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>
355    /// event handlers.</remarks>
356    public virtual void AddVariable(IVariable variable) {
357      myVariables.Add(variable.Name, variable);
358      variable.NameChanging += new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);
359      variable.NameChanged += new EventHandler(Variable_NameChanged);
360      OnVariableAdded(variable);
361    }
362    /// <inheritdoc/>
363    /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>
364    /// event handlers.</remarks>
365    public virtual bool TryAddVariable(IVariable variable) {
366      myVariables.Add(variable.Name, variable);
367      if (IsValid()) {
368        variable.NameChanging += new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);
369        variable.NameChanged += new EventHandler(Variable_NameChanged);
370        OnVariableAdded(variable);
371        return true;
372      } else {
373        myVariableInfos.Remove(variable.Name);
374        return false;
375      }
376    }
377    /// <inheritdoc/>
378    /// <remarks>Calls <see cref="OnVariableAdded"/> and adds <c>NameChanging</c> and <c>NameChanged</c>
379    /// event handlers.</remarks>
380    public virtual bool TryAddVariable(IVariable variable, out ICollection<IConstraint> violatedConstraints) {
381      myVariables.Add(variable.Name, variable);
382      if (IsValid(out violatedConstraints)) {
383        variable.NameChanging += new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);
384        variable.NameChanged += new EventHandler(Variable_NameChanged);
385        OnVariableAdded(variable);
386        return true;
387      } else {
388        myVariableInfos.Remove(variable.Name);
389        return false;
390      }
391    }
392    /// <inheritdoc/>
393    /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>
394    /// event handlers.</remarks>
395    public virtual void RemoveVariable(string name) {
396      IVariable variable;
397      if (myVariables.TryGetValue(name, out variable)) {
398        variable.NameChanging -= new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);
399        variable.NameChanged -= new EventHandler(Variable_NameChanged);
400        myVariables.Remove(name);
401        OnVariableRemoved(variable);
402      }
403    }
404    /// <inheritdoc/>
405    /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>
406    /// event handlers.</remarks>
407    public virtual bool TryRemoveVariable(string name) {
408      IVariable variable;
409      if (myVariables.TryGetValue(name, out variable)) {
410        myVariables.Remove(name);
411        if (IsValid()) {
412          variable.NameChanging -= new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);
413          variable.NameChanged -= new EventHandler(Variable_NameChanged);
414          OnVariableRemoved(variable);
415          return true;
416        } else {
417          myVariables.Add(name, variable);
418          return false;
419        }
420      }
421      return true;
422    }
423    /// <inheritdoc/>
424    /// <remarks>Calls <see cref="OnVariableRemoved"/> and removes <c>NameChanging</c> and <c>NameChanged</c>
425    /// event handlers.</remarks>
426    public virtual bool TryRemoveVariable(string name, out ICollection<IConstraint> violatedConstraints) {
427      IVariable variable;
428      if (myVariables.TryGetValue(name, out variable)) {
429        myVariables.Remove(name);
430        if (IsValid(out violatedConstraints)) {
431          variable.NameChanging -= new EventHandler<CancelEventArgs<string>>(Variable_NameChanging);
432          variable.NameChanged -= new EventHandler(Variable_NameChanged);
433          OnVariableRemoved(variable);
434          return true;
435        } else {
436          myVariables.Add(name, variable);
437          return false;
438        }
439      }
440      violatedConstraints = new List<IConstraint>();
441      return true;
442    }
443    private void Variable_NameChanging(object sender, CancelEventArgs<string> e) {
444      e.Cancel = myVariables.ContainsKey(e.Value);
445    }
446    private void Variable_NameChanged(object sender, EventArgs e) {
447      IVariable variable = (IVariable)sender;
448      string oldName = null;
449      foreach (KeyValuePair<string, IVariable> element in myVariables) {
450        if (element.Value == variable)
451          oldName = element.Key;
452      }
453      myVariables.Remove(oldName);
454      myVariables.Add(variable.Name, variable);
455    }
456    /// <inheritdoc cref="IOperator.GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool)"/>
457    ///  <remarks>Calls <see cref="GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool, bool)"/>
458    /// with <c>throwOnError</c> set to <c>false</c>.</remarks>
459    public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup) where T : class, IItem {
460      return GetVariableValue<T>(formalName, scope, recursiveLookup, true);
461    }
462    /// <inheritdoc cref="IOperator.GetVariableValue&lt;T&gt;(string, HeuristicLab.Core.IScope, bool, bool)"/>
463    /// <remarks>Calls
464    /// <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>.</remarks>
465    public T GetVariableValue<T>(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) where T : class, IItem {
466      return (T)GetVariableValue(formalName, scope, recursiveLookup, throwOnError);
467    }
468    /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool)"/>
469    /// <remarks>Calls <see cref="GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>
470    /// with <c>throwOnError</c> set to <c>false</c>.</remarks>
471    public IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup) {
472      return GetVariableValue(formalName, scope, recursiveLookup, true);
473    }
474    /// <inheritdoc cref="IOperator.GetVariableValue(string, HeuristicLab.Core.IScope, bool, bool)"/>
475    public virtual IItem GetVariableValue(string formalName, IScope scope, bool recursiveLookup, bool throwOnError) {
476      IVariableInfo info = GetVariableInfo(formalName);
477      if (info.Local) {
478        IVariable variable;
479        if (myVariables.TryGetValue(info.ActualName, out variable))
480          return variable.Value;
481        else {
482          if (throwOnError)
483            throw new ArgumentException("Variable " + info.ActualName + " not found");
484          else
485            return null;
486        }
487      } else {
488        return scope.GetVariableValue(formalName, recursiveLookup, throwOnError);
489      }
490    }
491    #endregion
492    /// <inheritdoc/>
493    public virtual IOperation Execute(IScope scope) {
494      myCanceled = false;
495
496      foreach (IVariableInfo variableInfo in VariableInfos)
497        scope.AddAlias(variableInfo.FormalName, variableInfo.ActualName);
498
499      IOperation next = Apply(scope);
500
501      foreach (IVariableInfo variableInfo in VariableInfos)
502        scope.RemoveAlias(variableInfo.FormalName);
503
504      OnExecuted();
505      return next;
506    }
507    /// <inheritdoc/>
508    /// <remarks>Sets property <see cref="Canceled"/> to <c>true</c>.</remarks>
509    public virtual void Abort() {
510      myCanceled = true;
511    }
512    /// <summary>
513    /// Performs the current operator on the specified <paramref name="scope"/>.
514    /// </summary>
515    /// <param name="scope">The scope where to execute the operator</param>
516    /// <returns><c>null</c>.</returns>
517    public virtual IOperation Apply(IScope scope) {
518      return null;
519    }
520    /// <inheritdoc/>
521    public event EventHandler NameChanged;
522    /// <summary>
523    /// Fires a new <c>NameChanged</c> event.
524    /// </summary>
525    protected virtual void OnNameChanged() {
526      if (NameChanged != null) {
527        NameChanged(this, new EventArgs());
528      }
529    }
530    /// <inheritdoc/>
531    public event EventHandler BreakpointChanged;
532    /// <summary>
533    /// Fires a new <c>BreakpointChanged</c> event.
534    /// </summary>
535    protected virtual void OnBreakpointChanged() {
536      if (BreakpointChanged != null) {
537        BreakpointChanged(this, new EventArgs());
538      }
539    }
540    /// <inheritdoc/>
541    public event EventHandler<EventArgs<IOperator, int>> SubOperatorAdded;
542    /// <summary>
543    /// Fires a new <c>SubOperatorAdded</c> event.
544    /// </summary>
545    /// <param name="subOperator">The sub operator that has been added.</param>
546    /// <param name="index">The position where the operator has been added.</param>
547    protected virtual void OnSubOperatorAdded(IOperator subOperator, int index) {
548      if (SubOperatorAdded != null)
549        SubOperatorAdded(this, new EventArgs<IOperator, int>(subOperator, index));
550    }
551    /// <inheritdoc/>
552    public event EventHandler<EventArgs<IOperator, int>> SubOperatorRemoved;
553    /// <summary>
554    /// Fires a new <c>SubOperatorRemoved</c> event.
555    /// </summary>
556    /// <param name="subOperator">The sub operator that has been removed.</param>
557    /// <param name="index">The position where the operator has been removed.</param>
558    protected virtual void OnSubOperatorRemoved(IOperator subOperator, int index) {
559      if (SubOperatorRemoved != null)
560        SubOperatorRemoved(this, new EventArgs<IOperator, int>(subOperator, index));
561    }
562    /// <inheritdoc/>
563    public event EventHandler<EventArgs<IVariableInfo>> VariableInfoAdded;
564    /// <summary>
565    /// Fires a new <c>VariableInfoAdded</c> event.
566    /// </summary>
567    /// <param name="variableInfo">The variable info that has been added.</param>
568    protected virtual void OnVariableInfoAdded(IVariableInfo variableInfo) {
569      if (VariableInfoAdded != null)
570        VariableInfoAdded(this, new EventArgs<IVariableInfo>(variableInfo));
571    }
572    /// <inheritdoc/>
573    public event EventHandler<EventArgs<IVariableInfo>> VariableInfoRemoved;
574    /// <summary>
575    /// Fires a new <c>VariableInfoRemoved</c> event.
576    /// </summary>
577    /// <param name="variableInfo">The variable info that has been removed.</param>
578    protected virtual void OnVariableInfoRemoved(IVariableInfo variableInfo) {
579      if (VariableInfoRemoved != null)
580        VariableInfoRemoved(this, new EventArgs<IVariableInfo>(variableInfo));
581    }
582    /// <inheritdoc/>
583    public event EventHandler<EventArgs<IVariable>> VariableAdded;
584    /// <summary>
585    /// Fires a new <c>VariableAdded</c> event.
586    /// </summary>
587    /// <param name="variable">The variable that has been added.</param>
588    protected virtual void OnVariableAdded(IVariable variable) {
589      if (VariableAdded != null)
590        VariableAdded(this, new EventArgs<IVariable>(variable));
591    }
592    /// <inheritdoc/>
593    public event EventHandler<EventArgs<IVariable>> VariableRemoved;
594    /// <summary>
595    /// Fires a new <c>VariableRemoved</c> event.
596    /// </summary>
597    /// <param name="variable">The variable that has been removed</param>
598    protected virtual void OnVariableRemoved(IVariable variable) {
599      if (VariableRemoved != null)
600        VariableRemoved(this, new EventArgs<IVariable>(variable));
601    }
602    /// <inheritdoc/>
603    public event EventHandler Executed;
604    /// <summary>
605    /// Fires a new <c>Executed</c> event.
606    /// </summary>
607    protected virtual void OnExecuted() {
608      if (Executed != null) {
609        Executed(this, new EventArgs());
610      }
611    }
612  }
613}
Note: See TracBrowser for help on using the repository browser.