public SelectFilesForm(MProjectSettingInfo projectSetting, string basePath, MSettingInfo settingInfo) { InitializeComponent(); _projectSetting = projectSetting; _basePath = basePath; _settingInfo = settingInfo ?? new MSettingInfo(); }
/// <summary> /// 加载项目设置文件 /// </summary> /// <param name="projectName"></param> /// <returns></returns> public static MProjectSettingInfo LoadProjectSettingInfo(string projectName) { MProjectSettingInfo res; var settingFile = GetProjConfigPath(projectName); if (!File.Exists(settingFile)) { res = new MProjectSettingInfo() { ProjectName = projectName }; } else { var str = File.ReadAllText(settingFile); res = str.DeserializeObject <MProjectSettingInfo>() ?? new MProjectSettingInfo() { ProjectName = projectName }; } if (res.SelectedFiles == null) { res.SelectedFiles = new List <string>(); } return(res); }
public ServiceForm(ProjectModel projectModel, MProjectSettingInfo projectSetting, MSettingInfo settingInfo) { InitializeComponent(); _projectModel = projectModel ?? new ProjectModel(); _projectSetting = projectSetting ?? new MProjectSettingInfo(); _settingInfo = settingInfo ?? new MSettingInfo(); _currSelectedServiceInfo = _settingInfo.GetCurrServiceInfo(); }
/// <summary> /// 保存项目设置文件 /// </summary> /// <param name="projectInfo"></param> /// <returns></returns> public static bool SaveProjectSettingInfo(MProjectSettingInfo projectInfo) { try { var settingFile = GetProjConfigPath(projectInfo.ProjectName); using (StreamWriter writer = File.CreateText(settingFile)) { writer.WriteLine(projectInfo.SerializeObject().FormatJsonString()); writer.Flush(); } return(true); } catch (Exception) { return(false); } }
private void DeployStepOnIndexChecked(object sender, EventArgs e) { try { StepControl control = (StepControl)sender; switch (control.StepIndex) { case 1: SetProcessVal(0); if (_projectModel?.ProjType == 1) { _projectSetting = ProjectHelper.LoadProjectSettingInfo(this._projectModel.ProjName); if (_projectModel.IsNetCore) { this.metroCbDeployType.Visible = true; _isUpdatingDeployType = true; for (int i = 0; i < _deployTypesStr.Length; i++) { if (_deployTypesStr[i] == _projectSetting.DeployType) { this.metroCbDeployType.SelectedIndex = i; } } if (this.metroCbDeployType.SelectedIndex < 0) { this.metroCbDeployType.SelectedIndex = 0; } _isUpdatingDeployType = false; } else { this.metroCbDeployType.Visible = false; } ControlHelper.ThreadRunExt(this, () => { bool isBuildSuccess = BuildProj(); if (!isBuildSuccess) { return; } SetProcessVal(100); SetStepIndex(2); }, null, this); } else { // 打开选择窗口,让人选择项目或者文件夹 SelectProjectForm form = new SelectProjectForm(_settingInfo); form.Activate(); SelectProjectForm.ProjSelectedEvent = (item) => { try { if (item.Type == 2) { // c# 项目 _projectModel = ProjectHelper.ParseProject(item.Path); _projectSetting = ProjectHelper.LoadProjectSettingInfo(this._projectModel.ProjName); if (_projectModel.IsNetCore) { SetDeployTypeVisible(true); bool find = false; for (int i = 0; i < _deployTypesStr.Length; i++) { if (_deployTypesStr[i] == _projectSetting.DeployType) { find = true; SetDeployTypeIndex(i); } } if (!find) { SetDeployTypeIndex(0); } } else { SetDeployTypeVisible(false); } bool isBuildSuccess = BuildProj(); SetProcessVal(100); if (!isBuildSuccess) { return; } SetStepIndex(2); } else { _projectModel = new ProjectModel() { Key = Guid.NewGuid().ToString(), OutPutType = string.Empty, ProjName = $"{item.Name}{item.Guid}", ProjPath = item.Path, ProjType = item.Type, }; _projectSetting = ProjectHelper.LoadProjectSettingInfo(this._projectModel.ProjName); SetDeployTypeVisible(false); _publishFilesDir = item.Path; SetStepIndex(2); } } catch (Exception ex) { MetroMessageBox.Show(this, ex.Message, "项目选择处理错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }; form.ShowDialog(); } break; case 2: { if (_publishFilesDir.IsNullOrEmpty()) { MetroMessageBox.Show(this, "请先选择文件目录或者项目文件", "无法打开文件选择窗口", MessageBoxButtons.OK, MessageBoxIcon.Error); SetStepAsync(1); return; } //_projectSetting = ProjectHelper.LoadProjectSettingInfo(this._projectModel.ProjName); SelectFilesForm filesForm = new SelectFilesForm(_projectSetting, _publishFilesDir, _settingInfo); filesForm.Activate(); SelectFilesForm.FileSaveEvent = list => { try { // 打开发布服务器窗口 _projectSetting.SelectedFiles = list; ProjectHelper.SaveProjectSettingInfo(_projectSetting); SetSteps(1, $"(已选择{list?.Where(n => !n.EndsWith("pdb"))?.Count() ?? 0}个文件)"); SetProcessVal(0); // 打包文件 LogAppend("开始压缩选中的文件"); _zipFilePath = ProjectHelper.GetZipPath(_projectModel.ProjName); ZipHelper.BatchZip(list, _zipFilePath, _publishFilesDir, (progressValue) => { SetProcessVal(progressValue); return(false); }); SetProcessVal(100); LogAppend("文件压缩完成"); SetStepIndex(3); } catch (Exception ex) { MetroMessageBox.Show(this, ex.Message, "文件处理错误", MessageBoxButtons.OK, MessageBoxIcon.Error); _zipFilePath = string.Empty; } }; filesForm.ShowDialog(); } break; case 3: { if (_projectSetting == null) { MetroMessageBox.Show(this, "请选择文件目录或者项目文件", "无法打开发布到服务器窗口", MessageBoxButtons.OK, MessageBoxIcon.Error); SetStepAsync(1); return; } if (_zipFilePath.IsNullOrEmpty()) { MetroMessageBox.Show(this, "重新选择需要发布的文件进行压缩", "未找到压缩文件", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); SetStepAsync(2); return; } ServiceForm form = new ServiceForm(_projectModel, _projectSetting, _settingInfo); form.Activate(); ServiceForm.ServiceSelectedEvent = (type, appId, serviceInfo) => { try { SetProcessVal(20, true); LogAppend("开始上传文件"); ApiHelper.UploadZipFile(_settingInfo, serviceInfo, type, appId, _zipFilePath); SetProcessVal(100); LogAppend("文件部署完成"); } catch (Exception ex) { MetroMessageBox.Show(this, ex.Message, "发布到服务器错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }; form.ShowDialog(); } break; } } catch (Exception exception) { //TxtLogService.WriteLog(exception, SettingHelper.GetLogDirPath(), "步骤执行失败"); LogAppend($"步骤执行失败:{exception.Message}", Color.Red); MetroMessageBox.Show(this, exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }