public void SetProperties() { String licenseId = "License ID7657654876587658765"; String companyName = "Company Name"; String departmentName = "Department Name"; long maxEvents = 0x12345678; int maxSeats = 25; DateTime expiryUtc = DateTime.Now.AddDays(1); bool isTrial = true; StackHashLicenseData licenseData = new StackHashLicenseData(true, "jih", ";oiu", "oiuy", 21, 22010, DateTime.Now.ToUniversalTime(), false); licenseData.LicenseId = licenseId; licenseData.CompanyName = companyName; licenseData.DepartmentName = departmentName; licenseData.MaxEvents = maxEvents; licenseData.MaxSeats = maxSeats; licenseData.ExpiryUtc = expiryUtc; licenseData.IsTrialLicense = isTrial; Assert.AreEqual(licenseId, licenseData.LicenseId); Assert.AreEqual(companyName, licenseData.CompanyName); Assert.AreEqual(departmentName, licenseData.DepartmentName); Assert.AreEqual(maxEvents, licenseData.MaxEvents); Assert.AreEqual(maxSeats, licenseData.MaxSeats); Assert.AreEqual(expiryUtc, licenseData.ExpiryUtc); Assert.AreEqual(isTrial, licenseData.IsTrialLicense); }
public void EncryptingSameLicenseDataTwiceShouldBeSame() { String licenseId = "License ID7657654876587658765"; String companyName = "Company Name"; String departmentName = "Department Name"; long maxEvents = 0x12345678; int maxSeats = 25; DateTime expiryUtc = DateTime.Now.AddDays(1); bool isTrial = true; StackHashLicenseData licenseData = new StackHashLicenseData(true, licenseId, companyName, departmentName, maxEvents, maxSeats, expiryUtc, isTrial); byte[] bytes1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; byte[] bytes2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; byte[] encryptedBytes1 = ProtectedData.Protect(bytes1, null, DataProtectionScope.LocalMachine); byte[] encryptedBytes2 = ProtectedData.Protect(bytes1, null, DataProtectionScope.LocalMachine); bool match = true; for (int i = 0; i < encryptedBytes1.Length; i++) { if (encryptedBytes1[i] != encryptedBytes2[i]) { match = false; } } // Should not match Assert.AreEqual(false, match); }
/// <summary> /// Deletes the current license. /// </summary> private void deleteLicense() { m_LicenseData = new StackHashLicenseData(false, null, null, null, 0, 0, new DateTime(0), false); if (File.Exists(m_LicenseFileName)) { File.Delete(m_LicenseFileName); } DiagnosticsHelper.LogMessage(DiagSeverity.Information, "License deleted"); }
public LicenseManager(String licenseFileName, String serviceGuid) { if (licenseFileName == null) { throw new ArgumentNullException(licenseFileName); } m_LicenseFileName = licenseFileName; m_ServiceGuid = serviceGuid; // Just set a default license. // To introduce license management - add code here to read the license file. // Expires in year 2100. // Events = 0x7fffffff. // Seats = 0x7fffffff. m_LicenseData = new StackHashLicenseData(true, "FULLLICENSE", "Company", "Department", 0x7fffffff, 0x7fffffff, new DateTime(2100, 1, 1), false); }
public void Constructor() { String licenseId = "License ID7657654876587658765"; String companyName = "Company Name"; String departmentName = "Department Name"; long maxEvents = 0x12345678; int maxSeats = 25; DateTime expiryUtc = DateTime.Now.AddDays(1); bool isTrial = true; StackHashLicenseData licenseData = new StackHashLicenseData(true, licenseId, companyName, departmentName, maxEvents, maxSeats, expiryUtc, isTrial); Assert.AreEqual(licenseId, licenseData.LicenseId); Assert.AreEqual(companyName, licenseData.CompanyName); Assert.AreEqual(departmentName, licenseData.DepartmentName); Assert.AreEqual(maxEvents, licenseData.MaxEvents); Assert.AreEqual(maxSeats, licenseData.MaxSeats); Assert.AreEqual(expiryUtc, licenseData.ExpiryUtc); Assert.AreEqual(isTrial, licenseData.IsTrialLicense); }
public void SaveLoad() { String licenseId = "License ID7657654876587658765"; String companyName = "Company Name"; String departmentName = "Department Name"; long maxEvents = 0x12345678; int maxSeats = 25; DateTime expiryUtc = DateTime.Now.AddDays(1); bool isTrial = true; StackHashLicenseData licenseData = new StackHashLicenseData(true, licenseId, companyName, departmentName, maxEvents, maxSeats, expiryUtc, isTrial); String tempFileName = Path.GetTempFileName(); try { licenseData.Save(tempFileName); StackHashLicenseData loadedLicenseData = StackHashLicenseData.Load(tempFileName); Assert.AreEqual(licenseId, loadedLicenseData.LicenseId); Assert.AreEqual(companyName, loadedLicenseData.CompanyName); Assert.AreEqual(departmentName, loadedLicenseData.DepartmentName); Assert.AreEqual(maxEvents, loadedLicenseData.MaxEvents); Assert.AreEqual(maxSeats, loadedLicenseData.MaxSeats); Assert.AreEqual(expiryUtc, loadedLicenseData.ExpiryUtc); Assert.AreEqual(isTrial, loadedLicenseData.IsTrialLicense); } finally { if (File.Exists(tempFileName)) { File.Delete(tempFileName); } } }
public void SaveTwiceCompareFiles() { String licenseId = "License ID7657654876587658765"; String companyName = "Company Name"; String departmentName = "Department Name"; long maxEvents = 0x12345678; int maxSeats = 25; DateTime expiryUtc = DateTime.Now.AddDays(1); bool isTrial = true; StackHashLicenseData licenseData = new StackHashLicenseData(true, licenseId, companyName, departmentName, maxEvents, maxSeats, expiryUtc, isTrial); String tempFileName = Path.GetTempFileName(); String tempFileName2 = Path.GetTempFileName(); try { licenseData.Save(tempFileName); licenseData.Save(tempFileName2); StackHashLicenseData loadedLicenseData = StackHashLicenseData.Load(tempFileName); Assert.AreEqual(licenseId, loadedLicenseData.LicenseId); Assert.AreEqual(companyName, loadedLicenseData.CompanyName); Assert.AreEqual(departmentName, loadedLicenseData.DepartmentName); Assert.AreEqual(maxEvents, loadedLicenseData.MaxEvents); Assert.AreEqual(maxSeats, loadedLicenseData.MaxSeats); Assert.AreEqual(expiryUtc, loadedLicenseData.ExpiryUtc); Assert.AreEqual(isTrial, loadedLicenseData.IsTrialLicense); loadedLicenseData = StackHashLicenseData.Load(tempFileName2); Assert.AreEqual(licenseId, loadedLicenseData.LicenseId); Assert.AreEqual(companyName, loadedLicenseData.CompanyName); Assert.AreEqual(departmentName, loadedLicenseData.DepartmentName); Assert.AreEqual(maxEvents, loadedLicenseData.MaxEvents); Assert.AreEqual(maxSeats, loadedLicenseData.MaxSeats); Assert.AreEqual(expiryUtc, loadedLicenseData.ExpiryUtc); Assert.AreEqual(isTrial, loadedLicenseData.IsTrialLicense); // Compare the files. byte[] licenseBytes1 = File.ReadAllBytes(tempFileName); byte[] licenseBytes2 = File.ReadAllBytes(tempFileName2); bool match = true; Assert.AreEqual(licenseBytes1.Length, licenseBytes2.Length); for (int i = 0; i < licenseBytes2.Length; i++) { if (licenseBytes1[i] == licenseBytes2[i]) { match = false; } } // Should not match. Assert.AreEqual(false, match); } finally { if (File.Exists(tempFileName)) { File.Delete(tempFileName); } } }