예제 #1
0
        public static StrongLicense Load(string fileName, out string errorMessage)
        {
            errorMessage = null;
            StrongLicense license = null;

            if (!File.Exists(fileName))
            {
                return(license);
            }

            try
            {
                license = new StrongLicense
                {
                    _fileName     = fileName,
                    ActivationKey = File.ReadAllText(fileName).Decrypt(PASSWORD)
                };
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                license      = null;
            }

            return(license);
        }
예제 #2
0
        public static StrongLicense Load(string serialKey, string activationKey, out string errorMessage)
        {
            errorMessage = null;
            StrongLicense license = null;

            try
            {
                license.ActivationKey = activationKey;
                if (!license.SerialKey.Equals(serialKey, StringComparison.InvariantCultureIgnoreCase))
                {
                    errorMessage = "Invalid serial key.";
                    license      = null;
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                license      = null;
            }

            return(license);
        }
예제 #3
0
        public static StrongLicense Generate(
            DateTime isssueDate,
            DateTime expirationDate,
            string email,
            string businessName,
            string contactPerson,
            string contactNumber,
            string machineName,
            string machineKey,
            string fileName = "")
        {
            var license = new StrongLicense();

            license.SerialKey = GenerateSerial();
            license.GenerateActivationKey(isssueDate, expirationDate, email, machineKey, machineName, businessName, contactPerson, contactNumber);

            if (!string.IsNullOrEmpty(fileName))
            {
                license.Save(fileName);
            }

            return(license);
        }
예제 #4
0
        bool IsValid(StrongLicense license)
        {
            var currentDate = DateTime.Now;

            if (currentDate.Date < license.IssueDate.Date)
            {
                return(false);
            }
            if (currentDate.Date > license.ExpirationDate.Date)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(license.MachineKey))
            {
                return(false);
            }
            if (!license.MachineKey.Equals(GetMachineKey()))
            {
                return(false);
            }

            return(true);
        }