private void UpdateServices(ResinService newResinService) { _resin = (Resin)_resinCmbBox.SelectedItem; if (_resin != null) { IList<ResinService> services = _setup.GetResinServices(_resin); ArrayList items = new ArrayList(); items.Add(_createService); items.AddRange((ICollection)services); _servicesCmbBox.BeginUpdate(); _servicesCmbBox.DataSource = items; if (services.Count == 0) { _servicesCmbBox.SelectedIndex = 0; } else if (services.Count > 0) { _servicesCmbBox.SelectedIndex = -1; StringBuilder builder = new StringBuilder("Select Service: ["); for (int i = 0; i < services.Count; i++) { ResinService service = services[i]; builder.Append(service.Name); if (i + 1 < services.Count) builder.Append(", "); } builder.Append(']'); _servicesCmbBox.Text = builder.ToString(); } _servicesCmbBox.EndUpdate(); } }
private void ServiceInstallBtnClick(object sender, EventArgs eventArgs) { bool isNew = MODE.NEW.Equals(_mode); if (isNew && !CheckServiceName()) return; if (isNew && !CheckConf()) return; ResinService resinService = new ResinService(); String resinExe = Util.FindResinExe(_resin.Home); resinService.Exe = resinExe; resinService.Home = _resin.Home; if (!_resinConfFile.Equals(_resin.Home + @"\" + _setup.GetResinConfFile(_resin))) resinService.Conf = _resinConfFile; if (!_javaHomeCmbBox.Text.StartsWith("Default: [")) resinService.JavaHome = _javaHome; if (!_resin.Home.Equals(_resinRoot)) resinService.Root = _resinRoot; if (!_resinLog.Equals(_resinRoot + @"\log")) resinService.Log = _resinLog; resinService.Name = _serviceNameTxtBox.Text; if ("Local Service".Equals(_serviceUserCmbBox.Text)) { } else if (_resinService == null && ("".Equals(_servicePassTxtBox.Text) || _servicePassTxtBox.Text == null)) { MessageBox.Show("Service Password is required", "Missing Password", MessageBoxButtons.OK, MessageBoxIcon.Error); _servicePassTxtBox.Focus(); return; } else { String user = _serviceUserCmbBox.Text; if (!(user.StartsWith(@".\") || user.StartsWith("\\"))) user = @".\" + user; String password = _servicePassTxtBox.Text; resinService.User = user; resinService.Password = password; } resinService.IsPreview = "Yes".Equals(_previewCmbBox.Text); ResinConfServer server = null; if (_serverCmbBox.SelectedItem is ResinConfServer) server = (ResinConfServer)_serverCmbBox.SelectedItem; if (isNew) { if (server != null) { resinService.Server = server.ID; } else { ResinConfServer dynamicServer = ResinConf.ParseDynamic(_serverCmbBox.Text); resinService.Cluster = dynamicServer.Cluster; resinService.Server = dynamicServer.ID; resinService.ElasticServer = true; resinService.DynamicServer = true; } } else { resinService.Cluster = _resinService.Cluster; resinService.Server = _resinService.Server; resinService.DynamicServer = _resinService.DynamicServer; resinService.ElasticServer = _resinService.ElasticServer; } if (resinService.ElasticServer && ! String.IsNullOrEmpty(ElasticAddressEdit.Text)) resinService.ElasticServerAddress = ElasticAddressEdit.Text.Trim(); if (resinService.ElasticServer && ! String.IsNullOrEmpty(ElasticPortEdit.Text)) resinService.ElasticServerPort = ElasticPortEdit.Text.Trim(); if (!"Not Specified".Equals(_jmxPortTxtBox.Text)) { String jmxPort = _resinConf.GetJmxPort(resinService.Cluster, resinService.Server); if (!_jmxPortTxtBox.Text.Equals(jmxPort)) resinService.JmxPort = int.Parse(_jmxPortTxtBox.Text); } if (!"Not Specified".Equals(_debugPortTxtBox.Text)) { String debugPort = _resinConf.GetDebugPort(resinService.Cluster, resinService.Server); if (!_debugPortTxtBox.Text.Equals(debugPort)) resinService.DebugPort = int.Parse(_debugPortTxtBox.Text); } if (!"Not Specified".Equals(_watchdogPortTxtBox.Text)) { String watchDogPort = _resinConf.GetWatchDogPort(resinService.Cluster, resinService.Server); if (!_watchdogPortTxtBox.Text.Equals(watchDogPort)) resinService.WatchdogPort = int.Parse(_watchdogPortTxtBox.Text); } resinService.ExtraParams = _extraParamsTxbBox.Text; String checkUser = null; bool success = false; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate(object delegateSender, DoWorkEventArgs delegateEvent) { try { while (_progressDialog == null || !_progressDialog.Visible) Thread.Sleep(10); if (isNew) { ProgressDialogAddStatus("Starting installation ..."); ProgressDialogAddStatus("Checking user ..."); } else { ProgressDialogAddStatus(String.Format("Updating service `{0}'", _resinService.Name)); } if (_resinService == null && resinService.User != null && !CheckUserCredentials(resinService.User, resinService.Password)) { checkUser = String.Format("User {0} failed to authenticate.\nPlease check user name and password", resinService.User); ProgressDialogError(checkUser); return; } _setup.InstallService(resinService, isNew); String message = null; if (isNew) message = String.Format("Service `{0}' is installed.", resinService.Name); else message = String.Format("Service `{0}' is updated.", resinService.Name); ProgressDialogSuccess(message, true); success = true; } catch (Exception e) { log.WriteEntry(e.Message + "\n" + e.StackTrace); String message = String.Format("Service installation failed due to message: {0}", e.Message); ProgressDialogError(message); } }; worker.RunWorkerAsync(); if (isNew) ProgressDialogDisplay("Installing Service " + resinService.Name, "Progress: "); else ProgressDialogDisplay("Updating Service " + resinService.Name, "Progress: "); if (success) { _setup.ResetResinServices(); UpdateServices(null); } else if (checkUser != null) { _errorProvider.SetError(_serviceUserCmbBox, checkUser); _serviceUserCmbBox.Focus(); } }
private void ServiceSelectionChanged(object sender, EventArgs e) { if (_createService.Equals(_servicesCmbBox.SelectedItem)) { _resinService = null; _mode = MODE.NEW; } else if (_servicesCmbBox.SelectedItem is ResinService) { _mode = MODE.EXISTING; _resinService = (ResinService)_servicesCmbBox.SelectedItem; } else { _mode = MODE.NONE; } bool enabled = MODE.NEW.Equals(_mode); _resinConfTxtBox.Enabled = enabled; _selectResinConfBtn.Enabled = enabled; _serverCmbBox.Enabled = enabled; _serviceNameTxtBox.Enabled = enabled; _serviceUserCmbBox.Enabled = enabled; _servicePassTxtBox.Enabled = enabled; enabled = !MODE.NONE.Equals(_mode); _javaHomeCmbBox.Enabled = enabled; _selectJavaHomeBtn.Enabled = enabled; _resinRootTxtBox.Enabled = enabled; _selectResinRootBtn.Enabled = enabled; _logDirTxtBox.Enabled = enabled; _selectLogDirBtn.Enabled = enabled; _previewCmbBox.Enabled = enabled; _jmxPortTxtBox.Enabled = enabled; _debugPortTxtBox.Enabled = enabled; _extraParamsTxbBox.Enabled = enabled; _watchdogPortTxtBox.Enabled = enabled; _serviceInstallBtn.Enabled = enabled; _serviceRemoveBtn.Enabled = MODE.EXISTING.Equals(_mode); UpdateDetails(); }