Former-commit-id: c1ad2feea5f91f845a97a443f0faa6c3123e2273
Former-commit-id: 752a0970ac945e67e30b729a3637e5b23a361780
TSXN
wanggang 5 years ago
parent 69f90f18cb
commit d13a203f65

@ -1,6 +1,5 @@
using CookComputing.XmlRpc; using CookComputing.XmlRpc;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
@ -20,16 +19,14 @@ namespace IoTDameon
{ {
private readonly ILogger<UpdateIoTNodeService> _logger; private readonly ILogger<UpdateIoTNodeService> _logger;
private readonly IWebHostEnvironment _env; private readonly IWebHostEnvironment _env;
private readonly IConfiguration _cfg;
private readonly IHttpClientFactory _httpClientFactory; private readonly IHttpClientFactory _httpClientFactory;
public bool IsUpdating { get; set; } public bool IsUpdating { get; set; }
public UpdateIoTNodeService(ILogger<UpdateIoTNodeService> logger, IWebHostEnvironment env, IConfiguration cfg, IHttpClientFactory httpClientFactory) public UpdateIoTNodeService(ILogger<UpdateIoTNodeService> logger, IWebHostEnvironment env, IHttpClientFactory httpClientFactory)
{ {
this._logger = logger; this._logger = logger;
this._env = env; this._env = env;
this._cfg = cfg;
this._httpClientFactory = httpClientFactory; this._httpClientFactory = httpClientFactory;
} }
@ -40,7 +37,7 @@ namespace IoTDameon
while (!stoppingToken.IsCancellationRequested) while (!stoppingToken.IsCancellationRequested)
{ {
this.Update(); this.Update();
await Task.Delay(1000 * 60, stoppingToken); await Task.Delay(60 * 10 * 1000, stoppingToken);
} }
await Task.CompletedTask; await Task.CompletedTask;
} }
@ -77,7 +74,6 @@ namespace IoTDameon
var name = $"{appFolder}.zip"; var name = $"{appFolder}.zip";
var backupPath = Path.Combine(root, $"{appFolder}_bk"); var backupPath = Path.Combine(root, $"{appFolder}_bk");
var file = Path.Combine(root, name); var file = Path.Combine(root, name);
var currentCheckSum = string.Empty;
//检查是否有更新 //检查是否有更新
this._logger.LogInformation("check last version"); this._logger.LogInformation("check last version");
var currentVersion = this._httpClientFactory.CreateClient().GetAsync($"http://localhost:{port}/Home/GetVersion").Result.Content.ReadAsStringAsync().Result; var currentVersion = this._httpClientFactory.CreateClient().GetAsync($"http://localhost:{port}/Home/GetVersion").Result.Content.ReadAsStringAsync().Result;
@ -95,7 +91,7 @@ namespace IoTDameon
//查看是否已下载更新并删除旧的更新文件 //查看是否已下载更新并删除旧的更新文件
if (File.Exists(file)) if (File.Exists(file))
{ {
currentCheckSum = getCheckSum(file); var currentCheckSum = GetCheckSum(file);
if (currentCheckSum != lastCheckSum) if (currentCheckSum != lastCheckSum)
{ {
this._logger.LogWarning($"current file hash {currentCheckSum} does not equals last file hash {lastCheckSum}"); this._logger.LogWarning($"current file hash {currentCheckSum} does not equals last file hash {lastCheckSum}");
@ -111,7 +107,7 @@ namespace IoTDameon
{ {
fs.Write(bytes); fs.Write(bytes);
} }
currentCheckSum = getCheckSum(file); var currentCheckSum = GetCheckSum(file);
if (currentCheckSum != lastCheckSum) if (currentCheckSum != lastCheckSum)
{ {
this._logger.LogWarning($"download file hash {currentCheckSum} does not math hash in xml {lastCheckSum}"); this._logger.LogWarning($"download file hash {currentCheckSum} does not math hash in xml {lastCheckSum}");
@ -196,7 +192,7 @@ namespace IoTDameon
} }
} }
private string getCheckSum(string file) private string GetCheckSum(string file)
{ {
using (var sha = SHA512.Create()) using (var sha = SHA512.Create())
{ {

Loading…
Cancel
Save