Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Grid/ClientForm.cs @ 24

Last change on this file since 24 was 24, checked in by gkronber, 16 years ago
  • fixed #31 by setting securityMode=None in the binding of client, server and distributed-engine
  • updated version number of Grid and DistributedEngine because new plugins had to be released
File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using System.ServiceModel;
31using HeuristicLab.Core;
32using System.Xml;
33using System.Threading;
34using System.IO;
35using System.IO.Compression;
36
37namespace HeuristicLab.Grid {
38  public partial class ClientForm : Form {
39
40    private ChannelFactory<IEngineStore> factory;
41    private System.Timers.Timer fetchOperationTimer;
42    private IEngineStore engineStore;
43
44    public ClientForm() {
45      InitializeComponent();
46      fetchOperationTimer = new System.Timers.Timer();
47      fetchOperationTimer.Interval = 200;
48      fetchOperationTimer.Elapsed += new System.Timers.ElapsedEventHandler(fetchOperationTimer_Elapsed);
49      statusTextBox.Text = "Stopped";
50    }
51
52    private void startButton_Click(object sender, EventArgs e) {
53      try {
54        NetTcpBinding binding = new NetTcpBinding();
55        binding.MaxReceivedMessageSize = 100000000; // 100Mbytes
56        binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
57        binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
58        binding.Security.Mode = SecurityMode.None;       
59        factory = new ChannelFactory<IEngineStore>(binding);
60        engineStore = factory.CreateChannel(new EndpointAddress(addressTextBox.Text));
61
62        fetchOperationTimer.Start();
63        startButton.Enabled = false;
64        stopButton.Enabled = true;
65        statusTextBox.Text = "Waiting for engine";
66
67      } catch (Exception ex) {
68        MessageBox.Show("Exception while connecting to the server: " + ex.Message);
69        startButton.Enabled = true;
70        stopButton.Enabled = false;
71        fetchOperationTimer.Stop();
72      }
73    }
74
75    private void stopButton_Click(object sender, EventArgs e) {
76      fetchOperationTimer.Stop();
77      factory.Abort();
78      statusTextBox.Text = "Stopped";
79      stopButton.Enabled = false;
80      startButton.Enabled = true;
81    }
82
83    private void fetchOperationTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
84      byte[] engineXml;
85      Guid guid;
86      fetchOperationTimer.Stop();
87      if (engineStore.TryTakeEngine(out guid, out engineXml)) {
88        ProcessingEngine engine = RestoreEngine(engineXml);
89        if (InvokeRequired) { Invoke((MethodInvoker)delegate() { statusTextBox.Text = "Executing engine"; }); } else statusTextBox.Text = "Executing engine";
90        engine.Finished += delegate(object src, EventArgs args) {
91          byte[] resultScopeXml = SaveScope(engine.InitialOperation.Scope);
92          engineStore.StoreResult(guid, resultScopeXml);
93          fetchOperationTimer.Interval = 100;
94          fetchOperationTimer.Start();
95        };
96        engine.Execute();
97      } else {
98        if(InvokeRequired) { Invoke((MethodInvoker)delegate() { statusTextBox.Text = "Waiting for engine"; }); } else statusTextBox.Text = "Waiting for engine";
99        fetchOperationTimer.Interval = 5000;
100        fetchOperationTimer.Start();
101      }
102    }
103    private ProcessingEngine RestoreEngine(byte[] engine) {
104      GZipStream stream = new GZipStream(new MemoryStream(engine), CompressionMode.Decompress);
105      return (ProcessingEngine)PersistenceManager.Load(stream);
106    }
107    private byte[] SaveScope(IScope scope) {
108      MemoryStream memStream = new MemoryStream();
109      GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
110      PersistenceManager.Save(scope, stream);
111      stream.Close();
112      return memStream.ToArray();
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.