public void Save(LicenseRegistration registration) { var decrypted = serializer.Serialize(registration); var encrypted = encryptor.Encrypt(decrypted); io.Write(encrypted); }
private async Task DemoSeedData(IContext context, CancellationToken cancellationToken) { var userName = "******"; var createdDate = DateTime.UtcNow; if (context.Companies.Any() == false) { _logger.LogDebug("Begin database seeding"); var company = new LicenseCompany { LicenseCompanyId = new Guid("A8AD667E-8DDC-4819-914F-55AA9B6CD50B"), CompanyName = "Demo-Company", CreatedByUser = userName, CreatedDateTimeUtc = createdDate }; context.Companies.Add(company); await context.SaveChangesAsync(cancellationToken); if (context.Products.Any() == false) { var product = new LicenseProduct { CompanyId = company.LicenseCompanyId, LicenseProductId = new Guid("C3F80BD7-9618-48F6-8250-65D113F9AED2"), ProductName = "Demo-Product-(Full License)", ProductDescription = "Demo-Product-Description-(Full License)", SignKeyName = "CN=Gnu.Licensing", CreatedDateTimeUtc = createdDate, CreatedByUser = userName }; context.Products.Add(product); await context.SaveChangesAsync(cancellationToken); if (context.Registrations.Any() == false) { var registration = new LicenseRegistration { LicenseRegistrationId = new Guid("D65321D5-B0F9-477D-828A-086F30E2BF89"), ProductId = product.LicenseProductId, CompanyId = company.LicenseCompanyId, LicenseName = "Demo-User", LicenseEmail = "Demo-User-Email", LicenseType = LicenseType.Standard, IsActive = true, Quantity = 2, ExpireUtc = null, CreatedDateTimeUtc = createdDate, CreatedByUser = userName }; context.Registrations.Add(registration); await context.SaveChangesAsync(cancellationToken); } } _logger.LogDebug("End database seeding"); } }
public void Submit(LicenseRegistration registration) { if (validator.Isvalid(registration)) { remote.Submit(registration); } }
private void SetStatus(LicenseRegistration details) { var status = checker.Check(details); IsLicensed = status.IsLicensed; IsTrial = status.IsTrial; }
public string BuildData(LicenseRegistration registration) { var fields = registration.GetLicenseFields().ToList(); fields.Add(new KeyValuePair <string, string>("ProcessorId", sys.GetProcessorId())); return(sys.Encode(fields)); }
public void SerializesTheObject() { var details = new LicenseRegistration(); sut.Save(details); serializer.Verify(it => it.Serialize(details)); }
private DateTime?GetExpirationDate(LicenseRegistration registration, string response) { var parsed = parser.Parse(response); return(parsed != null && parsed.Key == registration.Key ? parsed.Expiration : (DateTime?)null); }
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 IHttpActionResult FetchForm1details(string userid) { LicenseRegistration registration = new LicenseRegistration(); var details = JsonConvert.SerializeObject(registration.getform1details(userid)).ToString(); var json1 = details.ToString().Replace("[{", "{Form1:[{"); var json2 = json1.ToString().Replace("}]", "}]}"); JObject json = JObject.Parse(json2); return(Ok(json)); }
private void UpdateRemainingRuns(LicenseRegistration details) { if (IsLicensed || details.Limits.Runs <= 0) { return; } details.Limits.Runs--; storage.Save(details); }
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 GetIsLicensed(LicenseRegistration registration) { if (!validator.Isvalid(registration)) { return(false); } var status = remote.Check(registration); return(status.IsLicensed); }
private void CheckStatus(LicenseRegistration details) { var oldExpiration = details.Expiration; SetStatus(details); if (details.Expiration != oldExpiration) { storage.Save(details); } }
public void EncryptsTheString() { var details = new LicenseRegistration(); serializer .Setup(it => it.Serialize(details)) .Returns("abc"); sut.Save(details); encryptor.Verify(it => it.Encrypt("abc")); }
private LicenseActivation CreateLicense(LicenseRegistration registration) { return(new LicenseActivation { LicenseId = registration.LicenseRegistrationId, ProductId = registration.ProductId, LicenseString = "license", LicenseChecksum = "checksum", ChecksumType = "sha256", CreatedDateTimeUtc = DateTime.UtcNow, CreatedByUser = "******", }); }
public bool Isvalid(LicenseRegistration registration) { if (registration == null) { return(false); } var valid = InternalIsValid(func(registration)); return(Next == null ? valid : valid && Next.Isvalid(registration)); }
public void WritesTheStringToTheOutput() { var details = new LicenseRegistration(); serializer .Setup(it => it.Serialize(details)) .Returns("abc"); encryptor .Setup(it => it.Encrypt("abc")) .Returns("def"); sut.Save(details); io.Verify(it => it.Write("def")); }
public void ReturnsTheDeserializedObject() { io .Setup(it => it.Read()) .Returns("abc"); encryptor .Setup(it => it.Decrypt("abc")) .Returns("def"); var details = new LicenseRegistration(); serializer .Setup(it => it.Deserialize("def")) .Returns(details); var result = sut.Load(); Assert.AreEqual(details, result); }
private async Task <int> CreateLicenseRecordAsync(LicenseRegistration registration, string licenseString, string attributesJson, string attributesChecksum, string userName, Guid activationId) { var license = new LicenseActivation { LicenseActivationId = activationId, LicenseId = registration.LicenseRegistrationId, ProductId = registration.ProductId, CompanyId = registration.CompanyId, LicenseString = licenseString, LicenseAttributes = attributesJson, AttributesChecksum = attributesChecksum, LicenseChecksum = Utils.GetSha256HashFromString(licenseString), ChecksumType = Utils.ChecksumType, CreatedDateTimeUtc = DateTime.UtcNow, CreatedByUser = userName }; _context.Licenses.Add(license); return(await _context.SaveChangesAsync(default));
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); }
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(); }
public void CreatesAndChecksExpiredTrial_1() { var registration = new LicenseRegistration { CreatedOn = new DateTime(2000, 1, 2), Limits = new Limits { Days = 10, Runs = -1, }, Key = null, Name = "Marcel", Contact = "*****@*****.**", Expiration = new DateTime(9999, 12, 31), }; licenser.SaveRegistration(registration); Assert.IsFalse(licenser.IsLicensed); Assert.IsFalse(licenser.IsTrial); }
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 IHttpActionResult FetchFilesFromF2details(string Fac_Id) { try { string host = Dns.GetHostName(); string ip = Dns.GetHostAddresses(host)[0].ToString(); FbisLogger.Log("Method Entry", ip, System.Reflection.MethodBase.GetCurrentMethod().ToString(), this.Request.RequestUri.AbsoluteUri); LicenseRegistration registration = new LicenseRegistration(); var details = JsonConvert.SerializeObject(registration.printSubmitedFormTwoDetail(Fac_Id)).ToString(); var json1 = details.ToString().Replace("[{", "{Form2Details:[{"); var json2 = json1.ToString().Replace("}]", "}]}"); JObject json = JObject.Parse(json2); return(Ok(json)); } catch (Exception ex) { Log log = new Log(); log.LogFile("Exception:" + ex.Message.ToString(), appRunningId); return(BadRequest()); } }
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 async void Initialize(IContext context) { if (context.Products.Any()) { return; // DB has been seeded } var createdDate = DateTime.UtcNow; var user = Environment.UserName; var company = new LicenseCompany { LicenseCompanyId = Guid.NewGuid(), CompanyName = "Gnu.Licensing.Api", CreatedDateTimeUtc = createdDate, CreatedByUser = user }; context.Companies.AddRange(company); await context.SaveChangesAsync(CancellationToken.None); var product = new LicenseProduct { CompanyId = company.LicenseCompanyId, LicenseProductId = Guid.NewGuid(), ProductName = "Gnu.Licensing.Api", ProductDescription = "Gnu.Licensing.Api description", SignKeyName = "CN=Gnu.Licensing", CreatedDateTimeUtc = createdDate, CreatedByUser = user }; context.Products.AddRange(product); await context.SaveChangesAsync(CancellationToken.None); var registration = new LicenseRegistration { LicenseRegistrationId = Guid.NewGuid(), ProductId = product.LicenseProductId, CompanyId = product.CompanyId, LicenseName = "test-name", LicenseEmail = "*****@*****.**", LicenseType = LicenseType.Standard, IsActive = true, Comment = "Comment", Quantity = 1, ExpireUtc = null, CreatedDateTimeUtc = createdDate, CreatedByUser = user }; context.Registrations.AddRange(registration); await context.SaveChangesAsync(CancellationToken.None); var license = new LicenseActivation { LicenseId = registration.LicenseRegistrationId, ProductId = registration.ProductId, CompanyId = registration.CompanyId, LicenseString = "license-string", LicenseAttributes = "license-attributes", LicenseChecksum = "checksum", AttributesChecksum = "checksum", ChecksumType = "sha256", CreatedDateTimeUtc = createdDate, CreatedByUser = user, }; context.Licenses.AddRange(license); await context.SaveChangesAsync(CancellationToken.None); }
public string BuildQuery(LicenseRegistration registration) { return(queryTemplate .Replace("{key}", registration.Key) .Replace("{pid}", sys.GetProcessorId())); }
public void Submit(LicenseRegistration registration) { var data = builder.BuildData(registration); remote.Post(data); }
public void Submit(LicenseRegistration registration) { // do nothing }