Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1667 was 1667, checked in by epitzer, 15 years ago

Convert persistence of Core plugin to new persistence framework. The target framework has been upgraded from 2.0 to 3.5 and events during persistence are not generated anymore. (#603)

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