StephaneLenclud@210: //
StephaneLenclud@210:
StephaneLenclud@210:
StephaneLenclud@210: using System;
Stephane@212: using System.Collections.Generic;
StephaneLenclud@210: using System.Runtime.Serialization;
StephaneLenclud@210: using System.Threading;
StephaneLenclud@210:
StephaneLenclud@210: namespace SharpLib.Ear
StephaneLenclud@210: {
StephaneLenclud@210: [DataContract]
Stephane@212: [KnownType("DerivedTypes")]
StephaneLenclud@210: public abstract class Action: IComparable
StephaneLenclud@210: {
StephaneLenclud@228: protected abstract void DoExecute();
StephaneLenclud@223:
StephaneLenclud@231: ///
StephaneLenclud@231: /// Allows testing from generic edit dialog.
StephaneLenclud@231: ///
StephaneLenclud@231: public void Test()
StephaneLenclud@231: {
StephaneLenclud@231: Console.WriteLine("Action test");
StephaneLenclud@231: Execute();
StephaneLenclud@231: }
StephaneLenclud@231:
StephaneLenclud@223: public void Execute()
StephaneLenclud@223: {
StephaneLenclud@229: Console.WriteLine("Action executing: " + Brief());
StephaneLenclud@223: DoExecute();
StephaneLenclud@223: }
StephaneLenclud@210:
StephaneLenclud@211: public string Name {
StephaneLenclud@211: //Get the name of this object action attribute
StephaneLenclud@231: get { return Utils.Reflection.GetAttribute(GetType()).Name; }
StephaneLenclud@211: private set { }
StephaneLenclud@211: }
StephaneLenclud@211:
StephaneLenclud@220: public virtual string Brief()
StephaneLenclud@220: {
StephaneLenclud@220: return Name;
StephaneLenclud@220: }
StephaneLenclud@220:
StephaneLenclud@210: public int CompareTo(object obj)
StephaneLenclud@210: {
StephaneLenclud@210: //Sort by action name
StephaneLenclud@231: return Utils.Reflection.GetAttribute(GetType()).Name.CompareTo(obj.GetType());
StephaneLenclud@210: }
Stephane@212:
Stephane@212: private static IEnumerable DerivedTypes()
Stephane@212: {
Stephane@212: return SharpLib.Utils.Reflection.GetDerivedTypes();
Stephane@212: }
Stephane@212:
StephaneLenclud@210: }
StephaneLenclud@210:
StephaneLenclud@210:
StephaneLenclud@210: }