Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/22/10 23:33:13 (14 years ago)
Author:
swagner
Message:

Finished refactoring of saving and loading items (#990)

File:
1 edited

Legend:

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

    r3483 r3500  
    6060    public static void Save(IStorableContent content, string filename, bool compressed) {
    6161      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
    62       instance.SaveContent(content, filename, compressed);
     62      instance.SaveContent((IStorableContent)content.Clone(), filename, compressed);
    6363      content.Filename = filename;
    6464    }
    6565    public static void SaveAsync(IStorableContent content, string filename, bool compressed, Action<IStorableContent, Exception> savingCompletedCallback) {
    6666      if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
    67       var action = new Action<IStorableContent, string, bool>(instance.SaveContent);
    68       action.BeginInvoke(content, filename, compressed, delegate(IAsyncResult result) {
    69         Exception error = null;
    70         try {
    71           action.EndInvoke(result);
    72           content.Filename = filename;
    73         }
    74         catch (Exception ex) {
    75           error = ex;
    76         }
    77         savingCompletedCallback(content, error);
    78       }, null);
     67
     68      IStorableContent clone = null;
     69      try {
     70        clone = (IStorableContent)content.Clone();
     71      }
     72      catch (Exception ex) {
     73        savingCompletedCallback(content, ex);
     74      }
     75
     76      if (clone != null) {
     77        var action = new Action<IStorableContent, string, bool>(instance.SaveContent);
     78        action.BeginInvoke(clone, filename, compressed, delegate(IAsyncResult result) {
     79          Exception error = null;
     80          try {
     81            action.EndInvoke(result);
     82            content.Filename = filename;
     83          }
     84          catch (Exception ex) {
     85            error = ex;
     86          }
     87          savingCompletedCallback(content, error);
     88        }, null);
     89      }
    7990    }
    8091    protected abstract void SaveContent(IStorableContent content, string filename, bool compressed);
Note: See TracChangeset for help on using the changeset viewer.