StephaneLenclud@238: using System; StephaneLenclud@238: using System.Collections.Generic; StephaneLenclud@238: using System.Linq; StephaneLenclud@238: using System.Text; StephaneLenclud@238: using System.Threading.Tasks; StephaneLenclud@238: StephaneLenclud@238: StephaneLenclud@238: using System; StephaneLenclud@238: using System.Collections.Generic; StephaneLenclud@238: using System.Runtime.Serialization; StephaneLenclud@244: using System.ComponentModel; StephaneLenclud@238: StephaneLenclud@238: namespace SharpLib.Ear StephaneLenclud@238: { StephaneLenclud@238: StephaneLenclud@238: /// StephaneLenclud@238: /// EAR object provides serialization support. StephaneLenclud@238: /// It assumes most derived class is decorated with AttributeObject. StephaneLenclud@238: /// StephaneLenclud@238: [DataContract] StephaneLenclud@238: [KnownType("DerivedTypes")] StephaneLenclud@244: public abstract class Object: IComparable, INotifyPropertyChanged StephaneLenclud@238: { Stephane@243: private bool iConstructed = false; Stephane@243: StephaneLenclud@244: protected Object() Stephane@243: { Stephane@243: Construct(); Stephane@243: } Stephane@243: Stephane@243: /// Stephane@243: /// Needed as our constructor is not called following internalization. Stephane@243: /// Stephane@243: public void Construct() Stephane@243: { Stephane@243: if (!iConstructed) Stephane@243: { Stephane@243: DoConstruct(); Stephane@243: iConstructed = true; Stephane@243: } Stephane@243: } Stephane@243: Stephane@243: /// Stephane@243: /// Stephane@243: /// Stephane@243: protected virtual void DoConstruct() Stephane@243: { Stephane@243: Stephane@243: } Stephane@243: StephaneLenclud@246: StephaneLenclud@246: public enum State StephaneLenclud@246: { StephaneLenclud@246: Rest=0, StephaneLenclud@246: Edit StephaneLenclud@246: } StephaneLenclud@246: StephaneLenclud@246: State iCurrentState = State.Rest; StephaneLenclud@246: public State CurrentState { get { return iCurrentState; } set { OnStateLeave(); iCurrentState = value; OnStateEnter(); } } StephaneLenclud@246: StephaneLenclud@246: /// StephaneLenclud@246: /// StephaneLenclud@246: /// StephaneLenclud@246: protected virtual void OnStateLeave() StephaneLenclud@246: { StephaneLenclud@246: StephaneLenclud@246: } StephaneLenclud@246: StephaneLenclud@246: /// StephaneLenclud@246: /// StephaneLenclud@246: /// StephaneLenclud@246: protected virtual void OnStateEnter() StephaneLenclud@246: { StephaneLenclud@246: StephaneLenclud@246: } StephaneLenclud@246: StephaneLenclud@239: /// StephaneLenclud@239: /// Static object name. StephaneLenclud@239: /// StephaneLenclud@238: public string Name StephaneLenclud@238: { StephaneLenclud@238: //Get the name of this object attribute StephaneLenclud@238: get { return Utils.Reflection.GetAttribute(GetType()).Name; } StephaneLenclud@238: private set { } StephaneLenclud@238: } StephaneLenclud@238: StephaneLenclud@239: /// StephaneLenclud@239: /// Static object description. StephaneLenclud@239: /// StephaneLenclud@238: public string Description StephaneLenclud@238: { StephaneLenclud@238: //Get the description of this object attribute StephaneLenclud@238: get { return Utils.Reflection.GetAttribute(GetType()).Description; } StephaneLenclud@238: private set { } StephaneLenclud@238: } StephaneLenclud@238: StephaneLenclud@239: /// StephaneLenclud@239: /// Dynamic object description. StephaneLenclud@239: /// StephaneLenclud@239: /// StephaneLenclud@238: public virtual string Brief() StephaneLenclud@238: { StephaneLenclud@238: return Name; StephaneLenclud@238: } StephaneLenclud@238: StephaneLenclud@239: /// StephaneLenclud@239: /// Needed to make sure our sorting makes sense StephaneLenclud@239: /// StephaneLenclud@239: /// StephaneLenclud@239: /// StephaneLenclud@238: public int CompareTo(object obj) StephaneLenclud@238: { StephaneLenclud@238: //Sort by object name StephaneLenclud@238: return Utils.Reflection.GetAttribute(GetType()).Name.CompareTo(obj.GetType()); StephaneLenclud@238: } StephaneLenclud@238: StephaneLenclud@238: /// StephaneLenclud@239: /// Tells whether the current object configuration is valid. StephaneLenclud@239: /// StephaneLenclud@239: /// StephaneLenclud@239: public virtual bool IsValid() StephaneLenclud@239: { StephaneLenclud@239: return true; StephaneLenclud@239: } StephaneLenclud@239: StephaneLenclud@239: /// StephaneLenclud@238: /// So that data contract knows all our types. StephaneLenclud@238: /// StephaneLenclud@238: /// StephaneLenclud@238: private static IEnumerable DerivedTypes() StephaneLenclud@238: { StephaneLenclud@238: return SharpLib.Utils.Reflection.GetDerivedTypes(); StephaneLenclud@238: } StephaneLenclud@238: StephaneLenclud@244: /// StephaneLenclud@244: /// StephaneLenclud@244: /// StephaneLenclud@244: public event PropertyChangedEventHandler PropertyChanged; StephaneLenclud@244: StephaneLenclud@246: StephaneLenclud@244: /// StephaneLenclud@244: /// Invoke our event. StephaneLenclud@244: /// StephaneLenclud@244: /// StephaneLenclud@244: protected void OnPropertyChanged(string name) StephaneLenclud@244: { StephaneLenclud@244: PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); StephaneLenclud@244: } StephaneLenclud@244: StephaneLenclud@244: StephaneLenclud@238: } StephaneLenclud@238: }