/// <summary> /// Saves the license data. /// </summary> public void Save() { Monitor.Enter(this); try { m_LicenseData.Save(m_LicenseFileName); } finally { Monitor.Exit(this); } }
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); } } }