/// <summary>
        /// Check whether the product build date of the provided assemblies
        /// exceeded the <see cref="License.Expiration"/> date.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="assemblies">The list of assemblies to check.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ProductBuildDate(this IStartValidationChain validationChain, Assembly[] assemblies)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

#if !NEW_REFLECTION
            validator.Validate = license => assemblies.All(
                asm =>
                asm.GetCustomAttributes(typeof(AssemblyBuildDateAttribute), false)
                .Cast <AssemblyBuildDateAttribute>()
                .All(a => a.BuildDate < license.Expiration));
#else
            validator.Validate = license => assemblies.All(
                asm =>
                asm.GetCustomAttributes <AssemblyBuildDateAttribute>()
                .Cast <AssemblyBuildDateAttribute>()
                .All(a => a.BuildDate < license.Expiration));
#endif

            validator.FailureResult = new LicenseExpiredValidationFailure()
            {
                Message      = "Licensing for this product has expired!",
                HowToResolve = @"Your license is expired. Please contact your distributor/vendor to renew the license."
            };

            return(validationChainBuilder);
        }
 internal static IValidationChain IsLicensedTo(this IStartValidationChain validationChain, string customerName, string contactEmail)
 {
     return(validationChain.AssertThat(license => CheckCustomer(license, customerName, contactEmail),
                                       new GeneralValidationFailure()
     {
         Message = "Wrong license file!",
         HowToResolve = "Please contact the system administrator!"
     }));
 }
 internal static IValidationChain HasValidValidationDate(this IStartValidationChain validationChain, DateTime validationDate)
 {
     return(validationChain.AssertThat(license => CheckValidationDate(validationDate),
                                       new GeneralValidationFailure()
     {
         Message = "System date-time changes detected! Please import extended license file or contact the system administrator!",
         HowToResolve = "Please contact the system administrator!"
     }));
 }
 internal static IValidationChain HasValidHardwareId(this IStartValidationChain validationChain)
 {
     return(validationChain.AssertThat(license => CheckHardwareId(license),
                                       new GeneralValidationFailure()
     {
         Message = "The Hardware ID of the current machine is not licensed!",
         HowToResolve = "Please contact the system administrator!"
     }));
 }
        /// <summary>
        /// Allows you to specify a custom assertion that validates the <see cref="License"/>.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="predicate">The predicate to determine of the <see cref="License"/> is valid.</param>
        /// <param name="failure">The <see cref="IValidationFailure"/> will be returned to the application when the <see cref="ILicenseValidator"/> fails.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain AssertThat(this IStartValidationChain validationChain, Predicate <License> predicate, IValidationFailure failure)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate      = predicate;
            validator.FailureResult = failure;

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates if the license has been expired.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ExpirationDate(this IStartValidationChain validationChain)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.ExpirationUtc > DateTime.UtcNow;

            validator.FailureResult = FailureStrings.Get(FailureStrings.VAL03Code);

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates the <see cref="License.Signature"/>.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain Signature(this IStartValidationChain validationChain)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.VerifySignature();

            validator.FailureResult = FailureStrings.Get(FailureStrings.VAL02Code);

            return(validationChainBuilder);
        }
示例#8
0
        /// <summary>
        /// Validates if the license has been expired.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ExpirationDate(this IStartValidationChain validationChain)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.ExpiresAt > DateTime.Now;

            validator.FailureResult = new LicenseExpiredValidationFailure {
                Message      = "This license is expired.",
                HowToResolve = @"Your license is expired. Please contact your distributor/vendor to renew the license."
            };

            return(validationChainBuilder);
        }
示例#9
0
        /// <summary>
        /// Validates if the license covers the correct product
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="product">The product name.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ProductName(this IStartValidationChain validationChain, string product)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.Product.Equals(product);

            validator.FailureResult = new ProductNotLicensedFailure {
                Message      = $"{product} is not covered by this license.",
                HowToResolve = @"Your license does not cover this license. Please contact your distributor/vendor to get the correct license."
            };

            return(validationChainBuilder);
        }
        /// <summary>
        /// Allows you to specify a custom assertion that validates the <see cref="License"/>.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="predicate">The predicate to determine of the <see cref="License"/> is valid.</param>
        /// <param name="failure">The <see cref="ValidationFailure"/> will be returned to the application when the <see cref="ILicenseValidator"/> fails.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain AssertThat(this IStartValidationChain validationChain, Predicate <License> predicate, ValidationFailure failure)
        {
            if (validationChain is not ValidationChainBuilder validationChainBuilder)
            {
                throw new ArgumentNullException(nameof(validationChain), "Supplied argument is not a valid ValidationChainBuilder");
            }

            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate      = predicate;
            validator.FailureResult = failure;

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates if the license id is the same.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain Id(this IStartValidationChain validationChain, string id)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.Id == id;

            validator.FailureResult = new ValidationFailure()
            {
                Message      = GlobalResources.LicenseIdMessage,
                HowToResolve = GlobalResources.LicenseIdResolve
            };

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates the <see cref="License.Signature"/>.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="publicKey">The public product key to validate the signature..</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain Signature(this IStartValidationChain validationChain, string publicKey)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.VerifySignature(publicKey);

            validator.FailureResult = new InvalidSignatureValidationFailure()
            {
                Message      = "License signature validation error!",
                HowToResolve = @"The license signature and data does not match. This usually happens when a license file is corrupted or has been altered."
            };

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates the cores number.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain Cores(this IStartValidationChain validationChain, int cores)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.Cores >= cores;

            validator.FailureResult = new ValidationFailure()
            {
                Message      = GlobalResources.LicenseCoresMessage,
                HowToResolve = GlobalResources.LicenseCoresResolve
            };

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates if the license has been expired.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ExpirationDate(this IStartValidationChain validationChain)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.Expiration > DateTime.Now.ToUniversalTime();

            validator.FailureResult = new LicenseExpiredValidationFailure()
            {
                Message      = "Licensing for this product has expired!",
                HowToResolve = @"Your license is expired. Please contact your distributor/vendor to renew the license."
            };

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates if the license has been expired.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ExpirationDate(this IStartValidationChain validationChain)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.Expiration > DateTime.Now;

            validator.FailureResult = new ValidationFailure()
            {
                Message      = GlobalResources.LicenseExpiredMessage,
                HowToResolve = GlobalResources.LicenseExpiredResolve
            };

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates the <see cref="License.Signature"/>.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="publicKey">The public product key to validate the signature..</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain Signature(this IStartValidationChain validationChain, string publicKey)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.VerifySignature(publicKey);

            validator.FailureResult = new ValidationFailure()
            {
                Message      = GlobalResources.LicenseSignatureMessage,
                HowToResolve = GlobalResources.LicenseSignatureResolve
            };

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates the <see cref="License.Signature"/>.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="publicKey">The public product key to validate the signature..</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain Signature(this IStartValidationChain validationChain, string publicKey)
        {
            if (validationChain is not ValidationChainBuilder validationChainBuilder)
            {
                throw new ArgumentNullException(nameof(validationChain), "Supplied argument is not a valid ValidationChainBuilder");
            }

            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.VerifySignature(publicKey);

            validator.FailureResult = new InvalidSignatureValidationFailure("License signature validation error!",
                                                                            @"The license signature and data does not match. This usually happens when a license file is corrupted or has been altered.");

            return(validationChainBuilder);
        }
        /// <summary>
        /// Validates if the license has been expired.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ExpirationDate(this IStartValidationChain validationChain)
        {
            if (validationChain is not ValidationChainBuilder validationChainBuilder)
            {
                throw new ArgumentNullException(nameof(validationChain), "Supplied argument is not a valid ValidationChainBuilder");
            }

            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => license.Expiration > DateTime.Now;

            validator.FailureResult = new LicenseExpiredValidationFailure(
                Message: "Licensing for this product has expired!",
                HowToResolve: @"Your license is expired. Please contact your distributor/vendor to renew the license.");

            return(validationChainBuilder);
        }
        /// <summary>
        /// Check whether the product build date of the provided assemblies
        /// exceeded the <see cref="License.Expiration"/> date.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="assemblies">The list of assemblies to check.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ProductBuildDate(this IStartValidationChain validationChain, Assembly[] assemblies)
        {
            if (validationChain is not ValidationChainBuilder validationChainBuilder)
            {
                throw new ArgumentNullException(nameof(validationChain), "Supplied argument is not a valid ValidationChainBuilder");
            }

            var validator = validationChainBuilder.StartValidatorChain();

            validator.Validate = license => assemblies.All(
                asm =>
                asm.GetCustomAttributes <AssemblyBuildDateAttribute>()
                .Cast <AssemblyBuildDateAttribute>()
                .All(a => a.BuildDate < license.Expiration));

            validator.FailureResult = new LicenseExpiredValidationFailure(
                Message: "Licensing for this product has expired!",
                HowToResolve: @"Your license is expired. Please contact your distributor/vendor to renew the license.");

            return(validationChainBuilder);
        }
        /// <summary>
        /// Check whether the product build date of the provided assemblies
        /// exceeded the <see cref="License.ExpirationUtc"/> date.
        /// </summary>
        /// <param name="validationChain">The current <see cref="IStartValidationChain"/>.</param>
        /// <param name="assemblies">The list of assemblies to check.</param>
        /// <returns>An instance of <see cref="IStartValidationChain"/>.</returns>
        public static IValidationChain ProductBuildDate(this IStartValidationChain validationChain, Assembly[] assemblies)
        {
            var validationChainBuilder = (validationChain as ValidationChainBuilder);
            var validator = validationChainBuilder.StartValidatorChain();

#if !NEW_REFLECTION
            validator.Validate = license => assemblies.All(
                asm =>
                asm.GetCustomAttributes(typeof(AssemblyBuildDateAttribute), false)
                .Cast <AssemblyBuildDateAttribute>()
                .All(a => a.BuildDateUtc < license.ExpirationUtc));
#else
            validator.Validate = license => assemblies.All(
                asm =>
                asm.GetCustomAttributes <AssemblyBuildDateAttribute>()
                .Cast <AssemblyBuildDateAttribute>()
                .All(a => a.BuildDateUtc < license.ExpirationUtc));
#endif

            validator.FailureResult = FailureStrings.Get(FailureStrings.VAL03Code);

            return(validationChainBuilder);
        }