public async Task <LicenseCheckResult> CheckLicenseStateAsync() { log.Debug("CheckLicenseStateAsync;"); // Get stored license info LicenseInfo lic = GetStoredLicenseInfo(); if (lic == null) // newly installed, not registered { return new LicenseCheckResult { State = LicenseState.Unregistered, Message = "未注册 License 或注册数据损坏。", } } ; if (!lic.Hardware.Equals(hardware)) // stored license not match current machine { return new LicenseCheckResult { State = LicenseState.MachineNotMatch, Message = "License 注册信息与设备不符。", } } ; try { var tuple = await CheckLicensesByServiceAsync(lic); bool foundActiveKey = tuple.Item1; int amount = tuple.Item2; lic.Counter = this.MaxCheckPostponeCount; if (!foundActiveKey) { return new LicenseCheckResult { State = LicenseState.NoValidLicense, Message = "未找到有效期内的 License。", } } ; return(new LicenseCheckResult { State = LicenseState.OK, Amount = amount, Message = "License 正常。", }); } catch (EndpointNotFoundException ex) { log.Warn(ex.Message, ex); if (!lic.CountDown()) { return new LicenseCheckResult { State = LicenseState.CheckByServiceRequired, Message = "无法连接 License 服务。", } } ; if (lic.IsExpired(DateTime.Today)) { return new LicenseCheckResult { State = LicenseState.NoValidLicense, Message = "无法连接 License 服务,本机 License 已过期。", } } ; return(new LicenseCheckResult { State = LicenseState.CheckByServicePostponed, Message = "无法连接 License 服务,本机 License 尚未过期,剩余 " + lic.Counter + " 次检查。", }); } finally { StoreLicenseInfo(lic); } }