Example #1
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;
        }
		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);
		}
Example #3
0
		public AddProductResult AddProduct(string url, string token,
			EncryptionInfo encryptionInfo, KeyPair serviceKeys, ServiceProduct product)
		{
			ProductsServiceClient client = ProductClientCreator(url);

			string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);
			string serializedPayload = _objectSerializationProvider.Serialize(product);
			string encryptedData = _asymmetricEncryptionProvider.EncryptPrivate(serializedPayload, serviceKeys);


			string encryptedResult = client.AddProduct(encryptedToken, encryptedData);
			string decryptedResult = _asymmetricEncryptionProvider.DecryptPublic(encryptedResult, serviceKeys);

			AddProductResult result = _objectSerializationProvider.Deserialize<AddProductResult>(decryptedResult);

			return result;
		}
		private void InsertServiceProduct(ServiceProduct product)
		{
			using (ScutexServiceEntities db1 = new ScutexServiceEntities())
			{
				License l = new License();
				l.LicenseId = product.LicenseId;
				l.Name = product.LicenseName;

				db1.AddToLicenses(l);
				db1.SaveChanges();
			}
		}
		private void UpdateServiceProduct(ServiceProduct product)
		{
			using (ScutexServiceEntities db1 = new ScutexServiceEntities())
			{
				var lic = (from l in db1.Licenses
									 where l.LicenseId == product.LicenseId
									 select l).First();

				lic.Name = product.LicenseName;

				db1.SaveChanges();
			}
		}
		public ServiceProduct SaveServiceProduct(ServiceProduct product)
		{
			if (GetProduct(product.LicenseId) != null)
				UpdateServiceProduct(product);
			else
				InsertServiceProduct(product);

			foreach (var ls in product.LicenseSets)
			{
				SaveServiceLicenseSet(ls);
			}

			return GetProduct(product.LicenseId);
		}
		public ServiceProduct SaveServiceProduct(ServiceProduct product)
		{
			return _serviceProductsRepository.SaveServiceProduct(product);
		}