/// <summary> /// Starts the execution. /// </summary> private void StartExecution() { pgBar.Value = 0; Boolean localEnabled = false, remoteEnabled = false; List<IRemoteGateClient> clients = new List<IRemoteGateClient>(); /* Manually control the status of local machine */ foreach (IServer server in m_WorkSpace.Servers) { if (server is LocalServer) { if (server.Enabled) { server.Status = ServerStatus.Running; localEnabled = true; } } if (server is RemoteServer) { if (server.Enabled) { RemoteServer rServer = (RemoteServer)server; server.Status = ServerStatus.Down; IRemoteGateClient newClient = null; if (rServer.ConnectionType == ConnectionType.Http) { if (rServer.SecurityKey != null) newClient = new HttpRemoteGateClient(rServer.Host, rServer.Port, rServer.SecurityKey, 1000); else newClient = new HttpRemoteGateClient(rServer.Host, rServer.Port, 1000); } else if (rServer.ConnectionType == ConnectionType.Tcp) { if (rServer.SecurityKey != null) newClient = new TcpRemoteGateClient(rServer.Host, rServer.Port, rServer.SecurityKey, 1000); else newClient = new TcpRemoteGateClient(rServer.Host, rServer.Port, 1000); } newClient.ConnectedToServer += newClient_ConnectedToServer; newClient.DisconnectedFromServer += newClient_DisconnectedFromServer; rServer.Client = newClient; clients.Add(newClient); remoteEnabled = true; } } } DispatchMode mode = DispatchMode.Combined; if (localEnabled && remoteEnabled) mode = DispatchMode.Combined; else if (localEnabled) mode = DispatchMode.LocalOnly; else if (remoteEnabled) mode = DispatchMode.RemoteOnly; UpdateAllNodes(); /* Runtime creation of Generic type */ Type dynamicDispatcher = typeof(Dispatcher<,,>).MakeGenericType(new Type[] { typeof(CSharpScriptAssembler), m_WorkSpace.LocalBalancer, m_WorkSpace.RemoteBalancer }); m_Dispatcher = (IDispatcher)Activator.CreateInstance(dynamicDispatcher, new Object[] { m_WorkSpace.QueueSize, (m_WorkSpace.NumberOfThreads == 0) ? Environment.ProcessorCount : m_WorkSpace.NumberOfThreads, mode }); m_Dispatcher.AlgorithmProgress += m_dispatcher_AlgorithmProgress; m_Dispatcher.AlgorithmComplete += m_dispatcher_AlgorithmComplete; /* Add remote hosts */ foreach (IRemoteGateClient client in clients) { m_Dispatcher.RegisterGate(client); } m_AlgorithmInstance = m_WorkSpace.Provider.GetAlgorithmInstance(); m_CurrentWorkValue = 0; m_LastWorkValue = 0; m_MaxWorkValue = 0; m_MeasurmentsDone = 0; m_AverageSpeed = 0; m_Finished = false; UpdateStatusLabel(); graphView.AddLine(0, Color.Red).Thickness = 2; m_Dispatcher.Execute(m_AlgorithmInstance); pgBarTimer.Start(); m_IsRunning = true; }