Disable place_order without Enova credentials

This commit is contained in:
2026-08-26 17:01:57 +00:00
parent f15f46945d
commit a92293eefa
5 changed files with 110 additions and 47 deletions

View File

@@ -48,19 +48,22 @@ public sealed class ServiceSettings
public RuntimeSettings ResolveRuntimeSettings()
{
var enovaPassword = Enova.Password
?? throw new ConfigurationException("Parametr 'enova.password' jest wymagany.");
var installationPath = Path.GetFullPath(
Environment.ExpandEnvironmentVariables(Enova.InstallationPath));
return new RuntimeSettings(
installationPath,
new EnovaAdapterConfiguration(
new EnovaConnectionOptions(Enova.Database, Enova.Operator, enovaPassword),
EnovaAdapterConfiguration? enovaConfiguration = null;
if (!string.IsNullOrWhiteSpace(Enova.Operator) && Enova.Password is not null)
{
enovaConfiguration = new EnovaAdapterConfiguration(
new EnovaConnectionOptions(Enova.Database, Enova.Operator, Enova.Password),
Enova.DocumentDefinition,
Enova.DefaultWarehouseCode,
Enova.SaveMode),
Enova.SaveMode);
}
return new RuntimeSettings(
installationPath,
enovaConfiguration,
Sql.ConnectionString,
Sql.CommandTimeoutSeconds,
ResolvePath(Diagnostics.LogDirectory),
@@ -78,8 +81,6 @@ public sealed class ServiceSettings
}
Require(Enova.InstallationPath, "enova.installationPath", errors);
Require(Enova.Database, "enova.database", errors);
Require(Enova.Operator, "enova.operator", errors);
RequirePresent(Enova.Password, "enova.password", errors);
Require(Enova.DocumentDefinition, "enova.documentDefinition", errors);
Require(Sql.ConnectionString, "sql.connectionString", errors);
if (Sql.CommandTimeoutSeconds <= 0)
@@ -101,14 +102,6 @@ public sealed class ServiceSettings
}
}
private static void RequirePresent(string? value, string name, ICollection<string> errors)
{
if (value is null)
{
errors.Add($"Parametr '{name}' jest wymagany.");
}
}
private static string ResolvePath(string path) =>
Path.IsPathRooted(path) ? Path.GetFullPath(path) : Path.GetFullPath(path, AppContext.BaseDirectory);
}
@@ -126,7 +119,7 @@ public sealed class EnovaSettings
public string Database { get; init; } = string.Empty;
public string Operator { get; init; } = "Administrator";
public string? Operator { get; init; }
public string? Password { get; init; }
@@ -153,7 +146,7 @@ public sealed class DiagnosticsSettings
public sealed record RuntimeSettings(
string EnovaInstallationPath,
EnovaAdapterConfiguration EnovaConfiguration,
EnovaAdapterConfiguration? EnovaConfiguration,
string SqlConnectionString,
int SqlCommandTimeoutSeconds,
string LogDirectory,

View File

@@ -7,13 +7,13 @@ namespace SmartB2B.Enova.Service.Diagnostics;
public sealed partial class DiagnosticsHandler
{
private readonly EnovaAdapterInfo _adapterInfo;
private readonly EnovaAdapterInfo? _adapterInfo;
private readonly string _enovaPath;
private readonly string _logDirectory;
private readonly string _logPrefix;
public DiagnosticsHandler(
EnovaAdapterInfo adapterInfo,
EnovaAdapterInfo? adapterInfo,
string enovaPath,
string logDirectory,
string logPrefix)
@@ -35,16 +35,25 @@ public sealed partial class DiagnosticsHandler
{
cancellationToken.ThrowIfCancellationRequested();
var serviceVersion = Assembly.GetExecutingAssembly().GetName().Version?.ToString(3) ?? "unknown";
var lines = new[]
var lines = new List<string>
{
$"SmartB2B Enova Sync version: {serviceVersion}",
$".NET version: {Environment.Version}",
$"Adapter version: {_adapterInfo.AdapterVersion}",
$"Soneta.Business version: {_adapterInfo.SonetaBusinessVersion}",
$"Soneta.Handel version: {_adapterInfo.SonetaHandelVersion}",
$"Enova path: {_enovaPath}",
$"Database: {_adapterInfo.DatabaseName}"
$"Enova path: {_enovaPath}"
};
if (_adapterInfo is null)
{
lines.Add("Adapter Enovy: nie zainicjalizowano (place_order jest wyłączony)");
}
else
{
lines.Add($"Adapter version: {_adapterInfo.AdapterVersion}");
lines.Add($"Soneta.Business version: {_adapterInfo.SonetaBusinessVersion}");
lines.Add($"Soneta.Handel version: {_adapterInfo.SonetaHandelVersion}");
lines.Add($"Database: {_adapterInfo.DatabaseName}");
}
return Task.FromResult<object?>(string.Join(Environment.NewLine, lines));
}

View File

@@ -1,3 +1,4 @@
using SmartB2B.Enova.Contracts;
using SmartB2B.Enova.Service.Configuration;
using SmartB2B.Enova.Service.Diagnostics;
using SmartB2B.Enova.Service.Orders;
@@ -28,7 +29,21 @@ internal static class Program
using var adapterLoader = new EnovaAdapterLoader(runtime.EnovaInstallationPath);
var adapter = adapterLoader.Load();
var adapterInfo = adapter.Initialize(runtime.EnovaConfiguration);
EnovaAdapterInfo? adapterInfo = null;
if (runtime.EnovaConfiguration is not null)
{
adapterInfo = adapter.Initialize(runtime.EnovaConfiguration);
Console.WriteLine(
$"Załadowano Enovę {adapterInfo.SonetaBusinessVersion} z '{runtime.EnovaInstallationPath}'.");
Console.WriteLine($"Baza: {adapterInfo.DatabaseName}; portal WAMP: {settings.Portal}.");
}
else
{
Console.WriteLine(
"Nie podano enova.operator lub enova.password; endpoint eu.smartb2b.place_order jest wyłączony.");
Console.WriteLine($"Portal WAMP: {settings.Portal}.");
}
_ = new System.Data.Common.DbConnectionStringBuilder
{
@@ -38,32 +53,32 @@ internal static class Program
runtime.SqlConnectionString,
runtime.SqlCommandTimeoutSeconds);
Console.WriteLine(
$"Załadowano Enovę {adapterInfo.SonetaBusinessVersion} z '{runtime.EnovaInstallationPath}'.");
Console.WriteLine($"Baza: {adapterInfo.DatabaseName}; portal WAMP: {settings.Portal}.");
if (commandLine.CheckConfigurationOnly)
{
Console.WriteLine("Konfiguracja i adapter Enovy są poprawne.");
Console.WriteLine(runtime.EnovaConfiguration is null
? "Konfiguracja jest poprawna; endpoint place_order pozostaje wyłączony."
: "Konfiguracja i adapter Enovy są poprawne.");
return 0;
}
var orders = new PlaceOrderHandler(adapter, runtime.EnovaConfiguration);
var diagnostics = new DiagnosticsHandler(
adapterInfo,
runtime.EnovaInstallationPath,
runtime.LogDirectory,
runtime.LogPrefix);
IReadOnlyList<IWampRpcOperation> operations =
[
new DelegateRpcOperation("eu.smartb2b.place_order", orders.HandleAsync),
new DelegateRpcOperation("eu.smartb2b.sql_raw", sql.HandleAsync),
new DelegateRpcOperation("eu.smartb2b.sync.get_version", diagnostics.GetVersionAsync),
new DelegateRpcOperation("eu.smartb2b.sync.get_info", diagnostics.GetInfoAsync),
new DelegateRpcOperation("eu.smartb2b.sync.get_log", diagnostics.GetLogAsync),
new DelegateRpcOperation("eu.smartb2b.sync.get_error_log", diagnostics.GetErrorLogAsync)
];
var operations = new List<IWampRpcOperation>();
if (runtime.EnovaConfiguration is not null)
{
var orders = new PlaceOrderHandler(adapter, runtime.EnovaConfiguration);
operations.Add(new DelegateRpcOperation("eu.smartb2b.place_order", orders.HandleAsync));
}
operations.Add(new DelegateRpcOperation("eu.smartb2b.sql_raw", sql.HandleAsync));
operations.Add(new DelegateRpcOperation("eu.smartb2b.sync.get_version", diagnostics.GetVersionAsync));
operations.Add(new DelegateRpcOperation("eu.smartb2b.sync.get_info", diagnostics.GetInfoAsync));
operations.Add(new DelegateRpcOperation("eu.smartb2b.sync.get_log", diagnostics.GetLogAsync));
operations.Add(new DelegateRpcOperation("eu.smartb2b.sync.get_error_log", diagnostics.GetErrorLogAsync));
var wampClient = new WampServiceClient(
settings.Wamp.ServerUrl,