109 lines
4.1 KiB
C#
109 lines
4.1 KiB
C#
// Probe LECTURE SEULE de l'accès aux fichiers HFSQL nécessaires au CREATE
|
|
// Intervention E2E, via BusinessOleDbConnection + HfSqlFileAccessResolver.
|
|
// Aucune écriture. Aucun secret affiché.
|
|
using System.Text.Json;
|
|
using Omika.Data.Configuration;
|
|
using Omika.Data.HfSql.Connection;
|
|
|
|
const string ConfigPath = @"D:\Avalonia\Omika\config\hfsql-test.local.json";
|
|
|
|
if (!File.Exists(ConfigPath))
|
|
{
|
|
Console.WriteLine("CONFIG ABSENTE : " + ConfigPath);
|
|
return;
|
|
}
|
|
|
|
var json = File.ReadAllText(ConfigPath);
|
|
using var doc = JsonDocument.Parse(json);
|
|
var root = doc.RootElement;
|
|
|
|
// --- Charger la section Hfsql (BATIK_TEST) ---
|
|
if (!root.TryGetProperty("Hfsql", out var hfsql))
|
|
{
|
|
Console.WriteLine("SECTION Hfsql ABSENTE dans la config.");
|
|
return;
|
|
}
|
|
|
|
var options = new HfsqlOptions
|
|
{
|
|
ConnectionName = GetString(hfsql, "ConnectionName") ?? "Business",
|
|
Server = GetString(hfsql, "Server"),
|
|
Port = GetInt(hfsql, "Port") ?? 4900,
|
|
DatabaseName = GetString(hfsql, "DatabaseName"),
|
|
Login = GetString(hfsql, "Login"),
|
|
Password = GetString(hfsql, "Password"),
|
|
Driver = GetString(hfsql, "Driver") ?? "HFSQL Client/Server",
|
|
ConnectionTimeoutSeconds = GetInt(hfsql, "ConnectionTimeoutSeconds") ?? 30
|
|
};
|
|
|
|
// --- FilePasswords (ProtectionStd / ProtectionPlus) ---
|
|
if (hfsql.TryGetProperty("FilePasswords", out var fp))
|
|
{
|
|
options.FilePasswords = new HfSqlFilePasswordOptions
|
|
{
|
|
ProtectionStd = GetString(fp, "ProtectionStd"),
|
|
ProtectionPlus = GetString(fp, "ProtectionPlus")
|
|
};
|
|
}
|
|
|
|
bool protectionStdConfigured = !string.IsNullOrWhiteSpace(options.FilePasswords.ProtectionStd);
|
|
Console.WriteLine($"ProtectionStd configured : {(protectionStdConfigured ? "YES" : "NO")}");
|
|
Console.WriteLine($"Database : {options.DatabaseName}");
|
|
Console.WriteLine($"Server : {options.Server}:{options.Port}");
|
|
Console.WriteLine();
|
|
|
|
// --- Construire les options OLE DB ---
|
|
var oleDbOptions = HfSqlConnectionOptionsFactory.Create(options, options.FilePasswords);
|
|
var factory = new HfSqlOleDbConnectionFactory();
|
|
var resolver = new HfSqlFileAccessResolver(factory, oleDbOptions);
|
|
|
|
// --- Fichiers nécessaires au CREATE Intervention Batik ---
|
|
var files = new List<HfSqlFileAccessProfile>
|
|
{
|
|
new() { LogicalFile = "Intervention", ExpectedGroup = "ProtectionStd" },
|
|
new() { LogicalFile = "ParametreMetier", ExpectedGroup = "ProtectionStd" },
|
|
new() { LogicalFile = "Intervention_Collaborateur", ExpectedGroup = "ProtectionStd" },
|
|
new() { LogicalFile = "Intervention_Personne", ExpectedGroup = "ProtectionStd" },
|
|
new() { LogicalFile = "EtatIntervention", ExpectedGroup = "ProtectionStd" }
|
|
};
|
|
|
|
try
|
|
{
|
|
var result = await resolver.ResolveAsync(files);
|
|
|
|
Console.WriteLine("=== Résolution d'accès (lecture seule) ===");
|
|
bool allOk = true;
|
|
foreach (var file in files)
|
|
{
|
|
var profile = result[file.LogicalFile];
|
|
string status = profile.ObservedAccess switch
|
|
{
|
|
HfSqlFileAccessMode.Direct => "DIRECT",
|
|
HfSqlFileAccessMode.ProtectionStd => "PROTECTION_STD",
|
|
HfSqlFileAccessMode.ProtectionPlus => "PROTECTION_PLUS",
|
|
HfSqlFileAccessMode.Failed => "FAILED",
|
|
_ => profile.ObservedAccess.ToString()
|
|
};
|
|
string error = profile.HfSqlErrorCode is null ? "" : $" (HFSQL code {profile.HfSqlErrorCode})";
|
|
Console.WriteLine($" {file.LogicalFile,-30} : {status}{error}");
|
|
if (profile.ObservedAccess == HfSqlFileAccessMode.Failed)
|
|
allOk = false;
|
|
}
|
|
|
|
Console.WriteLine();
|
|
Console.WriteLine(allOk
|
|
? "RESULTAT : TOUS LES FICHIERS ACCESSIBLES"
|
|
: "RESULTAT : AU MOINS UN FICHIER INACCESSIBLE");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"ERREUR GLOBALE : {ex.Message}");
|
|
Console.WriteLine($" Type : {ex.GetType().FullName}");
|
|
}
|
|
|
|
static string? GetString(JsonElement el, string name)
|
|
=> el.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.String ? v.GetString() : null;
|
|
|
|
static int? GetInt(JsonElement el, string name)
|
|
=> el.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.Number ? v.GetInt32() : null;
|