Example #1
0
        public void Save(LicenseRegistration registration)
        {
            var decrypted = serializer.Serialize(registration);
            var encrypted = encryptor.Encrypt(decrypted);

            io.Write(encrypted);
        }
Example #2
0
        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");
            }
        }
Example #3
0
 public void Submit(LicenseRegistration registration)
 {
     if (validator.Isvalid(registration))
     {
         remote.Submit(registration);
     }
 }
Example #4
0
        private void SetStatus(LicenseRegistration details)
        {
            var status = checker.Check(details);

            IsLicensed = status.IsLicensed;
            IsTrial    = status.IsTrial;
        }
Example #5
0
        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));
            }
Example #7
0
        private DateTime?GetExpirationDate(LicenseRegistration registration, string response)
        {
            var parsed = parser.Parse(response);

            return(parsed != null && parsed.Key == registration.Key
        ? parsed.Expiration
        : (DateTime?)null);
        }
Example #8
0
        public void SaveRegistration(LicenseRegistration details)
        {
            // overwrite the currently saved registration information
            storage.Save(details);
            checker.Submit(details);

            CheckStatus(details);
        }
Example #9
0
        public LicenseStatus Check(LicenseRegistration registration)
        {
            var status = new LicenseStatus();

            status.IsLicensed = GetIsLicensed(registration);
            status.IsTrial    = status.IsLicensed || GetIsTrial(registration);

            return(status);
        }
Example #10
0
        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));
        }
Example #11
0
        private void UpdateRemainingRuns(LicenseRegistration details)
        {
            if (IsLicensed || details.Limits.Runs <= 0)
            {
                return;
            }

            details.Limits.Runs--;
            storage.Save(details);
        }
Example #12
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());
        }
Example #13
0
        private bool GetIsLicensed(LicenseRegistration registration)
        {
            if (!validator.Isvalid(registration))
            {
                return(false);
            }

            var status = remote.Check(registration);

            return(status.IsLicensed);
        }
Example #14
0
        private void CheckStatus(LicenseRegistration details)
        {
            var oldExpiration = details.Expiration;

            SetStatus(details);

            if (details.Expiration != oldExpiration)
            {
                storage.Save(details);
            }
        }
Example #15
0
            public void EncryptsTheString()
            {
                var details = new LicenseRegistration();

                serializer
                .Setup(it => it.Serialize(details))
                .Returns("abc");

                sut.Save(details);

                encryptor.Verify(it => it.Encrypt("abc"));
            }
Example #16
0
 private LicenseActivation CreateLicense(LicenseRegistration registration)
 {
     return(new LicenseActivation
     {
         LicenseId = registration.LicenseRegistrationId,
         ProductId = registration.ProductId,
         LicenseString = "license",
         LicenseChecksum = "checksum",
         ChecksumType = "sha256",
         CreatedDateTimeUtc = DateTime.UtcNow,
         CreatedByUser = "******",
     });
 }
Example #17
0
        public bool Isvalid(LicenseRegistration registration)
        {
            if (registration == null)
            {
                return(false);
            }

            var valid = InternalIsValid(func(registration));

            return(Next == null
        ? valid
        : valid && Next.Isvalid(registration));
        }
Example #18
0
            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"));
            }
Example #19
0
            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);
            }
Example #20
0
        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));
Example #21
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);
        }
Example #22
0
        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();
        }
Example #23
0
        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);
        }
Example #24
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,
            });
        }
Example #25
0
        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());
            }
        }
Example #26
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);
 }
Example #27
0
        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);
        }
Example #28
0
 public string BuildQuery(LicenseRegistration registration)
 {
     return(queryTemplate
            .Replace("{key}", registration.Key)
            .Replace("{pid}", sys.GetProcessorId()));
 }
Example #29
0
        public void Submit(LicenseRegistration registration)
        {
            var data = builder.BuildData(registration);

            remote.Post(data);
        }
Example #30
0
 public void Submit(LicenseRegistration registration)
 {
     // do nothing
 }