public async Task <LicenseResult> RegisterAsync(Guid licenseKey, Guid productId, IDictionary <string, string> attributes) { if (licenseKey == Guid.Empty) { throw new ArgumentNullException(nameof(licenseKey)); } if (productId == Guid.Empty) { throw new ArgumentNullException(nameof(productId)); } if (attributes == null) { attributes = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); } LicenseRegisterResult result = null; try { var url = GetLicenseServerUrl(); result = await RegisterHttpAsync(licenseKey, productId, attributes, url); } catch (Exception ex) { var failure = FailureStrings.Get(FailureStrings.ACT00Code); return(new LicenseResult(null, ex, new[] { failure })); // TODO: log } if (string.IsNullOrWhiteSpace(result.License)) { return(new LicenseResult(null, null, new[] { result.Failure })); } try { using (var sw = LicenseOpenWrite()) { var element = XElement.Parse(result.License); element.Save(sw); } } catch (Exception ex) { var failure = FailureStrings.Get(FailureStrings.VAL01Code); return(new LicenseResult(null, ex, new[] { failure })); // TODO: log } var validationResult = await ValidateAsync(); if (validationResult.Failures.Any()) { return(new LicenseResult(null, null, validationResult.Failures)); } return(new LicenseResult(validationResult.License, null, null)); }
public Task <LicenseResult> ValidateAsync(bool onlineCheck = false) { var task = Task.Run(async() => { var results = new List <IValidationFailure>(); License actual = null; try { using (var stream = LicenseOpenRead()) { if (stream == null) { var nf = FailureStrings.Get(FailureStrings.VAL00Code); return(new LicenseResult(null, null, new[] { nf })); } actual = License.Load(stream); } var failures = await ValidateInternalAsync(actual); foreach (var f in failures) { results.Add(f); } if (results.Any() == false && onlineCheck && IsConnected()) { var activationActiveResult = await CheckAsync(actual.ActivationUuid); if (activationActiveResult == false) { var vf = FailureStrings.Get(FailureStrings.VAL06Code); results.Add(vf); } } return(new LicenseResult(results.Any() ? null : actual, null, results)); } catch (Exception ex) { // TODO: log var failure = FailureStrings.Get(FailureStrings.VAL01Code); results.Add(failure); return(new LicenseResult(null, ex, results)); } }); return(task); }