private static void UpdateCode(ProjectSetting project) { if (project.CodeMgr != null) { ICodeFile codeMgr = CreateCodeMgr(project.CodeMgr); LogType.WriteLog(project.ProjectName, "签出代码文件", string.Format("正在签出代码文件:{0},请不要做其他操作", (project.CodeMgr.Source))); var rest = codeMgr.Clone(); LogType.WriteLog(project.ProjectName, "签出代码文件", string.Format("代码文件签出成功:{0} msg:{1}", project.CodeMgr.Source, rest.Log)); } }
public static ProjectStatusEnum Builder(string name) { var project = Tool.ProjectSettingServe.GetProjectbyName(name); var status = GetStatus(name); if (status.Status == ProjectStatusEnum.Underway) { return(ProjectStatusEnum.Underway); } var thread = new Thread(() => { lock (status) { status.Status = ProjectStatusEnum.Underway; try { if (project != null) { LogType.WriteLog(project.ProjectName, "开始执行生成任务", "开始生成项目文件"); //更新代码文件 UpdateCode(project); //生成项目文件 取消生成项目文件 //BuildProject(project); //发布项目文件 PubilshWeb(project); LogType.WriteLog(project.ProjectName, "结束执行生成任务", "完成成项目文件"); } else { LogType.WriteLog(name, "结束执行生成任务", "未找到指定的项目:" + name); } } catch (Exception e) { var sb = new StringBuilder(); sb.AppendLine(e.Message); sb.AppendLine(e.StackTrace); LogType.WriteLog(project.ProjectName, "生成错误", sb.ToString()); } finally { if (status.Status == ProjectStatusEnum.Underway) { status.Status = ProjectStatusEnum.Stop; } } } }); thread.Start(); return(ProjectStatusEnum.Underway); }
private static void BuildProject(ProjectSetting project) { BuildContext buildContext = null; ICodeBuild build = null; if (project.Solution != null) { buildContext = CreateBuildContext(project); build = ACodeBuild.CreateBuild(buildContext); LogType.WriteLog(project.ProjectName, "生成解决方案", string.Format("开始生成解决方案:{0}", buildContext.BuildPath)); try { build.Build(buildContext); } catch (Exception ee) { LogType.WriteLog(project.ProjectName, "生成解决方案", string.Format("生成错误:{0}", ee.Message)); } LogType.WriteLog(project.ProjectName, "生成解决方案", string.Format("解决方案生成完成:{0}", buildContext.Log)); } }
private static void PubilshWeb(ProjectSetting project) { if (project.Publish != null && project.Publish.TargetDirectorys.Count > 0) { var buildContext = CreateBuildContext(project); var build = ACodeBuild.CreateBuild(buildContext); var target = project.Publish.TargetDirectorys.FirstOrDefault().Path; buildContext.publishDirectory = target + "_temp_" + project.ProjectName;; buildContext.PublishItemPath = project.Publish.Path; LogType.WriteLog(project.ProjectName, "发布网站项目", string.Format("开始发布网站项目:{0}", project.Publish.Path)); if (!Directory.Exists(buildContext.publishDirectory)) { Directory.CreateDirectory(buildContext.publishDirectory); } LogType.WriteLog(project.ProjectName, "发布网站项目", string.Format("发布地址:{0}", buildContext.publishDirectory)); try { build.Publish(buildContext); } catch (Exception ee) { LogType.WriteLog(project.ProjectName, "发布网站项目", string.Format("网站发布错误:{0}", ee.Message)); } LogType.WriteLog(project.ProjectName, "发布网站项目", string.Format("网站项目发布完成:{0}:", buildContext.Log)); var log = buildContext.Log; if (log.IndexOf("0 个错误") < 0) { var status = GetStatus(project.ProjectName); status.Status = ProjectStatusEnum.Error; } MoveToLose(project);/*生成后再移动忽略文件*/ //拷贝发布成功的文件 CopyPublish(project, buildContext); MoveToLose(project, false); } }
private static void CopyPublish(ProjectSetting project, BuildContext buildContext) { var dir = new DirectoryInfo(buildContext.publishDirectory); foreach (var newPath in project.Publish.TargetDirectorys) { LogType.WriteLog(project.ProjectName, "发布成功正在拷贝文件", string.Format("拷贝目标:{0}", newPath.Path)); if (!Directory.Exists(newPath.Path)) { LogType.WriteLog(project.ProjectName, "发布成功正在拷贝文件", string.Format("拷贝文件失败:{0}", newPath.Path)); continue; } try { CopyFiles(dir, buildContext.publishDirectory, newPath.Path); LogType.WriteLog(project.ProjectName, "发布成功正在拷贝文件", string.Format("拷贝文件成功:{0}", newPath.Path)); } catch (Exception e) { LogType.WriteLog(project.ProjectName, "发布成功正在拷贝文件", string.Format("拷贝文件成功:{0} msg:{1}", newPath.Path, e.Message)); } } dir.Delete(true); }
/// <summary> /// /// </summary> /// <param name="project"></param> /// <param name="isMove">true移动 false还原</param> private static void MoveToLose(ProjectSetting project, bool isMove = true) { LogType.WriteLog(project.ProjectName, "缓存忽略文件夹", string.Format("正在缓存忽略文件夹")); foreach (var t in project.Publish.TargetDirectorys) { foreach (var l in project.Publish.LoseContext) { var path = Path.GetFullPath(t.Path + Path.DirectorySeparatorChar + l.Path); var newPath = path + "_temp_" + project.ProjectName; if (l.LoseType == LoseTypeEnum.Directory) { if (isMove) { if (Directory.Exists(newPath)) { Directory.Delete(newPath, true); } if (Directory.Exists(path)) { Directory.Move(path, newPath); } } else { if (Directory.Exists(path)) { Directory.Delete(path, true); } if (Directory.Exists(newPath)) { Directory.Move(newPath, path); } } } else { if (isMove) { if (File.Exists(newPath)) { File.Delete(newPath); } if (File.Exists(path)) { File.Move(path, newPath); } } else { if (File.Exists(path)) { File.Delete(path); } if (File.Exists(newPath)) { File.Move(newPath, path); } } } } } LogType.WriteLog(project.ProjectName, "缓存忽略文件夹", string.Format("完成缓存忽略文件夹:{0}", isMove ? "缓存" : "还原")); }