예제 #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);
 }