Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2954 for trunk/sources


Ignore:
Timestamp:
03/07/10 05:16:02 (14 years ago)
Author:
swagner
Message:

Made file operations in algorithm views asynchronous (#895)

Location:
trunk/sources/HeuristicLab.Optimization.Views/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r2949 r2954  
    200200      openFileDialog.Title = "Open Problem";
    201201      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
    202         IProblem problem = null;
    203         try {
    204           problem = XmlParser.Deserialize(openFileDialog.FileName) as IProblem;
    205         }
    206         catch (Exception ex) {
    207           Auxiliary.ShowErrorMessageBox(ex);
    208         }
    209         if (problem == null)
    210           MessageBox.Show(this, "The selected file does not contain a problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
    211         else if (!Content.ProblemType.IsInstanceOfType(problem))
    212           MessageBox.Show(this, "The selected file contains a problem type which is not supported by this algorithm.", "Invalid Problem Type", MessageBoxButtons.OK, MessageBoxIcon.Error);
    213         else
    214           Content.Problem = problem;
     202        this.Cursor = Cursors.AppStarting;
     203        newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = false;
     204
     205        var call = new Func<string, object>(XmlParser.Deserialize);
     206        call.BeginInvoke(openFileDialog.FileName, delegate(IAsyncResult a) {
     207          IProblem problem = null;
     208          try {
     209            problem = call.EndInvoke(a) as IProblem;
     210          } catch (Exception ex) {
     211            Auxiliary.ShowErrorMessageBox(ex);
     212          }
     213          Invoke(new Action(delegate() {
     214            if (problem == null)
     215              MessageBox.Show(this, "The selected file does not contain a problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
     216            else if (!Content.ProblemType.IsInstanceOfType(problem))
     217              MessageBox.Show(this, "The selected file contains a problem type which is not supported by this algorithm.", "Invalid Problem Type", MessageBoxButtons.OK, MessageBoxIcon.Error);
     218            else
     219              Content.Problem = problem;
     220            newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = true;
     221            this.Cursor = Cursors.Default;
     222          }));
     223        }, null);
    215224      }
    216225    }
     
    218227      saveFileDialog.Title = "Save Problem";
    219228      if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
    220         try {
    221           if (saveFileDialog.FilterIndex == 1)
    222             XmlGenerator.Serialize(Content.Problem, saveFileDialog.FileName, 0);
    223           else
    224             XmlGenerator.Serialize(Content.Problem, saveFileDialog.FileName, 9);
    225         }
    226         catch (Exception ex) {
    227           Auxiliary.ShowErrorMessageBox(ex);
    228         }
     229        this.Cursor = Cursors.AppStarting;
     230        newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = false;
     231
     232        var call = new Action<IProblem, string, int>(XmlGenerator.Serialize);
     233        int compression = 9;
     234        if (saveFileDialog.FilterIndex == 1) compression = 0;
     235        call.BeginInvoke(Content.Problem, saveFileDialog.FileName, compression, delegate(IAsyncResult a) {
     236          try {
     237            call.EndInvoke(a);
     238          }
     239          catch (Exception ex) {
     240            Auxiliary.ShowErrorMessageBox(ex);
     241          }
     242          Invoke(new Action(delegate() {
     243            newProblemButton.Enabled = openProblemButton.Enabled = saveProblemButton.Enabled = true;
     244            this.Cursor = Cursors.Default;
     245          }));
     246        }, null);
    229247      }
    230248    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.cs

    r2949 r2954  
    9090      openFileDialog.Title = "Open Operator Graph";
    9191      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
    92         OperatorGraph operatorGraph = null;
    93         try {
    94           operatorGraph = XmlParser.Deserialize(openFileDialog.FileName) as OperatorGraph;
    95         }
    96         catch (Exception ex) {
    97           Auxiliary.ShowErrorMessageBox(ex);
    98         }
    99         if (operatorGraph == null)
    100           MessageBox.Show(this, "The selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
    101         else
    102           Content.OperatorGraph = operatorGraph;
     92        this.Cursor = Cursors.AppStarting;
     93        newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = false;
     94
     95        var call = new Func<string, object>(XmlParser.Deserialize);
     96        call.BeginInvoke(openFileDialog.FileName, delegate(IAsyncResult a) {
     97          OperatorGraph operatorGraph = null;
     98          try {
     99            operatorGraph = call.EndInvoke(a) as OperatorGraph;
     100          }
     101          catch (Exception ex) {
     102            Auxiliary.ShowErrorMessageBox(ex);
     103          }
     104          Invoke(new Action(delegate() {
     105            if (operatorGraph == null)
     106              MessageBox.Show(this, "The selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
     107            else
     108              Content.OperatorGraph = operatorGraph;
     109            newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = true;
     110            this.Cursor = Cursors.Default;
     111          }));
     112        }, null);
    103113      }
    104114    }
     
    106116      saveFileDialog.Title = "Save Operator Graph";
    107117      if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
    108         try {
    109           if (saveFileDialog.FilterIndex == 1)
    110             XmlGenerator.Serialize(Content.OperatorGraph, saveFileDialog.FileName, 0);
    111           else
    112             XmlGenerator.Serialize(Content.OperatorGraph, saveFileDialog.FileName, 9);
    113         }
    114         catch (Exception ex) {
    115           Auxiliary.ShowErrorMessageBox(ex);
    116         }
     118        this.Cursor = Cursors.AppStarting;
     119        newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = false;
     120
     121        var call = new Action<OperatorGraph, string, int>(XmlGenerator.Serialize);
     122        int compression = 9;
     123        if (saveFileDialog.FilterIndex == 1) compression = 0;
     124        call.BeginInvoke(Content.OperatorGraph, saveFileDialog.FileName, compression, delegate(IAsyncResult a) {
     125          try {
     126            call.EndInvoke(a);
     127          }
     128          catch (Exception ex) {
     129            Auxiliary.ShowErrorMessageBox(ex);
     130          }
     131          Invoke(new Action(delegate() {
     132            newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = true;
     133            this.Cursor = Cursors.Default;
     134          }));
     135        }, null);
    117136      }
    118137    }
Note: See TracChangeset for help on using the changeset viewer.