Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/22/10 05:14:39 (14 years ago)
Author:
swagner
Message:

Worked on the refactoring of saving and loading items (#990)

File:
1 edited

Legend:

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

    r3412 r3483  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading;
    27 using System.Reflection;
    2823
    2924namespace HeuristicLab.Common {
    30   public abstract class StorableContent : Content, IStorableContent {
    31     public StorableContent()
    32       : base() {
    33       this.filename = string.Empty;
    34     }
    35     public StorableContent(string filename)
    36       : base() {
    37       this.Filename = filename;
    38     }
    39 
     25  public class StorableContent : IStorableContent {
    4026    private string filename;
    4127    public string Filename {
    42       get { return this.filename; }
     28      get { return filename; }
    4329      set {
    44         if (this.filename != value) {
    45           this.filename = value;
    46           this.OnFilenameChanged();
     30        if (!filename.Equals(value)) {
     31          filename = value;
     32          OnFilenameChanged();
    4733        }
    4834      }
    4935    }
    5036
    51     protected abstract void Save();
    52     void IStorableContent.Save() {
    53       this.OnSaveOperationStarted();
    54       Exception ex = null;
    55       try {
    56         this.Save();
    57       }
    58       catch (Exception e) {
    59         ex = e;
    60       }
    61       this.OnSaveOperationFinished(ex);
    62     }
    63     public void Save(string filename) {
    64       this.Filename = filename;
    65       ((IStorableContent)this).Save();
    66     }
    67 
    68     protected virtual void SaveAsnychronous() {
    69       ThreadPool.QueueUserWorkItem(
    70         new WaitCallback(delegate(object arg) {
    71         this.Save();
    72       })
    73       );
    74     }
    75     void IStorableContent.SaveAsynchronous() {
    76       this.OnSaveOperationStarted();
    77       this.SaveAsnychronous();
    78       this.OnSaveOperationFinished(null);
    79     }
    80     public void SaveAsynchronous(string filename) {
    81       this.Filename = filename;
    82       ((IStorableContent)this).SaveAsynchronous();
     37    public StorableContent() {
     38      filename = string.Empty;
    8339    }
    8440
     
    8844      if (handler != null) handler(this, EventArgs.Empty);
    8945    }
    90     public event EventHandler SaveOperationStarted;
    91     protected virtual void OnSaveOperationStarted() {
    92       EventHandler handler = SaveOperationStarted;
    93       if (handler != null) handler(this, EventArgs.Empty);
    94     }
    95     public event EventHandler<EventArgs<Exception>> SaveOperationFinished;
    96     protected virtual void OnSaveOperationFinished(Exception ex) {
    97       EventHandler<EventArgs<Exception>> handler = SaveOperationFinished;
    98       if (handler != null) handler(this, new EventArgs<Exception>(ex));
    99     }
    10046  }
    10147}
Note: See TracChangeset for help on using the changeset viewer.