/// <summary> /// Connects to the executor in dedicated mode. /// </summary> /// <param name="ep">end point of the executor</param> public void ConnectDedicated(EndPoint ep) { logger.Debug("Trying to connect Dedicated to executor: " + _Id); if (!VerifyExists(ep)) { logger.Debug("The supplied Executor ID does not exist."); throw new InvalidExecutorException("The supplied Executor ID does not exist.", null); } bool success = false; IExecutor executor; EndPointReference epr = null; try { epr = GNode.GetRemoteRef(ep, typeof(IExecutor)); executor = (IExecutor)epr.Instance; executor.PingExecutor(); //connect back to executor. success = true; logger.Debug("Connected dedicated. Executor_id=" + _Id); ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id); executorStorage.Connected = success; executorStorage.Dedicated = true; executorStorage.HostName = ep.Host; executorStorage.Port = ep.Port; // update state in db (always happens even if cannnot connect back to executor ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage); logger.Debug("Updated db after ping back to executor. dedicated executor_id=" + _Id + ", dedicated = true, connected = " + success); // update hashtable //for thread-safety lock (_DedicatedExecutors) { //TODO: change this collection to a collection of EndPointReferences of the connections will not be properly disposed. if (!_DedicatedExecutors.ContainsKey(_Id)) { _DedicatedExecutors.Add(_Id, executor); logger.Debug("Added to list of dedicated executors: executor_id=" + _Id); } else { //WCF ( doesnt remoting do that to ) closes the connection if executor connects and disconects. //So we must remove the old and add the new record //Jure Subara _DedicatedExecutors.Remove(_Id); _DedicatedExecutors.Add(_Id, executor); logger.Debug("Refreshed the record in list od dedicated executors: executor_id=" + _Id); } } } catch (Exception e) { logger.Error("Error connecting to exec: " + _Id, e); throw new ExecutorCommException(_Id, e); } }
private void btnOK_Click(object sender, EventArgs e) { //int port; //try //{ // port = int.Parse(txtPort.Text); //} //catch (System.FormatException) //{ // MessageBox.Show("Invalid name for 'Port' field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} connection = new GConnection(); //config.Host = connection.Host = txtHost.Text; //config.Port = connection.Port = port; config.Username = connection.Username = txtUsername.Text; config.Password = connection.Password = txtPassword.Text; if (config.EndPointConfig == null) { config.EndPointConfig = new EndPointConfiguration(); } ucEndPointConfig.WriteEndPointConfiguration(config.EndPointConfig); connection.RemoteEP = config.EndPointConfig.GetEndPoint(); config.Write(Role); IManager mgr; EndPointReference mgrEpr = null; try { mgrEpr = GNode.GetRemoteManagerRef(connection.RemoteEP); mgr = (IManager)mgrEpr.Instance; } catch (RemotingException) { MessageBox.Show("Could not connect to grid at " + connection.Host + ":" + connection.Port + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { mgr.AuthenticateUser(new SecurityCredentials(config.Username, config.Password)); } catch (AuthenticationException) { MessageBox.Show("Access denied.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (mgrEpr != null) { mgrEpr.Dispose(); mgrEpr = null; } DialogResult = DialogResult.OK; }