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 void AddLicenseKeysForLicenseSet(int licenseSetId, List<string> licenseKeys)
		{
			foreach (string k in licenseKeys)
			{
				if (DoesKeyExistForLicenseSet(k, licenseSetId) == false)
				{
					ServiceLicenseKey key = new ServiceLicenseKey();
					key.ActivationCount = 0;
					key.CreatedOn = DateTime.Now;
					key.Deactivated = false;
					key.Key = k;
					key.LicenseSetId = licenseSetId;

					_serviceProductsRepository.SaveServiceLicenseKey(key);
				}
			}
		}
		private void InsertServiceLicenseKey(ServiceLicenseKey serviceLicenseKey)
		{
			using (ScutexServiceEntities db1 = new ScutexServiceEntities())
			{
				LicenseKey licKey = new LicenseKey();
				licKey.Key = serviceLicenseKey.Key;
				licKey.ActivationCount = serviceLicenseKey.ActivationCount;
				licKey.Deactivated = serviceLicenseKey.Deactivated;
				licKey.DeactivatedOn = serviceLicenseKey.DeactivatedOn;
				licKey.DeactivatedReason = serviceLicenseKey.DeactivatedReason;
				licKey.LicenseSetId = serviceLicenseKey.LicenseSetId;
				licKey.CreatedOn = serviceLicenseKey.CreatedOn;

				db1.AddToLicenseKeys(licKey);
				db1.SaveChanges();
			}
		}
		private void UpdateServiceLicenseKey(ServiceLicenseKey serviceLicenseKey)
		{
			using (ScutexServiceEntities db1 = new ScutexServiceEntities())
			{
				var licKey = (from lk in db1.LicenseKeys
											where lk.Key == serviceLicenseKey.Key
											select lk).First();

				licKey.Key = serviceLicenseKey.Key;
				licKey.CreatedOn = serviceLicenseKey.CreatedOn;
				licKey.ActivationCount = serviceLicenseKey.ActivationCount;
				licKey.Deactivated = serviceLicenseKey.Deactivated;
				licKey.DeactivatedOn = serviceLicenseKey.DeactivatedOn;
				licKey.DeactivatedReason = serviceLicenseKey.DeactivatedReason;
				licKey.LicenseSetId = serviceLicenseKey.LicenseSetId;

				db1.SaveChanges();
			}
		}
		public ServiceLicenseKey SaveServiceLicenseKey(ServiceLicenseKey serviceLicenseKey)
		{
			if (GetServiceLicenseKeyByKey(serviceLicenseKey.Key) != null)
				UpdateServiceLicenseKey(serviceLicenseKey);
			else
				InsertServiceLicenseKey(serviceLicenseKey);

			return GetServiceLicenseKeyByKey(serviceLicenseKey.Key);
		}