Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3412 for trunk/sources


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

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

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  
    2727namespace HeuristicLab.Common {
    2828  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() {
    5131    }
    5232  }
  • trunk/sources/HeuristicLab.Common/3.3/Content/IContent.cs

    r3405 r3412  
    2626
    2727namespace HeuristicLab.Common {
    28   public interface IContent :IDeepCloneable{
    29     bool ReadOnlyView { get; set; }
    30 
    31     event EventHandler ReadOnlyViewChanged;
     28  public interface IContent{
    3229  }
    3330}
  • trunk/sources/HeuristicLab.Common/3.3/Content/IStorableContent.cs

    r3405 r3412  
    2828  public interface IStorableContent : IContent {
    2929    string Filename { get; set; }
    30     bool SaveEnabled { get; set; }
    3130
    3231    void Save();
     
    3635
    3736    event EventHandler FilenameChanged;
    38     event EventHandler SaveEnabledChanged;
    3937    event EventHandler SaveOperationStarted;
    4038    event EventHandler<EventArgs<Exception>> SaveOperationFinished;
  • 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.