Ejemplo n.º 1
0
        public ServiceProduct CreateTestProduct(string licenseKey)
        {
            DeleteTestServiceProduct();

            ServiceProduct prod = new ServiceProduct();

            prod.LicenseId   = int.MaxValue;
            prod.LicenseName = "Test Product License";
            prod.LicenseSets = new List <ServiceLicenseSet>();

            ServiceLicenseSet ls = new ServiceLicenseSet();

            ls.LicenseSetId   = int.MaxValue;
            ls.LicenseId      = int.MaxValue;
            ls.Keys           = new List <ServiceLicenseKey>();
            ls.LicenseSetName = "Test Product License Set";
            ls.LicenseType    = LicenseKeyTypeFlag.MultiUser;
            ls.MaxUsers       = 2;

            ServiceLicenseKey key = new ServiceLicenseKey();

            key.CreatedOn       = DateTime.Now;
            key.Key             = _hashingProvider.ComputeHash(licenseKey, "SHA256");
            key.LicenseSetId    = int.MaxValue;
            key.ActivationCount = 0;
            ls.Keys.Add(key);

            prod.LicenseSets.Add(ls);

            _serviceProductsRepository.SaveServiceProduct(prod);

            return(_serviceProductsRepository.GetProduct(int.MaxValue));
        }
Ejemplo n.º 2
0
        public bool AddProductToService(License license, List <LicenseSet> licenseSets, Service service)
        {
            ServiceProduct sp = new ServiceProduct();

            sp.LicenseId   = license.LicenseId;
            sp.LicenseName = license.Name;
            sp.LicenseSets = new List <ServiceLicenseSet>();

            foreach (var ls in licenseSets)
            {
                ServiceLicenseSet set = new ServiceLicenseSet();
                set.LicenseId      = license.LicenseId;
                set.LicenseSetId   = ls.LicenseSetId;
                set.LicenseSetName = ls.Name;
                set.LicenseType    = ls.SupportedLicenseTypes;
                set.MaxUsers       = ls.MaxUsers;

                sp.LicenseSets.Add(set);
            }

            string mgmtToken = _packingService.PackToken(service.GetManagementToken());

            AddProductResult result = _productsProvider.AddProduct(service.ManagementUrl, mgmtToken,
                                                                   GetManagementStandardEncryptionInfo(service),
                                                                   service.GetManagementServiceKeyPair(), sp);

            if (IsResultValid(result))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        private void InsertServiceLicenseSet(ServiceLicenseSet licenseSet)
        {
            using (ScutexServiceEntities db1 = new ScutexServiceEntities())
            {
                LicenseSet ls = new LicenseSet();
                ls.LicenseSetId = licenseSet.LicenseSetId;
                ls.LicenseId    = licenseSet.LicenseId;
                ls.Name         = licenseSet.LicenseSetName;
                ls.LicenseType  = (int)licenseSet.LicenseType;
                ls.MaxUsers     = licenseSet.MaxUsers;

                db1.AddToLicenseSets(ls);
                db1.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        private void UpdateServiceLicenseSet(ServiceLicenseSet licenseSet)
        {
            using (ScutexServiceEntities db1 = new ScutexServiceEntities())
            {
                var licSet = (from ls in db1.LicenseSets
                              where ls.LicenseSetId == licenseSet.LicenseSetId
                              select ls).First();

                licSet.LicenseSetId = licenseSet.LicenseSetId;
                licSet.LicenseId    = licenseSet.LicenseId;
                licSet.Name         = licenseSet.LicenseSetName;
                licSet.LicenseType  = (int)licenseSet.LicenseType;
                licSet.MaxUsers     = licenseSet.MaxUsers;

                db1.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        public ServiceLicenseSet SaveServiceLicenseSet(ServiceLicenseSet licenseSet)
        {
            if (GetServiceLicenseSetById(licenseSet.LicenseSetId) != null)
            {
                UpdateServiceLicenseSet(licenseSet);
            }
            else
            {
                InsertServiceLicenseSet(licenseSet);
            }

            foreach (var key in licenseSet.Keys)
            {
                SaveServiceLicenseKey(key);
            }

            return(GetServiceLicenseSetById(licenseSet.LicenseSetId));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks the database to see if the key has already been used, and if it's a multi-use capable key
        /// the number of valid activations will be check to ensure it doesn't exceed the maximum activation
        /// count. If the key is hardware based it will check the existing key's fingerprint against the one
        /// saved to see if it matches.
        /// </summary>
        /// <param name="licenseKey"></param>
        /// <param name="licenseSetId"></param>
        /// <param name="hardwareFingerprint"></param>
        /// <returns></returns>
        public bool IsKeyAvialable(string licenseKey, int licenseSetId, string hardwareFingerprint)
        {
            ServiceLicenseSet ls = _serviceProductsRepository.GetServiceLicenseSetById(licenseSetId);
            ServiceLicenseKey lk = _serviceProductsRepository.GetServiceLicenseKeyByKeyLicenseSet(licenseKey, licenseSetId);
            LicenseActivation la = _clientRepository.GetLicenseActivationByKeyAndSetId(licenseKey, licenseSetId);

            if (la == null)
            {
                return(true);
            }

            Debug.WriteLine(ls.LicenseType.ToString());

            // Enterprise and Unlimited keys have no activation restrictions
            if (ls.LicenseType.IsSet(LicenseKeyTypeFlag.Unlimited) || ls.LicenseType.IsSet(LicenseKeyTypeFlag.Enterprise))
            {
                return(true);
            }

            // If the key is multi-user, ensure that they are under the MaxUsers count
            if (ls.LicenseType.IsSet(LicenseKeyTypeFlag.MultiUser))
            {
                if (ls.MaxUsers.HasValue && ((lk.ActivationCount + 1) <= ls.MaxUsers.Value))
                {
                    return(true);
                }
            }

            // Hardware keys can activate as many times as they want, provided the hardware fingerprints match.
            if (ls.LicenseType.IsSet(LicenseKeyTypeFlag.HardwareLock))
            {
                if (la != null)
                {
                    if (la.HardwareHash == hardwareFingerprint)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }