refactor: save current workspace state including FinlyticAnalyzer fixes, FinlyticApp trade route alignment, and DTO audit documentation

This commit is contained in:
2026-08-12 18:30:42 +02:00
parent a9553e9fbf
commit 3d8af3940b
163 changed files with 3421 additions and 1751 deletions
+67 -48
View File
@@ -40,10 +40,12 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
{
Host = _configuration["MQTT:Host"] ?? _configuration["MQTT__Host"] ?? "localhost",
Port = Convert.ToInt32(_configuration["MQTT:Port"] ?? _configuration["MQTT__Port"] ?? "1883"),
ClientId = $"{(_configuration["MQTT:ClientId"] ?? _configuration["MQTT__ClientId"] ?? "FinlyticNews")}_{Guid.NewGuid()}"
ClientId =
$"{(_configuration["MQTT:ClientId"] ?? _configuration["MQTT__ClientId"] ?? "FinlyticNews")}_{Guid.NewGuid()}"
};
_logger.LogInformation("Starting News MQTT client. Host: {Host}, ClientId: {ClientId}", config.Host, config.ClientId);
_logger.LogInformation("Starting News MQTT client. Host: {Host}, ClientId: {ClientId}", config.Host,
config.ClientId);
await ConnectAsync(config);
}
@@ -58,7 +60,7 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
protected override async Task OnConnectedAsync()
{
_logger.LogInformation("News MQTT client connected. Subscribing to RPC topics...");
// ZUSAMMENGELEGT: Unified News Fetching (news_Get deckt news_GetDaily mit ab)
await SubscribeAsync("services/request/news_Get/#");
await SubscribeAsync("services/request/news_GetById/#");
@@ -99,6 +101,7 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
{
await OnConfigUpdatedAsync(payload);
}
return;
}
@@ -112,7 +115,6 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
switch (channel)
{
case "news_Get":
case "news_GetDaily": // Abwärtskompatibel weitergeleitet
await OnGetNewsAsync(payload, correlationId);
break;
@@ -153,40 +155,28 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
{
try
{
using var doc = JsonDocument.Parse(payload);
var root = doc.RootElement;
if (root.TryGetProperty("limit", out var limitProp) && limitProp.TryGetInt32(out var parsedLimit)) limit = parsedLimit;
if (root.TryGetProperty("offset", out var offsetProp) && offsetProp.TryGetInt32(out var parsedOffset)) offset = parsedOffset;
if (root.TryGetProperty("isin", out var isinProp) && isinProp.ValueKind == JsonValueKind.String) isin = isinProp.GetString();
if (root.TryGetProperty("symbol", out var symProp) && symProp.ValueKind == JsonValueKind.String && string.IsNullOrEmpty(isin)) isin = symProp.GetString();
if (root.TryGetProperty("status", out var stProp) && stProp.ValueKind == JsonValueKind.String) status = stProp.GetString();
if (root.TryGetProperty("query", out var qProp) && qProp.ValueKind == JsonValueKind.String) searchQuery = qProp.GetString();
if (root.TryGetProperty("date", out var dProp) && dProp.ValueKind == JsonValueKind.String)
{
var dStr = dProp.GetString();
if (!string.IsNullOrWhiteSpace(dStr))
{
if (string.Equals(dStr, "today", StringComparison.OrdinalIgnoreCase))
date = DateTime.UtcNow.Date;
else if (DateTime.TryParse(dStr, out var parsedDate))
date = parsedDate.Date;
}
}
// Direktes Deserialisieren über das DailyNewsRequest-DTO
var req = JsonSerializer.Deserialize(payload, FinlyticJsonSerializerContext.Default.DailyNewsRequest);
if (root.TryGetProperty("hasSentiment", out var hsProp))
if (req != null)
{
bool isTrue = hsProp.ValueKind == JsonValueKind.True ||
(hsProp.ValueKind == JsonValueKind.String && bool.TryParse(hsProp.GetString(), out var b) && b);
if (isTrue && string.IsNullOrEmpty(status)) status = "Analyzed";
limit = req.Limit > 0 ? req.Limit : 20;
offset = req.Offset >= 0 ? req.Offset : 0;
isin = !string.IsNullOrWhiteSpace(req.Isin) ? req.Isin : null;
status = req.Status;
searchQuery = req.Query;
date = req.Date;
// Status anpassen, falls HasSentiment gesetzt ist
if (req.HasSentiment == true && string.IsNullOrEmpty(status))
{
status = "Analyzed";
}
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to parse RPC payload on news_Get");
_logger.LogWarning(ex, "Failed to parse DailyNewsRequest payload on news_Get");
}
}
@@ -199,12 +189,23 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
var dtos = (await Task.WhenAll(articles.Select(a => MapToDtoAsync(a)))).ToList();
string responseTopic = $"services/response/news_Get/{correlationId}";
_logger.LogInformation("Publishing RPC response to {ResponseTopic} with {Count} articles.", responseTopic, dtos.Count);
_logger.LogInformation("Publishing RPC response to {ResponseTopic} with {Count} articles.", responseTopic,
dtos.Count);
await PublishAsync(responseTopic, dtos);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to compile RPC response for news_Get");
// Antworte mit leerer Liste, um RPC-Timeouts im Gateway zu vermeiden
try
{
string responseTopic = $"services/response/news_Get/{correlationId}";
await PublishAsync(responseTopic, new List<NewsArticleDto>());
}
catch
{
}
}
}
@@ -221,7 +222,9 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
try
{
var request = JsonSerializer.Deserialize<ArticleRequest>(payload, FinlyticJsonSerializerContext.Default.ArticleRequest);
var request =
JsonSerializer.Deserialize<ArticleRequest>(payload,
FinlyticJsonSerializerContext.Default.ArticleRequest);
var targetIdStr = request?.ArticleId ?? request?.Id;
if (Guid.TryParse(targetIdStr, out var articleId))
@@ -256,12 +259,15 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
try
{
using var doc = JsonDocument.Parse(payload);
if (doc.RootElement.TryGetProperty("limit", out var limitProp) && limitProp.TryGetInt32(out var parsedLimit))
if (doc.RootElement.TryGetProperty("limit", out var limitProp) &&
limitProp.TryGetInt32(out var parsedLimit))
{
limit = Math.Min(parsedLimit, 10);
}
}
catch { }
catch
{
}
}
try
@@ -273,7 +279,8 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
var dtos = (await Task.WhenAll(pendingArticles.Take(limit).Select(a => MapToDtoAsync(a)))).ToList();
string responseTopic = $"services/response/news_GetPending/{correlationId}";
_logger.LogInformation("Publishing RPC news_GetPending response to {ResponseTopic} with {Count} articles.", responseTopic, dtos.Count);
_logger.LogInformation("Publishing RPC news_GetPending response to {ResponseTopic} with {Count} articles.",
responseTopic, dtos.Count);
await PublishAsync(responseTopic, dtos);
}
catch (Exception ex)
@@ -289,7 +296,8 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
try
{
var request = JsonSerializer.Deserialize<UpdateNewsStatusRequest>(payload, FinlyticJsonSerializerContext.Default.UpdateNewsStatusRequest);
var request = JsonSerializer.Deserialize<UpdateNewsStatusRequest>(payload,
FinlyticJsonSerializerContext.Default.UpdateNewsStatusRequest);
if (request != null && request.Id != Guid.Empty)
{
using var scope = _scopeFactory.CreateScope();
@@ -345,8 +353,10 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
if (isForMe)
{
string respTopic = $"services/response/health_Ping/{correlationId}";
await PublishAsync(respTopic, new ServiceHealthResponse("FinlyticNews", "Online", DateTime.UtcNow, "Connected"));
_logger.LogInformation("Responded to live health_Ping RPC request [CorrelationId: {CorrelationId}].", correlationId);
await PublishAsync(respTopic,
new ServiceHealthResponse("FinlyticNews", "Online", DateTime.UtcNow, "Connected"));
_logger.LogInformation("Responded to live health_Ping RPC request [CorrelationId: {CorrelationId}].",
correlationId);
}
}
@@ -366,15 +376,19 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
IsinAnalysisEntry? sentimentEntry = null;
// 1. Snappy Local Disk Check for Article File
var articlePath = Path.Combine(Directory.GetCurrentDirectory(), "data", "summaries", "articles", $"{targetId}.json");
var articlePath = Path.Combine(Directory.GetCurrentDirectory(), "data", "summaries", "articles",
$"{targetId}.json");
if (File.Exists(articlePath))
{
try
{
var json = await File.ReadAllTextAsync(articlePath);
sentimentEntry = JsonSerializer.Deserialize<IsinAnalysisEntry>(json, FinlyticJsonSerializerContext.Default.IsinAnalysisEntry);
sentimentEntry = JsonSerializer.Deserialize<IsinAnalysisEntry>(json,
FinlyticJsonSerializerContext.Default.IsinAnalysisEntry);
}
catch
{
}
catch { }
}
// 2. ISIN Summary File Fallback
@@ -383,16 +397,19 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
foreach (var asset in a.MatchedAssets)
{
if (string.IsNullOrWhiteSpace(asset.Isin)) continue;
var isinPath = Path.Combine(Directory.GetCurrentDirectory(), "data", "summaries", "isin", $"{asset.Isin.Trim()}.json");
var isinPath = Path.Combine(Directory.GetCurrentDirectory(), "data", "summaries", "isin",
$"{asset.Isin.Trim()}.json");
if (File.Exists(isinPath))
{
try
{
var json = await File.ReadAllTextAsync(isinPath);
var isinDoc = JsonSerializer.Deserialize<IsinSentimentSummaryDto>(json, FinlyticJsonSerializerContext.Default.IsinSentimentSummaryDto);
var match = isinDoc?.Analyses?.FirstOrDefault(entry =>
string.Equals(entry.Article?.ArticleId?.Trim(), targetId, StringComparison.OrdinalIgnoreCase));
var isinDoc = JsonSerializer.Deserialize<IsinSentimentSummaryDto>(json,
FinlyticJsonSerializerContext.Default.IsinSentimentSummaryDto);
var match = isinDoc?.Analyses?.FirstOrDefault(entry =>
string.Equals(entry.Article?.ArticleId?.Trim(), targetId,
StringComparison.OrdinalIgnoreCase));
if (match != null)
{
@@ -400,7 +417,9 @@ public class NewsMqttClient : ManagedMqttClient, IHostedService
break;
}
}
catch { }
catch
{
}
}
}
}