private static void SendClientResponse(PendingClientLicenseResponse clientLicenseResponse) { if (clientLicenseResponse != null) { EventLogManager.WriteToEventLog("Sending client license response", clientLicenseResponse.LicenseType.ToString() + ":" + clientLicenseResponse.IPAddress); var clientLicenseResponseAsEncodedXml = clientLicenseResponse.ToEncodedXml(); var clientEncodedLicenseResponseMessage = new PendingClientLicenseResponseMessage(); clientEncodedLicenseResponseMessage.Message = clientLicenseResponseAsEncodedXml; ConnectionManager.SendAsXML(clientEncodedLicenseResponseMessage, System.Net.IPAddress.Parse(clientLicenseResponse.IPAddress), 11000); EventLogManager.WriteToEventLog("Send client license response", clientLicenseResponse.LicenseType.ToString() + ":" + clientLicenseResponse.IPAddress); } }
public static void ConnectionManager_AtumClientLicenseResponse(PendingClientLicenseResponse clientLicenseResponse) { lock (PendingClientLicenseRequests) { foreach (var pendingLicense in PendingClientLicenseRequests) { if (pendingLicense.Id == clientLicenseResponse.Id) { if (!ActivedLicenses.Exists(s => s.Id == pendingLicense.Id)) { ActivedLicenses.Add(pendingLicense); } PendingClientLicenseRequests.Remove(pendingLicense); DAL.Managers.LoggingManager.WriteToLog("License Manager", "Pending License: " + clientLicenseResponse.LicenseType.ToString(), "Removed"); break; } } } lock (AvailableLicenses) { var currentLicenseFound = false; foreach (var availableLicense in AvailableLicenses) { if (availableLicense.LicenseType == clientLicenseResponse.LicenseType) { currentLicenseFound = true; availableLicense.ExpirationDate = availableLicense.ExpirationDate.AddHours(4); DAL.Managers.LoggingManager.WriteToLog("License Manager", "License: " + clientLicenseResponse.LicenseType.ToString(), "EndsOn Timestamp updated"); PendingLicensesChanged?.Invoke(null, null); break; } } if (!currentLicenseFound) { AvailableLicenses.Add(new AvailableLicense() { Activated = true, ExpirationDate = DateTime.Now.AddDays(1), LicenseType = clientLicenseResponse.LicenseType }); DAL.Managers.LoggingManager.WriteToLog("License Manager", "License: " + clientLicenseResponse.LicenseType.ToString(), "Added"); AvailableLicensesChanged?.Invoke(null, null); } } }
public static void ConnectionManager_AtumClientLicenseRequest(PendingClientLicenseRequest clientLicenseRequest) { EventLogManager.WriteToEventLog("Received client license request", clientLicenseRequest.LicenseType.ToString() + ":" + clientLicenseRequest.IPAddress); //license available? if (AvailableLicenses != null) { foreach (var availableLicense in AvailableLicenses) { if (availableLicense != null) { if (clientLicenseRequest.LicenseType == PendingClientLicenseRequest.TypeOfClientLicenseRequest.Studio) { if (availableLicense.LicenseType == AvailableLicense.TypeOfLicense.StudioStandard) { //check if client computer has activity if (availableLicense.Activities.Count(s => s.Computername.ToLower() == clientLicenseRequest.Computername.ToLower()) == 0) { if (availableLicense.Amount - 1 >= availableLicense.Activities.Count) { //add activity availableLicense.Activities.Add(new AvailableLicenseActivity() { Computername = clientLicenseRequest.Computername.ToLower(), Username = clientLicenseRequest.Username.ToLower(), EndsOn = DateTime.Now.AddHours(2) }); EventLogManager.WriteToEventLog("Added license activity", availableLicense.LicenseType.ToString() + ":" + clientLicenseRequest.Computername); EventLogManager.WriteToEventLog("Amount of licenses", availableLicense.LicenseType.ToString() + ":" + availableLicense.Activities.Count + "/" + availableLicense.Amount); } else { EventLogManager.WriteToEventLog("Maximum amount of available licenses reached", availableLicense.LicenseType.ToString()); } } else { //update endson foreach (var activity in availableLicense.Activities) { if (activity.Computername == clientLicenseRequest.Computername.ToLower()) { activity.EndsOn = DateTime.Now.AddHours(2); EventLogManager.WriteToEventLog("Update license activity expiretime", availableLicense.LicenseType.ToString() + ":" + clientLicenseRequest.Computername); } } } var pendingClientLicenseResponse = new PendingClientLicenseResponse(); pendingClientLicenseResponse.LicenseType = AvailableLicense.TypeOfLicense.StudioStandard; pendingClientLicenseResponse.IPAddress = clientLicenseRequest.IPAddress; pendingClientLicenseResponse.Id = clientLicenseRequest.Id; SendClientResponse(pendingClientLicenseResponse); break; } } } } } }