/// <summary> /// List CALs /// </summary> public static string List() { StringBuilder response = new StringBuilder(); try { // Initiate backend client var backendClient = new QMSBackendClient(); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = backendClient.GetTimeLimitedServiceKey(); // Get available QlikView Servers var serviceList = backendClient.GetServices(ServiceTypes.QlikViewServer); response.AppendLine("UserName;LastUsed;QuarantinedUntil;Document;Server"); // Loop through available servers foreach (var server in serviceList) { // Get Named CALs var config = backendClient.GetCALConfiguration(server.ID, CALConfigurationScope.NamedCALs); foreach (var c in config.NamedCALs.AssignedCALs) { response.AppendLine(String.Format("{0};{1};{2};{3};{4}", c.UserName, c.LastUsed.Year > 0001 ? c.LastUsed.ToString() : "", c.QuarantinedUntil.Year > 0001 ? c.QuarantinedUntil.ToString() : "", "", server.Name)); } // Get Document CAL's var userDocuments = backendClient.GetUserDocuments(server.ID); foreach (var docNode in userDocuments) { var metaData = backendClient.GetDocumentMetaData(docNode, DocumentMetaDataScope.Licensing); foreach (var c in metaData.Licensing.AssignedCALs) { response.AppendLine(String.Format("{0};{1};{2};{3};{4}", c.UserName, c.LastUsed.Year > 0001 ? c.LastUsed.ToString() : "", c.QuarantinedUntil.Year > 0001 ? c.QuarantinedUntil.ToString() : "", docNode.Name, server.Name)); } } } } catch (Exception ex) { response.AppendLine(ex.Message); } return(response.ToString()); }
/// <summary> /// List DMS users /// </summary> /// <param name="documents"></param> public static string List(ICollection <string> documents) { StringBuilder response = new StringBuilder(); try { // Initiate backend client var backendClient = new QMSBackendClient(); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = backendClient.GetTimeLimitedServiceKey(); // Get available QlikView Servers var serviceList = backendClient.GetServices(ServiceTypes.QlikViewServer); response.AppendLine("UserName;Document;Server"); // Loop through available servers foreach (var server in serviceList) { // Get documents on each server var userDocuments = backendClient.GetUserDocuments(server.ID); // Loop through available documents foreach (var docNode in userDocuments) { if (documents.Count != 0 && !documents.Contains(docNode.Name.ToLower())) { continue; } // Get authorization meta data var metaData = backendClient.GetDocumentMetaData(docNode, DocumentMetaDataScope.Authorization); foreach (var user in metaData.Authorization.Access) { response.AppendLine(String.Format("{0};{1};{2}", user.UserName, docNode.Name, server.Name)); } } } } catch (Exception ex) { response.AppendLine(ex.Message); } return(response.ToString()); }
/// <summary> /// List information about CALs /// </summary> public static string CalInfo() { StringBuilder response = new StringBuilder(); try { // Initiate backend client var backendClient = new QMSBackendClient(); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = backendClient.GetTimeLimitedServiceKey(); // Get available QlikView Servers var serviceList = backendClient.GetServices(ServiceTypes.QlikViewServer); response.AppendLine("Server;NamedAssigned;NamedInLicense;NamedLeased;NamedAllowDynamic;NamedAllowLease;DocAssigned;DocInLicense;SessionAvailable;SessionInLicense;UsageAvailable;UsageInLicense"); // Loop through available servers foreach (var server in serviceList) { // Get Named CALs var config = backendClient.GetCALConfiguration(server.ID, CALConfigurationScope.All); response.Append(server.Name + ";"); response.Append(config.NamedCALs.AssignedCALs.Count + ";"); response.Append(config.NamedCALs.InLicense + ";"); response.Append(config.NamedCALs.LeasedCALs.Count + ";"); response.Append(config.NamedCALs.AllowDynamicAssignment + ";"); response.Append(config.NamedCALs.AllowLicenseLease + ";"); response.Append(config.DocumentCALs.Assigned + ";"); response.Append(config.DocumentCALs.InLicense + ";"); response.Append(config.SessionCALs.Available + ";"); response.Append(config.SessionCALs.InLicense + ";"); response.Append(config.UsageCALs.Available + ";"); response.AppendLine(config.UsageCALs.InLicense.ToString()); } } catch (Exception ex) { response.AppendLine(ex.Message); } return(response.ToString()); }
/// <summary> /// Add DMS users /// </summary> /// <param name="documents"></param> /// <param name="users"></param> public static string Add(ICollection <string> documents, ICollection <string> users) { StringBuilder response = new StringBuilder(); try { // Initiate backend client var backendClient = new QMSBackendClient(); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = backendClient.GetTimeLimitedServiceKey(); // Get available QlikView Servers var serviceList = backendClient.GetServices(ServiceTypes.QlikViewServer); // Loop through available servers foreach (var server in serviceList) { // Get documents on each server var userDocuments = backendClient.GetUserDocuments(server.ID); // Loop through available documents foreach (var docNode in userDocuments) { // Continue if no matching documents if (documents.Count != 0 && !documents.Contains(docNode.Name.ToLower())) { continue; } // Get authorization metadata var metaData = backendClient.GetDocumentMetaData(docNode, DocumentMetaDataScope.Authorization); // Filter users already in DMS from the supplied list of users to avoid duplicates var uniqueUsers = users.Except(metaData.Authorization.Access.Select(user => user.UserName).ToList()); // Get number of users on each document var numberOfUsers = metaData.Authorization.Access.Count; // Add new users foreach (var user in uniqueUsers.Select(u => new DocumentAccessEntry { UserName = u, AccessMode = DocumentAccessEntryMode.Always, DayOfWeekConstraints = new List <DayOfWeek>() })) { metaData.Authorization.Access.Add(user); } // Save changes backendClient.SaveDocumentMetaData(metaData); // Get number of users AFTER modifications var addedUsers = metaData.Authorization.Access.Count - numberOfUsers; if (addedUsers <= 0) { response.AppendLine(String.Format("Nothing to add to '{0}' on {1}", docNode.Name, server.Name)); } else { response.AppendLine(String.Format("Added {0} users to '{1}' on {2}", addedUsers, docNode.Name, server.Name)); } } } } catch (Exception ex) { response.AppendLine(ex.Message); } return(response.ToString()); }
public static string DocInfo(ICollection <string> documents) { StringBuilder response = new StringBuilder(); try { // Initiate backend client var backendClient = new QMSBackendClient(); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = backendClient.GetTimeLimitedServiceKey(); // Get available QlikView Servers var serviceList = backendClient.GetServices(ServiceTypes.QlikViewServer); response.AppendLine("Document;Server;Preloaded;LoadedDays;LoadedBetween;Plugin;Mobile;AjaxZfc;Download;Category;SourceDocument"); // Loop through available servers foreach (var server in serviceList) { // Get documents on each server var userDocuments = backendClient.GetUserDocuments(server.ID); // Loop through available documents foreach (var docNode in userDocuments) { if (documents.Count != 0 && !documents.Contains(docNode.Name.ToLower())) { continue; } // Get authorization meta data var metaData = backendClient.GetDocumentMetaData(docNode, DocumentMetaDataScope.All); // Check if PreloadMode is Restricted, if so get the dates var preloadMode = metaData.Server.Preload.Mode.ToString(); var loadedDays = ""; var between = ""; if (preloadMode == "Restricted") { loadedDays = metaData.Server.Preload.DaysOfWeek.Aggregate(loadedDays, (current, dayOfWeek) => current + (dayOfWeek.ToString().Substring(0, 2) + " ")).Trim(); between = metaData.Server.Preload.StartTime.ToShortTimeString() + "-" + metaData.Server.Preload.EndTime.ToShortTimeString(); } // Check which clients are enabled var accessMethods = metaData.Server.Access.Methods.ToString(); var pluginClient = accessMethods.Contains("PluginClient") ? 1 : 0; var ajaxClient = accessMethods.Contains("ZeroFootprintClient") ? 1 : 0; var download = accessMethods.Contains("Download") ? 1 : 0; var mobileClient = accessMethods.Contains("MobileClient") ? 1 : 0; // Check if we have subfolders var relativePath = docNode.RelativePath; if (relativePath != "") { relativePath += "\\"; } response.AppendLine(String.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10}", relativePath + docNode.Name, server.Name, preloadMode, loadedDays, between, pluginClient, mobileClient, ajaxClient, download, metaData.DocumentInfo.Category, metaData.DocumentInfo.SourceName)); } } } catch (Exception ex) { response.AppendLine(ex.Message); } return(response.ToString()); }
/// <summary> /// Remove DMS users /// </summary> /// <param name="documents"></param> /// <param name="users"></param> public static string Remove(ICollection <string> documents, List <string> users) { StringBuilder response = new StringBuilder(); try { // Initiate backend client var backendClient = new QMSBackendClient(); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = backendClient.GetTimeLimitedServiceKey(); // Get available QlikView Servers var serviceList = backendClient.GetServices(ServiceTypes.QlikViewServer); // Convert all usernames to lowercase users = users.ConvertAll(d => d.ToLower()); // Loop through available servers foreach (var server in serviceList) { // Get documents on each server var userDocuments = backendClient.GetUserDocuments(server.ID); // Loop through available documents foreach (var docNode in userDocuments) { // Continue if no matching documents if (documents.Count != 0 && !documents.Contains(docNode.Name.ToLower())) { continue; } // Get authorization metadata var metaData = backendClient.GetDocumentMetaData(docNode, DocumentMetaDataScope.Authorization); // Get number of users BEFORE modifications var numberOfUsers = metaData.Authorization.Access.Count; if (users.Count == 0) { // Remove all users if no users were specified metaData.Authorization.Access.RemoveRange(0, numberOfUsers); } else { // Remove matching users foreach (var u in metaData.Authorization.Access.ToList().Where(u => users.Contains(u.UserName.ToLower()))) { metaData.Authorization.Access.Remove(u); } } // Save changes backendClient.SaveDocumentMetaData(metaData); // Get number of users AFTER modifications var removedUsers = numberOfUsers - metaData.Authorization.Access.Count; if (removedUsers <= 0) { response.AppendLine(String.Format("Nothing to remove from '{0}' on {1}", docNode.Name, server.Name)); } else { response.AppendLine(String.Format("Removed {0} users from '{1}' on {2}", removedUsers, docNode.Name, server.Name)); } } } } catch (Exception ex) { response.AppendLine(ex.Message); } return(response.ToString()); }
/// <summary> /// ADD CALs /// </summary> /// <param name="documents"></param> /// <param name="users"></param> public static string Add(ICollection <string> documents, ICollection <string> users) { StringBuilder response = new StringBuilder(); try { // Initiate backend client var backendClient = new QMSBackendClient(); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = backendClient.GetTimeLimitedServiceKey(); // Get available QlikView Servers var serviceList = backendClient.GetServices(ServiceTypes.QlikViewServer); if (documents.Count == 0) // NAMED CALS { // Loop through available servers foreach (var server in serviceList) { // Get Named CALs var config = backendClient.GetCALConfiguration(server.ID, CALConfigurationScope.NamedCALs); // Get number of users BEFORE modifications var numberOfCals = config.NamedCALs.AssignedCALs.Count; // Add CAL's (already existing CAL's seems unaffected, but how to check for them? Is it necessary?) foreach (var user in users.Select(u => new AssignedNamedCAL { UserName = u.ToUpper(), })) { config.NamedCALs.AssignedCALs.Add(user); } // Save changes backendClient.SaveCALConfiguration(config); // Get number of users AFTER modifications var addedCals = config.NamedCALs.AssignedCALs.Count - numberOfCals; if (addedCals <= 0) { response.AppendLine(String.Format("Nothing to add on {0}", server.Name)); } else { response.AppendLine(String.Format("Added {0} CALs on {1}", addedCals, server.Name)); } var inLicense = config.NamedCALs.InLicense; var assigned = config.NamedCALs.Assigned; // Warn if not enough available CAL's if (addedCals >= inLicense) { response.AppendLine(String.Format("WARNING: Attempted to assign {0} CALs on {1} but the license only allows {2} CALs.", addedCals, server.Name, inLicense)); } else if (assigned >= inLicense) { response.AppendLine("WARNING: All available CALs in the license have been assigned."); } } } // DOCUMENT CALS else { // Loop through available servers foreach (var server in serviceList) { // Get documents on each server var userDocuments = backendClient.GetUserDocuments(server.ID); // Loop through available documents foreach (var docNode in userDocuments) { // Continue if no matching documents if (!documents.Contains(docNode.Name.ToLower())) { continue; } var metaData = backendClient.GetDocumentMetaData(docNode, DocumentMetaDataScope.Licensing); // Get allocated CAL's for document var allocatedCals = metaData.Licensing.CALsAllocated; // Allocate more CAL's if necessary if (users.Count > allocatedCals) { metaData.Licensing.CALsAllocated = users.Count(); } // Add document CAL's foreach (var user in users.Select(u => new AssignedNamedCAL { UserName = u })) { metaData.Licensing.AssignedCALs.Add(user); } // Save changes backendClient.SaveDocumentMetaData(metaData); response.AppendLine(String.Format("Added {0} Document CALs to '{1}' on {2}", users.Count(), docNode.Name, server.Name)); } } } } catch (Exception ex) { response.AppendLine(ex.Message); } return(response.ToString()); }
/// <summary> /// Remove CALs /// </summary> public static string Remove() { StringBuilder response = new StringBuilder(); try { // Initiate backend client var backendClient = new QMSBackendClient(); // Get a time limited service key ServiceKeyClientMessageInspector.ServiceKey = backendClient.GetTimeLimitedServiceKey(); // Get available QlikView Servers var serviceList = backendClient.GetServices(ServiceTypes.QlikViewServer); // Number of inactive days const int days = -30; // Loop through available servers foreach (var server in serviceList) { /********************** * NAMED CALS **********************/ // Get CAL configuration var config = backendClient.GetCALConfiguration(server.ID, CALConfigurationScope.NamedCALs); // Get number of users BEFORE modifications var numberOfUsers = config.NamedCALs.AssignedCALs.Count; // Iterate through all CAL's and remove the inactive ones foreach (var c in config.NamedCALs.AssignedCALs.ToList().Where(u => u.LastUsed.Year > 0001 && u.LastUsed.CompareTo(DateTime.UtcNow.AddDays(days)) == -1)) { config.NamedCALs.AssignedCALs.Remove(c); } // Save changes backendClient.SaveCALConfiguration(config); // Get number of users BEFORE modifications var removedUsers = numberOfUsers - config.NamedCALs.AssignedCALs.Count; if (removedUsers <= 0) { response.AppendLine(String.Format("No CALs to remove on {0}", server.Name)); } else { response.AppendLine(String.Format("Removed {0} CALs on {1}", removedUsers, server.Name)); } /********************** * DOCUMENT CALS **********************/ // Get Document CAL's var userDocuments = backendClient.GetUserDocuments(server.ID); foreach (var docNode in userDocuments) { // Get licensing meta data var metaData = backendClient.GetDocumentMetaData(docNode, DocumentMetaDataScope.Licensing); // Get number of users BEFORE modifications numberOfUsers = metaData.Licensing.AssignedCALs.Count; // Iterate through all CAL's and remove the inactive ones foreach (var c in metaData.Licensing.AssignedCALs.ToList().Where(u => u.LastUsed.Year > 0001 && u.LastUsed.CompareTo(DateTime.UtcNow.AddDays(days)) == -1)) { metaData.Licensing.AssignedCALs.Remove(c); } // Save changes backendClient.SaveDocumentMetaData(metaData); // Get number of users AFTER modifications removedUsers = numberOfUsers - metaData.Licensing.AssignedCALs.Count; if (removedUsers <= 0) { response.AppendLine(String.Format("No Document CALs to remove from '{0}' on {1}", docNode.Name, server.Name)); } else { response.AppendLine(String.Format("Removed {0} Document CALs from '{1}' on {2}", removedUsers, docNode.Name, server.Name)); } } } } catch (Exception ex) { response.AppendLine(ex.Message); } return(response.ToString()); }