Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/19/10 17:21:14 (14 years ago)
Author:
mkommend
Message:

adapted contents according to discussions with swa (ticket #980)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/Content/StorableContent.cs

    r3406 r3412  
    3232      : base() {
    3333      this.filename = string.Empty;
    34       this.saveEnabled = true;
    3534    }
    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() {
    4337      this.Filename = filename;
    4438    }
     
    5549    }
    5650
    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 
    7951    protected abstract void Save();
    8052    void IStorableContent.Save() {
    81       if (this.SaveEnabled) {
    82         this.OnSaveOperationStarted();
     53      this.OnSaveOperationStarted();
     54      Exception ex = null;
     55      try {
    8356        this.Save();
    84         this.OnSaveOperationFinished(null);
    8557      }
     58      catch (Exception e) {
     59        ex = e;
     60      }
     61      this.OnSaveOperationFinished(ex);
    8662    }
    8763    public void Save(string filename) {
     
    9369      ThreadPool.QueueUserWorkItem(
    9470        new WaitCallback(delegate(object arg) {
    95         try { this.Save(); }
    96         catch (Exception ex) {
    97           this.OnSaveOperationFinished(ex);
    98         }
     71        this.Save();
    9972      })
    10073      );
     
    11588      if (handler != null) handler(this, EventArgs.Empty);
    11689    }
    117     public event EventHandler SaveEnabledChanged;
    118     protected virtual void OnSaveEnabledChanged() {
    119       EventHandler handler = SaveEnabledChanged;
    120       if (handler != null) handler(this, EventArgs.Empty);
    121     }
    12290    public event EventHandler SaveOperationStarted;
    12391    protected virtual void OnSaveOperationStarted() {
     
    13098      if (handler != null) handler(this, new EventArgs<Exception>(ex));
    13199    }
    132 
    133100  }
    134101}
Note: See TracChangeset for help on using the changeset viewer.