///<summary> /// Asks DeployLX to assert that the application has a valid license. ///</summary> ///<exception cref = "DeployLX.Licensing.v4.NoLicenseException">Thrown when a valid license could not be obtained. See exception ValidationRecords for details.</exception> ///<param name = "silent">Indicates if DeployLX should validate without showing any forms to the user.</param> public void Required(bool silent) { try { var info = new LicenseValidationRequestInfo(); info.DontShowForms = !silent; #if DEBUG // See http://xheo.com/knowledge-base/deploylx/licensing/enabling-developer-mode info.DeveloperMode = false; // See http://xheo.com/knowledge-base/deploylx/licensing/how-to-testing-license-time-or-subscription-limits info.TestDate = DateTime.UtcNow.AddDays(30); #endif var license = SecureLicenseManager.Validate(this, null, info); if (_license != null && license != _license) { _license.Dispose(); } _license = license; _lastError = null; } catch (NoLicenseException ex) { _lastError = ex; RecordLicenseError(ex); throw; } }
/// <summary> /// Get error codes from licensing exception /// </summary> /// <param name="e">Exception</param> /// <returns>List of error codes</returns> public static List <string> GetErrorCodes(NoLicenseException e) { var errorCodes = new List <string>(); foreach (ValidationRecord validationRecord in e.ValidationRecords) { foreach (ValidationRecord subRecord in validationRecord.SubRecords) { errorCodes.Add(subRecord.ErrorCode); } errorCodes.Add(validationRecord.ErrorCode); } return(errorCodes); }
/// <summary> /// Called when a valid license could not be found when calling <see cref="Required" /> or <see cref="Check" />. /// </summary> /// <param name="ex">Exception reported by DeployLX.</param> public void RecordLicenseError(NoLicenseException ex) { #warning Log license validation errors. }
/// <summary> /// License validation /// </summary> public bool Validate() { licenseInfos.Clear(); // workaround for obfuscation var licenseTypes = new LicenseType[] { LicenseType.XRayTrial, LicenseType.XRayHoldem, LicenseType.XRayOmaha, LicenseType.XRayCombo }; // validate each possible type foreach (LicenseType licenseType in licenseTypes) { SecureLicense license = null; NoLicenseException validationException = null; var isExpired = false; var serial = string.Empty; var licenseManager = ServiceLocator.Current.GetInstance <ILicenseManager>(licenseType.ToString()); try { var requestInfo = new LicenseValidationRequestInfo { DontShowForms = true }; license = licenseManager.Validate(requestInfo); if (!license.IsTrial) { LogProvider.Log.Info(CustomModulesNames.PlayerXRay, string.Format("Found license: {0}-*", license.SerialNumber.Substring(0, 4))); } } catch (NoLicenseException ex) { validationException = ex; var exceptionData = ParseException(ex); if (exceptionData != null && exceptionData.ContainsKey("errorCode") && exceptionData["errorCode"].Equals("LCS_EXP")) { isExpired = true; serial = exceptionData["serial"]; } } catch (Exception ex) { LogProvider.Log.Error(CustomModulesNames.PlayerXRay, "Validation: License validation error", ex); } // Trial license - check if real trial is expired or does not exists if (license != null && license.IsTrial) { licenseManager.ResetCacheForLicense(license); var requestInfo = new LicenseValidationRequestInfo { DontShowForms = true, DisableTrials = true }; try { license = licenseManager.Validate(requestInfo); } catch (NoLicenseException ex) { validationException = ex; } } var licenseInfo = new LicenseInfo(license, licenseType); licenseInfo.ValidationException = validationException; // if license expired we must specify that if (isExpired && license == null) { licenseInfo.IsExpired = true; licenseInfo.Serial = serial; } if (!licenseInfo.IsTrial || licenseInfos.All(x => !x.IsTrial)) { licenseInfos.Add(licenseInfo); } } isInitialized = true; UpdateExpirationDates(licenseInfos); var isValid = licenseInfos.Any(x => x.IsRegistered); return(isValid); }
/// <summary> /// Called when a valid license could not be found when calling <see cref="Required"/> or <see cref="Check"/>. /// </summary> /// <param name="ex">Exception reported by DeployLX.</param> public void RecordLicenseError(NoLicenseException ex) { }