private async Task <LicenseValidationResult> ValidateLicense( string licenseCode) { AspNetZeroLicenseChecker zeroLicenseChecker = this; LicenseValidationResult result; using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("https://www.aspnetzero.com/"); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); LicenseCheckInfo licenseInfo = new LicenseCheckInfo() { LicenseCode = licenseCode, UniqueComputerId = zeroLicenseChecker._uniqueComputerId, ComputerName = AspNetZeroLicenseChecker.GetComputerName(), ControlCode = Guid.NewGuid().ToString(), DateOfClient = DateTime.Now, ProjectAssemblyName = zeroLicenseChecker.GetAssemblyName(), LicenseController = zeroLicenseChecker.GetLicenseController() }; HttpResponseMessage httpResponseMessage = await httpClient.PostAsync("LicenseManagement/CheckLicense", (HttpContent) new StringContent(licenseInfo.ToJsonString(false, false), Encoding.UTF8, "application/json")); if (!httpResponseMessage.IsSuccessStatusCode) { throw new AbpException("Failed on license check"); } AjaxResponse <LicenseValidationResult> ajaxResponse = JsonConvert.DeserializeObject <AjaxResponse <LicenseValidationResult> >(await httpResponseMessage.Content.ReadAsStringAsync()); if (ajaxResponse.Success && ajaxResponse.Result != null) { if (zeroLicenseChecker.GetHashedValue(licenseInfo.ControlCode) != ajaxResponse.Result.ControlCode) { throw new AspNetZeroLicenseException("Failed on license check"); } result = ajaxResponse.Result; licenseInfo = (LicenseCheckInfo)null; } else { ErrorInfo error = ajaxResponse.Error; throw new AbpException(error == null || error.Message == null ? "Failed on license check" : error.Message); } } return(result); }
private async Task CheckInternal() { AspNetZeroLicenseChecker zeroLicenseChecker = this; try { zeroLicenseChecker._uniqueComputerId = AspNetZeroLicenseChecker.GetUniqueComputerId(); zeroLicenseChecker._licenseCheckFilePath = Path.Combine(Path.GetTempPath(), zeroLicenseChecker.GetHashedValue(zeroLicenseChecker.GetLicenseCode()) + ".tmp"); zeroLicenseChecker.Logger.Debug(zeroLicenseChecker._licenseCheckFilePath); } catch { return; } try { if (!zeroLicenseChecker.IsProjectNameValid()) { throw new AspNetZeroLicenseException("Failed to validate project name. Should not rename a project downloaded from aspnetzero.com. You can contact to [email protected] if you are using a licensed product."); } if (zeroLicenseChecker.CheckedBefore()) { return; } } catch (Exception ex) { zeroLicenseChecker.Logger.Fatal("Failed to validate project name. Should not rename a project downloaded from aspnetzero.com. You can contact to [email protected] if you are using a licensed product." + Environment.NewLine + ex.Message, ex); Environment.Exit(-42); } await zeroLicenseChecker.ValidateLicenseOnServer(); }