private async Task CheckNewVersion() { string scripts = Path.Combine(Environment.CurrentDirectory, "Scripts"); InstallService service = new InstallService(scripts); _vm.CurrentVersion = service.GetInstalledVersion(PackageName); _client = new HmacAuthWebApiClient(Url, CdmId, ApiKey); try { UpdateInformation apiVersion = await _client.ReadAsync <UpdateInformation>(!string.IsNullOrWhiteSpace(_vm.CurrentVersion)?ConfigurationManager.AppSettings["api:downloadUrl"] + _vm.CurrentVersion + ConfigurationManager.AppSettings["api:downloadUrlMethod"] : ConfigurationManager.AppSettings["api:downloadUrlLatestUpdate"]); if (apiVersion == null || (!string.IsNullOrWhiteSpace(_vm.CurrentVersion) && new Version(apiVersion.Version) < new Version(_vm.CurrentVersion))) // when current version is disabled or unknown => the provided new version is lower than current one ... { _vm.ApiVersion = new UpdateInformation { Version = _vm.CurrentVersion } } ; // ... do like there is no new version => avoid impossible downgrade else { _vm.ApiVersion = apiVersion; } } catch (Exception ex) { _logger.Error("CheckNewVersion() failed on ", ex); } }
private async Task CheckNewVersion() { string scripts = Path.Combine(Environment.CurrentDirectory, "Scripts"); InstallService service = new InstallService(scripts); _vm.CurrentVersion = service.GetInstalledVersion(PackageName); _client = new HmacAuthWebApiClient(Url, CdmId, ApiKey); try { UpdateInformation apiVersion = await _client.ReadAsync<UpdateInformation>(!string.IsNullOrWhiteSpace(_vm.CurrentVersion) ? ConfigurationManager.AppSettings["api:downloadUrl"] + _vm.CurrentVersion + ConfigurationManager.AppSettings["api:downloadUrlMethod"] : ConfigurationManager.AppSettings["api:downloadUrlLatestUpdate"]); if (apiVersion == null || (!string.IsNullOrWhiteSpace(_vm.CurrentVersion) && new Version(apiVersion.Version) < new Version(_vm.CurrentVersion))) // when current version is disabled or unknown => the provided new version is lower than current one ... _vm.ApiVersion = new UpdateInformation { Version = _vm.CurrentVersion }; // ... do like there is no new version => avoid impossible downgrade else _vm.ApiVersion = apiVersion; } catch (Exception ex) { _logger.Error("CheckNewVersion() failed on ", ex); } }
public async Task<string> DownloadASync(HmacAuthWebApiClient client, string version, string destination) { string versionDl = string.Format("{0}{1}{2}",ConfigurationManager.AppSettings["api:downloadUrl"], version,ConfigurationManager.AppSettings["api:downloadMethod"]); HttpResponseMessage requestMessage = await client.GetAsync(versionDl); string fileName = requestMessage.Headers.FirstOrDefault(h => h.Key == "x-filename").Value.First(); string fileDestination = Path.Combine(destination, fileName); using (FileStream a = new FileStream(fileDestination, FileMode.OpenOrCreate)) { await requestMessage.Content.CopyToAsync(a); } return fileDestination; }