using System; using System.Collections.Generic; namespace Chernobyl.Threading { public abstract class DataAccessor { /// /// Constructor. /// /// The to attach to. /// The rights granted to this accessor. public DataAccessor(DataSafe attachTo, AccessRights accessRights) { AccessRights = accessRights; attachTo.Attach(this); IsAttached = true; } /// /// When this DataAccess is attached to a /// (using ). /// This method is called after the attaching has been done. If this /// method is overwritten then the implementor must remember to set /// the property to true on a successful attach /// and set to the passed in /// . /// /// The that this accessor /// is attaching to public virtual void OnAttach(DataSafe attachTo) { MyDataSafe = attachTo; IsAttached = true; } /// /// This method is called when the DataSafe is synchronized. /// The passed in changeRecords are to be run on the accessors /// data so that it can have it's data synchronized with the other /// accessors. /// /// The change records to run on the internal /// data. public abstract void Synchronize(Queue.ChangeRecord> changeRecords); /// /// Gets/sets the AccessPermissions of this class.. /// public AccessRights AccessRights {get; internal set;} /// /// True if this DataAccessor has been attached to a DataSafe. /// public bool IsAttached {get; private set;} /// /// The that this accessor is attached to. /// protected DataSafe MyDataSafe {get; set;} } /// /// Used to specify what rights are granted to the /// when accessing the /// synchronized data in the . /// [Flags] public enum AccessRights { None = 0, CanRead = 1, CanWrite = 2, } }