• WPF 程序 分布式 自动更新 登录 打包


    服务器server端 core api 

    客户端WPF

     // 检查应用更新
       //1、获取最新文件列表
       // 
       var files = fileService.GetUpgradeFiles();
       // 2、文件判断,新增的直接下载;更新的直接下载;删除的直接删除
       //    客户端本地需要一个记录,最后更新的记录()

    服务器端 api

    orm  dal

    客户端

    1、更新文件对比
    2、自动更新程序与逻辑梳理
    3、进程间更新数据传输
    4、更新数据接收与准备
    5、更新程序UI处理
    6、文件下载服务接口逻辑

    1文件对比 客户端本地对比upgrade_temp.json文件

     // 开始下载文件    从服务器上下载相关文件

    1. // 服务器拿到文件列表中的文件都得下载
    2. if (update_file.Count > 0)
    3. {
    4. // 启动更新程序,并且将更新文件列表传给它
    5. Process.Start("Zhaoxi.PMS.Client.Upgrade.exe", update_file);
    6. //
    7. // 下载完成进行服务文件列表的保存(Json序列化)
    8. // 这个逻辑需要在Upgrade.exe进程里处理,判断正常更新完成后写入
    9. //json_str = System.Text.Json.JsonSerializer.Serialize(update_file);
    10. //File.WriteAllText("upgrade_temp.json", json_str);
    11. //Application.Current.Shutdown();
    12. System.Environment.Exit(0);// 结束进程
    13. }

    启动线程 调试 更新程序 进程间更新数据传递

    细节  文字省略

    1. 进度
    2. "{Binding FileName}" VerticalAlignment="Bottom"
    3. Grid.Column="1" Grid.ColumnSpan="2" Margin="10,0" FontWeight="Bold"
    4. TextTrimming="WordEllipsis"/>
    5. "{Binding FileLenght}" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1"
    6. Margin="10,3" FontSize="11" Foreground="#888"/>
    7. "{Binding CompletedLen}" VerticalAlignment="Top" Grid.Column="2" Margin="10,3"
    8. Grid.Row="1" FontSize="11" Foreground="#888"/>
    9. "{Binding Progress,StringFormat={}{0:P0}}"
    10. VerticalAlignment="Center" HorizontalAlignment="Center"
    11. Grid.Column="3" Grid.RowSpan="2"/>

    正在更新

    1. "2"
    2. Margin="30,0,0,0" VerticalAlignment="Center">
    3. "正在更新...."/>
    4. "["/>"{Binding Completed}"/>"/"/>"{Binding TotalCount}"/>"]"/>
    5. HorizontalAlignment="Right" VerticalAlignment="Center"
    6. Padding="10,5" BorderThickness="0"
    7. Background="Orange" Foreground="White"
    8. Command="{Binding StartCommand}"/>

    download sever

    注意:关键点 坑点! 下载的文件路径 

         // http://localhost:5000/api/file/download/modules/dll_name
         // http://localhost:5273/api/File/download/none/       Client.BLL.dll

    1. [HttpGet("download/{p}/{file}")]
    2. public ActionResult Download([FromRoute(Name = "p")] string path, [FromRoute] string file)
    3. {
    4. //if (!System.IO.File.Exists(path))
    5. // return NotFound("123123123");
    6. // 服务器中存放更新文件的根目录
    7. var root = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
    8. string filePath = Path.Combine(root, "WebFiles", "UpgradeFiles");
    9. // 如果有子目录,则拼进来
    10. if (path != "none")
    11. filePath = Path.Combine(filePath, path);
    12. // 最终文件路径
    13. filePath = Path.Combine(filePath, file);
    14. ResFileStream fs = new ResFileStream(filePath, FileMode.Open, FileAccess.Read);
    15. var type = new MediaTypeHeaderValue("application/oct-stream").MediaType;
    16. // 最终返回文件对象
    17. return File(fs, type, fileDownloadName: file);
    18. }

    1. internal class ResFileStream : FileStream
    2. {
    3. public ResFileStream(string path, FileMode mode, FileAccess access) : base(path, mode, access) { }
    4. ///
    5. /// 偏移量
    6. /// 读取的最大字节数
    7. ///
    8. public override int Read(byte[] array, int offset, int count)
    9. {
    10. // 此处可以限制下载速度
    11. //count = 256;
    12. //Thread.Sleep(10);
    13. return base.Read(array, offset, count);
    14. }
    15. }

    取巧调试 这里坑比较大 哈 备注下

    Zhaoxi.PMS.Client.BLL.dll|UpgradeFiles|100
    Zhaoxi.PMS.Client.IBLL.dll|UpgradeFiles|110
    Zhaoxi.PMS.Client.IDAL.dll|UpgradeFiles|120
     

    Zhaoxi.PMS.Client.BLL.dll|Modules|100
    Zhaoxi.PMS.Client.IBLL.dll||110
    Zhaoxi.PMS.Client.IDAL.dll||120

    取巧部分不知道能否上生产环境哈 待验证 目测应该不能

    --分割 演示

    vip.xspf|.\|4577|101c3def4146d1e7f018583bd7aa5483
    箭头.png|.\|1823|8d15c94446a411344c0535898663bdf2
    宣讲PPT.txt|.\|1249|f747c130458731baf49b28a3a4d5b587

    验证

    请求下载

    downloadFile 去下载

    服务器端

    客户端

    文件读写权限修改 也不行 ?

    --

    疑问 这两个程序相互打开关系 杀毒软件不打架?

    c端

    c端更新程序

    测试了下只是开发环境的主流程部分跑起来了。。离生产环境使用 还有诸多细节处理。

    %AppData%

    wpf 分布式登录 server api

    带token jwt

    C端 

    setup 没有

    先潦草的写下后面真能跑起来在来改吧    

    先这样吧 。。。坑对新手不是很友好。。。目测跑个测试环境都费劲。。。

  • 相关阅读:
    13.4 GAS与攻击
    VR钢铁实训 | 铁前事业部虚拟仿真培训软件
    C语言进阶C++知识点补充(二)
    路特软件戚俊:云原生助力SaaS类业务租户高效隔离
    LeetCode | 只出现一次的值(python解法)
    机器学习面试中常见问题整理
    C++ [STL之vector模拟实现]
    JavaWeb i18n 国际化
    Pod控制器
    【CSS布局】实现中间自适应,左右宽度固定的三栏布局
  • 原文地址:https://blog.csdn.net/cao919/article/details/139730080