Changeset 3412 for trunk/sources
- Timestamp:
- 04/19/10 17:21:14 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Common/3.3/Content
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/Content/Content.cs
r3405 r3412 27 27 namespace HeuristicLab.Common { 28 28 public class Content : DeepCloneable, IContent { 29 public Content() { 30 this.readOnlyView = false; 31 } 32 public Content(bool readOnlyView) 33 : this() { 34 this.ReadOnlyView = readOnlyView; 35 } 36 37 private bool readOnlyView; 38 public virtual bool ReadOnlyView { 39 get { return readOnlyView; } 40 set { 41 if (readOnlyView != value) { 42 readOnlyView = value; 43 OnReadOnlyViewChanged(); 44 } 45 } 46 } 47 public event EventHandler ReadOnlyViewChanged; 48 protected virtual void OnReadOnlyViewChanged() { 49 EventHandler handler = ReadOnlyViewChanged; 50 if (handler != null) handler(this, EventArgs.Empty); 29 public Content() 30 : base() { 51 31 } 52 32 } -
trunk/sources/HeuristicLab.Common/3.3/Content/IContent.cs
r3405 r3412 26 26 27 27 namespace HeuristicLab.Common { 28 public interface IContent :IDeepCloneable{ 29 bool ReadOnlyView { get; set; } 30 31 event EventHandler ReadOnlyViewChanged; 28 public interface IContent{ 32 29 } 33 30 } -
trunk/sources/HeuristicLab.Common/3.3/Content/IStorableContent.cs
r3405 r3412 28 28 public interface IStorableContent : IContent { 29 29 string Filename { get; set; } 30 bool SaveEnabled { get; set; }31 30 32 31 void Save(); … … 36 35 37 36 event EventHandler FilenameChanged; 38 event EventHandler SaveEnabledChanged;39 37 event EventHandler SaveOperationStarted; 40 38 event EventHandler<EventArgs<Exception>> SaveOperationFinished; -
trunk/sources/HeuristicLab.Common/3.3/Content/StorableContent.cs
r3406 r3412 32 32 : base() { 33 33 this.filename = string.Empty; 34 this.saveEnabled = true;35 34 } 36 public StorableContent(bool saveEnabled) 37 : this() { 38 this.saveEnabled = saveEnabled; 39 //NOTE: important do not call propagate changes, because derived objects are not constructed 40 } 41 public StorableContent(bool saveEnabled, string filename) 42 : this(saveEnabled) { 35 public StorableContent(string filename) 36 : base() { 43 37 this.Filename = filename; 44 38 } … … 55 49 } 56 50 57 private bool saveEnabled;58 public virtual bool SaveEnabled {59 get { return this.saveEnabled; }60 set {61 if (this.saveEnabled != value) {62 this.saveEnabled = value;63 this.PropagateSaveEnabledChanges();64 this.OnSaveEnabledChanged();65 }66 }67 }68 69 protected void PropagateSaveEnabledChanges() {70 Type type = this.GetType();71 foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Default)) {72 if (typeof(IStorableContent).IsAssignableFrom(fieldInfo.GetType())) {73 IStorableContent storableContent = (IStorableContent)fieldInfo.GetValue(this);74 storableContent.SaveEnabled = this.saveEnabled;75 }76 }77 }78 79 51 protected abstract void Save(); 80 52 void IStorableContent.Save() { 81 if (this.SaveEnabled) { 82 this.OnSaveOperationStarted(); 53 this.OnSaveOperationStarted(); 54 Exception ex = null; 55 try { 83 56 this.Save(); 84 this.OnSaveOperationFinished(null);85 57 } 58 catch (Exception e) { 59 ex = e; 60 } 61 this.OnSaveOperationFinished(ex); 86 62 } 87 63 public void Save(string filename) { … … 93 69 ThreadPool.QueueUserWorkItem( 94 70 new WaitCallback(delegate(object arg) { 95 try { this.Save(); } 96 catch (Exception ex) { 97 this.OnSaveOperationFinished(ex); 98 } 71 this.Save(); 99 72 }) 100 73 ); … … 115 88 if (handler != null) handler(this, EventArgs.Empty); 116 89 } 117 public event EventHandler SaveEnabledChanged;118 protected virtual void OnSaveEnabledChanged() {119 EventHandler handler = SaveEnabledChanged;120 if (handler != null) handler(this, EventArgs.Empty);121 }122 90 public event EventHandler SaveOperationStarted; 123 91 protected virtual void OnSaveOperationStarted() { … … 130 98 if (handler != null) handler(this, new EventArgs<Exception>(ex)); 131 99 } 132 133 100 } 134 101 }
Note: See TracChangeset
for help on using the changeset viewer.