コード例 #1
0
        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);
            }
        }