diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj index bab04e3..3837f19 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj @@ -1,6 +1,6 @@  - 10.21.10 + 10.30.0 1.0.0.0 Live Integration Live Integration @@ -14,7 +14,7 @@ Copyright © 2023 Dynamicweb Software A/S - net8.0 + net10.0 true true true @@ -23,12 +23,12 @@ snupkg - - - - - - + + + + + + diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Licensing/LicenseService.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Licensing/LicenseService.cs index 42eb3b7..f1dd3f5 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Licensing/LicenseService.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Licensing/LicenseService.cs @@ -1,6 +1,7 @@ using Dynamicweb.Configuration; using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration; using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Logging; +using Dynamicweb.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -11,6 +12,8 @@ namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Licensing { internal class LicenseService { + internal const string BCFeatureName = "eCom_DataIntegrationERPLiveIntegration_BC"; + private static readonly ILogger SystemLogger = LogManager.System.GetLogger(LogCategory.DataIntegration, "LiveIntegration"); private static readonly ConcurrentDictionary EndpointCollection = new ConcurrentDictionary(); private static readonly Version D365BCMinVersion = new Version(13, 0, 0, 0); private static readonly Version D365BCMaxVersion = new Version(101, 0, 0, 0); @@ -19,7 +22,7 @@ private static bool IsBCFeatureEnabled { get { - return Security.Licensing.LicenseManager.LicenseHasFeature("eCom_DataIntegrationERPLiveIntegration_BC"); + return Security.Licensing.LicenseManager.LicenseHasFeature(BCFeatureName); } } @@ -36,6 +39,26 @@ internal static bool IsLicenseValid(string endpoint) } } + /// + /// Gets the license feature that the last validated response from any of the endpoints needed but the license does not have. + /// + internal static string GetMissingLicenseFeature(IEnumerable endpoints) + { + if (IsBCFeatureEnabled) + { + return null; + } + foreach (string endpoint in endpoints.Where(e => !string.IsNullOrEmpty(e))) + { + LicenseStatus status = GetStatus(endpoint); + if (status != null && status.IsFeatureMissing) + { + return BCFeatureName; + } + } + return null; + } + private static LicenseStatus GetStatus(string endpoint) { EndpointCollection.TryGetValue(endpoint, out LicenseStatus status); @@ -113,7 +136,7 @@ private static void ValidateLicense(LicenseStatus status, XmlAttribute versionAt { if (versionAttribute != null) { - bool isValid = IsVersionValid(versionAttribute.Value, logger); + bool isValid = IsVersionValid(versionAttribute.Value, logger, out bool isFeatureMissing); bool isFeatureEnabled = true; if (!isValid) { @@ -121,15 +144,18 @@ private static void ValidateLicense(LicenseStatus status, XmlAttribute versionAt } status.UpdateStatus(isValid); status.SetFeatureEnabled(isFeatureEnabled); + status.SetFeatureMissing(isFeatureMissing); } else { status.UpdateStatus(true); + status.SetFeatureMissing(false); } } - private static bool IsVersionValid(string version, Logger logger) + private static bool IsVersionValid(string version, Logger logger, out bool isFeatureMissing) { + isFeatureMissing = false; if (VersionInfo.TryParse(version, logger, out VersionInfo erpVersion)) { if (!string.IsNullOrEmpty(erpVersion.ServerVersion) && VersionInfo.TryParseServerVersion(erpVersion.ServerVersion, logger, out Version navServerVersion)) @@ -145,7 +171,10 @@ private static bool IsVersionValid(string version, Logger logger) } else { - logger.Log(ErrorLevel.Error, $"License is not valid."); + isFeatureMissing = true; + string message = $"License is not valid: the license is missing the '{BCFeatureName}' module required for the ERP version '{version}'."; + logger.Log(ErrorLevel.Error, message); + SystemLogger.Error($"Live Integration: {message}"); return false; } } diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Licensing/LicenseStatus.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Licensing/LicenseStatus.cs index 06013c8..fab575f 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Licensing/LicenseStatus.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Licensing/LicenseStatus.cs @@ -9,6 +9,8 @@ internal class LicenseStatus internal bool? IsFeatureEnabled { get; private set; } + internal bool IsFeatureMissing { get; private set; } + public DateTime? LastUpdateTime { get; set; } public bool Expired @@ -43,5 +45,10 @@ public void SetFeatureEnabled(bool enabled) { IsFeatureEnabled = enabled; } + + public void SetFeatureMissing(bool missing) + { + IsFeatureMissing = missing; + } } } diff --git a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/LiveIntegrationAddIn.cs b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/LiveIntegrationAddIn.cs index c4ee907..59039bd 100644 --- a/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/LiveIntegrationAddIn.cs +++ b/src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/LiveIntegrationAddIn.cs @@ -829,6 +829,27 @@ private Settings GetCurrentSettings() return settings; } + /// + /// Gets the license feature that the ERP responses of this instance need but the license does not have. + /// + /// The missing license feature name, or null when nothing is missing or no response has been validated yet. + public override string GetMissingLicenseFeature() + { + Settings settings = GetCurrentSettings(); + IEnumerable urls; + if (!string.IsNullOrEmpty(settings.Endpoint)) + { + var logger = new Logger(settings); + urls = UrlHandler.GetEndpointUrls(settings.Endpoint) + .Select(endpointId => UrlHandler.Instance.GetEndpoint(endpointId, false, logger, null, SubmitType.Backend)?.Url); + } + else + { + urls = UrlHandler.GetWebServiceUrls(settings.WebServiceURI).Select(UrlHandler.GetUrl); + } + return Licensing.LicenseService.GetMissingLicenseFeature(urls); + } + /// /// Check if the web service is available for the live integration ///