- Timestamp:
- 04/19/10 17:21:14 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.