コード例 #1
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");
            }
        }
コード例 #2
0
 /// <summary>
 /// Initialize the <see cref="LicenseInformation"/>.
 /// </summary>
 /// <param name="company">Company.</param>
 /// <param name="product">Product.</param>
 /// <param name="expireDate">Expire date.</param>
 /// <param name="landmark">Landmark.</param>
 private void _Init(string company, LicenseProduct product, DateTime expireDate, string landmark)
 {
     _company    = company;
     _product    = product;
     _expireDate = expireDate;
     _landmark   = landmark;
 }
コード例 #3
0
 private LicenseRegistration CreateRegistration(LicenseProduct product)
 {
     return(new LicenseRegistration
     {
         LicenseRegistrationId = Guid.NewGuid(),
         ProductId = product.LicenseProductId,
         LicenseName = "test-name",
         LicenseEmail = "test-email",
         LicenseType = LicenseType.Standard,
         IsActive = true,
         Quantity = 1,
         ExpireUtc = null,
         CreatedDateTimeUtc = DateTime.UtcNow,
         CreatedByUser = "******"
     });
 }
コード例 #4
0
        private Snapshot_LicenseProduct CastToLicenseProductSnapshot(LicenseProduct licenseProduct)
        {
            var snapshot = new Snapshot_LicenseProduct();

            snapshot.CloneLicenseProductId = licenseProduct.LicenseProductId;
            snapshot.LicenseId             = licenseProduct.LicenseId;
            if (licenseProduct.ProductHeader != null)
            {
                snapshot.ProductHeaderId = (int)licenseProduct.ProductHeader.Id;
            }
            snapshot.ProductHeader            = CastToProductHeaderSnapshot(licenseProduct.ProductHeader, licenseProduct.LicenseProductId);
            snapshot.ScheduleId               = licenseProduct.ScheduleId;
            snapshot.ProductId                = licenseProduct.ProductId;
            snapshot.LicensePRecordingsNo     = licenseProduct.LicensePRecordingsNo;
            snapshot.LicenseClaimException    = licenseProduct.LicenseClaimException;
            snapshot.TotalLicenseConfigAmount = (int)licenseProduct.TotalLicenseConfigAmount;
            snapshot.title             = licenseProduct.title;
            snapshot.PaidQuarter       = licenseProduct.PaidQuarter;
            snapshot.RelatedLicensesNo = licenseProduct.RelatedLicensesNo;

            /*
             * if (licenseProduct.ProductConfigurations != null)
             * {
             *  snapshot.ProductConfigurations = CastToRecsConfigurationsSnapshot(licenseProduct.ProductConfigurations,
             *      (int)snapshot.ProductHeaderId);
             * }
             */
            snapshot.CreatedDate  = licenseProduct.CreatedDate;
            snapshot.CreatedBy    = licenseProduct.CreatedBy;
            snapshot.ModifiedDate = licenseProduct.ModifiedDate;
            snapshot.ModifiedBy   = licenseProduct.ModifiedBy;
            snapshot.Deleted      = licenseProduct.Deleted;
            if (licenseProduct.Recordings != null)
            {
                snapshot.Recordings = CastToSnapshotRecordings(licenseProduct.Recordings, licenseProduct.ProductId,
                                                               licenseProduct.LicenseProductId);
            }
            return(snapshot);
        }
コード例 #5
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);
        }
コード例 #6
0
        private Task <string> CreateLicenseAsync(LicenseRegisterRequest request, LicenseRegistration registration, LicenseProduct product, Guid activationId)
        {
            var task = Task.Run(() =>
            {
                try
                {
                    var license = License.New()
                                  .WithUniqueIdentifier(registration.LicenseRegistrationId)
                                  .WithActivationId(activationId)
                                  .As(registration.LicenseType)
                                  .ExpiresAt(registration.ExpireUtc == null ? DateTime.MaxValue : registration.ExpireUtc.Value)
                                  .WithMaximumUtilization(registration.Quantity)
                                  .LicensedTo(registration.LicenseName, registration.LicenseEmail, (c) => c.Company = registration.LicenseName)
                                  .WithAdditionalAttributes(request.Attributes != null ? request.Attributes : new Dictionary <string, string>())
                                  .CreateAndSign(product.SignKeyName);

                    return(license.ToString());
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, ex.Message);

                    throw;
                }
            });

            return(task);
        }
コード例 #7
0
 /// <summary>
 /// Create a <see cref="LicenseInformation"/> object from the company, product code, expire date and landmark.
 /// </summary>
 /// <param name="company">Company.</param>
 /// <param name="product">Product.</param>
 /// <param name="expireDate">Expire date.</param>
 /// <param name="landmark">Landmark.</param>
 public LicenseInformation(string company, LicenseProduct product, DateTime expireDate, string landmark)
 {
     _Init(company, product, expireDate, landmark);
 }
コード例 #8
0
 /// <summary>
 /// Create a <see cref="LicenseInformation"/> object from the company, product code and the expire date.
 /// </summary>
 /// <param name="company">Company.</param>
 /// <param name="product">Product.</param>
 /// <param name="expireDate">Expire date.</param>
 public LicenseInformation(string company, LicenseProduct product, DateTime expireDate)
 {
     _Init(company, product, expireDate, "");
 }
コード例 #9
0
 /// <summary>
 /// Adds a LicenseProduct object in the collection.
 /// </summary>
 /// <param name="product">The LicenseProduct object</param>
 public void Add(LicenseProduct product)
 {
     List.Add(product);
 }