Example #1
0
        public object Post(IssueLicense issueRequest)
        {
            var machineKeySection = WebConfigurationManager.GetSection("system.web/machineKey") as MachineKeySection;

            if (machineKeySection == null || StringComparer.OrdinalIgnoreCase.Compare(machineKeySection.Decryption, "Auto") == 0)
            {
                throw new Exception(Properties.Resources.InvalidMachineKeySection);
            }

            var license = documentSession
                          .Include <Model.License, Customer>(lic => lic.CustomerId)
                          .Include <Product>(lic => lic.ProductId)
                          .Load <Model.License>(issueRequest.Id);

            if (license == null)
            {
                HttpError.NotFound("License not found!");
            }

            var customer = documentSession.Load <Customer>(license.CustomerId);
            var product  = documentSession.Load <Product>(license.ProductId);

            var licenseFile =
                Portable.Licensing.License.New()
                .WithUniqueIdentifier(license.LicenseId)
                .As(license.LicenseType)
                .WithMaximumUtilization(license.Quantity)
                .ExpiresAt(license.Expiration)
                .LicensedTo(c =>
            {
                c.Name    = customer.Name;
                c.Email   = customer.Email;
                c.Company = customer.Company;
            })
                .WithProductFeatures(license.ProductFeatures)
                .WithAdditionalAttributes(license.AdditionalAttributes)
                .CreateAndSignWithPrivateKey(product.KeyPair.EncryptedPrivateKey,
                                             machineKeySection.DecryptionKey);

            var issueToken = Guid.NewGuid();

            cacheClient.Set(UrnId.Create <Model.License>("IssueToken", issueToken.ToString()), licenseFile, new TimeSpan(0, 5, 0));

            return(new HttpResult(new IssueLicenseResponse {
                Token = issueToken
            })
            {
                StatusCode = HttpStatusCode.Created,
                Headers =
                {
                    { HttpHeaders.Location, Request.AbsoluteUri.AddQueryParam("token", issueToken) }
                }
            });
        }
Example #2
0
        public object Post(IssueLicense issueRequest)
        {
            var machineKeySection = WebConfigurationManager.GetSection("system.web/machineKey") as MachineKeySection;
            if (machineKeySection == null || StringComparer.OrdinalIgnoreCase.Compare(machineKeySection.Decryption, "Auto") == 0)
                throw new Exception(Properties.Resources.InvalidMachineKeySection);

            var license = documentSession
                .Include<Model.License, Customer>(lic => lic.CustomerId)
                .Include<Product>(lic => lic.ProductId)
                .Load<Model.License>(issueRequest.Id);

            if (license == null)
                HttpError.NotFound("License not found!");

            var customer = documentSession.Load<Customer>(license.CustomerId);
            var product = documentSession.Load<Product>(license.ProductId);

            var licenseFile =
                Portable.Licensing.License.New()
                        .WithUniqueIdentifier(license.LicenseId)
                        .As(license.LicenseType)
                        .WithMaximumUtilization(license.Quantity)
                        .ExpiresAt(license.Expiration)
                        .LicensedTo(c =>
                                        {
                                            c.Name = customer.Name;
                                            c.Email = customer.Email;
                                            c.Company = customer.Company;
                                        })
                        .WithProductFeatures(license.ProductFeatures)
                        .WithAdditionalAttributes(license.AdditionalAttributes)
                        .CreateAndSignWithPrivateKey(product.KeyPair.EncryptedPrivateKey,
                                                     machineKeySection.DecryptionKey);

            var issueToken = Guid.NewGuid();
            cacheClient.Set(UrnId.Create<Model.License>("IssueToken", issueToken.ToString()), licenseFile, new TimeSpan(0, 5, 0));

            return new HttpResult(new IssueLicenseResponse {Token = issueToken})
                       {
                           StatusCode = HttpStatusCode.Created,
                           Headers =
                               {
                                   {HttpHeaders.Location, Request.AbsoluteUri.AddQueryParam("token", issueToken)}
                               }
                       };
        }