Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4245


Ignore:
Timestamp:
08/17/10 16:42:58 (14 years ago)
Author:
mkommend
Message:

Removed cloning of saved contents and refactored FileManager (ticket #1143).

Location:
trunk/sources
Files:
2 edited

Legend:

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

    r3500 r4245  
    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((IStorableContent)content.Clone(), filename, compressed);
     62      instance.SaveContent(content, 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);
    6779
    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       }
    9080    }
    9181    protected abstract void SaveContent(IStorableContent content, string filename, bool compressed);
  • trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs

    r4068 r4245  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Windows.Forms;
    2425using HeuristicLab.Common;
     
    4243      if (newItemDialog.ShowDialog() == DialogResult.OK) {
    4344        IView view = MainFormManager.MainForm.ShowContent(newItemDialog.Item);
    44         if (view == null) MessageBox.Show("There is no view for the new item. It cannot be displayed.", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
     45        if (view == null)
     46          ErrorHandling.ShowErrorDialog("There is no view for the new item. It cannot be displayed.", new InvalidOperationException("No View Available"));
    4547      }
    4648    }
     
    6668      try {
    6769        if (error != null) throw error;
    68         Invoke(delegate() {
    69           IView view = MainFormManager.MainForm.ShowContent(content);
    70           if (view == null) MessageBox.Show("There is no view for the loaded item. It cannot be displayed.", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
    71         });
     70        IView view = MainFormManager.MainForm.ShowContent(content);
     71        if (view == null)
     72          ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
    7273      }
    7374      catch (Exception ex) {
     
    8788    private static void Save(IContentView view) {
    8889      IStorableContent content = view.Content as IStorableContent;
    89       if (!view.Locked && (content != null)) {
     90      if (!view.Locked && content != null) {
    9091        if (string.IsNullOrEmpty(content.Filename))
    9192          SaveAs(view);
    9293        else {
    9394          ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor();
     95          var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList();
     96          views.ForEach(v => v.ReadOnly = true);
     97          views.ForEach(v => v.Locked = true);
    9498          ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted);
    9599        }
     
    104108    public static void SaveAs(IContentView view) {
    105109      IStorableContent content = view.Content as IStorableContent;
    106       if (!view.Locked && (content != null)) {
     110      if (!view.Locked && content != null) {
    107111        if (saveFileDialog == null) {
    108112          saveFileDialog = new SaveFileDialog();
     
    116120        if (saveFileDialog.ShowDialog() == DialogResult.OK) {
    117121          ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor();
     122          var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList();
     123          views.ForEach(v => v.ReadOnly = true);
     124          views.ForEach(v => v.Locked = true);
    118125          if (saveFileDialog.FilterIndex == 1) {
    119126            ContentManager.SaveAsync(content, saveFileDialog.FileName, false, SavingCompleted);
     
    126133    private static void SavingCompleted(IStorableContent content, Exception error) {
    127134      try {
     135        var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList();
     136        views.ForEach(v => v.ReadOnly = false);
     137        views.ForEach(v => v.Locked = false);
    128138        if (error != null) throw error;
    129         Invoke(delegate() {
    130           ((OptimizerMainForm)MainFormManager.MainForm).UpdateTitle();
    131         });
     139        MainFormManager.GetMainForm<OptimizerMainForm>().UpdateTitle();
    132140      }
    133141      catch (Exception ex) {
     
    138146      }
    139147    }
    140 
    141     private static void Invoke(Action a) {
    142       Form form = MainFormManager.MainForm as Form;
    143       if (form.InvokeRequired)
    144         form.Invoke(a);
    145       else
    146         a.Invoke();
    147     }
    148148  }
    149149}
Note: See TracChangeset for help on using the changeset viewer.