Changeset 32 for trunk/sources/HeuristicLab.Grid/ClientForm.cs
- Timestamp:
- 02/29/08 19:22:27 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Grid/ClientForm.cs
r24 r32 34 34 using System.IO; 35 35 using System.IO.Compression; 36 using System.Net; 36 37 37 38 namespace HeuristicLab.Grid { 38 public partial class ClientForm : Form {39 39 [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)] 40 public partial class ClientForm : Form, IClient { 40 41 private ChannelFactory<IEngineStore> factory; 42 private ServiceHost clientHost; 41 43 private System.Timers.Timer fetchOperationTimer; 42 44 private IEngineStore engineStore; 45 private Guid currentGuid; 46 private ProcessingEngine currentEngine; 47 private string clientUrl; 43 48 44 49 public ClientForm() { … … 48 53 fetchOperationTimer.Elapsed += new System.Timers.ElapsedEventHandler(fetchOperationTimer_Elapsed); 49 54 statusTextBox.Text = "Stopped"; 55 currentGuid = Guid.Empty; 50 56 } 51 57 52 58 private void startButton_Click(object sender, EventArgs e) { 59 clientUrl = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8002/Grid/Client"; 60 clientHost = new ServiceHost(this, new Uri(clientUrl)); 53 61 try { 54 62 NetTcpBinding binding = new NetTcpBinding(); … … 56 64 binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars 57 65 binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements; 58 binding.Security.Mode = SecurityMode.None; 66 binding.Security.Mode = SecurityMode.None; 67 68 clientHost.AddServiceEndpoint(typeof(IClient), binding, clientUrl); 69 clientHost.Open(); 70 59 71 factory = new ChannelFactory<IEngineStore>(binding); 60 72 engineStore = factory.CreateChannel(new EndpointAddress(addressTextBox.Text)); … … 65 77 statusTextBox.Text = "Waiting for engine"; 66 78 67 } catch ( Exception ex) {79 } catch (CommunicationException ex) { 68 80 MessageBox.Show("Exception while connecting to the server: " + ex.Message); 81 clientHost.Abort(); 69 82 startButton.Enabled = true; 70 83 stopButton.Enabled = false; … … 76 89 fetchOperationTimer.Stop(); 77 90 factory.Abort(); 91 clientHost.Close(); 78 92 statusTextBox.Text = "Stopped"; 79 93 stopButton.Enabled = false; … … 83 97 private void fetchOperationTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { 84 98 byte[] engineXml; 85 Guid guid;86 99 fetchOperationTimer.Stop(); 87 if (engineStore.TryTakeEngine( out guid, out engineXml)) {88 ProcessingEngine engine = RestoreEngine(engineXml);100 if (engineStore.TryTakeEngine(clientUrl, out currentGuid, out engineXml)) { 101 currentEngine = RestoreEngine(engineXml); 89 102 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); 103 currentEngine.Finished += delegate(object src, EventArgs args) { 104 byte[] resultScopeXml = SaveScope(currentEngine.InitialOperation.Scope); 105 engineStore.StoreResult(currentGuid, resultScopeXml); 106 currentGuid = Guid.Empty; 107 currentEngine = null; 93 108 fetchOperationTimer.Interval = 100; 94 109 fetchOperationTimer.Start(); 95 110 }; 96 engine.Execute();111 currentEngine.Execute(); 97 112 } else { 98 113 if(InvokeRequired) { Invoke((MethodInvoker)delegate() { statusTextBox.Text = "Waiting for engine"; }); } else statusTextBox.Text = "Waiting for engine"; … … 100 115 fetchOperationTimer.Start(); 101 116 } 117 } 118 public void Abort(Guid guid) { 119 if(!IsRunningEngine(guid)) return; 120 currentEngine.Abort(); 121 } 122 public bool IsRunningEngine(Guid guid) { 123 return currentGuid == guid; 102 124 } 103 125 private ProcessingEngine RestoreEngine(byte[] engine) {
Note: See TracChangeset
for help on using the changeset viewer.