private DateTime? GetExpirationDate(LicenseRegistration registration, string response) { var parsed = parser.Parse(response); return parsed != null && parsed.Key == registration.Key ? parsed.Expiration : (DateTime?) null; }
public string BuildData(LicenseRegistration registration) { var fields = registration.GetLicenseFields().ToList(); fields.Add(new KeyValuePair<string, string>("ProcessorId", sys.GetProcessorId())); return sys.Encode(fields); }
private bool GetIsLicensed(LicenseRegistration registration) { if (!validator.Isvalid(registration)) return false; var status = remote.Check(registration); return status.IsLicensed; }
public void SaveRegistration(LicenseRegistration details) { // overwrite the currently saved registration information storage.Save(details); checker.Submit(details); CheckStatus(details); }
public LicenseStatus Check(LicenseRegistration registration) { var status = new LicenseStatus(); status.IsLicensed = GetIsLicensed(registration); status.IsTrial = status.IsLicensed || GetIsTrial(registration); return status; }
public bool Isvalid(LicenseRegistration registration) { if (registration == null) return false; var valid = InternalIsValid(func(registration)); return Next == null ? valid : valid && Next.Isvalid(registration); }
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(); }
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; }
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, }; }
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); }
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(); }
private void CheckStatus(LicenseRegistration details) { var oldExpiration = details.Expiration; SetStatus(details); if (details.Expiration != oldExpiration) storage.Save(details); }
public string BuildQuery(LicenseRegistration registration) { return queryTemplate .Replace("{key}", registration.Key) .Replace("{pid}", sys.GetProcessorId()); }
private void UpdateRemainingRuns(LicenseRegistration details) { if (IsLicensed || details.Limits.Runs <= 0) return; details.Limits.Runs--; storage.Save(details); }
private void SetStatus(LicenseRegistration details) { var status = checker.Check(details); IsLicensed = status.IsLicensed; IsTrial = status.IsTrial; }
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); }
public void Save(LicenseRegistration registration) { var decrypted = serializer.Serialize(registration); var encrypted = encryptor.Encrypt(decrypted); io.Write(encrypted); }
public void Submit(LicenseRegistration registration) { if (validator.Isvalid(registration)) remote.Submit(registration); }
public void Submit(LicenseRegistration registration) { // do nothing }
public LicenseStatus Check(LicenseRegistration registration) { return new LicenseStatus {IsLicensed = true, IsTrial = true}; }
public void Submit(LicenseRegistration registration) { var data = builder.BuildData(registration); remote.Post(data); }