public IHttpActionResult Get(string domain) { if (string.IsNullOrEmpty(domain)) { return(BadRequest()); } LicenseData license = LicenseRepository.Instance.LicenseTable[domain] as LicenseData; if (license == null) { return(NotFound()); } var clientData = DataRepository.Instance.ClienDataList.SingleOrDefault(data => data.Domain == domain); if (clientData == null) { return(NotFound()); } var publicKey = clientData.RemoteKey; // var licenseData = Encoding.UTF8.GetString(ObjectSerializer.Serialize(license)); // byte[] encryptedLicense = AsymmetricEncryption.Encrypt(ObjectSerializer.Serialize(license), 1024, clientData.Key.PublicKey); var encryptedLicense = AsymmetricEncryption.Encrypt(ObjectSerializer.Serialize(license), 4096, publicKey); string encryptedLicenseStr = Convert.ToBase64String(encryptedLicense); Dictionary <string, string> dataDict = new Dictionary <string, string> { { "data", encryptedLicenseStr } }; return(Ok(dataDict)); }
public void CreateLicenseData() { try { List <DataModel.LicenseData> LicenseDataList = new List <LicenseData>(); LicenseData data1 = new LicenseData(); data1.LicenseKey = Guid.NewGuid().ToString(); data1.ProductId = 1; data1.UserSubscriptionId = sub.Id; data1.AdminUserId = user.UserId; LicenseDataList.Add(data1); LicenseData data2 = new LicenseData(); data2.LicenseKey = Guid.NewGuid().ToString(); data2.ProductId = 1; data2.UserSubscriptionId = sub.Id; data2.AdminUserId = user.UserId; LicenseDataList.Add(data2); LicenseData data3 = new LicenseData(); data3.LicenseKey = Guid.NewGuid().ToString(); data3.ProductId = 1; data3.UserSubscriptionId = sub.Id; data3.AdminUserId = user.UserId; LicenseDataList.Add(data3); licLogic.CreateLicenseData(LicenseDataList); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void updateLicense(LicenseData ld) { using (var db = new LicensesDataConnection()) { db.Update(ld); } }
public static void NetCheck(String ApplicationName) { return; try { LicenseData ld = new LicenseData(ApplicationName); String loadurl = String.Format(Checkkeyurlformat, ld.LicenseKey); String urlresults = GetURL(loadurl); urlresults = urlresults.Replace("\n", ""); bool checkresult; if (!bool.TryParse(urlresults, out checkresult)) { checkresult = false; } if (!checkresult) //blocked... { LicenseData.DeleteApplicationRegData(ApplicationName); //delete our data, this will "unregister" the given application. } } catch (Exception ee) { //either a WebException or another problem. Ignore it. The application being functional to possibly legit users //is more important than preventing illegitimate users from using the program. } }
public override async Task SilentValidadeLicense() { //base.SilentValidadeLicense(); var updateInstructionList = this._UpdateService.GetUpdateInstructionList(); foreach (var updateInstruction in updateInstructionList) { var licenseData = new LicenseData { ProductID = updateInstruction.Name, ProductName = updateInstruction.Name, ProductVersion = this._UpdateService.GetCurrentAssemblyVersion(updateInstruction).ToString() }; string ValidationResult = string.Empty; if (!this.HasPermissionToUse(licenseData)) { ValidationResult = $"Unauthorized to use '{updateInstruction.Name}' - '{_UpdateService.GetCurrentAssemblyVersion(updateInstruction)}'"; } else { ValidationResult = $"Authorized to use '{updateInstruction.Name}' - '{_UpdateService.GetCurrentAssemblyVersion(updateInstruction)}'"; } await this._AnalyticsService.SendInformation("MVLicenseService.SilentValidadeLicense", ValidationResult); } }
private void promptSave(LicenseData licenseData) { SaveFileDialog dialog = new SaveFileDialog(); dialog.FileName = "license"; dialog.DefaultExt = ".json"; dialog.Filter = "JSON file (.json)|*.json"; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); bool?result = dialog.ShowDialog(); if (true != result) { statusText.Text = $"License generated but not saved to file"; return; } // Save to file try { var options = new JsonSerializerOptions { WriteIndented = true, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, }; string jsonString = JsonSerializer.Serialize(licenseData, options); File.WriteAllText(dialog.FileName, jsonString); statusText.Text = $"License file saved to:{Environment.NewLine}{dialog.FileName}"; } catch (Exception exception) { statusText.Text = $"Error while saving license file:{Environment.NewLine}{exception.Message}"; } }
public void addLicense(LicenseData ld) { using (var db = new LicensesDataConnection()) { db.Insert(ld); } }
// Fill the LicenseData structure with information about this license key private void FillLicenseData(string licenseKey, out LicenseData licData) { licData = new LicenseData(); if (!string.IsNullOrEmpty(licenseKey)) { BBSLic bbsLic; licData.Initialize(); licData.licState = LoadAndValidateLicense(licenseKey, out bbsLic); if (bbsLic != null) { licData.isTrial = IsLicenseTrial(bbsLic); licData.key = licenseKey; licData.numLicensedServers = GetLicenseCount(bbsLic); licData.numLicensedServersStr = CountToString(licData.numLicensedServers); licData.licenseRepositoryID = 0; licData.forStr = GetLicenseScopeStr(bbsLic); licData.typeStr = GetLicenseTypeStr(bbsLic); licData.expirationDateStr = GetLicenseExpirationDateStr(bbsLic); licData.daysToExpireStr = GetLicenseDaysToExpirationStr(bbsLic); licData.daysToExpire = bbsLic.DaysToExpiration; if (licData.typeStr == BBSLicenseConstants.LicenseTypeProduction && licData.daysToExpire <= BBSLicenseConstants.ExpirationDayToWarnProduction || licData.typeStr == BBSLicenseConstants.LicenseTypeTrial && licData.daysToExpire <= BBSLicenseConstants.ExpirationDayToWarnTrial) { licData.isAboutToExpire = true; } else { licData.isAboutToExpire = false; } } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { string email = context.Request.Params["email"]; string name = context.Request.Params["name"]; string check = context.Request.Params["check"]; string product = context.Request.Params["product"]; if (check != "vertex5L34") { throw new Exception("Bad code"); } LicenseData licdata = new LicenseData(); string license = LicenseTool.CreateLicense(name, email, "name", product + "-eval", null, licdata); context.Response.Write(license); } catch (Exception err) { context.Response.Write(err.Message); } }
public string RevokeLicenseFromUser(string[] SelectedSubscription) { List <string> userIdList = new List <string>(); userIdList.Add(Convert.ToString(TempData["UserId"])); List <LicenseData> lstLicData = new List <LicenseData>(); foreach (var data in SelectedSubscription) { var splitValue = data.Split(new char[] { '-' }); var prodId = splitValue[0].Split(new char[] { ':' })[1]; var subscriptionId = splitValue[1].Split(new char[] { ':' })[1]; LicenseData licData = new LicenseData() { UserSubscriptionId = Convert.ToInt32(subscriptionId), ProductId = Convert.ToInt32(prodId) }; lstLicData.Add(licData); } UserLicenseDataMapping mapping = new UserLicenseDataMapping() { TeamId = LicenseSessionState.Instance.SelectedTeam.Id, LicenseDataList = lstLicData, UserList = userIdList }; HttpClient client = WebApiServiceLogic.CreateClient(ServiceType.OnPremiseWebApi); var response = client.PostAsJsonAsync("api/License/RevokeUserLicence", mapping).Result; if (!response.IsSuccessStatusCode) { var jsonData = response.Content.ReadAsStringAsync().Result; var obj = JsonConvert.DeserializeObject <ResponseFailure>(jsonData); return(response.ReasonPhrase + " - " + obj.Message); } return(String.Empty); }
private void Button_Click_1(object sender, RoutedEventArgs e) { LicenceGenerator licenceGenerator = new LicenceGenerator(); LicenseData licenseData = new LicenseData(); List <LicenseDevice> devices = new List <LicenseDevice>(); LicenseDevice deviceNumberOne = new LicenseDevice(); deviceNumberOne.HasIndividualDate = false; deviceNumberOne.StartDate = Convert.ToDateTime("01/01/0001"); deviceNumberOne.EndDate = Convert.ToDateTime("01/01/0001"); deviceNumberOne.RemainingRunTime = TimeSpan.Zero; deviceNumberOne.ConnectorName = "USB 1"; deviceNumberOne.DeviceName = UsbOneName.Text; deviceNumberOne.LockDeviceName = UsbOneLockedName.Text; deviceNumberOne.Locked = (LockedOne.IsChecked == true) ? true : false;; LicenseDevice deviceNumberTwo = new LicenseDevice(); deviceNumberTwo.HasIndividualDate = false; deviceNumberTwo.StartDate = Convert.ToDateTime("01/01/0001"); deviceNumberTwo.EndDate = Convert.ToDateTime("01/01/0001"); deviceNumberTwo.RemainingRunTime = TimeSpan.Zero; deviceNumberTwo.ConnectorName = "USB 2"; deviceNumberTwo.DeviceName = UsbTwoName.Text; deviceNumberTwo.LockDeviceName = UsbTwoLockedName.Text; deviceNumberTwo.Locked = (LockedTwo.IsChecked == true) ? true : false; licenseData.Data = null; licenseData.Version = 1; licenseData.StartDate = Convert.ToDateTime(DateCreate.SelectedDate); licenseData.EndDate = Convert.ToDateTime(DateEnd.SelectedDate); licenseData.LastRunDate = Convert.ToDateTime(LastUse.SelectedDate); licenseData.RemainingRunTime = TimeSpan.Zero; licenseData.LicenseDevices = devices; devices.Add(deviceNumberOne); devices.Add(deviceNumberTwo); Byte[] license; license = licenceGenerator.SaveToBytes(licenseData); string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string filename = "\\license.lic"; string licenseNewFile = desktopPath += filename; using (StreamWriter streamWriter = new StreamWriter(licenseNewFile)) streamWriter.Write(Convert.ToBase64String(license)); SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav"); simpleSound.Play(); ProgressBar.Value = 100; }
private void dgvLicenseOwners_SelectionChanged(object sender, EventArgs e) { if (dgvLicenseOwners.SelectedRows.Count > 0) { LicenseData ld = (LicenseData)dgvLicenseOwners.SelectedRows[0].DataBoundItem; loadDetails(ld.CustomerID); } }
public virtual void testVerifyLicense2() { LicenseGenerator lg = new LicenseGenerator(getResource("privkey.pem")); LicenseData licenseData = new LicenseData("Test", "Karl"); string license = lg.makeLicense(licenseData); bool verified = lg.verifyLicense(licenseData, license); Assert.IsTrue(verified); }
public virtual void testFailedVerifyLicense() { LicenseGenerator lg = new LicenseGenerator(getResource("privkey.pem")); LicenseData licenseData = new LicenseData("Test", "Karl"); Assert.IsTrue(lg.verifyLicense(licenseData, "GAWQE-F9AVF-8YSF3-NBDUH-C6M2J-JYAYC-X692H-H65KR-A9KAQ-R9SB7-A374H-T6AH3-87TAB-CVV6K-SKUGG-A")); //Assert.IsTrue(lg.verifyLicense(licenseData, "GAWQE-F9AVF-8YSF3-NBDUH-C6M2J-JYAYC-X692H-H65KR-A9KAQ-R9SB7-A374H-T6AH3-87TAB-CVV6K-SKAGG-A")); //Assert.IsTrue(lg.verifyLicense(licenseData, "GAWQE-F9AVF-8YSF3-NBDUH-C6M2J-JYAYC-X692H-H65KR-A9KAQ-R9SB7-A374H-T6AH3-87TAB-DVV6K-SKUGG-A")); }
public static bool AreSame(this LicenseData a, LicenseData b) { return(a.LicenseExpiration == b.LicenseExpiration && a.LicenseState == b.LicenseState && a.LicenseStateChecked == b.LicenseStateChecked && a.SiteOwnerUserId == b.SiteOwnerUserId && a.AnonymousPermissions == b.AnonymousPermissions && a.LicenseDoc == b.LicenseDoc); }
public LicenseData DetermineLicenseState(LicenseData licenseData, bool verifyProductKey, bool seatLicensingEnabled) { if (licenseData == null) { throw new ArgumentNullException("licenseData"); } _log.DebugFormat("verifying license state with initial state: {0}", licenseData.LicenseState); return(BuildLicenseData(licenseData.LicenseDoc, verifyProductKey, seatLicensingEnabled)); }
public virtual void Initialize(IServiceContainer container) { Services.ICanvasService canvasService = container.CanvasService; Services.IDataModelService dataModelService = container.DataModelService; Services.ILicenseService licenseService = container.LicenseService; _licenseData = licenseService.LicenseData; _dataModel = dataModelService.DataModel; }
public void Setup() { _userMock = new Mock<IUserBL>(); _licenseData = new LicenseData(); _licenseBLMock = new Mock<ILicenseBL>(); _licenseControllerMock = new Mock<ILicenseController>(); _instanceSettingsMock = new Mock<IInstanceSettings>(); _seatingBLMock = new Mock<ISeatingBL>(); _licenseStateTransitionMock = new LicenseStateTransitionMock(); _manager = new LicenseManager(_licenseControllerMock.Object, _userMock.Object, _licenseData, _licenseBLMock.Object, _instanceSettingsMock.Object, _seatingBLMock.Object, _licenseStateTransitionMock.Callback); }
// Check to see if SQLsecure is licensed // Returns the combined license results and list of all licenses; public bool IsProductLicensed() { bool bInitialized = false; bool bLicensed = false; m_CombinedLicensedData = new LicenseData(); m_CombinedLicensedData.Initialize(); foreach (LicenseData licData in m_Licenses) { if (!bInitialized) { bLicensed = true; m_CombinedLicensedData = licData; bInitialized = true; } else { m_CombinedLicensedData.key = BBSLicenseConstants.CombinedLicenses; if (!licData.isTrial && licData.licState == LicenseState.Valid) { if (licData.numLicensedServers == -1) { m_CombinedLicensedData.numLicensedServers = -1; m_CombinedLicensedData.numLicensedServersStr = CountToString(m_CombinedLicensedData.numLicensedServers); } else if (m_CombinedLicensedData.numLicensedServers != -1) { m_CombinedLicensedData.numLicensedServers += licData.numLicensedServers; m_CombinedLicensedData.numLicensedServersStr = CountToString(m_CombinedLicensedData.numLicensedServers); } } if (m_CombinedLicensedData.expirationDateStr != licData.expirationDateStr) { if (licData.isAboutToExpire) { m_CombinedLicensedData.isAboutToExpire = true; } m_CombinedLicensedData.expirationDateStr = BBSLicenseConstants.CombinedLicensesMultiExpirationDates; m_CombinedLicensedData.daysToExpireStr = BBSLicenseConstants.CombinedLicensesMultiExpirationDates; } if (m_CombinedLicensedData.forStr != licData.forStr) { m_CombinedLicensedData.forStr = string.Format(BBSLicenseConstants.CombinedLicensesMultiTypes, m_scopeString); } } } if (!bLicensed) { m_CombinedLicensedData.Initialize(); } return(bLicensed); }
public LicenseData GenerateLicense(string domain, uint days) { LicenseData license = new LicenseData { LicensePeriodInDays = days }; LicenseTable[domain] = license; return(license); }
public void Setup() { _userMock = new Mock <IUserBL>(); _licenseData = new LicenseData(); _licenseBLMock = new Mock <ILicenseBL>(); _licenseControllerMock = new Mock <ILicenseController>(); _instanceSettingsMock = new Mock <IInstanceSettings>(); _seatingBLMock = new Mock <ISeatingBL>(); _licenseStateTransitionMock = new LicenseStateTransitionMock(); _manager = new LicenseManager(_licenseControllerMock.Object, _userMock.Object, _licenseData, _licenseBLMock.Object, _instanceSettingsMock.Object, _seatingBLMock.Object, _licenseStateTransitionMock.Callback); }
public ActionResult License() { try { LicenseData license = LicenseFile.Read(DataRepository.Instance.Key.PrivateKey); return(View((object)license)); } catch (Exception) { return(View("Index")); } }
public override LicenseData VerifyLicenseData(LicenseData licenseData, ILicenseBL licenseBL, ISeatingBL seatingBL) { _log.Debug("verifying license: " + licenseData.LicenseState); // load authoritative license from remote var license = LicenseDoc; var verified = licenseBL.DetermineLicenseState(new LicenseData().WithLicenseDocument(license), true, seatingBL.IsSeatLicensingEnabled(licenseData)); if(!(new[] { LicenseStateType.COMMERCIAL, LicenseStateType.TRIAL, LicenseStateType.INACTIVE, LicenseStateType.EXPIRED }).Contains(verified.LicenseState)) { _log.DebugFormat("license state '{0}' is not allowed for remotely managed instances", verified.LicenseState); throw new MindTouchRemoteLicenseFailedException(); } _log.Debug("verified license: " + verified.LicenseState); return verified; }
private void UpdateLicenseInfo(string filename, AGXUnity.LicenseInfo licenseInfo) { for (int i = 0; i < m_licenseData.Count; ++i) { if (m_licenseData[i].Filename == filename) { m_licenseData[i] = new LicenseData() { Filename = filename, LicenseInfo = licenseInfo } } ; } }
public void Can_update_license_seat_licensing() { // Arrange var currentLicense = new XDoc("current"); var newLicense = new XDoc("new"); var newExpiration = DateTime.UtcNow.AddDays(1); var newPermissions = Permissions.BROWSE; ulong?newOwnerId = 1; var currentLicenseData = new LicenseData() .WithLicenseDocument(currentLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(DateTime.UtcNow) .WithPermissions(Permissions.NONE) .WithSiteOwnerUserId(1) .Checked(DateTime.UtcNow); var newLicenseData = new LicenseData().WithLicenseDocument(newLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(newExpiration) .WithPermissions(newPermissions) .WithSiteOwnerUserId(newOwnerId) .Checked(DateTime.UtcNow); var tempLicenseNewLicenseData = new LicenseData().WithLicenseDocument(newLicense); _licenseBLMock.Setup(x => x.BuildLicenseData(newLicense, true, true)).Returns(tempLicenseNewLicenseData).Verifiable(); _licenseBLMock.Setup(x => x.ValidateNewLicenseTransition(It.Is <LicenseData>(l => l.AreSame(tempLicenseNewLicenseData)), It.Is <LicenseData>(l => l.AreSame(currentLicenseData)))) .Returns(newLicenseData) .Verifiable(); _seatingBLMock.Setup(x => x.IsSeatLicensingEnabled(currentLicenseData)).Returns(true); _seatingBLMock.Setup(x => x.IsSeatLicensingEnabled(newLicense)).Returns(true); _seatingBLMock.Setup(x => x.HandleSeatTransition(newLicense)).Returns(new SeatAssignmentInfo(2, 5)); MockPlug.Setup(_storagePlug).At(_wikiId, "license.xml").Verb("Put").WithBody(newLicense).ExpectAtLeastOneCall(); // Act var updatedLicense = _licenseController.UpdateLicense(newLicense, currentLicenseData, _licenseBLMock.Object, _seatingBLMock.Object); // Assert MockPlug.VerifyAll(); _licenseBLMock.Verify(x => x.Validate(newLicense), Times.Once()); _licenseBLMock.Verify(x => x.ValidateNewLicenseTransition(It.Is <LicenseData>(l => l.AreSame(tempLicenseNewLicenseData)), It.Is <LicenseData>(l => l.AreSame(currentLicenseData))), Times.Once()); _seatingBLMock.Verify(x => x.IsSeatLicensingEnabled(currentLicenseData), Times.Once()); _seatingBLMock.Verify(x => x.IsSeatLicensingEnabled(newLicense), Times.Once()); _seatingBLMock.Verify(x => x.ValidateLicenseUpdateUser(newLicense), Times.Once()); _seatingBLMock.Verify(x => x.HandleSeatTransition(newLicense), Times.Once()); _seatingBLMock.Verify(x => x.SetOwnerUserSeat(newLicenseData), Times.Once()); Assert.AreSame(newLicenseData, updatedLicense); Assert.AreEqual(newLicense, newLicenseData.LicenseDoc); Assert.AreEqual(newExpiration, newLicenseData.LicenseExpiration); Assert.AreEqual(newOwnerId, newLicenseData.SiteOwnerUserId); Assert.AreEqual(newPermissions, newLicenseData.AnonymousPermissions); }
private void MainForm_Shown(object sender, EventArgs e) { if (ShowSplash) { Logger.Trace("Showing splash form"); SplashForm.DoShowDialog(this, FormStyle.ModernRed); } LicenseData licenseDataGoogle = GoogleVasLicense.Get(); LicenseData licenseDataApple = AppleVasLicense.Get(); ApplyLicense(licenseDataGoogle); ApplyLicense(licenseDataApple); }
//============================================================================= private void Window_Drop(object sender, DragEventArgs e) { if (m_VM == null) { return; } if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // Note that you can have more than one file. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); // if (files.Count() > 0) { string strFilePath = files[0]; if (!System.IO.File.Exists(strFilePath)) { m_VM.DoesStatusContainsError = true; m_VM.Status = "Dropped file doesnt exist."; return; } // try { LicenseData licData = Utilities.Deserialize <LicenseData>(strFilePath, true); if (licData == null) { m_VM.DoesStatusContainsError = true; m_VM.Status = "Error occurred while extracting data from the license file."; return; } m_VM.License = licData; m_VM.LicenseFileDirectory = System.IO.Path.GetDirectoryName(strFilePath); m_VM.LicenseFileName = System.IO.Path.GetFileName(strFilePath); } catch { m_VM.DoesStatusContainsError = true; m_VM.Status = "Error occurred while extracting data from the license file."; return; } } } }
public static bool IsLicensed(String ProductName) { if (!OnWindows()) { return(true); //free on other operating systems... } try { LicenseData ld = new LicenseData(ProductName); return(true); } catch (Exception exx) { return(false); } }
private void ApplyLicense(LicenseData licenseData) { if (licenseData == null) { MessageBox.Show(this, "Please click the \"License\" link to request a new license, or enter your licence data.", "No license found.", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { lbEvaluation.Visible = licenseData.IsEvaluation; if (licenseData.HasTimeLimit) { string title = licenseData.IsEvaluation ? "Evaluation license" : "Restricted license"; MessageBox.Show(this, string.Format("This software will stop running after {0} minutes.", licenseData.TimeLimit), title, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
//checking installed version async Task CkeckLicense() { if (SyncFKey == null) { LicenseData LData = await VersionService.Instance.CheckLicense(); if (LData != null) { SyncFKey = LData.SyncFusionkey; Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(LData.SyncFusionkey); } } else { Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(SyncFKey); } }
public void Can_update_license_without_seat_licensing() { // Arrange var currentLicense = new XDoc("current"); var newLicense = new XDoc("new"); var newExpiration = DateTime.UtcNow.AddDays(1); var newPermissions = Permissions.BROWSE; ulong?newOwnerId = 1; var currentLicenseData = new LicenseData() .WithLicenseDocument(currentLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(DateTime.UtcNow) .WithPermissions(Permissions.NONE) .WithSiteOwnerUserId(1) .Checked(DateTime.UtcNow); var newLicenseData = new LicenseData().WithLicenseDocument(newLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(newExpiration) .WithPermissions(newPermissions) .WithSiteOwnerUserId(newOwnerId) .Checked(DateTime.UtcNow); var tempLicenseNewLicenseData = new LicenseData().WithLicenseDocument(newLicense); _licenseBLMock.Setup(x => x.BuildLicenseData(newLicense, true, false)).Returns(tempLicenseNewLicenseData); _licenseBLMock.Setup(x => x.ValidateNewLicenseTransition(It.Is <LicenseData>(l => l.AreSame(tempLicenseNewLicenseData)), It.Is <LicenseData>(l => l.AreSame(currentLicenseData)))) .Returns(newLicenseData); _seatingBLMock.Setup(x => x.IsSeatLicensingEnabled(currentLicenseData)).Returns(false); _seatingBLMock.Setup(x => x.IsSeatLicensingEnabled(newLicense)).Returns(false); // Act var updatedLicense = _licenseController.UpdateLicense(newLicense, currentLicenseData, _licenseBLMock.Object, _seatingBLMock.Object); // Assert _licenseBLMock.Verify(x => x.Validate(newLicense), Times.Once()); _licenseBLMock.Verify(x => x.ValidateNewLicenseTransition(It.Is <LicenseData>(l => l.AreSame(tempLicenseNewLicenseData)), It.Is <LicenseData>(l => l.AreSame(currentLicenseData))), Times.Once()); _seatingBLMock.Verify(x => x.IsSeatLicensingEnabled(currentLicenseData), Times.AtLeastOnce()); _seatingBLMock.Verify(x => x.IsSeatLicensingEnabled(newLicense), Times.AtLeastOnce()); _seatingBLMock.Verify(x => x.RevokeSeats(currentLicenseData), Times.Once()); _seatingBLMock.Verify(x => x.RevokeSeats(newLicenseData), Times.Once()); Assert.AreSame(newLicenseData, updatedLicense); Assert.AreEqual(newLicense, updatedLicense.LicenseDoc); Assert.AreEqual(newExpiration, updatedLicense.LicenseExpiration); Assert.AreEqual(newOwnerId, updatedLicense.SiteOwnerUserId); Assert.AreEqual(newPermissions, updatedLicense.AnonymousPermissions); }
public void SeatingBL_candidate_check_makes_UpdateLicense_throw() { // Arrange var newLicense = new XDoc("new"); var licenseData = new LicenseData(); var testException = new Utils.TestException(); _seatingBLMock.Setup(x => x.ValidateLicenseUpdateUser(newLicense)).Throws(testException); // Act try { _licenseController.UpdateLicense(newLicense, licenseData, _licenseBLMock.Object, _seatingBLMock.Object); // Assert Assert.Fail("wow, no throw"); } catch(Utils.TestException e) { Assert.AreSame(testException, e); } }
/// <summary> /// called when a new license has been received /// </summary> /// <param name="sender"></param> /// <param name="args"></param> void on_new_licensemail(object sender, StatusEventArgs args) { if (args.eStatus == StatusType.license_mail) { utils.helpers.addLog("received new License Data\r\n"); LicenseData data = args.licenseData; //add data and refresh datagrid int InsertedID = _licenseDataBase.add(data._deviceid, data._customer, data._key, data._ordernumber, data._orderdate, data._ponumber, data._endcustomer, data._product, data._quantity, data._receivedby, data._sendat); //add data to datagrid //if (InsertedID!=-1) // addDataToGrid(InsertedID, data._deviceid, data._customer, data._key, data._ordernumber, data._orderdate, data._ponumber, data._endcustomer, data._product, data._quantity, data._receivedby, data._sendat); setLblStatus("new data"); } else { _ews_stateChanged1(sender, args); } }
public void Can_update_license() { // Arrange var currentLicense = new XDoc("current"); var newLicense = new XDoc("new"); var newExpiration = DateTime.UtcNow.AddDays(2); var newPermissions = Permissions.BROWSE; ulong? newOwnerId = 1; var checkedDate = DateTime.UtcNow; var inputData = new LicenseData() .WithLicenseDocument(currentLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(DateTime.UtcNow.AddDays(1)) .WithPermissions(Permissions.NONE) .WithSiteOwnerUserId(1) .Checked(DateTime.UtcNow); _licenseData.Update(inputData); var expected = _licenseData.Clone(); _licenseControllerMock.Setup(x => x.UpdateLicense(newLicense, It.Is<LicenseData>(l => l.AreSame(expected)), _licenseBLMock.Object, _seatingBLMock.Object)) .Returns(new LicenseData() .WithLicenseDocument(newLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(newExpiration) .WithPermissions(newPermissions) .WithSiteOwnerUserId(newOwnerId) .Checked(checkedDate) ); // Act _manager.UpdateLicense(null, newLicense); // Assert _licenseControllerMock.Verify(x => x.VerifyLicenseData(It.IsAny<LicenseData>(), _licenseBLMock.Object, _seatingBLMock.Object), Times.Never()); _licenseControllerMock.Verify(x => x.UpdateLicense(newLicense, It.Is<LicenseData>(l => l.AreSame(expected)), _licenseBLMock.Object, _seatingBLMock.Object), Times.Once()); _licenseStateTransitionMock.Verify(LicenseStateType.COMMERCIAL, LicenseStateType.COMMERCIAL, 1); Assert.AreEqual(LicenseStateType.COMMERCIAL, _licenseData.LicenseState); Assert.AreEqual(newLicense, _licenseData.LicenseDoc); Assert.AreEqual(newExpiration, _licenseData.LicenseExpiration); Assert.AreEqual(newOwnerId, _licenseData.SiteOwnerUserId); Assert.AreEqual(newPermissions, _licenseData.AnonymousPermissions); Assert.GreaterOrEqual(_licenseData.LicenseStateChecked, checkedDate); }
protected virtual void HandleExcessSeats(LicenseData license, ISeatingBL seatingBL, SeatAssignmentInfo seats) { _log.WarnFormat("site has {0} assigned seats, but is only licensed for {1} (revoking seats)", seats.Assigned, seats.Allowed); seatingBL.RevokeSeats(license); }
//--- Methods --- public virtual LicenseData UpdateLicense(XDoc license, LicenseData currentLicense, ILicenseBL licenseBL, ISeatingBL seatingBL) { licenseBL.Validate(license); // Only site owner of a license can upload a license that has seat licensing enabled. seatingBL.ValidateLicenseUpdateUser(license); var newLicense = HandleLicenseTransition(license, currentLicense, seatingBL, licenseBL); _licenseStoragePlug.At(_wikiId, LICENSE_FILE).Put(license); return newLicense; }
public bool IsSeatLicensingEnabled(LicenseData license) { return IsSeatLicensingEnabled(license.LicenseDoc); }
private int GetSeatsLicensed(LicenseData license) { return _licenseBL.GetSeatsLicensed(license.LicenseDoc); }
private void RemoveSeatFromUserInternal(UserBE user, LicenseData license) { if(!user.LicenseSeat) { return; } // Site owner may not have their license removed var siteOwnerUserId = GetSiteOwnerUserId(license) ?? 0; if(user.ID == siteOwnerUserId) { throw new MindTouchLicenseRemovalFromSiteOwnerException(); } user.LicenseSeat = false; _userBL.UpdateUser(user); _log.InfoFormat("Seat licensing: Removed a seat from '{0}'", user.Name); }
private bool AreSeatsExceedingLicense(LicenseData license) { // enforce seat licensing limits var seatsAssigned = GetSeatedUsers().Count(); var seatsAllowed = GetSeatsLicensed(license); // ensure a seat is available if(seatsAllowed < seatsAssigned) { _log.Warn(String.Format("Seat licensing: Number of seats used is exceeding allowed. Seats allowed: {0}; Seats assigned:{1}", seatsAllowed, seatsAssigned)); return true; } return false; }
//--- Constructors --- public LicenseManager(ILicenseController licenseController, IUserBL userBL, LicenseData licenseData, ILicenseBL licenseBL, IInstanceSettings settings, ISeatingBL seatingBL, LicenseStateTransitionCallback licenseStateTransitionCallback) { _licenseController = licenseController; _userBL = userBL; _licenseData = licenseData; _licenseBL = licenseBL; _settings = settings; _seatingBL = seatingBL; _licenseStateTransitionCallback = licenseStateTransitionCallback; }
public void Can_update_license_seat_licensing() { // Arrange var currentLicense = new XDoc("current"); var newLicense = new XDoc("new"); var newExpiration = DateTime.UtcNow.AddDays(1); var newPermissions = Permissions.BROWSE; ulong? newOwnerId = 1; var currentLicenseData = new LicenseData() .WithLicenseDocument(currentLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(DateTime.UtcNow) .WithPermissions(Permissions.NONE) .WithSiteOwnerUserId(1) .Checked(DateTime.UtcNow); var newLicenseData = new LicenseData().WithLicenseDocument(newLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(newExpiration) .WithPermissions(newPermissions) .WithSiteOwnerUserId(newOwnerId) .Checked(DateTime.UtcNow); _licenseBLMock.Setup(x => x.GetSiteOwnerUserId(newLicense)).Returns(newOwnerId); var tempLicenseNewLicenseData = new LicenseData().WithLicenseDocument(newLicense); _licenseBLMock.Setup(x => x.BuildLicenseData(newLicense, true, true)).Returns(tempLicenseNewLicenseData).Verifiable(); _licenseBLMock.Setup(x => x.ValidateNewLicenseTransition(It.Is<LicenseData>(l => l.AreSame(tempLicenseNewLicenseData)), It.Is<LicenseData>(l => l.AreSame(currentLicenseData)))) .Returns(newLicenseData) .Verifiable(); _seatingBLMock.Setup(x => x.IsSeatLicensingEnabled(currentLicenseData)).Returns(true); _seatingBLMock.Setup(x => x.IsSeatLicensingEnabled(newLicense)).Returns(true); _seatingBLMock.Setup(x => x.HandleSeatTransition(newLicense)).Returns(new SeatAssignmentInfo(2, 5)); // Act var updatedLicense = _licenseController.UpdateLicense(newLicense, currentLicenseData, _licenseBLMock.Object, _seatingBLMock.Object); // Assert _licenseBLMock.Verify(x => x.Validate(newLicense), Times.Once()); _licenseBLMock.Verify(x => x.ValidateNewLicenseTransition(It.Is<LicenseData>(l => l.AreSame(tempLicenseNewLicenseData)), It.Is<LicenseData>(l => l.AreSame(currentLicenseData))), Times.Once()); _seatingBLMock.Verify(x => x.IsSeatLicensingEnabled(currentLicenseData), Times.Once()); _seatingBLMock.Verify(x => x.IsSeatLicensingEnabled(newLicense), Times.Once()); _seatingBLMock.Verify(x => x.HandleSeatTransition(newLicense), Times.Once()); _seatingBLMock.Verify(x => x.SetOwnerUserSeat(newLicenseData), Times.Once()); Assert.AreSame(newLicenseData, updatedLicense); Assert.AreEqual(newLicense, newLicenseData.LicenseDoc); Assert.AreEqual(newExpiration, newLicenseData.LicenseExpiration); Assert.AreEqual(newOwnerId, newLicenseData.SiteOwnerUserId); Assert.AreEqual(newPermissions, newLicenseData.AnonymousPermissions); }
public void License_check_happens_periodically_on_known_good() { // Arrange var currentLicense = new XDoc("license"); var newLicense = new XDoc("new"); var newState = LicenseStateType.COMMERCIAL; var newExpiration = DateTime.UtcNow.AddDays(1); var newPermissions = Permissions.BROWSE; ulong? newOwnerId = 1; var oldCheckedDate = DateTime.UtcNow.AddHours(-1); var checkedDate = DateTime.UtcNow; var inputData = new LicenseData() .WithLicenseDocument(currentLicense) .WithState(LicenseStateType.COMMERCIAL) .WithExpiration(DateTime.UtcNow) .WithPermissions(Permissions.NONE) .WithSiteOwnerUserId(1) .Checked(oldCheckedDate); _licenseData.Update(inputData); _licenseControllerMock.Setup(x => x.VerifyLicenseData(_licenseData, _licenseBLMock.Object, _seatingBLMock.Object)) .Returns(new LicenseData() .WithLicenseDocument(newLicense) .WithState(newState) .WithExpiration(newExpiration) .WithPermissions(newPermissions) .WithSiteOwnerUserId(newOwnerId) .Checked(checkedDate) ); // Act var state = _manager.LicenseState; // Assert _licenseControllerMock.Verify(x => x.VerifyLicenseData(_licenseData, _licenseBLMock.Object, _seatingBLMock.Object), Times.Once()); Assert.AreEqual(newState, state); Assert.AreEqual(newLicense, _licenseData.LicenseDoc); Assert.AreEqual(newState, _licenseData.LicenseState); Assert.AreEqual(newExpiration, _licenseData.LicenseExpiration); Assert.AreEqual(newOwnerId, _licenseData.SiteOwnerUserId); Assert.AreEqual(newPermissions, _licenseData.AnonymousPermissions); Assert.GreaterOrEqual(_licenseData.LicenseStateChecked, checkedDate); }
public LicenseData ValidateNewLicenseTransition(LicenseData newLicense, LicenseData currentLicense) { var currentState = currentLicense.LicenseState; /* * State transitions: * community -> community * community -> commercial * trial -> commercial * trial -> trial * commercial -> commercial * expired -> trial * expired -> commercial * inactive -> trial * inactive -> commercial * inactive -> community * invalid -> * */ // retrieve desired license state var exception = true; // check if the license transition is valid if(newLicense.LicenseState == LicenseStateType.INVALID) { // cannot switch to an invalid license throw new MindTouchLicenseUpdateInvalidArgumentException(); } if(newLicense.LicenseState == LicenseStateType.EXPIRED) { // cannot switch to an expired license throw new MindTouchLicenseExpiredInvalidOperationException(newLicense.LicenseExpiration); } switch(currentState) { case LicenseStateType.COMMUNITY: switch(newLicense.LicenseState) { case LicenseStateType.COMMUNITY: case LicenseStateType.COMMERCIAL: exception = false; break; } break; case LicenseStateType.INACTIVE: switch(newLicense.LicenseState) { case LicenseStateType.COMMUNITY: case LicenseStateType.COMMERCIAL: case LicenseStateType.TRIAL: exception = false; break; } break; case LicenseStateType.TRIAL: switch(newLicense.LicenseState) { case LicenseStateType.COMMERCIAL: case LicenseStateType.TRIAL: exception = false; break; } break; case LicenseStateType.COMMERCIAL: switch(newLicense.LicenseState) { case LicenseStateType.COMMERCIAL: exception = false; break; } break; case LicenseStateType.EXPIRED: switch(newLicense.LicenseState) { case LicenseStateType.TRIAL: case LicenseStateType.COMMERCIAL: exception = false; break; } break; case LicenseStateType.INVALID: exception = false; break; default: throw new MindTouchLicenseUpdateInvalidArgumentException(); } // verify that this license of for this installations if(exception) { throw new MindTouchLicenseTransitionForbiddenLicenseTransitionException(currentState, newLicense.LicenseState); } // Extra validation when updating or transitioning to commerical license if(newLicense.LicenseState == LicenseStateType.COMMERCIAL) { //user count var maxUsers = newLicense.LicenseDoc["/license.private/grants/active-users"].AsUInt; if(maxUsers != null) { //Reject license if its user limit is lower than current number of users var currentActiveUsers = DbUtils.CurrentSession.Users_GetCount(); if(currentActiveUsers > maxUsers.Value) { var userDelta = currentActiveUsers - maxUsers.Value; throw new MindTouchLicenseTooManyUsersForbiddenException(currentActiveUsers, maxUsers.Value, userDelta); } } } return newLicense; }
public void Clear() { MakeNewGuid(); _projectMustBeAdministratorToInstall = false; _project64BitTarget = false; _projectTargetName = "Setup"; _projectType = 0; _projectVersion = "1.0.0"; _projectName = ""; _projectUpgradeUuid = System.Guid.NewGuid().ToString(); _projectFeatures = new List<WarSetup.SetupFeature>(); _projectMergeModules = new List<MergeModule>(); _projectInstallForCurrentOrAllUsers = 0; _projectUserInterface = "WixUI_Mondo"; _projectProperties = new ProjectProperties(); _projectWixModules = new List<WixModule>(); _projectProperties.UiCultures.Clear(); _License = new LicenseData(); }
//--- Methods --- public void Update(LicenseData licenseData) { _data = licenseData._data; }
protected LicenseData HandleLicenseTransition(XDoc licenseDoc, LicenseData currentLicense, ISeatingBL seatingBL, ILicenseBL licenseBL) { var seatingEnabledInNewLicense = seatingBL.IsSeatLicensingEnabled(licenseDoc); var tempLicense = licenseBL.BuildLicenseData(licenseDoc, true, seatingEnabledInNewLicense); var newLicense = licenseBL.ValidateNewLicenseTransition(tempLicense, currentLicense); _log.DebugFormat("new license with state '{0}' has passed validation and will be accepted", newLicense.LicenseState); // Ensure that all seats are cleared if seat licensing is disabled. // This will allow a known clean seat state if it becomes enabled. if(!seatingBL.IsSeatLicensingEnabled(currentLicense)) { _log.Debug("old license did not have seat licensing"); seatingBL.RevokeSeats(currentLicense); } // Seat licensing if(seatingEnabledInNewLicense) { var seats = seatingBL.HandleSeatTransition(licenseDoc); if(seats.Assigned > seats.Allowed) { HandleExcessSeats(currentLicense, seatingBL, seats); } // set a seat for the owner seatingBL.SetOwnerUserSeat(newLicense); } else { _log.Debug("new license does not contain seat licensing"); // Clear the seat state when going to non-seat license seatingBL.RevokeSeats(newLicense); } _log.DebugFormat("transitioned license from '{0}' to '{1}'", currentLicense.LicenseState, newLicense.LicenseState); return newLicense; }
protected override void HandleExcessSeats(LicenseData license, ISeatingBL seatingBL, SeatAssignmentInfo seats) { _log.WarnFormat("site '{0}' has {1} assigned seats, but is only licensed for {2} (not revoking)", _wikiId, seats.Assigned, seats.Allowed); }
public LicenseData BuildLicenseData(XDoc license, bool verifyProductKey, bool seatLicensingEnabled) { var builtLicense = new LicenseData().WithLicenseDocument(license); // check if a valid license was passed in if(license.IsEmpty) { _log.Debug("license document was empty"); return builtLicense; } // check if the deki assembly is signed var assembly = typeof(DekiWikiService).Assembly; if(ArrayUtil.IsNullOrEmpty(assembly.GetName().GetPublicKey())) { // no signature, default to community _log.Warn("Unable to validate signature of license since the MindTouch Core service was not signed by MindTouch. Reverting to community edition."); return builtLicense.WithState(LicenseStateType.COMMUNITY).WithPermissions(PermissionSets.ALL); } // assembly is signed: validate xml signature var rsa = RSAUtil.ProviderFrom(assembly); if((rsa == null) || !license.HasValidSignature(rsa)) { _log.Warn("License failed XML validation"); return builtLicense.WithState(LicenseStateType.INVALID); } // check license matched product key var productKey = license["licensee/product-key"].AsText; // license product key may be generated based on either the instance or master apikeys if(verifyProductKey && !IsValidProductKey(productKey, _instanceApiKey) && !IsValidProductKey(productKey, _masterApiKey)) { _log.Warn("Invalid product-key in license"); return builtLicense.WithState(LicenseStateType.INVALID); } // determine license type switch(license["@type"].AsText ?? "inactive") { case "trial": builtLicense = builtLicense.WithState(LicenseStateType.TRIAL); break; case "inactive": builtLicense = builtLicense.WithState(LicenseStateType.INACTIVE); break; case "community": builtLicense = builtLicense.WithState(LicenseStateType.COMMUNITY); break; case "commercial": builtLicense = builtLicense.WithState(LicenseStateType.COMMERCIAL); break; default: _log.Warn("Unknown license type"); builtLicense = builtLicense.WithState(LicenseStateType.INVALID); break; } // check expiration builtLicense = builtLicense.WithExpiration(license["date.expiration"].AsDate ?? DateTime.MaxValue); if(builtLicense.LicenseState == LicenseStateType.COMMERCIAL) { // check if license is passed grace period if(builtLicense.LicenseExpiration <= DateTime.UtcNow.AddDays(-GRACE_PERIOD)) { _log.DebugFormat("commercial license has expired and is past grace period: {0}", builtLicense.LicenseExpiration); return builtLicense.WithState(LicenseStateType.EXPIRED); } _log.DebugFormat("commercial license has not expired or is at least not past grace period: {0}", builtLicense.LicenseExpiration); } else if(builtLicense.LicenseExpiration <= DateTime.UtcNow) { _log.DebugFormat("non-commercial license has expired: {0}", builtLicense.LicenseExpiration); return builtLicense.WithState(LicenseStateType.EXPIRED); } // check version var licenseVersion = (license["version"].AsText ?? "*").Split('.'); var assemblyVersion = typeof(LicenseBL).Assembly.GetName().Version; var appVersion = new[] { assemblyVersion.Major, assemblyVersion.Minor, assemblyVersion.Revision, assemblyVersion.Build }; for(var i = 0; (i < licenseVersion.Length) && (i < appVersion.Length); ++i) { var pattern = licenseVersion[i]; int value; if(pattern.Equals("*") || (int.TryParse(pattern, out value) && (value >= appVersion[i]))) { continue; } return builtLicense.WithState(LicenseStateType.EXPIRED); } // determine permissions for anonymous user builtLicense = builtLicense.WithPermissions(PermissionsBL.MaskFromString(DekiLicense.GetCapability(license, "anonymous-permissions")) | PermissionSets.MINIMAL_ANONYMOUS_PERMISSIONS); // retrieve the site owner from the license var siteOwnerUserId = GetSiteOwnerUserId(license); if(seatLicensingEnabled && (siteOwnerUserId ?? 0) == 0) { throw new MindTouchLicenseNoSiteOwnerDefinedException(); } return builtLicense.WithSiteOwnerUserId(siteOwnerUserId); }
public virtual void UpdateLicense(XDoc currentLicense, XDoc newLicense) { LicenseData currentLicenseData; if(currentLicense == null) { currentLicenseData = LicenseData.Clone(); } else { var tempLicense = new LicenseData().WithLicenseDocument(currentLicense); currentLicenseData = _licenseBL.DetermineLicenseState(tempLicense, false, _seatingBL.IsSeatLicensingEnabled(tempLicense)); } lock(_sync) { var updated = _licenseController.UpdateLicense(newLicense, currentLicenseData, _licenseBL, _seatingBL).Checked(DateTime.UtcNow); _settings.ClearConfigCache(); _licenseData.Update(updated); _licenseStateTransitionCallback(currentLicenseData, updated); } _log.DebugFormat("license updated to state {0} and last checked date {1}", _licenseData.LicenseState, _licenseData.LicenseStateChecked); }
public LicenseData DetermineLicenseState(LicenseData licenseData, bool verifyProductKey, bool seatLicensingEnabled) { if(licenseData == null) { throw new ArgumentNullException("licenseData"); } _log.DebugFormat("verifying license state with initial state: {0}", licenseData.LicenseState); return BuildLicenseData(licenseData.LicenseDoc, verifyProductKey, seatLicensingEnabled); }
public void SetUserSeat(UserBE user, LicenseData license) { if(!IsSeatLicensingEnabled(license)) { throw new MindTouchLicenseSeatLicensingNotInUseException(); } if(_userBL.IsAnonymous(user)) { throw new MindTouchLicenseAnonymousSeat(); } if(user.LicenseSeat) { // giving a seat to a seated user is not an error _log.DebugFormat("user {0} already has a seat license", user.ID); return; } if(AreSeatsExceedingLicense(license)) { throw new MindTouchLicenseInsufficientSeatsException(GetSeatsLicensed(license)); } _log.DebugFormat("settings licenseSeat to true for user {0}", user.ID); user.LicenseSeat = true; _userBL.UpdateUser(user); // ensure that another server or thread hasn't concurrently granted a seat thus going over the limit. // Both seats may potentially be revoked. if(AreSeatsExceedingLicense(license)) { RemoveSeatFromUserInternal(user, license); throw new MindTouchLicenseInsufficientSeatsException(GetSeatsLicensed(license)); } _log.InfoFormat("Seat licensing: Granted a seat to '{0}'", user.Name); }
public virtual LicenseData VerifyLicenseData(LicenseData licenseData, ILicenseBL licenseBL, ISeatingBL seatingBL) { if(licenseData.LicenseDoc.IsEmpty) { licenseData = licenseData.WithLicenseDocument(LicenseDoc); } return licenseBL.DetermineLicenseState(licenseData, true, seatingBL.IsSeatLicensingEnabled(licenseData)); }
public ulong? GetSiteOwnerUserId(LicenseData license) { if(IsSeatLicensingEnabled(license)) { if(license.SiteOwnerUserId == null) { _log.Warn("Seat licensing is enabled but no site owner is defined."); } return license.SiteOwnerUserId; } return null; }
public void RemoveSeatFromUser(UserBE user, LicenseData licenseData) { if(!IsSeatLicensingEnabled(licenseData)) { throw new MindTouchLicenseSeatLicensingNotInUseException(); } RemoveSeatFromUserInternal(user, licenseData); }
public void RevokeSeats(LicenseData license) { var ownerUserId = GetSiteOwnerUserId(license) ?? 0; var seatedUsers = GetSeatedUsers().Where(u => u.ID != ownerUserId).ToArray(); foreach(var u in seatedUsers) { RemoveSeatFromUserInternal(u, license); } if(seatedUsers.Any()) { _log.Warn(String.Format("Seat licensing: Revoked {0} seats from users", seatedUsers.Count())); } }
public void License_check_always_fetches_from_remote() { // Arrange var license = new XDoc("license"); var newLicenseState = LicenseStateType.COMMERCIAL; var newExpiration = DateTime.UtcNow.AddDays(1); var newPermissions = Permissions.BROWSE; ulong? newSiteOwnerId = 1; var checkedDate = DateTime.UtcNow; SetupGetRemoteLicense(_wikiId, license); var licenseData = new LicenseData(); var licenseDataWithLicense = new LicenseData().WithLicenseDocument(license); _licenseBLMock.Setup(x => x.DetermineLicenseState(It.Is<LicenseData>(l => l.AreSame(licenseDataWithLicense)), true, false)) .Returns(new LicenseData().WithLicenseDocument(license) .WithState(newLicenseState) .WithExpiration(newExpiration) .WithPermissions(newPermissions) .WithSiteOwnerUserId(newSiteOwnerId) .Checked(checkedDate) ); _seatingBLMock.Setup(x => x.IsSeatLicensingEnabled(license)).Returns(false); // Act var checkedLicense = _licenseController.VerifyLicenseData(licenseData, _licenseBLMock.Object, _seatingBLMock.Object); // Assert VerifyGetRemoteLicense(); _licenseBLMock.Verify(x => x.DetermineLicenseState(It.Is<LicenseData>(l => l.AreSame(licenseDataWithLicense)), true, false), Times.Once()); Assert.AreEqual(license, checkedLicense.LicenseDoc); Assert.AreEqual(newLicenseState, checkedLicense.LicenseState); Assert.AreEqual(newExpiration, checkedLicense.LicenseExpiration); Assert.AreEqual(newSiteOwnerId, checkedLicense.SiteOwnerUserId); Assert.AreEqual(newPermissions, checkedLicense.AnonymousPermissions); Assert.AreEqual(checkedDate, checkedLicense.LicenseStateChecked); }
public void SetOwnerUserSeat(LicenseData checkedLicense) { // Give a seat to the site owner if they don't already have one (the owner id has already been validated) var ownerUserId = GetSiteOwnerUserId(checkedLicense) ?? 0; if(ownerUserId == 0) { _log.Warn("Unable to assign a seat to the owner since it was not defined in the license"); return; } var siteOwner = _userBL.GetUserById((uint)ownerUserId); if(siteOwner == null) { _log.Warn(String.Format("Unable to look up site owner user id '{0}'", ownerUserId)); return; } SetUserSeat(siteOwner, checkedLicense); // reset current user to reflect seat status of owner if(_userContext.User != null && _userContext.User.ID == siteOwner.ID) { _userContext.User = siteOwner; } }
//--- Methods --- public void Callback(LicenseData previous, LicenseData @new) { _previous = previous; _new = @new; _called++; }
//--- Methods --- public override LicenseData UpdateLicense(XDoc license, LicenseData currentLicense, ILicenseBL licenseBL, ISeatingBL seatingBL) { _log.DebugFormat("updating license from '{1}' to '{0}'", license["@type"].Contents, currentLicense.LicenseState); licenseBL.Validate(license); return HandleLicenseTransition(license, currentLicense, seatingBL, licenseBL); }