经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » ASP.net » 查看文章
基于DotNetty实现自动发布 - 项目的配置与发现
来源:cnblogs  作者:Broadm  时间:2023/12/8 11:49:24  对本文有异议

前言

上一篇,我们实现了基于 DotNetty 的通信基础模块的搭建,本篇,主要实现待发布 Web 项目的集成。

创建待发布项目

  • 为了测试, 我创建了一个基于 .NET 4.8 的 Web 项目 OpenDeploy.TestWebProject
    image

    image

  • 我本机的代码仓储路径是: D:\Projects\Back\dotnet\Study\OpenDeploy.TestWebProject
    image

待发布项目集成 Git

Git 是一个开源的分布式版本控制系统。我们使用它实现自动化检测需要发布的文件。

配置待发布项目

  • 先放一下实现的效果图, 因为我对 WPF 也不是很精通,不足之处请大家见谅

image
image
image

  • 客户端基于 WPF 实现
  • 数据持久化使用的 SQLite
  • 增加了几个常用的 Git 命令
  • 简单贴点代码,其他请大家看源码吧,最下面有地址

解决方案模型

  1. /// <summary> 解决方案领域模型 </summary>
  2. [Table("Solution")]
  3. public class Solution
  4. {
  5. [Key]
  6. public int Id { get; set; }
  7. /// <summary> 解决方案名称 </summary>
  8. public string SolutionName { get; set; } = string.Empty;
  9. /// <summary> 解决方案Git仓储路径 </summary>
  10. public string GitRepositoryPath { get; set; } = string.Empty;
  11. }

确定配置解决方案

  1. /// <summary> 确定配置解决方案 </summary>
  2. [RelayCommand]
  3. private void OkConfigSolution()
  4. {
  5. try
  6. {
  7. if (string.IsNullOrEmpty(ConfigSolution.SolutionName))
  8. {
  9. throw new Exception("请填写解决方案名称");
  10. }
  11. if (!GitHelper.IsValidRepository(ConfigSolution.GitRepositoryPath))
  12. {
  13. throw new Exception("非法的Git仓储路径");
  14. }
  15. }
  16. catch (Exception ex)
  17. {
  18. Growl.ClearGlobal();
  19. Growl.WarningGlobal(ex.Message);
  20. return;
  21. }
  22. //持久化到Sqlite
  23. solutionRepository.AddSolution(ConfigSolution.Map2Entity());
  24. Growl.SuccessGlobal("操作成功");
  25. //重新加载解决方案
  26. LoadSolutions();
  27. //关闭弹窗
  28. configSolutionDialog?.Close();
  29. }

执行 Git 命令

  1. /// <summary> 执行git命令 </summary>
  2. private async Task RunGitCommand(string cmd)
  3. {
  4. var loading = Loading.Show();
  5. string output = string.Empty;
  6. LogText = string.Empty;
  7. await Task.Run(() =>
  8. {
  9. var _process = new Process();
  10. _process.StartInfo.WorkingDirectory = GitRepositoryPath;
  11. _process.StartInfo.FileName = "cmd.exe";
  12. _process.StartInfo.Arguments = "/C " + cmd;
  13. _process.StartInfo.UseShellExecute = false;
  14. _process.StartInfo.CreateNoWindow = true;
  15. _process.StartInfo.RedirectStandardInput = true;
  16. _process.StartInfo.RedirectStandardOutput = true;
  17. _process.StartInfo.RedirectStandardError = true;
  18. _process.Start();//启动程序
  19. output = _process.StandardOutput.ReadToEnd();
  20. if (string.IsNullOrEmpty(output))
  21. {
  22. output = _process.StandardError.ReadToEnd();
  23. if (string.IsNullOrEmpty(output))
  24. {
  25. output = "没有返回值";
  26. }
  27. }
  28. _process.WaitForExit();
  29. _process.Close();
  30. });
  31. LogText = output;
  32. loading.Close();
  33. }

总结

至此,我们实现了待发布项目的配置与发现,简单集成了常用的 Git 命令等

代码仓库

项目暂且就叫 OpenDeploy

欢迎大家拍砖,Star

下一步

计划下一步,实现一键发布,自动检测到自上次发布以来的代码变化,自动识别要发布的文件,一次性打包通过 DotNetty 发送到服务器

原文链接:https://www.cnblogs.com/broadm/p/17879195.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号