private static void RemoveCALs(List <String> removeCALs) { Console.WriteLine("Removing ALL Named CAL's..."); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey(); ServiceInfo qvs = GetQlikViewServer(); CALConfiguration config = apiClient.GetCALConfiguration(qvs.ID, CALConfigurationScope.NamedCALs); // convert list<string> to list<AssignedNameCAL> var r = removeCALs.Select(cal => new AssignedNamedCAL { UserName = cal }).ToList(); // Remove named CALs foreach ( AssignedNamedCAL c in config.NamedCALs.AssignedCALs.ToList().SelectMany( cals => r.Where(item => item.UserName == cals.UserName).Select(item => cals))) { LogHelper.Log(LogLevel.Debug, "REMOVE: " + c.UserName, LogProperties); config.NamedCALs.AssignedCALs.Remove(c); config.NamedCALs.RemovedAssignedCALs.Add(c); } // save changes apiClient.SaveCALConfiguration(config); Console.WriteLine("Done!"); }
public static List <string> GetUsersFromServer() { // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey(); ServiceInfo qvs = GetQlikViewServer(); Console.Write("Reading CAL information from {0}...", qvs.Name); var currentCals = new List <string>(); CALConfiguration config = apiClient.GetCALConfiguration(qvs.ID, CALConfigurationScope.NamedCALs); // Get Named CALs currentCals.AddRange(config.NamedCALs.AssignedCALs.Select(c => c.UserName.ToUpper())); Console.WriteLine(" (Found " + currentCals.Count + ")"); return(currentCals); }
private static void SynqronizeCALs(List <String> removeCALs, List <String> allocateCALs) { if (removeCALs.Count + allocateCALs.Count <= 0) { return; } Console.WriteLine("Synqronizing..."); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey(); ServiceInfo qvs = GetQlikViewServer(); CALConfiguration config = apiClient.GetCALConfiguration(qvs.ID, CALConfigurationScope.NamedCALs); // Get number of users BEFORE modifications var namedCALsAssigned = config.NamedCALs.AssignedCALs.Count; var inLicense = config.NamedCALs.InLicense; var namedCALsLimit = config.NamedCALs.Limit; // Check if there's enough available licenses if ((allocateCALs.Count - removeCALs.Count) <= (inLicense - namedCALsAssigned)) { // convert list<string> to list<AssignedNameCAL> var r = removeCALs.Select(cal => new AssignedNamedCAL { UserName = cal }).ToList(); // Remove named CALs foreach ( AssignedNamedCAL c in config.NamedCALs.AssignedCALs.ToList().SelectMany( cals => r.Where(item => item.UserName == cals.UserName).Select(item => cals))) { LogHelper.Log(LogLevel.Debug, "REMOVE: " + c.UserName, LogProperties); config.NamedCALs.AssignedCALs.Remove(c); config.NamedCALs.RemovedAssignedCALs.Add(c); } // Add named CALs foreach (var cal in allocateCALs) { LogHelper.Log(LogLevel.Debug, "ADD: " + cal, LogProperties); config.NamedCALs.AssignedCALs.Add(new AssignedNamedCAL { UserName = cal }); } // save changes apiClient.SaveCALConfiguration(config); // Get number of users AFTER modifications namedCALsAssigned = config.NamedCALs.AssignedCALs.Count; inLicense = config.NamedCALs.InLicense; namedCALsLimit = config.NamedCALs.Limit; LogHelper.Log(LogLevel.Debug, "ASSIGNED: " + namedCALsAssigned, LogProperties); LogHelper.Log(LogLevel.Debug, "IN LICENSE: " + inLicense, LogProperties); if (inLicense != namedCALsLimit) { LogHelper.Log(LogLevel.Debug, "LIMIT: " + namedCALsLimit, LogProperties); } LogHelper.Log(LogLevel.Debug, "AVAILABLE: " + (inLicense - namedCALsAssigned), LogProperties); Console.WriteLine("Done!"); } else { LogHelper.Log(LogLevel.Error, "Not enough CAL's available on server", LogProperties); } }
public QVServer(QMSClient client) { this.client = client; qvs = client.GetServices(ServiceTypes.QlikViewServer).FirstOrDefault(); calls = client.GetCALConfiguration(qvs.ID, CALConfigurationScope.All); }