- Timestamp:
- 04/22/10 05:14:39 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/Content/StorableContent.cs
r3412 r3483 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 using System.Threading;27 using System.Reflection;28 23 29 24 namespace 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 { 40 26 private string filename; 41 27 public string Filename { 42 get { return this.filename; }28 get { return filename; } 43 29 set { 44 if ( this.filename != value) {45 this.filename = value;46 this.OnFilenameChanged();30 if (!filename.Equals(value)) { 31 filename = value; 32 OnFilenameChanged(); 47 33 } 48 34 } 49 35 } 50 36 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; 83 39 } 84 40 … … 88 44 if (handler != null) handler(this, EventArgs.Empty); 89 45 } 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 }100 46 } 101 47 }
Note: See TracChangeset
for help on using the changeset viewer.