/// <summary>
        /// Creates new licensee object with given properties. See NetLicensingAPI JavaDoc for details:
        /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseeService.html
        /// </summary>
        public static Licensee create(Context context, String productNumber, Licensee newLicensee)
        {
            newLicensee.productNumber = productNumber;
            netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.Licensee.ENDPOINT_PATH, newLicensee.ToDictionary());

            return(new Licensee(output.items.item[0]));
        }
        /// <summary>
        /// Updates licensee properties. See NetLicensingAPI JavaDoc for details:
        /// http://netlicensing.labs64.com/javadoc/v2/com/labs64/netlicensing/core/service/LicenseeService.html
        /// </summary>
        public static Licensee update(Context context, String number, Licensee updateLicensee)
        {
            updateLicensee.number = number;
            netlicensing output = NetLicensingAPI.request(context, NetLicensingAPI.Method.POST, Constants.Licensee.ENDPOINT_PATH + "/" + number, updateLicensee.ToDictionary());

            return(new Licensee(output.items.item[0]));
        }
Пример #3
0
        public IHttpActionResult PutLicensee(int id, Licensee licensee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != licensee.Licensees_id)
            {
                return(BadRequest());
            }

            db.Entry(licensee).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LicenseeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        private Licensee CreateLicensee(LicenseeStatus status)
        {
            var randomString = TestDataGenerator.GetRandomString();

            var licensee = new Licensee
            {
                Id                  = Guid.NewGuid(),
                Name                = "Name" + randomString,
                AffiliateSystem     = false,
                CompanyName         = "CName" + randomString,
                ContractStart       = DateTimeOffset.UtcNow.AddDays(-7),
                Email               = TestDataGenerator.GetRandomEmail(),
                AllowedBrandCount   = 10,
                AllowedWebsiteCount = 10,
                TimezoneId          = TestDataGenerator.GetRandomTimeZone().Id,
                Status              = status,
            };

            licensee.Contracts.Add(new Contract
            {
                Id                = Guid.NewGuid(),
                LicenseeId        = licensee.Id,
                Licensee          = licensee,
                StartDate         = licensee.ContractStart,
                EndDate           = licensee.ContractEnd,
                IsCurrentContract = true
            });

            _fakeBrandRepository.Licensees.Add(licensee);
            _fakeBrandRepository.SaveChanges();

            return(licensee);
        }
Пример #5
0
 public override void BeforeAll()
 {
     base.BeforeAll();
     _playerTestHelper   = _container.Resolve <PlayerTestHelper>();
     _securityTestHelper = _container.Resolve <SecurityTestHelper>();
     _brandTestHelper    = _container.Resolve <BrandTestHelper>();
     _defaultLicensee    = _brandTestHelper.GetDefaultLicensee();
     _playerQueries      = _container.Resolve <PlayerQueries>();
 }
Пример #6
0
        public IHttpActionResult GetLicensee(int id)
        {
            Licensee licensee = db.Licensees.Find(id);

            if (licensee == null)
            {
                return(NotFound());
            }

            return(Ok(licensee));
        }
Пример #7
0
        }                            // default constructor is required for publishing event to MQ

        public LicenseeCreated(Licensee licensee)
        {
            Id              = licensee.Id;
            Name            = licensee.Name;
            CompanyName     = licensee.CompanyName;
            Email           = licensee.Email;
            AffiliateSystem = licensee.AffiliateSystem;
            ContractStart   = licensee.ContractStart;
            ContractEnd     = licensee.ContractEnd;
            CreatedBy       = licensee.CreatedBy;
            DateCreated     = licensee.DateCreated;
            Languages       = licensee.Cultures.Select(c => c.Code);
        }
Пример #8
0
        public IHttpActionResult DeleteLicensee(int id)
        {
            Licensee licensee = db.Licensees.Find(id);

            if (licensee == null)
            {
                return(NotFound());
            }

            db.Licensees.Remove(licensee);
            db.SaveChanges();

            return(Ok(licensee));
        }
Пример #9
0
        }                            // default constructor is required for publishing event to MQ

        public LicenseeUpdated(Licensee licensee)
        {
            Id              = licensee.Id;
            Name            = licensee.Name;
            CompanyName     = licensee.CompanyName;
            Email           = licensee.Email;
            AffiliateSystem = licensee.AffiliateSystem;
            ContractStart   = licensee.ContractStart;
            ContractEnd     = licensee.ContractEnd;
            Languages       = licensee.Cultures.Select(x => x.Code);
            Countries       = licensee.Countries.Select(x => x.Code);
            Currencies      = licensee.Currencies.Select(x => x.Code);
            Products        = licensee.Products.Select(x => x.ProductId);
            Remarks         = licensee.Remarks;
        }
Пример #10
0
        public Brand CreateBrand(
            Licensee licensee   = null,
            Country country     = null,
            CultureCode culture = null,
            Currency currency   = null
            )
        {
            licensee = licensee ?? _brandRepository.Licensees.FirstOrDefault() ?? CreateLicensee();
            country  = country ?? CreateCountry("CA", "Canada");
            culture  = culture ?? CreateCulture("en-CA", "English (Canada)");
            currency = currency ?? CreateCurrency("CAD", "Canadian Dollar");
            var    brandName = TestDataGenerator.GetRandomString(20);
            var    brandCode = TestDataGenerator.GetRandomString(20);
            string playerPrefix;

            do
            {
                playerPrefix = TestDataGenerator.GetRandomString(3);
            } while (_brandRepository.Brands.Any(x => x.PlayerPrefix == playerPrefix && x.Licensee.Id == licensee.Id));

            _brandCommands.AddBrand(new AddBrandData
            {
                Code = brandCode,
                EnablePlayerPrefix = true,
                InternalAccounts   = 10,
                Licensee           = licensee.Id,
                Name                   = brandName,
                PlayerPrefix           = playerPrefix,
                TimeZoneId             = TestDataGenerator.GetRandomTimeZone().Id,
                Type                   = BrandType.Credit,
                PlayerActivationMethod = PlayerActivationMethod.Automatic
            });
            var brand    = _brandQueries.GetBrands().Single(b => b.Name == brandName);
            var vipLevel = _brandRepository.VipLevels.FirstOrDefault(vl => vl.IsDefault && vl.Brand.Id == brand.Id)
                           ?? CreateVipLevel(brand);

            brand.Countries.Add(country);
            brand.Cultures.Add(culture);
            brand.DefaultCulture = culture;
            brand.Currencies.Add(currency);
            brand.DefaultCurrency = currency.Code;
            brand.VipLevels.Add(_brandRepository.VipLevels.FirstOrDefault(vl => vl.IsDefault) ?? CreateVipLevel(brand));
            CreatePaymentLevel(brand, currency);
            CreateWallet(brand);
            return(brand);
        }
Пример #11
0
        public override void BeforeAll()
        {
            base.BeforeAll();
            //create a brand for the default licensee
            var brandTestHelper = _container.Resolve <BrandTestHelper>();

            _defaultLicensee = brandTestHelper.GetDefaultLicensee();
            _brand           = brandTestHelper.CreateBrand(_defaultLicensee, null, null, null, true);

            //create a player for the brand
            var player = _container.Resolve <PlayerTestHelper>().CreatePlayer(isActive: true, brandId: _brand.Id);

            _playerUsername = player.Username;
            _playerFullName = player.FirstName + " " + player.LastName;

            _securityTestHelper = _container.Resolve <SecurityTestHelper>();
        }
Пример #12
0
        public void AddLicensee(Guid id)
        {
            if (_repository.Licensees.Any(x => x.Id == id))
            {
                return;
            }
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var licensee = new Licensee
                {
                    Id = id
                };
                _repository.Licensees.AddOrUpdate(licensee);

                _repository.SaveChanges();
                scope.Complete();
            }
        }
Пример #13
0
        public Licensee CreateLicensee()
        {
            var name     = TestDataGenerator.GetRandomString(5);
            var licensee = new Licensee
            {
                Id                = Guid.NewGuid(),
                Name              = name,
                CompanyName       = name + " Inc.",
                Email             = TestDataGenerator.GetRandomEmail(),
                ContractStart     = DateTime.Now.Date,
                ContractEnd       = DateTime.Now.Date.AddMonths(1),
                AllowedBrandCount = 10,
                Status            = LicenseeStatus.Inactive
            };

            _brandRepository.Licensees.Add(licensee);
            _bus.Publish(new LicenseeCreated(licensee));
            return(licensee);
        }
Пример #14
0
        public User CreateUser(Role role, Licensee licensee, IEnumerable <Brand> brands = null)
        {
            var userName = "******" + TestDataGenerator.GetRandomString(5);
            var userId   = Guid.NewGuid();
            var user     = new User
            {
                Id                = userId,
                Username          = userName,
                FirstName         = userName,
                LastName          = userName,
                PasswordEncrypted = PasswordHelper.EncryptPassword(userId, TestDataGenerator.GetRandomString()),
                Language          = "English",
                Status            = UserStatus.Active
            };

            user.SetLicensees(new [] { licensee.Id });
            user.SetAllowedBrands(brands != null ? brands.Select(b => b.Id) : null);
            return(_userService.CreateUser(user, role.Id));
        }
Пример #15
0
        public override void BeforeAll()
        {
            base.BeforeAll();

            // create a brand for default licensee
            _brandTestHelper = _container.Resolve <BrandTestHelper>();
            var brandQueries = _container.Resolve <BrandQueries>();

            _licensee          = brandQueries.GetLicensees().First(x => x.Name == DefaultLicensee);
            _defaultLicenseeId = brandQueries.GetLicensees().First(x => x.Name == DefaultLicensee).Id;
            _brand             = _brandTestHelper.CreateBrand(_licensee);

            // create a role
            _securityTestHelper = _container.Resolve <SecurityTestHelper>();
            _role = _securityTestHelper.CreateRole(new[] { _defaultLicenseeId });

            // create a user
            _adminData = _securityTestHelper.CreateAdmin(_defaultLicenseeId, new[] { _brand }, new[] { "RMB" }, _userPassword, _role.Id);
        }
Пример #16
0
 public bool CanActivateLicensee(Licensee licensee)
 {
     return((licensee.Status == LicenseeStatus.Inactive || licensee.Status == LicenseeStatus.Deactivated) &&
            (!licensee.ContractEnd.HasValue || licensee.ContractEnd > DateTimeOffset.UtcNow));
 }
Пример #17
0
 public override void BeforeAll()
 {
     base.BeforeAll();
     _brandTestHelper = _container.Resolve <BrandTestHelper>();
     _defaultLicensee = _brandTestHelper.GetDefaultLicensee();
 }
Пример #18
0
        static int Main(string[] args)
        {
            // ServicePointManager.ServerCertificateValidationCallback = delegate { return true;  // Trust any (self-signed) certificate };

            Context context = new Context();

            context.baseUrl = "https://go.netlicensing.io/core/v2/rest";

            context.username     = "******";
            context.password     = "******";
            context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

            String randomNumber = randomString(8);

            String  demoProductNumber              = numberWithPrefix("P", randomNumber);
            String  demoProductModuleNumber        = numberWithPrefix("PM", randomNumber);
            String  demoLicensingModel             = Constants.LicensingModel.TryAndBuy.NAME;
            String  demoLicenseTemplate1_Number    = numberWithPrefix("LT", randomNumber);
            String  demoLicenseTemplate1_Name      = "Demo Evaluation Period";
            String  demoLicenseTemplate1_Type      = "FEATURE";
            Decimal demoLicenseTemplate1_Price     = 12.50M;
            String  demoLicenseTemplate1_Currency  = "EUR";
            Boolean demoLicenseTemplate1_Automatic = false;
            Boolean demoLicenseTemplate1_Hidden    = false;
            String  demoLicenseeNumber             = numberWithPrefix("L", randomNumber);
            String  demoLicenseNumber              = numberWithPrefix("LC", randomNumber);
            String  demoLicenseeName = "Demo Licensee";

            try
            {
                #region ****************** Lists

                List <String> licenseTypes = UtilityService.listLicenseTypes(context);
                ConsoleWriter.WriteList("License Types:", licenseTypes);

                List <String> licensingModels = UtilityService.listLicensingModels(context);
                ConsoleWriter.WriteList("Licensing Models:", licensingModels);

                #endregion

                #region ****************** Product

                Product newProduct = new Product();
                newProduct.number = demoProductNumber;
                newProduct.name   = "Demo product";
                Product product = ProductService.create(context, newProduct);
                ConsoleWriter.WriteEntity("Added product:", product);

                product = ProductService.get(context, demoProductNumber);
                ConsoleWriter.WriteEntity("Got product:", product);

                List <Product> products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following products:", products);

                Product updateProduct = new Product();
                updateProduct.productProperties.Add("Updated property name", "Updated value");
                product = ProductService.update(context, demoProductNumber, updateProduct);
                ConsoleWriter.WriteEntity("Updated product:", product);

                ProductService.delete(context, demoProductNumber, true);
                ConsoleWriter.WriteMsg("Deleted Product!");

                products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following Products:", products);

                product = ProductService.create(context, newProduct);
                ConsoleWriter.WriteEntity("Added product again:", product);

                products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following Products:", products);

                #endregion

                #region ****************** ProductModule

                ProductModule newProductModule = new ProductModule();
                newProductModule.number         = demoProductModuleNumber;
                newProductModule.name           = "Demo product module";
                newProductModule.licensingModel = demoLicensingModel;
                ProductModule productModule = ProductModuleService.create(context, demoProductNumber, newProductModule);
                ConsoleWriter.WriteEntity("Added product module:", productModule);

                productModule = ProductModuleService.get(context, demoProductModuleNumber);
                ConsoleWriter.WriteEntity("Got product module:", productModule);

                List <ProductModule> productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                ProductModule updateProductModule = new ProductModule();
                updateProductModule.productModuleProperties.Add("Updated property name", "Updated property value");
                productModule = ProductModuleService.update(context, demoProductModuleNumber, updateProductModule);
                ConsoleWriter.WriteEntity("Updated product module:", productModule);

                ProductModuleService.delete(context, demoProductModuleNumber, true);
                ConsoleWriter.WriteMsg("Deleted ProductModule!");

                productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                productModule = ProductModuleService.create(context, demoProductNumber, newProductModule);
                ConsoleWriter.WriteEntity("Added product module again:", productModule);

                productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                #endregion

                #region ****************** LicenseTemplate

                LicenseTemplate newLicenseTemplate = new LicenseTemplate();
                newLicenseTemplate.number      = demoLicenseTemplate1_Number;
                newLicenseTemplate.name        = demoLicenseTemplate1_Name;
                newLicenseTemplate.licenseType = demoLicenseTemplate1_Type;
                newLicenseTemplate.price       = demoLicenseTemplate1_Price;
                newLicenseTemplate.currency    = demoLicenseTemplate1_Currency;
                newLicenseTemplate.automatic   = demoLicenseTemplate1_Automatic;
                newLicenseTemplate.hidden      = demoLicenseTemplate1_Hidden;
                ConsoleWriter.WriteEntity("Adding license template:", newLicenseTemplate);
                LicenseTemplate licenseTemplate = LicenseTemplateService.create(context, demoProductModuleNumber, newLicenseTemplate);
                ConsoleWriter.WriteEntity("Added license template:", licenseTemplate);

                licenseTemplate = LicenseTemplateService.get(context, demoLicenseTemplate1_Number);
                ConsoleWriter.WriteEntity("Got licenseTemplate:", licenseTemplate);

                List <LicenseTemplate> licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                LicenseTemplate updateLicenseTemplate = new LicenseTemplate();
                updateLicenseTemplate.active    = true;
                updateLicenseTemplate.automatic = demoLicenseTemplate1_Automatic; // workaround: at the moment not specified booleans treated as "false"
                updateLicenseTemplate.hidden    = demoLicenseTemplate1_Hidden;    // workaround: at the moment not specified booleans treated as "false"
                licenseTemplate = LicenseTemplateService.update(context, demoLicenseTemplate1_Number, updateLicenseTemplate);
                ConsoleWriter.WriteEntity("Updated license template:", licenseTemplate);

                LicenseTemplateService.delete(context, demoLicenseTemplate1_Number, true);
                ConsoleWriter.WriteMsg("Deleted LicenseTemplate!");

                licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                licenseTemplate = LicenseTemplateService.create(context, demoProductModuleNumber, newLicenseTemplate);
                ConsoleWriter.WriteEntity("Added license template again:", licenseTemplate);

                licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);


                #endregion

                #region ****************** Licensee

                Licensee newLicensee = new Licensee();
                newLicensee.number = demoLicenseeNumber;
                Licensee licensee = LicenseeService.create(context, demoProductNumber, newLicensee);
                ConsoleWriter.WriteEntity("Added licensee:", licensee);

                List <Licensee> licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                LicenseeService.delete(context, demoLicenseeNumber, true);
                ConsoleWriter.WriteMsg("Deleted licensee!");

                licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees after delete:", licensees);

                licensee = LicenseeService.create(context, demoProductNumber, newLicensee);
                ConsoleWriter.WriteEntity("Added licensee again:", licensee);

                licensee = LicenseeService.get(context, demoLicenseeNumber);
                ConsoleWriter.WriteEntity("Got licensee:", licensee);

                Licensee updateLicensee = new Licensee();
                updateLicensee.licenseeProperties.Add("Updated property name", "Updated value");
                licensee = LicenseeService.update(context, demoLicenseeNumber, updateLicensee);
                ConsoleWriter.WriteEntity("Updated licensee:", licensee);

                licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                #endregion

                #region ****************** License

                License newLicense = new License();
                newLicense.number = demoLicenseNumber;
                License license = LicenseService.create(context, demoLicenseeNumber, demoLicenseTemplate1_Number, null, newLicense);
                ConsoleWriter.WriteEntity("Added license:", license);

                List <License> licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following licenses:", licenses);

                LicenseService.delete(context, demoLicenseNumber);
                Console.WriteLine("Deleted license");

                licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following licenses:", licenses);

                license = LicenseService.create(context, demoLicenseeNumber, demoLicenseTemplate1_Number, null, newLicense);
                ConsoleWriter.WriteEntity("Added license again:", license);

                license = LicenseService.get(context, demoLicenseNumber);
                ConsoleWriter.WriteEntity("Got license:", license);

                License updateLicense = new License();
                updateLicense.licenseProperties.Add("Updated property name", "Updated value");
                license = LicenseService.update(context, demoLicenseNumber, null, updateLicense);
                ConsoleWriter.WriteEntity("Updated license:", license);

                #endregion

                #region ****************** PaymentMethod

                List <PaymentMethod> paymentMethods = PaymentMethodService.list(context);
                ConsoleWriter.WriteList("Got the following payment methods:", paymentMethods);

                #endregion

                #region ****************** Token

                //NetLicensing supports API Key Identification to allow limited API access on vendor's behalf.
                //See: https://netlicensing.io/wiki/security for details.
                Token newToken = new Token();
                newToken.tokenType = Constants.Token.TYPE_APIKEY;
                Token apiKey = TokenService.create(context, newToken);
                ConsoleWriter.WriteEntity("Created APIKey:", apiKey);
                context.apiKey = apiKey.number;

                newToken.tokenType = Constants.Token.TYPE_SHOP;
                newToken.tokenProperties.Add(Constants.Licensee.LICENSEE_NUMBER, demoLicenseeNumber);
                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                Token shopToken = TokenService.create(context, newToken);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Got the following shop token:", shopToken);

                String       filter = Constants.Token.TOKEN_TYPE + "=" + Constants.Token.TYPE_SHOP;
                List <Token> tokens = TokenService.list(context, filter);
                ConsoleWriter.WriteList("Got the following shop tokens:", tokens);

                TokenService.delete(context, shopToken.number);
                ConsoleWriter.WriteMsg("Deactivated shop token!");

                tokens = TokenService.list(context, filter);
                ConsoleWriter.WriteList("Got the following shop tokens after deactivate:", tokens);

                #endregion

                #region ****************** Validate

                ValidationParameters validationParameters = new ValidationParameters();
                validationParameters.setLicenseeName(demoLicenseeName);
                validationParameters.setProductNumber(demoProductNumber);
                validationParameters.put(demoProductModuleNumber, "paramKey", "paramValue");
                ValidationResult validationResult = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                ConsoleWriter.WriteEntity("Validation result for created licensee:", validationResult);

                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                validationResult     = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Validation repeated with APIKey:", validationResult);

                #endregion

                #region ****************** Transfer

                Licensee transferLicensee = new Licensee();
                transferLicensee.number = "TR" + demoLicenseeNumber;
                transferLicensee.licenseeProperties.Add(Constants.Licensee.PROP_MARKED_FOR_TRANSFER, Boolean.TrueString.ToLower());
                transferLicensee = LicenseeService.create(context, demoProductNumber, transferLicensee);
                ConsoleWriter.WriteEntity("Added transfer licensee:", transferLicensee);

                License transferLicense = new License();
                transferLicense.number = "LTR" + demoLicenseNumber;
                License newTransferLicense = LicenseService.create(context, transferLicensee.number, demoLicenseTemplate1_Number, null, transferLicense);
                ConsoleWriter.WriteEntity("Added license for transfer:", newTransferLicense);

                LicenseeService.transfer(context, licensee.number, transferLicensee.number);

                licenses = LicenseService.list(context, Constants.Licensee.LICENSEE_NUMBER + "=" + licensee.number);
                ConsoleWriter.WriteList("Got the following licenses after transfer:", licenses);

                Licensee transferLicenseeWithApiKey = new Licensee();
                transferLicenseeWithApiKey.number = "Key" + demoLicenseeNumber;
                transferLicenseeWithApiKey.licenseeProperties.Add(Constants.Licensee.PROP_MARKED_FOR_TRANSFER, Boolean.TrueString.ToLower());
                transferLicenseeWithApiKey = LicenseeService.create(context, demoProductNumber, transferLicenseeWithApiKey);

                License transferLicenseWithApiKey = new License();
                transferLicenseWithApiKey.number = "Key" + demoLicenseNumber;
                LicenseService.create(context, transferLicenseeWithApiKey.number, demoLicenseTemplate1_Number, null,
                                      transferLicenseWithApiKey);

                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                LicenseeService.transfer(context, licensee.number, transferLicenseeWithApiKey.number);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

                licenses = LicenseService.list(context, Constants.Licensee.LICENSEE_NUMBER + "=" + licensee.number);
                ConsoleWriter.WriteList("Got the following licenses after transfer:", licenses);

                #endregion

                #region ****************** Transactions

                List <Transaction> transactions = TransactionService.list(context, Constants.Transaction.SOURCE_SHOP_ONLY + "=" + Boolean.TrueString.ToLower());
                ConsoleWriter.WriteList("Got the following transactions shop only:", transactions);

                transactions = TransactionService.list(context, null);
                ConsoleWriter.WriteList("Got the following transactions after transfer:", transactions);

                #endregion

                Console.WriteLine("All done.");

                return(0);
            }
            catch (NetLicensingException e)
            {
                Console.WriteLine("Got NetLicensing exception:");
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Got exception:");
                Console.WriteLine(e);
            }
            finally
            {
                try
                {
                    // Cleanup:
                    context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

                    // deactivate api key in case APIKey was used (exists)
                    if (!String.IsNullOrEmpty(context.apiKey))
                    {
                        TokenService.delete(context, context.apiKey);
                    }
                    // delete test product with all its related items
                    ProductService.delete(context, demoProductNumber, true);
                }
                catch (NetLicensingException e)
                {
                    Console.WriteLine("Got NetLicensing exception during cleanup:");
                    Console.WriteLine(e);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got exception during cleanup:");
                    Console.WriteLine(e);
                }
            }

            return(1);
        }
Пример #19
0
        public Guid Add(AddLicenseeData data)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = _licenseeQueries.ValidateCanAdd(data);

                if (!validationResult.IsValid)
                {
                    throw new RegoValidationException(validationResult);
                }

                var licensee = new Licensee
                {
                    Id                  = data.Id ?? Guid.NewGuid(),
                    Name                = data.Name,
                    CompanyName         = data.CompanyName,
                    AffiliateSystem     = data.AffiliateSystem,
                    ContractStart       = data.ContractStart,
                    ContractEnd         = data.ContractEnd,
                    Email               = data.Email,
                    AllowedBrandCount   = data.BrandCount,
                    AllowedWebsiteCount = data.WebsiteCount,
                    TimezoneId          = data.TimeZoneId,
                    Status              = LicenseeStatus.Inactive,
                    DateCreated         = DateTimeOffset.UtcNow,
                    CreatedBy           = _actorInfoProvider.Actor.UserName,
                    Contracts           = new List <Contract>
                    {
                        new Contract
                        {
                            Id                = Guid.NewGuid(),
                            StartDate         = data.ContractStart,
                            EndDate           = data.ContractEnd,
                            IsCurrentContract = true
                        }
                    }
                };

                if (data.Products != null)
                {
                    EnumerableExtensions.ForEach(data.Products, x =>
                                                 licensee.Products.Add(new LicenseeProduct
                    {
                        ProductId = new Guid(x)
                    }));
                }

                EnumerableExtensions.ForEach(data.Currencies, x => licensee.Currencies.Add(_repository.Currencies.Single(y => y.Code == x)));
                EnumerableExtensions.ForEach(data.Countries, x => licensee.Countries.Add(_repository.Countries.Single(y => y.Code == x)));
                EnumerableExtensions.ForEach(data.Languages, x => licensee.Cultures.Add(_repository.Cultures.Single(y => y.Code == x)));

                _repository.Licensees.Add(licensee);
                _repository.SaveChanges();

                _eventBus.Publish(new LicenseeCreated
                {
                    Id              = licensee.Id,
                    Name            = licensee.Name,
                    CompanyName     = licensee.CompanyName,
                    Email           = licensee.Email,
                    AffiliateSystem = licensee.AffiliateSystem,
                    ContractStart   = licensee.ContractStart,
                    ContractEnd     = licensee.ContractEnd,
                    Languages       = licensee.Cultures.Select(c => c.Code)
                });

                scope.Complete();

                return(licensee.Id);
            }
        }
Пример #20
0
        static void Main(string[] args)
        {
            // ServicePointManager.ServerCertificateValidationCallback = delegate { return true;  // Trust any (self-signed) certificate };

            Context context = new Context();

            context.baseUrl      = "https://netlicensing.labs64.com";
            context.username     = "******";
            context.password     = "******";
            context.securityMode = SecutiryMode.BASIC_AUTHENTICATION;

            String  demoProductNumber              = "P001demo";
            String  demoProductModuleNumber        = "M001demo";
            String  demoLicensingModel             = "TimeLimitedEvaluation";
            String  demoLicenseTemplate1_Number    = "E001demo";
            String  demoLicenseTemplate1_Name      = "Demo Evaluation Period";
            String  demoLicenseTemplate1_Type      = "FEATURE";
            Decimal demoLicenseTemplate1_Price     = 12.50M;
            String  demoLicenseTemplate1_Currency  = "EUR";
            Boolean demoLicenseTemplate1_Automatic = false;
            Boolean demoLicenseTemplate1_Hidden    = false;
            String  demoLicenseeNumber             = "I001demo";
            String  demoLicenseNumber              = "L001demoTV";

            try
            {
                #region ****************** Lists

                List <String> licenseTypes = UtilityService.listLicenseTypes(context);
                ConsoleWriter.WriteList("License Types:", licenseTypes);

                List <String> licensingModels = UtilityService.listLicensingModels(context);
                ConsoleWriter.WriteList("Licensing Models:", licensingModels);

                #endregion

                #region ****************** Product

                Product newProduct = new Product();
                newProduct.number = demoProductNumber;
                newProduct.name   = "Demo product";
                Product product = ProductService.create(context, newProduct);
                ConsoleWriter.WriteEntity("Added product:", product);

                product = ProductService.get(context, demoProductNumber);
                ConsoleWriter.WriteEntity("Got product:", product);

                List <Product> products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following products:", products);

                Product updateProduct = new Product();
                updateProduct.productProperties.Add("Updated property name", "Updated value");
                product = ProductService.update(context, demoProductNumber, updateProduct);
                ConsoleWriter.WriteEntity("Updated product:", product);

                ProductService.delete(context, demoProductNumber, true);
                ConsoleWriter.WriteMsg("Deleted Product!");

                products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following Products:", products);

                product = ProductService.create(context, newProduct);
                ConsoleWriter.WriteEntity("Added product again:", product);

                products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following Products:", products);

                #endregion

                #region ****************** ProductModule

                ProductModule newProductModule = new ProductModule();
                newProductModule.number         = demoProductModuleNumber;
                newProductModule.name           = "Demo product module";
                newProductModule.licensingModel = demoLicensingModel;
                ProductModule productModule = ProductModuleService.create(context, demoProductNumber, newProductModule);
                ConsoleWriter.WriteEntity("Added product module:", productModule);

                productModule = ProductModuleService.get(context, demoProductModuleNumber);
                ConsoleWriter.WriteEntity("Got product module:", productModule);

                List <ProductModule> productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                ProductModule updateProductModule = new ProductModule();
                updateProductModule.productModuleProperties.Add("Updated property name", "Updated property value");
                productModule = ProductModuleService.update(context, demoProductModuleNumber, updateProductModule);
                ConsoleWriter.WriteEntity("Updated product module:", productModule);

                ProductModuleService.delete(context, demoProductModuleNumber, true);
                ConsoleWriter.WriteMsg("Deleted ProductModule!");

                productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                productModule = ProductModuleService.create(context, demoProductNumber, newProductModule);
                ConsoleWriter.WriteEntity("Added product module again:", productModule);

                productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                #endregion

                #region ****************** LicenseTemplate
                LicenseTemplate newLicenseTemplate = new LicenseTemplate();
                newLicenseTemplate.number      = demoLicenseTemplate1_Number;
                newLicenseTemplate.name        = demoLicenseTemplate1_Name;
                newLicenseTemplate.licenseType = demoLicenseTemplate1_Type;
                newLicenseTemplate.price       = demoLicenseTemplate1_Price;
                newLicenseTemplate.currency    = demoLicenseTemplate1_Currency;
                newLicenseTemplate.automatic   = demoLicenseTemplate1_Automatic;
                newLicenseTemplate.hidden      = demoLicenseTemplate1_Hidden;
                ConsoleWriter.WriteEntity("Adding license template:", newLicenseTemplate);
                LicenseTemplate licenseTemplate = LicenseTemplateService.create(context, demoProductModuleNumber, newLicenseTemplate);
                ConsoleWriter.WriteEntity("Added license template:", licenseTemplate);

                licenseTemplate = LicenseTemplateService.get(context, demoLicenseTemplate1_Number);
                ConsoleWriter.WriteEntity("Got licenseTemplate:", licenseTemplate);

                List <LicenseTemplate> licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                LicenseTemplate updateLicenseTemplate = new LicenseTemplate();
                updateLicenseTemplate.active    = true;
                updateLicenseTemplate.automatic = demoLicenseTemplate1_Automatic; // workaround: at the moment not specified booleans treated as "false"
                updateLicenseTemplate.hidden    = demoLicenseTemplate1_Hidden;    // workaround: at the moment not specified booleans treated as "false"
                licenseTemplate = LicenseTemplateService.update(context, demoLicenseTemplate1_Number, updateLicenseTemplate);
                ConsoleWriter.WriteEntity("Updated license template:", licenseTemplate);

                LicenseTemplateService.delete(context, demoLicenseTemplate1_Number, true);
                ConsoleWriter.WriteMsg("Deleted LicenseTemplate!");

                licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                licenseTemplate = LicenseTemplateService.create(context, demoProductModuleNumber, newLicenseTemplate);
                ConsoleWriter.WriteEntity("Added license template again:", licenseTemplate);

                licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);


                #endregion

                #region ****************** Licensee

                Licensee newLicensee = new Licensee();
                newLicensee.number = demoLicenseeNumber;
                Licensee licensee = LicenseeService.create(context, demoProductNumber, newLicensee);
                ConsoleWriter.WriteEntity("Added licensee:", licensee);

                List <Licensee> licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                LicenseeService.delete(context, demoLicenseeNumber, true);
                ConsoleWriter.WriteMsg("Deleted licensee!");

                licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees after delete:", licensees);

                licensee = LicenseeService.create(context, demoProductNumber, newLicensee);
                ConsoleWriter.WriteEntity("Added licensee again:", licensee);

                licensee = LicenseeService.get(context, demoLicenseeNumber);
                ConsoleWriter.WriteEntity("Got licensee:", licensee);

                Licensee updateLicensee = new Licensee();
                updateLicensee.licenseeProperties.Add("Updated property name", "Updated value");
                licensee = LicenseeService.update(context, demoLicenseeNumber, updateLicensee);
                ConsoleWriter.WriteEntity("Updated licensee:", licensee);

                licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                #endregion

                #region ****************** License
                License newLicense = new License();
                newLicense.number = demoLicenseNumber;
                License license = LicenseService.create(context, demoLicenseeNumber, demoLicenseTemplate1_Number, null, newLicense);
                ConsoleWriter.WriteEntity("Added license:", license);

                List <License> licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenses);

                LicenseService.delete(context, demoLicenseNumber);
                Console.WriteLine("Deleted license");

                licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenses);

                license = LicenseService.create(context, demoLicenseeNumber, demoLicenseTemplate1_Number, null, newLicense);
                ConsoleWriter.WriteEntity("Added license again:", license);

                license = LicenseService.get(context, demoLicenseNumber);
                ConsoleWriter.WriteEntity("Got license:", license);

                License updateLicense = new License();
                updateLicense.licenseProperties.Add("Updated property name", "Updated value");
                license = LicenseService.update(context, demoLicenseNumber, null, updateLicense);
                ConsoleWriter.WriteEntity("Updated license:", license);

                #endregion

                #region ****************** PaymentMethod

                List <PaymentMethod> paymentMethods = PaymentMethodService.list(context);
                ConsoleWriter.WriteList("Got the following payment methods:", paymentMethods);

                #endregion

                #region ****************** Token

                Token newToken = new Token();
                newToken.tokenType = Constants.Token.TYPE_APIKEY;
                Token apiKey = TokenService.create(context, newToken);
                ConsoleWriter.WriteEntity("Created API Key:", apiKey);
                context.apiKey = apiKey.number;

                newToken.tokenType = Constants.Token.TYPE_SHOP;
                newToken.tokenProperties.Add(Constants.Licensee.LICENSEE_NUMBER, demoLicenseeNumber);
                context.securityMode = SecutiryMode.APIKEY_IDENTIFICATION;
                Token shopToken = TokenService.create(context, newToken);
                context.securityMode = SecutiryMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Got the following shop token:", shopToken);

                List <Token> tokens = TokenService.list(context, Constants.Token.TYPE_SHOP, null);
                ConsoleWriter.WriteList("Got the following shop tokens:", tokens);

                TokenService.deactivate(context, shopToken.number);
                ConsoleWriter.WriteMsg("Deactivated shop token!");

                tokens = TokenService.list(context, Constants.Token.TYPE_SHOP, null);
                ConsoleWriter.WriteList("Got the following shop tokens after deactivate:", tokens);

                #endregion

                #region ****************** Validate

                ValidationResult validationResult = LicenseeService.validate(context, demoLicenseeNumber, demoProductNumber);
                ConsoleWriter.WriteEntity("Validation result for created licensee:", validationResult);

                context.securityMode = SecutiryMode.APIKEY_IDENTIFICATION;
                validationResult     = LicenseeService.validate(context, demoLicenseeNumber, demoProductNumber);
                context.securityMode = SecutiryMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Validation repeated with API Key:", validationResult);

                #endregion
            }
            catch (NetLicensingException e)
            {
                Console.WriteLine("Got NetLicensing exception:");
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Got exception:");
                Console.WriteLine(e);
            }
            finally
            {
                try
                {
                    // Cleanup:
                    context.securityMode = SecutiryMode.BASIC_AUTHENTICATION;
                    // deactivate api key
                    TokenService.deactivate(context, context.apiKey);
                    // delete test product with all its related items
                    ProductService.delete(context, demoProductNumber, true);
                }
                catch (NetLicensingException e)
                {
                    Console.WriteLine("Got NetLicensing exception during cleanup:");
                    Console.WriteLine(e);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got exception during cleanup:");
                    Console.WriteLine(e);
                }
            }

            Console.WriteLine("Press <Enter> to exit...");
            Console.ReadLine();
        }
Пример #21
0
        static int Main(string[] args)
        {
            Context context = new Context();

            context.baseUrl = "https://go.netlicensing.io/core/v2/rest";

            context.username     = "******";
            context.password     = "******";
            context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

            String randomNumber = randomString(8);

            String  demoProductNumber              = numberWithPrefix("P", randomNumber);
            String  demoProductModuleNumber        = numberWithPrefix("PM", randomNumber);
            String  demoLicensingModel             = Constants.LicensingModel.TryAndBuy.NAME;
            String  demoLicenseTemplate1_Number    = numberWithPrefix("LT", randomNumber);
            String  demoLicenseTemplate1_Name      = "Demo Evaluation Period";
            String  demoLicenseTemplate1_Type      = "FEATURE";
            Decimal demoLicenseTemplate1_Price     = 12.50M;
            String  demoLicenseTemplate1_Currency  = "EUR";
            Boolean demoLicenseTemplate1_Automatic = false;
            Boolean demoLicenseTemplate1_Hidden    = false;
            String  demoLicenseeNumber             = numberWithPrefix("L", randomNumber);
            String  demoLicenseNumber              = numberWithPrefix("LC", randomNumber);
            String  demoLicenseeName = "Demo Licensee";

            try
            {
                #region ****************** Lists

                List <String> licenseTypes = UtilityService.listLicenseTypes(context);
                ConsoleWriter.WriteList("License Types:", licenseTypes);

                List <String> licensingModels = UtilityService.listLicensingModels(context);
                ConsoleWriter.WriteList("Licensing Models:", licensingModels);

                #endregion

                #region ****************** Product

                Product newProduct = new Product();
                newProduct.number = demoProductNumber;
                newProduct.name   = "Demo product";
                Product product = ProductService.create(context, newProduct);
                ConsoleWriter.WriteEntity("Added product:", product);

                product = ProductService.get(context, demoProductNumber);
                ConsoleWriter.WriteEntity("Got product:", product);

                List <Product> products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following products:", products);

                Product updateProduct = new Product();
                updateProduct.productProperties.Add("Updated property name", "Updated value");
                product = ProductService.update(context, demoProductNumber, updateProduct);
                ConsoleWriter.WriteEntity("Updated product:", product);

                ProductService.delete(context, demoProductNumber, true);
                ConsoleWriter.WriteMsg("Deleted Product!");

                products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following Products:", products);

                product = ProductService.create(context, newProduct);
                ConsoleWriter.WriteEntity("Added product again:", product);

                products = ProductService.list(context, null);
                ConsoleWriter.WriteList("Got the following Products:", products);

                #endregion

                #region ****************** ProductModule

                ProductModule newProductModule = new ProductModule();
                newProductModule.number         = demoProductModuleNumber;
                newProductModule.name           = "Demo product module";
                newProductModule.licensingModel = demoLicensingModel;
                ProductModule productModule = ProductModuleService.create(context, demoProductNumber, newProductModule);
                ConsoleWriter.WriteEntity("Added product module:", productModule);

                productModule = ProductModuleService.get(context, demoProductModuleNumber);
                ConsoleWriter.WriteEntity("Got product module:", productModule);

                List <ProductModule> productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                ProductModule updateProductModule = new ProductModule();
                updateProductModule.productModuleProperties.Add("Updated property name", "Updated property value");
                productModule = ProductModuleService.update(context, demoProductModuleNumber, updateProductModule);
                ConsoleWriter.WriteEntity("Updated product module:", productModule);

                ProductModuleService.delete(context, demoProductModuleNumber, true);
                ConsoleWriter.WriteMsg("Deleted ProductModule!");

                productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                productModule = ProductModuleService.create(context, demoProductNumber, newProductModule);
                ConsoleWriter.WriteEntity("Added product module again:", productModule);

                productModules = ProductModuleService.list(context, null);
                ConsoleWriter.WriteList("Got the following ProductModules:", productModules);

                #endregion

                #region ****************** LicenseTemplate

                LicenseTemplate newLicenseTemplate = new LicenseTemplate();
                newLicenseTemplate.number      = demoLicenseTemplate1_Number;
                newLicenseTemplate.name        = demoLicenseTemplate1_Name;
                newLicenseTemplate.licenseType = demoLicenseTemplate1_Type;
                newLicenseTemplate.price       = demoLicenseTemplate1_Price;
                newLicenseTemplate.currency    = demoLicenseTemplate1_Currency;
                newLicenseTemplate.automatic   = demoLicenseTemplate1_Automatic;
                newLicenseTemplate.hidden      = demoLicenseTemplate1_Hidden;
                ConsoleWriter.WriteEntity("Adding license template:", newLicenseTemplate);
                LicenseTemplate licenseTemplate = LicenseTemplateService.create(context, demoProductModuleNumber, newLicenseTemplate);
                ConsoleWriter.WriteEntity("Added license template:", licenseTemplate);

                licenseTemplate = LicenseTemplateService.get(context, demoLicenseTemplate1_Number);
                ConsoleWriter.WriteEntity("Got licenseTemplate:", licenseTemplate);

                List <LicenseTemplate> licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                LicenseTemplate updateLicenseTemplate = new LicenseTemplate();
                updateLicenseTemplate.active    = true;
                updateLicenseTemplate.automatic = demoLicenseTemplate1_Automatic; // workaround: at the moment not specified booleans treated as "false"
                updateLicenseTemplate.hidden    = demoLicenseTemplate1_Hidden;    // workaround: at the moment not specified booleans treated as "false"
                licenseTemplate = LicenseTemplateService.update(context, demoLicenseTemplate1_Number, updateLicenseTemplate);
                ConsoleWriter.WriteEntity("Updated license template:", licenseTemplate);

                LicenseTemplateService.delete(context, demoLicenseTemplate1_Number, true);
                ConsoleWriter.WriteMsg("Deleted LicenseTemplate!");

                licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);

                licenseTemplate = LicenseTemplateService.create(context, demoProductModuleNumber, newLicenseTemplate);
                ConsoleWriter.WriteEntity("Added license template again:", licenseTemplate);

                licenseTemplates = LicenseTemplateService.list(context, null);
                ConsoleWriter.WriteList("Got the following license templates:", licenseTemplates);


                #endregion

                #region ****************** Licensee

                Licensee newLicensee = new Licensee();
                newLicensee.number = demoLicenseeNumber;
                Licensee licensee = LicenseeService.create(context, demoProductNumber, newLicensee);
                ConsoleWriter.WriteEntity("Added licensee:", licensee);

                List <Licensee> licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                LicenseeService.delete(context, demoLicenseeNumber, true);
                ConsoleWriter.WriteMsg("Deleted licensee!");

                licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees after delete:", licensees);

                licensee = LicenseeService.create(context, demoProductNumber, newLicensee);
                ConsoleWriter.WriteEntity("Added licensee again:", licensee);

                licensee = LicenseeService.get(context, demoLicenseeNumber);
                ConsoleWriter.WriteEntity("Got licensee:", licensee);

                Licensee updateLicensee = new Licensee();
                updateLicensee.licenseeProperties.Add("Updated property name", "Updated value");
                licensee = LicenseeService.update(context, demoLicenseeNumber, updateLicensee);
                ConsoleWriter.WriteEntity("Updated licensee:", licensee);

                licensees = LicenseeService.list(context, null);
                ConsoleWriter.WriteList("Got the following licensees:", licensees);

                #endregion

                #region ****************** License

                License newLicense = new License();
                newLicense.number = demoLicenseNumber;
                License license = LicenseService.create(context, demoLicenseeNumber, demoLicenseTemplate1_Number, null, newLicense);
                ConsoleWriter.WriteEntity("Added license:", license);

                List <License> licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following licenses:", licenses);

                LicenseService.delete(context, demoLicenseNumber);
                Console.WriteLine("Deleted license");

                licenses = LicenseService.list(context, null);
                ConsoleWriter.WriteList("Got the following licenses:", licenses);

                license = LicenseService.create(context, demoLicenseeNumber, demoLicenseTemplate1_Number, null, newLicense);
                ConsoleWriter.WriteEntity("Added license again:", license);

                license = LicenseService.get(context, demoLicenseNumber);
                ConsoleWriter.WriteEntity("Got license:", license);

                License updateLicense = new License();
                updateLicense.licenseProperties.Add("Updated property name", "Updated value");
                license = LicenseService.update(context, demoLicenseNumber, null, updateLicense);
                ConsoleWriter.WriteEntity("Updated license:", license);

                #endregion

                #region ****************** PaymentMethod

                List <PaymentMethod> paymentMethods = PaymentMethodService.list(context);
                ConsoleWriter.WriteList("Got the following payment methods:", paymentMethods);

                #endregion

                #region ****************** Token

                string privateKey      = @"-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7mCuhtyeM+HM6
/IbTkM45bpKVQgpruiaEksheXwPx+iG4dRpkugYDYWi3g4/+oVKDQMrh6BsJtT6k
Otqwy8q81MIzPDTKnNvIERphKbrC0R5TjmmlrCPQeM6Hc1GnYOzSFHzFIwoVFz/h
3zuGySPKMpc6qg5mGqNfBiTuhwh7oAM+kXhgKzl5jj/cIvUmci12UpBGyXxknRip
75+KB/1qAJa9DQ7R9pF2aCavt5SFT1pc29IlpUlduDpOOGHFW6PN6EXyyH/uzGAb
CpvK6cTXk5ajp0CtELI1R5E6770mni0RP7ZED8+6pBtZboRslYGGmSo13OL0Ji6G
5SO+TyZ3AgMBAAECggEBAItqwjKDbg9kri7Ocl1Vpw4j0SjAVgJN7EZm2CbaspHp
dZoi3aSyY7mrcSnBywhQWIRXaPCPkVibrJxdaR4vttKzxEhTnGBgRy7fFx3S54vV
4pXypy2LS2qp/cPIvoyIijhvJXNVYS7fgoiZYSIA5mplQuNEc0MK1RPP+y6SiIlm
0SEXUXl5OYn3AGQ6hJJXxbN36kOtcwb33C/cY3b9jPl1acAVk84dFl0aAv92ArST
PahsxQDbRDaDxZ/lfk1mZqPexiWorAZWMck8nOyZhKu5/oXy6OcXfqVjdwmlqY05
hNS7mxSOUy+7umqbcV/bdhvqMJr+DeI1vqQS5J+t3vECgYEA8GZ6oxUiuwYJ98jS
Nx+i7Jj+ZTEFJ7WiepX5mOU13GlS0vAvhPdK9juEYbS7Znpp35WgwxuPsCn9hXIO
gjR0eSYN7QB5RVn7zjo+SQRw2C+HAt7G/wazq3ekSdNgKe8+Wa7YxLL8ypaOy1me
7L4JQGgM6ORgnYH/+BC7P/KO80MCgYEAx8R7W2Fzo1I+RPfKQeVQ/i4a+/DMK0js
XhpkMh/8NXbdHYNDdsQTQ2E8V+5gNi+zCqMuwIxA8cx9lAL32x1fMWnbHV9YwSFZ
ZOEG/YFyqcBOtQztt8jHGtXN70FQdwSwqcFdntNTCjJquN2gX1n2qFR2bezcULaj
Iiyc/j3AWr0CgYBQmbtidFKpq/OpnS5GBxhkBUO9/7p/vtlUCnad+bOeS73WNWtp
RFRgzEGtVKBEUqSurwcwg0wgv2Nd24jbxOSMPeMLZE5En0/arBJ3/sIq6Xx1zOWh
Wcjho4J0sicayDj6brIE+RHihqonqcusCmclrf0uFGwEQzLkJA/z98pP6wKBgAti
iEE5+ZQqQMA/evhscEQ8Lm+DVq901Xu7d1BgAEivwIRJEdQ38n0Zko3UWQldiI+n
oyd4Fs9w/wsrbCLBtsYjKUiwQWeoVebo6DQUZ4uDGTk6RmX9/FLsMnNbPpG547OZ
AJPnqUjgfLKSduxYPTV0stcq85dqATwWXNAkhszlAoGBAOKLU6IKuiRLcOrVon/a
KlXkjBMP2EkTVhuIzgZp6v7P8LK+UfU/6vkJvBW5U9ZosS7f13t7/bJ0AzfJLW6m
J1IedEJExbLmuW7+HfEMyZ5g8dFJZvYBmN/zHQEhFUKDISDI2O2gmd9cPPsMnOxW
WW8VMSYMi1Wtb9v7eRPvRZlE
-----END PRIVATE KEY-----";
                string publicKey       = @"-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu5grobcnjPhzOvyG05DO
OW6SlUIKa7omhJLIXl8D8fohuHUaZLoGA2Fot4OP/qFSg0DK4egbCbU+pDrasMvK
vNTCMzw0ypzbyBEaYSm6wtEeU45ppawj0HjOh3NRp2Ds0hR8xSMKFRc/4d87hskj
yjKXOqoOZhqjXwYk7ocIe6ADPpF4YCs5eY4/3CL1JnItdlKQRsl8ZJ0Yqe+figf9
agCWvQ0O0faRdmgmr7eUhU9aXNvSJaVJXbg6TjhhxVujzehF8sh/7sxgGwqbyunE
15OWo6dArRCyNUeROu+9Jp4tET+2RA/PuqQbWW6EbJWBhpkqNdzi9CYuhuUjvk8m
dwIDAQAB
-----END PUBLIC KEY-----";
                string publicKey_wrong = @"-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtq96itv1m00/czFD7IzE
mLiXPpvok1vjqB9VU6kTkq6QFGAfJF1G+m1fbK5NvpiDCsfuofdCFuhVnvLnzrpd
xUlse8erWEr9p9RAyh25NMK9/v0MAEAYV7zRa+ZOh31G54DwR7zk0TxyVzxKpjPi
wQSnv7UCY/IR7remLIYO92K7jAg9ZB4IHTuVulCtSrSQajZ8Ep2rFGPr8OeTsj9c
rBPpmL/ShdJOnL4NR0UnVWSpsCFW6wEqNafcUWnWpb98V49/p7fWDFJ1Tg6+OlVg
lgsNrqrqwJpxDLKnGAkkxHaVxSnZzAYh+HP8CbJmbzzE1GRXNgy3w+smWMv6M996
9wIDAQAB
-----END PUBLIC KEY-----";
                Console.WriteLine("loaded privateKey: {0}", privateKey);
                Console.WriteLine("loaded publicKey: {0}", publicKey);
                Console.WriteLine("loaded publicKey_wrong: {0}", publicKey_wrong);

                //NetLicensing supports API Key Identification to allow limited API access on vendor's behalf.
                //See: https://netlicensing.io/wiki/security for details.
                Token newToken = new Token();
                newToken.tokenType = Constants.Token.TYPE_APIKEY;
                newToken.tokenProperties.Add(Constants.Token.TOKEN_PROP_PRIVATE_KEY, privateKey);
                Token apiKey = TokenService.create(context, newToken);
                ConsoleWriter.WriteEntity("Created APIKey:", apiKey);
                context.apiKey = apiKey.number;

                newToken.tokenType = Constants.Token.TYPE_SHOP;
                newToken.tokenProperties.Add(Constants.Licensee.LICENSEE_NUMBER, demoLicenseeNumber);
                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                Token shopToken = TokenService.create(context, newToken);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                ConsoleWriter.WriteEntity("Got the following shop token:", shopToken);

                String       filter = Constants.Token.TOKEN_TYPE + "=" + Constants.Token.TYPE_SHOP;
                List <Token> tokens = TokenService.list(context, filter);
                ConsoleWriter.WriteList("Got the following shop tokens:", tokens);

                TokenService.delete(context, shopToken.number);
                ConsoleWriter.WriteMsg("Deactivated shop token!");

                tokens = TokenService.list(context, filter);
                ConsoleWriter.WriteList("Got the following shop tokens after deactivate:", tokens);

                #endregion

                #region ****************** Validate

                ValidationParameters validationParameters = new ValidationParameters();
                validationParameters.setLicenseeName(demoLicenseeName);
                validationParameters.setProductNumber(demoProductNumber);
                validationParameters.put(demoProductModuleNumber, "paramKey", "paramValue");

                ValidationResult validationResult = null;

                // Validate using Basic Auth
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                validationResult     = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                ConsoleWriter.WriteEntity("Validation result (Basic Auth):", validationResult);

                OSPlatform operatingSystem = GetOperatingSystem();
                Console.WriteLine("operatingSystem: {0}", operatingSystem);

                // Verify signature on Linux or OSX only
                // TODO: https://github.com/Labs64/NetLicensingClient-csharp/issues/25
                if (operatingSystem.Equals(OSPlatform.Linux) || operatingSystem.Equals(OSPlatform.OSX))
                {
                    // Validate using APIKey
                    context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                    validationResult     = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                    ConsoleWriter.WriteEntity("Validation result (APIKey):", validationResult);

                    // Validate using APIKey signed
                    context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                    context.publicKey    = publicKey;
                    validationResult     = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                    ConsoleWriter.WriteEntity("Validation result (APIKey / signed):", validationResult);

                    // Validate using APIKey wrongly signed
                    context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                    context.publicKey    = publicKey_wrong;
                    try
                    {
                        validationResult = LicenseeService.validate(context, demoLicenseeNumber, validationParameters);
                    }
                    catch (NetLicensingException e)
                    {
                        Console.WriteLine("Validation result exception (APIKey / wrongly signed): {0}", e);
                    }
                }

                // Reset context for futher use
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;
                context.publicKey    = null;

                #endregion

                #region ****************** Transfer

                Licensee transferLicensee = new Licensee();
                transferLicensee.number = "TR" + demoLicenseeNumber;
                transferLicensee.licenseeProperties.Add(Constants.Licensee.PROP_MARKED_FOR_TRANSFER, Boolean.TrueString.ToLower());
                transferLicensee = LicenseeService.create(context, demoProductNumber, transferLicensee);
                ConsoleWriter.WriteEntity("Added transfer licensee:", transferLicensee);

                License transferLicense = new License();
                transferLicense.number = "LTR" + demoLicenseNumber;
                License newTransferLicense = LicenseService.create(context, transferLicensee.number, demoLicenseTemplate1_Number, null, transferLicense);
                ConsoleWriter.WriteEntity("Added license for transfer:", newTransferLicense);

                LicenseeService.transfer(context, licensee.number, transferLicensee.number);

                licenses = LicenseService.list(context, Constants.Licensee.LICENSEE_NUMBER + "=" + licensee.number);
                ConsoleWriter.WriteList("Got the following licenses after transfer:", licenses);

                Licensee transferLicenseeWithApiKey = new Licensee();
                transferLicenseeWithApiKey.number = "Key" + demoLicenseeNumber;
                transferLicenseeWithApiKey.licenseeProperties.Add(Constants.Licensee.PROP_MARKED_FOR_TRANSFER, Boolean.TrueString.ToLower());
                transferLicenseeWithApiKey = LicenseeService.create(context, demoProductNumber, transferLicenseeWithApiKey);

                License transferLicenseWithApiKey = new License();
                transferLicenseWithApiKey.number = "Key" + demoLicenseNumber;
                LicenseService.create(context, transferLicenseeWithApiKey.number, demoLicenseTemplate1_Number, null,
                                      transferLicenseWithApiKey);

                context.securityMode = SecurityMode.APIKEY_IDENTIFICATION;
                LicenseeService.transfer(context, licensee.number, transferLicenseeWithApiKey.number);
                context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

                licenses = LicenseService.list(context, Constants.Licensee.LICENSEE_NUMBER + "=" + licensee.number);
                ConsoleWriter.WriteList("Got the following licenses after transfer:", licenses);

                #endregion

                #region ****************** Transactions

                List <Transaction> transactions = TransactionService.list(context, Constants.Transaction.SOURCE_SHOP_ONLY + "=" + Boolean.TrueString.ToLower());
                ConsoleWriter.WriteList("Got the following transactions shop only:", transactions);

                transactions = TransactionService.list(context, null);
                ConsoleWriter.WriteList("Got the following transactions after transfer:", transactions);

                #endregion

                Console.WriteLine("All done.");

                return(0);
            }
            catch (NetLicensingException e)
            {
                Console.WriteLine("Got NetLicensing exception:");
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Got exception:");
                Console.WriteLine(e);
            }
            finally
            {
                try
                {
                    // Cleanup
                    context.securityMode = SecurityMode.BASIC_AUTHENTICATION;

                    // Deactivate APIKey in case this was used (exists)
                    if (!String.IsNullOrEmpty(context.apiKey))
                    {
                        TokenService.delete(context, context.apiKey);
                    }
                    // Delete test product with all its related items
                    ProductService.delete(context, demoProductNumber, true);
                }
                catch (NetLicensingException e)
                {
                    Console.WriteLine("Got NetLicensing exception during cleanup:");
                    Console.WriteLine(e);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got exception during cleanup:");
                    Console.WriteLine(e);
                }
            }

            return(1);
        }
Пример #22
0
        static SdkSetup()
        {
            MenuLicenseHandlers = new Dictionary <string, Action <EventArgs> >();
            Strings             = new Translations {
                JObject.Parse(Resources.Strings)
            };
            Auth = new Netlicensing(Licensee.GetUserId(), ValidateKey);
            Menu = new Menu("sdk")
            {
                new Menu("modes"),
                new Menu("humanizer")
                {
                    new MenuBool("disable", false),
                    new MenuInt("apm", 200, 600, 400)
                },
                new Menu("menu")
                {
                    new MenuKey("key", Key.ShiftKey),
                    new MenuBool("toggle", false),
                    new MenuAction("apply", SetMenuTriggers),
                    new MenuBool("arrows", true),
                    new MenuText("position"),
                    new MenuInt("x", 0, 500, 40),
                    new MenuInt("y", 0, 500, 40)
                },
                new Menu("notifications")
                {
                    new MenuFloat("decayTime", 0f, 10f, 4.5f),
                    new MenuBool("borders", true),
                    new MenuAction("spawnTest", SpawnTestNotification)
                },
                new Menu("clock")
                {
                    new MenuList("mode"),
                    new MenuList("elements", Theme.WatermarkOffset == 0 ? 0 : 2),
                    new MenuBool("background", false),
                    new MenuColorBool("customColor", Color.LawnGreen, true)
                },
                new MenuList("theme"),
                new MenuList("language")
                {
                    Options = EnumCache <Language> .Names
                },
                new Menu("loader")
                {
                    new MenuAction("refresh", Platform.ScriptLoader.Load),
                    new MenuText("loaded")
                },
                new Menu("license")
                {
                    new MenuText("core"),
                    new MenuText("sdk"),
                    new MenuAction("shop", OpenIndividualShop),
                    new MenuAction("sdkLicenseRefresh", SetSdkAuth)
                },
                new Menu("about")
                {
                    new MenuText("version"),
                    new MenuText("contact"),
                    new MenuText("credits")
                }
            };

            if (Platform.HasRenderAPI)
            {
                var texture = Texture.FromMemory(Render.Device, Resources.Banner, 295, 100, 0, Usage.None, Format.Unknown, Pool.Managed, Filter.Default, Filter.Default, 0);

                Menu.Add(new MenuTexture("banner", texture));
            }

            Mode.Initialize(Menu.GetMenu("modes"));
            Menu.Build(Menu, GetMenuTranslations());

            LoadedItem     = Menu.GetMenu("loader").Get <MenuText>("loaded");
            loadedBaseText = LoadedItem.Text;

            SetupMenu(out FirstRun);

            if (Platform.HasCoreAPI)
            {
                typeof(DelayAction).Trigger();
            }

            typeof(DamageLibraryService).Trigger();
            typeof(TargetSelectorService).Trigger();
            typeof(HealthPredictionService).Trigger();
            typeof(MovementPredictionService).Trigger();
            typeof(Orbwalker.Orbwalker).Trigger();
            typeof(EvadeService).Trigger();
            typeof(UtilityService).Trigger();
            typeof(ChampionService).Trigger();

            if (!Platform.HasUserInputAPI)
            {
                Menu.SetOpen(true);

                Menu.IsExpanded = true;
                Menu.GetMenu("menu").IsExpanded = true;

                Notification.Send("This platform can't interact with the game!", "UserInputAPI not present", float.MaxValue);
            }

            Platform.ScriptLoader.Load();
        }
Пример #23
0
 public bool CanRenewLicenseeContract(Licensee licensee)
 {
     return(licensee.ContractEnd.HasValue &&
            licensee.ContractEnd.Value < DateTimeOffset.UtcNow &&
            licensee.Status == LicenseeStatus.Active);
 }