public void Connect(string serverName, string defaultApplication) { var server = (from ServerElement element in _config.ServerCollection where element.Name == serverName select element).LastOrDefault(); _client = new ThinClient(server.HostName, server.Port); _client.ConnectTimeout = _config.ConnectTimeout * 1000; _client.ReceiveTimeout = _config.ReceiveTimeout * 1000; _client.SendTimeout = _config.SendTimeout * 1000; ConfigurationRequest request = new ConfigurationRequest(); ConfigurationResponse response = null; int callCount = 0; while (true) { DateTime startTime = DateTime.Now; try { callCount++; response = _client.Invoke <ConfigurationRequest, ConfigurationResponse>(request); break; } catch (ServerFaultException ex) { HandleServerFaultException(ex); return; } catch (Exception ex) { if (callCount >= _config.RetryCount + 1) { callCount = 0; if (MessageBox.Show(string.Format("Unable to contact the server. Do you want to retry?\n\n{0}", ex.Message), _form.Text, MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Cancel) { return; } } else { TimeSpan processingTime = DateTime.Now - startTime; if (processingTime.TotalMilliseconds < _client.ConnectTimeout) { int sleepTime = _client.ConnectTimeout - (int)processingTime.TotalMilliseconds; Thread.Sleep(sleepTime); } } } } using (ApplicationForm applicationForm = new ApplicationForm()) { _form.Visible = false; try { applicationForm.Presenter.Client = _client; applicationForm.Presenter.NativeDriver = _nativeDriver; applicationForm.Presenter.Config = _config; applicationForm.Presenter.ServerConfiguration = response; applicationForm.Presenter.DefaultApplication = defaultApplication; applicationForm.Left = _form.Left; applicationForm.Top = _form.Top; applicationForm.Width = _form.Width; applicationForm.Height = _form.Height; applicationForm.ShowDialog(); } finally { _form.Visible = true; } } }
public ApplicationPresenter(ApplicationForm form) { _form = form; }