From b0647b85d1809cf7836d96a199dc14c502c30385 Mon Sep 17 00:00:00 2001 From: Mirko Schimandl Date: Thu, 13 Jun 2024 16:48:11 +0200 Subject: [PATCH 1/2] Show License Status on the Dashboard when no license is installed but required --- ...icationOverviewDashboardContentRenderer.cs | 304 +++++++++--------- 1 file changed, 154 insertions(+), 150 deletions(-) diff --git a/MFiles.VAF.Extensions/Dashboards/ApplicationOverviewDashboardContent/DefaultApplicationOverviewDashboardContentRenderer.cs b/MFiles.VAF.Extensions/Dashboards/ApplicationOverviewDashboardContent/DefaultApplicationOverviewDashboardContentRenderer.cs index eacd1f6..558ae04 100644 --- a/MFiles.VAF.Extensions/Dashboards/ApplicationOverviewDashboardContent/DefaultApplicationOverviewDashboardContentRenderer.cs +++ b/MFiles.VAF.Extensions/Dashboards/ApplicationOverviewDashboardContent/DefaultApplicationOverviewDashboardContentRenderer.cs @@ -66,7 +66,7 @@ public class DefaultApplicationOverviewDashboardContentRenderer vaultApplication) { - this.VaultApplication = vaultApplication + this.VaultApplication = vaultApplication ?? throw new ArgumentNullException(nameof(vaultApplication)); } @@ -79,7 +79,7 @@ public virtual IDashboardContent GetDashboardContent() var content = new DashboardContentCollection(); IDashboardContent root = content; - if(this.VaultApplication.DashboardLogo != null) + if (this.VaultApplication.DashboardLogo != null) { // Create a table so we can put the logo on as well. var table = new DashboardTable(); @@ -111,7 +111,7 @@ public virtual IDashboardContent GetDashboardContent() { var licensingPanel = this.GetLicensingDetailsDashboardContent ( - this.VaultApplication?.License?.Content(), + this.VaultApplication?.License ?? null, this.VaultApplication?.License?.ServerLicense ); if (null != licensingPanel) @@ -127,10 +127,10 @@ public virtual IDashboardContent GetDashboardContent() /// Generates the "Licensing Status" dashboard content. /// /// The dashboard panel, or null if nothing should be shown. - public virtual DashboardPanelEx GetLicensingDetailsDashboardContent(TLicenseContent licenseContent, LicenseStatus serverLicenseStatus) + public virtual DashboardPanelEx GetLicensingDetailsDashboardContent(IApplicationLicense applicationLicense, LicenseStatus serverLicenseStatus) { // Sanity. - if (null == licenseContent || false == this.ShowLicenseStatus) + if (null == applicationLicense || false == this.ShowLicenseStatus) return null; // Let's generate the various statements! @@ -138,209 +138,213 @@ public virtual DashboardPanelEx GetLicensingDetailsDashboardContent(TLicenseCont // General status. { - var licenseStatus = this.GetLicenseStatusDashboardContent(licenseContent.LicenseStatus); - if(null != licenseStatus) + var licenseStatus = this.GetLicenseStatusDashboardContent(applicationLicense.LicenseStatus); + if (null != licenseStatus) content.Add(licenseStatus); } - // Who is it licensed to? + var licenseContent = applicationLicense?.Content(); + if (null != licenseContent) { - if (false == string.IsNullOrWhiteSpace(licenseContent?.LicensedTo)) - content.Add(this.GetStatementDashboardContent - ( - string.Format(Resources.Licensing.LicensingStatusPanel_LicensedTo, licenseContent?.LicensedTo), - StatementType.Okay - )); - } - - // Is it okay for this serial number? - { - var serialNumber = serverLicenseStatus?.SerialNumber; - if(false == string.IsNullOrWhiteSpace(licenseContent.MFilesSerialNumber)) - content.Add(this.GetTernaryStatementDashboardContent - ( - serialNumber == licenseContent.MFilesSerialNumber, - Resources.Licensing.LicensingStatusPanel_ValidForThisServer, - Resources.Licensing.LicensingStatusPanel_NotValidForThisServer - )); - } - - // Server version? - { - if (licenseContent.ServerVersions?.Any() ?? false) - { - MFilesVersion serverVersion = this.VaultApplication.PermanentVault.GetServerVersionOfVault(); - content.Add(this.GetTernaryStatementDashboardContent - ( - licenseContent.ServerVersions.Any((string f) => VersionMatch(serverVersion, f)), - Resources.Licensing.LicensingStatusPanel_ValidInThisServerVersion, - string.Format(Resources.Licensing.LicensingStatusPanel_NotValidInThisServerVersion, serverVersion?.ToString()) - )); - } - } - - // Is it okay in this vault? - { - if (licenseContent.Vaults?.Any() ?? false) + // Who is it licensed to? { - var vaultGuid = this.VaultApplication.PermanentVault.GetGUID(); - content.Add(this.GetTernaryStatementDashboardContent - ( - licenseContent.Vaults == null || licenseContent.Vaults.Any(v => v.Equals(vaultGuid, StringComparison.OrdinalIgnoreCase)), - Resources.Licensing.LicensingStatusPanel_ValidInThisVault, - string.Format(Resources.Licensing.LicensingStatusPanel_NotValidInThisVault, vaultGuid) - )); + if (false == string.IsNullOrWhiteSpace(licenseContent?.LicensedTo)) + content.Add(this.GetStatementDashboardContent + ( + string.Format(Resources.Licensing.LicensingStatusPanel_LicensedTo, licenseContent?.LicensedTo), + StatementType.Okay + )); } - } - // When does it expire? - { - if (DateTime.TryParseExact(licenseContent.LicenseExpireDate, "d.M.yyyy", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out DateTime expiry)) + // Is it okay for this serial number? { - var days = expiry.Subtract(DateTime.Now).Days; - content.Add(this.GetTernaryStatementDashboardContent - ( - expiry > DateTime.Now, - string.Format(Resources.Licensing.LicensingStatusPanel_LicenseExpiresInXXXXDays, days), - string.Format(Resources.Licensing.LicensingStatusPanel_LicenseExpiredXXXXDaysAgo, DateTime.Now.Subtract(expiry).Days), - successfulStatementType: days > 30 - ? StatementType.Okay - : StatementType.Warning - )); + var serialNumber = serverLicenseStatus?.SerialNumber; + if (false == string.IsNullOrWhiteSpace(licenseContent.MFilesSerialNumber)) + content.Add(this.GetTernaryStatementDashboardContent + ( + serialNumber == licenseContent.MFilesSerialNumber, + Resources.Licensing.LicensingStatusPanel_ValidForThisServer, + Resources.Licensing.LicensingStatusPanel_NotValidForThisServer + )); } - } - // Maintenance. - { - if (DateTime.TryParseExact(licenseContent.MaintenanceExpireDate, "d.M.yyyy", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out DateTime expiry)) + // Server version? { - var days = expiry.Subtract(DateTime.Now).Days; - content.Add(this.GetTernaryStatementDashboardContent - ( - expiry > DateTime.Now, - string.Format(Resources.Licensing.LicensingStatusPanel_MaintenanceExpiresInXXXXDays, days), - string.Format(Resources.Licensing.LicensingStatusPanel_MaintenanceExpiredXXXXDaysAgo, DateTime.Now.Subtract(expiry).Days), - successfulStatementType: days > 30 - ? StatementType.Okay - : StatementType.Warning - )); + if (licenseContent.ServerVersions?.Any() ?? false) + { + MFilesVersion serverVersion = this.VaultApplication.PermanentVault.GetServerVersionOfVault(); + content.Add(this.GetTernaryStatementDashboardContent + ( + licenseContent.ServerVersions.Any((string f) => VersionMatch(serverVersion, f)), + Resources.Licensing.LicensingStatusPanel_ValidInThisServerVersion, + string.Format(Resources.Licensing.LicensingStatusPanel_NotValidInThisServerVersion, serverVersion?.ToString()) + )); + } } - } - // Users. - { - // Named users. - if(licenseContent.NamedUsers >= 0) + // Is it okay in this vault? { + if (licenseContent.Vaults?.Any() ?? false) { - var licensed = licenseContent.NamedUsers; - var used = serverLicenseStatus.NumOfNamedUserLicenses; + var vaultGuid = this.VaultApplication.PermanentVault.GetGUID(); content.Add(this.GetTernaryStatementDashboardContent ( - used == -1 || licensed >= used, - string.Format(Resources.Licensing.LicensingStatusPanel_NamedUsers_Valid, licensed, used == -1 ? "unlimited" : used.ToString()), - string.Format(Resources.Licensing.LicensingStatusPanel_NamedUsers_Exceeded, licensed, used == -1 ? "unlimited" : used.ToString()) + licenseContent.Vaults == null || licenseContent.Vaults.Any(v => v.Equals(vaultGuid, StringComparison.OrdinalIgnoreCase)), + Resources.Licensing.LicensingStatusPanel_ValidInThisVault, + string.Format(Resources.Licensing.LicensingStatusPanel_NotValidInThisVault, vaultGuid) )); } } - // Concurrent users. - if (licenseContent.ConcurrentUsers >= 0) + // When does it expire? { + if (DateTime.TryParseExact(licenseContent.LicenseExpireDate, "d.M.yyyy", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out DateTime expiry)) { - var licensed = licenseContent.ConcurrentUsers; - var used = serverLicenseStatus.NumOfConcurrentUserLicenses; + var days = expiry.Subtract(DateTime.Now).Days; content.Add(this.GetTernaryStatementDashboardContent ( - used == -1 || licensed >= used, - string.Format(Resources.Licensing.LicensingStatusPanel_ConcurrentUsers_Valid, licensed, used == -1 ? "unlimited" : used.ToString()), - string.Format(Resources.Licensing.LicensingStatusPanel_ConcurrentUsers_Exceeded, licensed, used == -1 ? "unlimited" : used.ToString()) + expiry > DateTime.Now, + string.Format(Resources.Licensing.LicensingStatusPanel_LicenseExpiresInXXXXDays, days), + string.Format(Resources.Licensing.LicensingStatusPanel_LicenseExpiredXXXXDaysAgo, DateTime.Now.Subtract(expiry).Days), + successfulStatementType: days > 30 + ? StatementType.Okay + : StatementType.Warning )); } } - // Read-only users. - if (licenseContent.ReadOnlyUsers >= 0) + // Maintenance. { + if (DateTime.TryParseExact(licenseContent.MaintenanceExpireDate, "d.M.yyyy", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out DateTime expiry)) { - var licensed = licenseContent.ReadOnlyUsers; - var used = serverLicenseStatus.NumOfReadonlyLicenses; + var days = expiry.Subtract(DateTime.Now).Days; content.Add(this.GetTernaryStatementDashboardContent ( - used == -1 || licensed >= used, - string.Format(Resources.Licensing.LicensingStatusPanel_ReadOnlyUsers_Valid, licensed, used == -1 ? "unlimited" : used.ToString()), - string.Format(Resources.Licensing.LicensingStatusPanel_ReadOnly_Exceeded, licensed, used == -1 ? "unlimited" : used.ToString()) + expiry > DateTime.Now, + string.Format(Resources.Licensing.LicensingStatusPanel_MaintenanceExpiresInXXXXDays, days), + string.Format(Resources.Licensing.LicensingStatusPanel_MaintenanceExpiredXXXXDaysAgo, DateTime.Now.Subtract(expiry).Days), + successfulStatementType: days > 30 + ? StatementType.Okay + : StatementType.Warning )); } } - } - // Groups. - { - if(licenseContent.Groups?.Any() ?? false) + // Users. { - foreach (var group in licenseContent.Groups) + // Named users. + if (licenseContent.NamedUsers >= 0) { - if (null == group || string.IsNullOrWhiteSpace(group.Group)) - continue; - int userGroupIDByAlias = this.VaultApplication.PermanentVault.UserGroupOperations.GetUserGroupIDByAlias(group.Group); - if (userGroupIDByAlias != -1) { - UserGroup userGroup = this.VaultApplication.PermanentVault.UserGroupOperations.GetUserGroupAdmin(userGroupIDByAlias).UserGroup; + var licensed = licenseContent.NamedUsers; + var used = serverLicenseStatus.NumOfNamedUserLicenses; content.Add(this.GetTernaryStatementDashboardContent ( - userGroup.Members.Count > group.Len, - string.Format(Resources.Licensing.LicensingStatusPanel_GroupMembership_Exceeded, group.Group, group.Len, userGroup.Members.Count), - string.Format(Resources.Licensing.LicensingStatusPanel_GroupMembership_Valid, group.Group, group.Len, userGroup.Members.Count) + used == -1 || licensed >= used, + string.Format(Resources.Licensing.LicensingStatusPanel_NamedUsers_Valid, licensed, used == -1 ? "unlimited" : used.ToString()), + string.Format(Resources.Licensing.LicensingStatusPanel_NamedUsers_Exceeded, licensed, used == -1 ? "unlimited" : used.ToString()) )); } } - } - } - // Modules. - { - if (licenseContent.Modules?.Any() ?? false) - { - var modules = new DashboardContentCollection + // Concurrent users. + if (licenseContent.ConcurrentUsers >= 0) { - new DashboardCustomContentEx($"

The following modules are licensed:

") - }; + { + var licensed = licenseContent.ConcurrentUsers; + var used = serverLicenseStatus.NumOfConcurrentUserLicenses; + content.Add(this.GetTernaryStatementDashboardContent + ( + used == -1 || licensed >= used, + string.Format(Resources.Licensing.LicensingStatusPanel_ConcurrentUsers_Valid, licensed, used == -1 ? "unlimited" : used.ToString()), + string.Format(Resources.Licensing.LicensingStatusPanel_ConcurrentUsers_Exceeded, licensed, used == -1 ? "unlimited" : used.ToString()) + )); + } + } - // If we know about all the modules then we can show the ones that are unlicensed too. - if (this.AllModules?.Any() ?? false) + // Read-only users. + if (licenseContent.ReadOnlyUsers >= 0) { - // We have more details about the modules - foreach (var kvp in this.AllModules) { - modules.Add + var licensed = licenseContent.ReadOnlyUsers; + var used = serverLicenseStatus.NumOfReadonlyLicenses; + content.Add(this.GetTernaryStatementDashboardContent ( - this.GetTernaryStatementDashboardContent - ( - licenseContent.Modules.Contains(kvp.Key), - kvp.Value, // Use the same value for success and failure. - kvp.Value, // Use the same value for success and failure. - failureStatementType: StatementType.Unknown // Unlicensed modules is not an error or warning. - ) - ); + used == -1 || licensed >= used, + string.Format(Resources.Licensing.LicensingStatusPanel_ReadOnlyUsers_Valid, licensed, used == -1 ? "unlimited" : used.ToString()), + string.Format(Resources.Licensing.LicensingStatusPanel_ReadOnly_Exceeded, licensed, used == -1 ? "unlimited" : used.ToString()) + )); } } - else + } + + // Groups. + { + if (licenseContent.Groups?.Any() ?? false) { - // We can just list out the data that was in the license. - foreach (var module in licenseContent.Modules) + foreach (var group in licenseContent.Groups) { - modules.Add(this.GetStatementDashboardContent(module, StatementType.Okay)); + if (null == group || string.IsNullOrWhiteSpace(group.Group)) + continue; + int userGroupIDByAlias = this.VaultApplication.PermanentVault.UserGroupOperations.GetUserGroupIDByAlias(group.Group); + if (userGroupIDByAlias != -1) + { + UserGroup userGroup = this.VaultApplication.PermanentVault.UserGroupOperations.GetUserGroupAdmin(userGroupIDByAlias).UserGroup; + content.Add(this.GetTernaryStatementDashboardContent + ( + userGroup.Members.Count > group.Len, + string.Format(Resources.Licensing.LicensingStatusPanel_GroupMembership_Exceeded, group.Group, group.Len, userGroup.Members.Count), + string.Format(Resources.Licensing.LicensingStatusPanel_GroupMembership_Valid, group.Group, group.Len, userGroup.Members.Count) + )); + } } } + } - // Add the panel for the modules. - var modulesPanel = new DashboardPanelEx() + // Modules. + { + if (licenseContent.Modules?.Any() ?? false) + { + var modules = new DashboardContentCollection { - InnerContent = modules + new DashboardCustomContentEx($"

The following modules are licensed:

") }; - modulesPanel.Styles.AddOrUpdate("margin", "8px 0px"); - content.Add(modulesPanel); + + // If we know about all the modules then we can show the ones that are unlicensed too. + if (this.AllModules?.Any() ?? false) + { + // We have more details about the modules + foreach (var kvp in this.AllModules) + { + modules.Add + ( + this.GetTernaryStatementDashboardContent + ( + licenseContent.Modules.Contains(kvp.Key), + kvp.Value, // Use the same value for success and failure. + kvp.Value, // Use the same value for success and failure. + failureStatementType: StatementType.Unknown // Unlicensed modules is not an error or warning. + ) + ); + } + } + else + { + // We can just list out the data that was in the license. + foreach (var module in licenseContent.Modules) + { + modules.Add(this.GetStatementDashboardContent(module, StatementType.Okay)); + } + } + + // Add the panel for the modules. + var modulesPanel = new DashboardPanelEx() + { + InnerContent = modules + }; + modulesPanel.Styles.AddOrUpdate("margin", "8px 0px"); + content.Add(modulesPanel); + } } } @@ -361,7 +365,7 @@ public virtual DashboardPanelEx GetLicensingDetailsDashboardContent(TLicenseCont /// /// The dashboard panel, or null if nothing should be shown. public virtual DashboardPanelEx GetApplicationDetailsDashboardContent() - { + { var innerContent = new DashboardContentCollection(); var table = new DashboardTable(); @@ -401,7 +405,7 @@ public virtual DashboardPanelEx GetApplicationDetailsDashboardContent() // Add a marker to say whether this is MSM-compatible. if (this.ShowMultiServerModeStatus) { - var element = + var element = ApplicationDefinition.MultiServerCompatible ? this.GetStatementDashboardContent(Resources.Licensing.ApplicationDetailsPanel_ApplicationIsMultiServerModeCompatible, StatementType.Okay) : this.GetStatementDashboardContent(Resources.Licensing.ApplicationDetailsPanel_ApplicationIsNotMultiServerModeCompatible, StatementType.Error); From 2fb9b283725ae3e2b2515245b5a62235d1f4fd3c Mon Sep 17 00:00:00 2001 From: Mirko Schimandl Date: Fri, 14 Jun 2024 12:56:24 +0200 Subject: [PATCH 2/2] Show License Status on the Dashboard when no license is installed but required --- .../DefaultApplicationOverviewDashboardContentRenderer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MFiles.VAF.Extensions/Dashboards/ApplicationOverviewDashboardContent/DefaultApplicationOverviewDashboardContentRenderer.cs b/MFiles.VAF.Extensions/Dashboards/ApplicationOverviewDashboardContent/DefaultApplicationOverviewDashboardContentRenderer.cs index 558ae04..7d98337 100644 --- a/MFiles.VAF.Extensions/Dashboards/ApplicationOverviewDashboardContent/DefaultApplicationOverviewDashboardContentRenderer.cs +++ b/MFiles.VAF.Extensions/Dashboards/ApplicationOverviewDashboardContent/DefaultApplicationOverviewDashboardContentRenderer.cs @@ -111,7 +111,7 @@ public virtual IDashboardContent GetDashboardContent() { var licensingPanel = this.GetLicensingDetailsDashboardContent ( - this.VaultApplication?.License ?? null, + this.VaultApplication?.License, this.VaultApplication?.License?.ServerLicense ); if (null != licensingPanel)