Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3424


Ignore:
Timestamp:
04/19/10 22:46:52 (15 years ago)
Author:
mkommend
Message:

created questionable stub of ContentManager (ticket #980)

File:
1 edited

Legend:

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

    r3405 r3424  
    2424using System.Linq;
    2525using System.Text;
     26using System.Threading;
    2627
    2728namespace HeuristicLab.Common {
    28   public class ContentManager {
     29  public abstract class ContentManager {
     30    protected ContentManager() {
     31    }
     32
     33    private static ContentManager instance;
     34    public static ContentManager Instance {
     35      get { return instance; }
     36    }
     37    public static void CreateInstance<T>() where T : ContentManager {
     38      if (instance != null)
     39        throw new InvalidOperationException("ContentManager was already created.");
     40      instance = Activator.CreateInstance<T>();
     41    }
     42
     43    public static void Save(IStorableContent content) {
     44      content.Save();
     45    }
     46    public static void Save(IStorableContent content, string filename) {
     47      content.Save(filename);
     48    }
     49
     50    protected abstract void Load(string filename, bool flag);
     51    public static void Load(string filename) {
     52      if (instance == null)
     53        throw new InvalidOperationException("ContentManager must be created before access is allowed.");
     54
     55      Exception ex = null;
     56      instance.OnLoadOperationStarted();
     57      try {
     58        instance.Load(filename, false);
     59      }
     60      catch (Exception e) {
     61        ex = e;
     62      }
     63      instance.OnLoadOperationFinished(ex);
     64    }
     65
     66    public static void LoadAsynchronous(string filename) {
     67      if (instance == null)
     68        throw new InvalidOperationException("ContentManager must be created before access is allowed.");
     69
     70      ThreadPool.QueueUserWorkItem(
     71        new WaitCallback(delegate(object arg) {
     72        Load(filename);
     73      })
     74      );
     75    }
     76   
     77
     78    public event EventHandler LoadOperationStarted;
     79    protected virtual void OnLoadOperationStarted() {
     80      EventHandler handler = LoadOperationStarted;
     81      if (handler != null)
     82        handler(this, EventArgs.Empty);
     83    }
     84    public event EventHandler<EventArgs<Exception>> LoadOperationFinished;
     85    protected virtual void OnLoadOperationFinished(Exception e) {
     86      EventHandler<EventArgs<Exception>> handler = LoadOperationFinished;
     87      if (handler != null)
     88        handler(this, new EventArgs<Exception>(e));
     89    }
    2990  }
    3091}
Note: See TracChangeset for help on using the changeset viewer.