Esempio n. 1
0
        /// <summary>
        /// Validates the license.
        /// </summary>
        /// <returns></returns>
        private static LicenseQueryResult ValidateLicense()
        {
            try
            {
                var validator = new LicenseValidation();

                var codebase     = Assembly.GetExecutingAssembly().CodeBase;
                var uri          = new UriBuilder(codebase);
                var path         = Uri.UnescapeDataString(uri.Path);
                var assemblyPath = Path.GetDirectoryName(path);

                var licenseFilePath = Path.Combine(assemblyPath, Strings.LicenseFileName);

                var lqr = validator.ValidateLicense(new FileInfo(licenseFilePath), Strings.ApplicationId);

                if (!lqr.ValidLicense)
                {
                    // if first use (no license file exists), will auto generate a trial license for the product
                    validator.CreateLicense(new FileInfo(licenseFilePath), Strings.TrialCode);
                    lqr = validator.ValidateLicense(new FileInfo(licenseFilePath), Strings.ApplicationId);
                }

                return(lqr);
            }
            catch (Exception)
            {
                return(new LicenseQueryResult()
                {
                    CurrentLicenseStatus = LicenseStatus.InValid
                });
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Activates the license.
        /// </summary>
        /// <param name="licenseCode">The license code.</param>
        /// <returns></returns>
        public static bool ActivateLicense(string licenseCode)
        {
            try
            {
                var validator = new LicenseValidation();

                var codebase     = Assembly.GetExecutingAssembly().CodeBase;
                var uri          = new UriBuilder(codebase);
                var path         = Uri.UnescapeDataString(uri.Path);
                var assemblyPath = Path.GetDirectoryName(path);

                var licenseFilePath = Path.Combine(assemblyPath, Strings.LicenseFileName);

                var lqr = validator.ValidateLicense(licenseCode, Strings.ApplicationId);

                if (lqr.ValidLicense)
                {
                    validator.CreateLicense(new FileInfo(licenseFilePath), licenseCode);
                }

                return(lqr.ValidLicense);
            }
            catch (Exception)
            {
                return(false);
            }
        }