Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.21.10</Version>
<Version>10.30.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Live Integration</Title>
<Description>Live Integration</Description>
Expand All @@ -14,7 +14,7 @@
<Copyright>Copyright © 2023 Dynamicweb Software A/S</Copyright>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -23,12 +23,12 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.Core" Version="10.21.5" />
<PackageReference Include="Dynamicweb.CoreUI" Version="10.21.5" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.21.5" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.21.5" />
<PackageReference Include="Dynamicweb.Ecommerce.UI" Version="10.21.5" />
<PackageReference Include="System.ServiceModel.Primitives" Version="8.0.0" />
<PackageReference Include="Dynamicweb.Core" Version="10.30.6" />
<PackageReference Include="Dynamicweb.CoreUI" Version="10.30.6" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.30.6" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.30.6" />
<PackageReference Include="Dynamicweb.Ecommerce.UI" Version="10.30.6" />
<PackageReference Include="System.ServiceModel.Primitives" Version="10.1.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<string, LicenseStatus> EndpointCollection = new ConcurrentDictionary<string, LicenseStatus>();
private static readonly Version D365BCMinVersion = new Version(13, 0, 0, 0);
private static readonly Version D365BCMaxVersion = new Version(101, 0, 0, 0);
Expand All @@ -19,7 +22,7 @@ private static bool IsBCFeatureEnabled
{
get
{
return Security.Licensing.LicenseManager.LicenseHasFeature("eCom_DataIntegrationERPLiveIntegration_BC");
return Security.Licensing.LicenseManager.LicenseHasFeature(BCFeatureName);
}
}

Expand All @@ -36,6 +39,26 @@ internal static bool IsLicenseValid(string endpoint)
}
}

/// <summary>
/// Gets the license feature that the last validated response from any of the endpoints needed but the license does not have.
/// </summary>
internal static string GetMissingLicenseFeature(IEnumerable<string> 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);
Expand Down Expand Up @@ -113,23 +136,26 @@ 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)
{
isFeatureEnabled = IsBCFeatureEnabled;
}
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))
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,5 +45,10 @@ public void SetFeatureEnabled(bool enabled)
{
IsFeatureEnabled = enabled;
}

public void SetFeatureMissing(bool missing)
{
IsFeatureMissing = missing;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,27 @@ private Settings GetCurrentSettings()
return settings;
}

/// <summary>
/// Gets the license feature that the ERP responses of this instance need but the license does not have.
/// </summary>
/// <returns>The missing license feature name, or <c>null</c> when nothing is missing or no response has been validated yet.</returns>
public override string GetMissingLicenseFeature()
{
Settings settings = GetCurrentSettings();
IEnumerable<string> 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);
}

/// <summary>
/// Check if the web service is available for the live integration
/// </summary>
Expand Down
Loading