示例#1
0
 private DateTime? GetExpirationDate(LicenseRegistration registration, string response)
 {
     var parsed = parser.Parse(response);
       return parsed != null && parsed.Key == registration.Key
     ? parsed.Expiration
     : (DateTime?) null;
 }
示例#2
0
        public string BuildData(LicenseRegistration registration)
        {
            var fields = registration.GetLicenseFields().ToList();
              fields.Add(new KeyValuePair<string, string>("ProcessorId", sys.GetProcessorId()));

              return sys.Encode(fields);
        }
示例#3
0
        private bool GetIsLicensed(LicenseRegistration registration)
        {
            if (!validator.Isvalid(registration))
            return false;

              var status = remote.Check(registration);
              return status.IsLicensed;
        }
示例#4
0
文件: Licenser.cs 项目: njmube/public
        public void SaveRegistration(LicenseRegistration details)
        {
            // overwrite the currently saved registration information
              storage.Save(details);
              checker.Submit(details);

              CheckStatus(details);
        }
示例#5
0
        public LicenseStatus Check(LicenseRegistration registration)
        {
            var status = new LicenseStatus();
              status.IsLicensed = GetIsLicensed(registration);
              status.IsTrial = status.IsLicensed || GetIsTrial(registration);

              return status;
        }
示例#6
0
        public bool Isvalid(LicenseRegistration registration)
        {
            if (registration == null)
            return false;

              var valid = InternalIsValid(func(registration));
              return Next == null
            ? valid
            : valid && Next.Isvalid(registration);
        }
示例#7
0
        private static string GetData(LicenseRegistration details)
        {
            var sb = new StringBuilder();

              sb.AppendLine(details.Name);
              sb.AppendLine(details.Contact);
              sb.AppendLine(details.Expiration.ToString(Constants.DATE_FORMAT));

              return sb.ToString();
        }
示例#8
0
 private bool GetIsTrial(LicenseRegistration registration)
 {
     if (registration == null)
     return false;
       if (registration.Limits == null)
     return false;
       if (registration.Limits.GetRemainingDays(registration.CreatedOn) <= 0)
     return false;
       if (registration.Limits.Runs == 0)
     return false;
       if (registration.Expiration < DateTime.Today)
     return false;
       return true;
 }
示例#9
0
        public LicenseStatus Check(LicenseRegistration registration)
        {
            var query = builder.BuildQuery(registration);
              var response = remote.Get(query);

              var expiration = GetExpirationDate(registration, response);
              if (expiration.HasValue)
              {
            registration.CreatedOn = DateTime.Today;
            registration.Limits.Days = 30;
            registration.Limits.Runs = -1;
            registration.Expiration = expiration.Value;
              }

              return new LicenseStatus
              {
            IsLicensed = expiration.HasValue && DateTime.Today <= registration.Expiration,
            IsTrial = true,
              };
        }
示例#10
0
        public void CreatesAndChecksExpiredTrial_2()
        {
            var registration = new LicenseRegistration
              {
            CreatedOn = DateTime.Today,
            Limits = new Limits
            {
              Days = 10,
              Runs = -1,
            },
            Key = null,
            Name = "Marcel",
            Contact = "*****@*****.**",
            Expiration = new DateTime(2000, 1, 2),
              };

              licenser.SaveRegistration(registration);

              Assert.IsFalse(licenser.IsLicensed);
              Assert.IsFalse(licenser.IsTrial);
        }
示例#11
0
文件: MainForm.cs 项目: njmube/public
        private void SaveLicense()
        {
            var registration = new LicenseRegistration
              {
            CreatedOn = DateTime.ParseExact(txtCreatedOn.Text, DATE_FORMAT, CultureInfo.InvariantCulture),
            Limits =
            {
              Days = string.IsNullOrWhiteSpace(txtLimitsDays.Text) ? -1 : int.Parse(txtLimitsDays.Text),
              Runs = string.IsNullOrWhiteSpace(txtLimitsRuns.Text) ? -1 : int.Parse(txtLimitsRuns.Text)
            },
            Key = txtKey.Text,
            Name = txtName.Text,
            Contact = txtContact.Text,
            Expiration = DateTime.ParseExact(txtExpiration.Text, DATE_FORMAT, CultureInfo.InvariantCulture),
              };

              licenser.SaveRegistration(registration);

              // refresh the details
              ShowLicense();
        }
示例#12
0
文件: Licenser.cs 项目: njmube/public
        private void CheckStatus(LicenseRegistration details)
        {
            var oldExpiration = details.Expiration;

              SetStatus(details);

              if (details.Expiration != oldExpiration)
            storage.Save(details);
        }
示例#13
0
 public string BuildQuery(LicenseRegistration registration)
 {
     return queryTemplate
     .Replace("{key}", registration.Key)
     .Replace("{pid}", sys.GetProcessorId());
 }
示例#14
0
文件: Licenser.cs 项目: njmube/public
        private void UpdateRemainingRuns(LicenseRegistration details)
        {
            if (IsLicensed || details.Limits.Runs <= 0)
            return;

              details.Limits.Runs--;
              storage.Save(details);
        }
示例#15
0
文件: Licenser.cs 项目: njmube/public
 private void SetStatus(LicenseRegistration details)
 {
     var status = checker.Check(details);
       IsLicensed = status.IsLicensed;
       IsTrial = status.IsTrial;
 }
示例#16
0
        public void CreatesAndChecksLicense()
        {
            var registration = new LicenseRegistration
              {
            CreatedOn = new DateTime(2000, 1, 2),
            Limits = new Limits
            {
              Days = -1,
              Runs = -1,
            },
            Key = "{2686AC7F-2DD7-468C-908A-E28C8CC92A74}",
            Name = "Marcel",
            Contact = "*****@*****.**",
            Expiration = new DateTime(9999, 12, 31),
              };

              licenser.SaveRegistration(registration);

              Assert.IsTrue(licenser.IsLicensed);
        }
示例#17
0
 public void Save(LicenseRegistration registration)
 {
     var decrypted = serializer.Serialize(registration);
       var encrypted = encryptor.Encrypt(decrypted);
       io.Write(encrypted);
 }
示例#18
0
 public void Submit(LicenseRegistration registration)
 {
     if (validator.Isvalid(registration))
     remote.Submit(registration);
 }
示例#19
0
 public void Submit(LicenseRegistration registration)
 {
     // do nothing
 }
示例#20
0
 public LicenseStatus Check(LicenseRegistration registration)
 {
     return new LicenseStatus {IsLicensed = true, IsTrial = true};
 }
示例#21
0
 public void Submit(LicenseRegistration registration)
 {
     var data = builder.BuildData(registration);
       remote.Post(data);
 }