ServiceStack.LicenseUtils.RegisterLicense C# (CSharp) Метод

RegisterLicense() публичный статический Метод

public static RegisterLicense ( string licenseKeyText ) : void
licenseKeyText string
Результат void
        public static void RegisterLicense(string licenseKeyText)
        {
            JsConfig.InitStatics();

            string subId = null;
#if !(PCL || NETSTANDARD1_1)
            var hold = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
#endif
            try
            {
                var parts = licenseKeyText.SplitOnFirst('-');
                subId = parts[0];

                int subIdInt;
                if (int.TryParse(subId, out subIdInt) && revokedSubs.Contains(subIdInt))
                    throw new LicenseException("This subscription has been revoked. " + ContactDetails);

                var key = PclExport.Instance.VerifyLicenseKeyText(licenseKeyText);

                var releaseDate = Env.GetReleaseDate();
                if (releaseDate > key.Expiry)
                    throw new LicenseException("This license has expired on {0} and is not valid for use with this release."
                        .Fmt(key.Expiry.ToString("d")) + ContactDetails).Trace();

                if (key.Type == LicenseType.Trial && DateTime.UtcNow > key.Expiry)
                    throw new LicenseException("This trial license has expired on {0}."
                        .Fmt(key.Expiry.ToString("d")) + ContactDetails).Trace();

                __activatedLicense = key;
            }
            catch (Exception ex)
            {
                if (ex is LicenseException)
                    throw;

                var msg = "This license is invalid." + ContactDetails;
                if (!string.IsNullOrEmpty(subId))
                    msg += " The id for this license is '{0}'".Fmt(subId);

                throw new LicenseException(msg).Trace();
            }
            finally
            {
#if !(PCL || NETSTANDARD1_1)
                Thread.CurrentThread.CurrentCulture = hold;
#endif
            }
        }

Usage Example

Пример #1
0
        public static void RegisterLicenseFromAppSettings(IAppSettings appSettings)
        {
            //Automatically register license key stored in <appSettings/>
            var licenceKeyText = appSettings.GetString(NetStandardPclExport.AppSettingsKey);

            if (!string.IsNullOrEmpty(licenceKeyText))
            {
                LicenseUtils.RegisterLicense(licenceKeyText);
            }
        }
All Usage Examples Of ServiceStack.LicenseUtils::RegisterLicense