public IceDeployVersionForm(AppMonitor.Froms.MonitorForm monitorForm, SessionConfig _config, IceMonitorItem ice) { InitializeComponent(); SkinUtil.SetFormSkin(this); this.monitorForm = monitorForm; config = _config; this.ice = ice; }
private void button1_Click(object sender, EventArgs e) { int index = tabControl1.SelectedIndex; bool isnew = false; if (monitorConfig == null) { isnew = true; } else { index = tabIndex; } if (index == 0) { // springboot SpringBootMonitorItem item = new SpringBootMonitorItem(); item.AppName = stb_app_name.Text; item.BuildFileName = stb_build_file.Text; item.CrlFileName = stb_ctl_file.Text; item.ShFileDir = stb_sh_dir.Text; if (item.ShFileDir.EndsWith("/")) { item.ShFileDir = item.ShFileDir.Substring(0, item.ShFileDir.Length); } item.ProjectSourceDir = stb_project_source_dir.Text; if (item.ProjectSourceDir.EndsWith("/")) { item.ProjectSourceDir = item.ProjectSourceDir.Substring(0, item.ProjectSourceDir.Length); } item.HomeUrl = stb_home_url.Text; item.RunStatus = RunState.NoCheck; if (string.IsNullOrWhiteSpace(item.HomeUrl)) { item.HomeUrl = "http://" + config.Host + ":8080/"; } if (string.IsNullOrWhiteSpace(item.AppName) || hasNonChar(item.AppName)) { MessageBox.Show(this, "请填写应用名称,且不能包含'\",:;|"); return; } else if (string.IsNullOrWhiteSpace(item.ShFileDir)) { MessageBox.Show(this, "请填写应用脚本目录"); return; } else if (string.IsNullOrWhiteSpace(item.BuildFileName)) { MessageBox.Show(this, "请填写应用编译脚本文件名称"); return; } else if (string.IsNullOrWhiteSpace(item.CrlFileName)) { MessageBox.Show(this, "请填写应用控制脚本文件名称"); return; } else if (string.IsNullOrWhiteSpace(item.ProjectSourceDir)) { MessageBox.Show(this, "请填写应用代码存放目录"); return; } item.NeedAdd = cb_need_add.Checked; if (item.NeedAdd) { item.ProjectSvnUrl = stb_project_svn.Text; if (string.IsNullOrWhiteSpace(item.ProjectSvnUrl)) { MessageBox.Show(this, "请填写应用SVN地址"); return; } } if (isnew) { item.Uuid = Guid.NewGuid().ToString("N"); monitorConfig = new MonitorItemConfig(); } else { item.Uuid = monitorConfig.spring.Uuid; } monitorConfig.spring = item; } else if (index == 1) { // tomcat TomcatMonitorItem item = new TomcatMonitorItem(); item.TomcatName = stb_tomcat_name.Text; item.TomcatDir = stb_tomcat_path.Text; item.TomcatPort = stb_tomcat_port.Text; item.RunStatus = RunState.NoCheck; if (string.IsNullOrWhiteSpace(item.TomcatName) || hasNonChar(item.TomcatName)) { MessageBox.Show(this, "请填写Tomcat名称,且不能包含'\",:;|"); return; } else if (string.IsNullOrWhiteSpace(item.TomcatDir)) { MessageBox.Show(this, "请填写Tomcat根目录"); return; } else if (string.IsNullOrWhiteSpace(item.TomcatPort)) { item.TomcatPort = "8080"; } if (isnew) { item.Uuid = Guid.NewGuid().ToString("N"); monitorConfig = new MonitorItemConfig(); } else { item.Uuid = monitorConfig.tomcat.Uuid; } monitorConfig.tomcat = item; } else if (index == 2) { // nginx NginxMonitorItem item = new NginxMonitorItem(); item.NginxName = stb_nginx_name.Text; item.NginxPath = stb_nginx_path.Text; item.NginxConfig = stb_nginx_conf.Text; item.RunStatus = RunState.NoCheck; if (string.IsNullOrWhiteSpace(item.NginxName) || hasNonChar(item.NginxName)) { MessageBox.Show(this, "请填写Nginx名称,且不能包含'\",:;|"); return; } else if (string.IsNullOrWhiteSpace(item.NginxPath)) { MessageBox.Show(this, "请填写Nginx执行文件完整路径"); return; } else if (string.IsNullOrWhiteSpace(item.NginxConfig)) { MessageBox.Show(this, "请填写Nginx配置文件完整路径"); return; } if (isnew) { monitorConfig = new MonitorItemConfig(); item.Uuid = Guid.NewGuid().ToString("N"); } else { item.Uuid = monitorConfig.nginx.Uuid; } monitorConfig.nginx = item; } else if (index == 3) { // ice IceMonitorItem item = new IceMonitorItem(); item.AppName = stb_ice_appname.Text; item.IceSrvDir = stb_ice_srvpath.Text; item.NodePorts = stb_ice_ports.Text; item.ServerName = stb_ice_servername.Text; item.RunStatus = RunState.NoCheck; if (string.IsNullOrWhiteSpace(item.AppName) || hasNonChar(item.AppName)) { MessageBox.Show(this, "请填写项目名称,且不能包含'\",:;|"); return; } else if (string.IsNullOrWhiteSpace(item.IceSrvDir)) { MessageBox.Show(this, "请填写项目Ice目录完整路径"); return; } else if (string.IsNullOrWhiteSpace(item.ServerName)) { MessageBox.Show(this, "请填写Ice服务名称"); return; } else if (string.IsNullOrWhiteSpace(item.NodePorts)) { MessageBox.Show(this, "请填写项目使用的端口号,多个以逗号(,)分隔"); return; } if (isnew) { monitorConfig = new MonitorItemConfig(); item.Uuid = Guid.NewGuid().ToString("N"); } else { item.Uuid = monitorConfig.ice.Uuid; } monitorConfig.ice = item; } if (isnew) { config.MonitorConfigList.Add(monitorConfig); } AppConfig.Instance.SaveConfig(2); if (null != parentForm && monitorConfig.spring != null) { // TODO 执行checkout if (monitorConfig.spring.NeedAdd) { string home = parentForm.getSftp().getHome(); string buildStr = YSTools.YSFile.readFileToString(MainForm.CONF_DIR + "__build.sh"); string ctlStr = YSTools.YSFile.readFileToString(MainForm.CONF_DIR + "__ctl.sh"); if (monitorConfig.spring.ProjectSourceDir.StartsWith(home)) { string path = monitorConfig.spring.ProjectSourceDir.Substring(home.Length); if (path.StartsWith("/")) { path = path.Substring(1); } buildStr = buildStr.Replace("_sourcePath_", "~/" + path); ctlStr = ctlStr.Replace("_sourcePath_", "~/" + path); } else { buildStr = buildStr.Replace("_sourcePath_", monitorConfig.spring.ProjectSourceDir); ctlStr = ctlStr.Replace("_sourcePath_", monitorConfig.spring.ProjectSourceDir); } buildStr = buildStr.Replace("_projectName_", monitorConfig.spring.AppName); ctlStr = ctlStr.Replace("_projectName_", monitorConfig.spring.AppName); ctlStr = ctlStr.Replace("_disconfigUrl_", stb_disconfig_url.Text); string localBuild = MainForm.CONF_DIR + monitorConfig.spring.BuildFileName; string localCtl = MainForm.CONF_DIR + monitorConfig.spring.CrlFileName; string remoteBuild = monitorConfig.spring.ShFileDir + "/" + monitorConfig.spring.BuildFileName; string remoteCtl = monitorConfig.spring.ShFileDir + "/" + monitorConfig.spring.CrlFileName; YSTools.YSFile.writeFileByString(localBuild, buildStr); YSTools.YSFile.writeFileByString(localCtl, ctlStr); ThreadPool.QueueUserWorkItem((a) => { Thread.Sleep(500); parentForm.BeginInvoke((MethodInvoker) delegate() { parentForm.getSftp().put(localBuild, remoteBuild, ChannelSftp.OVERWRITE); parentForm.getSftp().put(localCtl, remoteCtl, ChannelSftp.OVERWRITE); parentForm.RunShell("cd " + monitorConfig.spring.ProjectSourceDir, true); parentForm.RunShell("svn checkout " + monitorConfig.spring.ProjectSvnUrl, true); File.Delete(localBuild); File.Delete(localCtl); }); }); } } this.Close(); }