Avalonia-Grundgeruest: plattformneutrale App laeuft (Shell + erstes Fenster)
Neues Projekt src/PolyTrader.App.Avalonia (net10.0, Avalonia 12.1.1, LiveCharts2 2.0.5) - laeuft unter Windows und Linux aus derselben Quelle. Enthalten: - Program.cs mit bewusst getrenntem Aufbau: BuildHost() stellt Persistenz, Dienste und Module ohne jeden UI-Bezug zusammen, erst Main haengt Avalonia daran. Damit ist der kopflose Linux-Betrieb (--headless, Stufe L2) ohne Umbau erreichbar - der Schalter ist bereits drin. - AvaloniaUiHost als IModuleUiHost: gleiche Semantik wie die WinForms-Shell (ein Fenster je View, offene nach vorn holen, alles maximiert). - Fenster-Menueleiste vollstaendig DEKLARATIV (Controls/WindowMenuBar.axaml + ItemsSource auf WindowMenuModel.Entries). Loest die alte Fassung ab, die menu.Items zur Laufzeit leerte und neu befuellte - genau der Punkt, den die neue Layout-Regel verbietet. - ViewIcons fuer Avalonia: dieselben Schluessel und dieselben PNGs wie zuvor, Core und Module bleiben unveraendert. - LauncherWindow, JobsWindow, ShutdownConfirmWindow (inkl. der 10-Sekunden-Sperre). - --smoke-ui als Nachfolger der WinForms-Konstruktionspruefung; startet den Host bewusst NICHT, damit ein reiner UI-Test nicht die Trading-Engine gegen echte Endpunkte anwirft. Dabei aufgeraeumt: - JobManager.Jobs: BindingList -> ObservableCollection. BindingList implementiert kein INotifyCollectionChanged; neu registrierte Jobs waeren in Avalonia unsichtbar geblieben. - StartupHydrationService aufgeteilt in CoreStateHydrationService (Core: Accounts + Demo-Positionen) und CopyTradingHydrationService (Modul: Settings + Trader). Behebt einen latenten Fehler: bei deaktiviertem Copytrading-Modul waeren die Accounts gar nicht mehr hydriert worden, obwohl sie zum Core gehoeren. Verifiziert: Solution baut, 442 Tests gruen, --smoke-ui gruen, die App laeuft real mit Fenster und allen Trading-Diensten (Market-Sync, Master-Trader-Analyse, RF-Scanner), und publisht fuer linux-x64. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyTrader.Modules.Supervis
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyTrader.Modules.Accounting", "src\PolyTrader.Modules.Accounting\PolyTrader.Modules.Accounting.csproj", "{A74EB53F-08E7-43A5-A664-A49E9AB50AEE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyTrader.Modules.Accounting", "src\PolyTrader.Modules.Accounting\PolyTrader.Modules.Accounting.csproj", "{A74EB53F-08E7-43A5-A664-A49E9AB50AEE}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyTrader.App.Avalonia", "src\PolyTrader.App.Avalonia\PolyTrader.App.Avalonia.csproj", "{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -115,6 +117,18 @@ Global
|
|||||||
{A74EB53F-08E7-43A5-A664-A49E9AB50AEE}.Release|x64.Build.0 = Release|Any CPU
|
{A74EB53F-08E7-43A5-A664-A49E9AB50AEE}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{A74EB53F-08E7-43A5-A664-A49E9AB50AEE}.Release|x86.ActiveCfg = Release|Any CPU
|
{A74EB53F-08E7-43A5-A664-A49E9AB50AEE}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{A74EB53F-08E7-43A5-A664-A49E9AB50AEE}.Release|x86.Build.0 = Release|Any CPU
|
{A74EB53F-08E7-43A5-A664-A49E9AB50AEE}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -126,6 +140,7 @@ Global
|
|||||||
{98C70A7B-DC3D-48E3-BE5D-03F867E9BFA8} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
|
{98C70A7B-DC3D-48E3-BE5D-03F867E9BFA8} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
|
||||||
{63F8B9B4-6F56-4A6B-BEBE-53DE49F913D1} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
|
{63F8B9B4-6F56-4A6B-BEBE-53DE49F913D1} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
|
||||||
{A74EB53F-08E7-43A5-A664-A49E9AB50AEE} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
|
{A74EB53F-08E7-43A5-A664-A49E9AB50AEE} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
|
||||||
|
{C4D9F31B-9FC5-4BC6-98FF-55AE7A6BF23A} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {60AA6BCF-B17E-4D52-A290-14154A3E97CF}
|
SolutionGuid = {60AA6BCF-B17E-4D52-A290-14154A3E97CF}
|
||||||
|
|||||||
+6
-3
@@ -159,7 +159,7 @@ internal static class Program
|
|||||||
|
|
||||||
// MUSS als erster HostedService laufen: hydriert den State, bevor die
|
// MUSS als erster HostedService laufen: hydriert den State, bevor die
|
||||||
// Trading-Services gegen einen leeren State anlaufen.
|
// Trading-Services gegen einen leeren State anlaufen.
|
||||||
services.AddHostedService<StartupHydrationService>();
|
services.AddHostedService<CoreStateHydrationService>();
|
||||||
|
|
||||||
// Module registrieren ihre eigenen Services/Channels/State selbst.
|
// Module registrieren ihre eigenen Services/Channels/State selbst.
|
||||||
foreach (var module in modules)
|
foreach (var module in modules)
|
||||||
@@ -460,7 +460,8 @@ internal static class Program
|
|||||||
services.AddCorePersistence(databaseOptions);
|
services.AddCorePersistence(databaseOptions);
|
||||||
services.AddSingleton<TerminalLogger>();
|
services.AddSingleton<TerminalLogger>();
|
||||||
services.AddSingleton<TradingState>();
|
services.AddSingleton<TradingState>();
|
||||||
services.AddSingleton<StartupHydrationService>();
|
services.AddSingleton<CoreStateHydrationService>();
|
||||||
|
services.AddSingleton<CopyTradingHydrationService>();
|
||||||
|
|
||||||
foreach (var module in modules)
|
foreach (var module in modules)
|
||||||
{
|
{
|
||||||
@@ -478,7 +479,9 @@ internal static class Program
|
|||||||
// State aus MySQL laden (Accounts/Trader/Settings), ohne die BackgroundServices zu starten.
|
// State aus MySQL laden (Accounts/Trader/Settings), ohne die BackgroundServices zu starten.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
host.Services.GetRequiredService<StartupHydrationService>()
|
host.Services.GetRequiredService<CoreStateHydrationService>()
|
||||||
|
.StartAsync(default).GetAwaiter().GetResult();
|
||||||
|
host.Services.GetRequiredService<CopyTradingHydrationService>()
|
||||||
.StartAsync(default).GetAwaiter().GetResult();
|
.StartAsync(default).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using PolyTraderSharp.Models;
|
using PolyTraderSharp.Models;
|
||||||
using PolyTraderSharp.Services;
|
using PolyTraderSharp.Services;
|
||||||
@@ -23,7 +23,7 @@ namespace PolyTraderSharp.Ui.Views
|
|||||||
|
|
||||||
public void Initialize(JobManager jobManager)
|
public void Initialize(JobManager jobManager)
|
||||||
{
|
{
|
||||||
dgvJobs.DataSource = jobManager.Jobs;
|
dgvJobs.DataSource = new System.ComponentModel.BindingList<JobStatusRow>(jobManager.Jobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DgvJobs_CellContentClick(object? sender, DataGridViewCellEventArgs e)
|
private void DgvJobs_CellContentClick(object? sender, DataGridViewCellEventArgs e)
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
appsettings.Local.json
|
||||||
|
server_settings.xml
|
||||||
|
master.key
|
||||||
|
openrouter.key
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<Application xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
x:Class="PolyTrader.App.Avalonia.App"
|
||||||
|
RequestedThemeVariant="Light">
|
||||||
|
|
||||||
|
<Application.Styles>
|
||||||
|
<FluentTheme />
|
||||||
|
|
||||||
|
<!-- Projektweite Grundgestaltung. Bewusst hier zentral statt je Fenster wiederholt,
|
||||||
|
damit alle Fenster gleich aussehen (wie zuvor die einheitliche Segoe-UI-Vorgabe). -->
|
||||||
|
<Style Selector="DataGrid">
|
||||||
|
<Setter Property="GridLinesVisibility" Value="Horizontal" />
|
||||||
|
<Setter Property="HeadersVisibility" Value="Column" />
|
||||||
|
<Setter Property="IsReadOnly" Value="True" />
|
||||||
|
<Setter Property="CanUserResizeColumns" Value="True" />
|
||||||
|
<Setter Property="CanUserSortColumns" Value="True" />
|
||||||
|
<Setter Property="RowHeight" Value="24" />
|
||||||
|
<Setter Property="FontSize" Value="12" />
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<!-- KPI-Kachel: entspricht den zweizeiligen Labels der WinForms-Oberflaeche
|
||||||
|
("<Titel> \n <Wert>"), siehe docs/UI-SPEZIFIKATION-WinForms.md. -->
|
||||||
|
<Style Selector="Border.kpi">
|
||||||
|
<Setter Property="Background" Value="#F5F5F5" />
|
||||||
|
<Setter Property="BorderBrush" Value="#DDDDDD" />
|
||||||
|
<Setter Property="BorderThickness" Value="1" />
|
||||||
|
<Setter Property="CornerRadius" Value="4" />
|
||||||
|
<Setter Property="Padding" Value="12,8" />
|
||||||
|
<Setter Property="Margin" Value="0,0,8,8" />
|
||||||
|
<Setter Property="MinWidth" Value="150" />
|
||||||
|
</Style>
|
||||||
|
<Style Selector="Border.kpi > StackPanel > TextBlock.caption">
|
||||||
|
<Setter Property="FontSize" Value="11" />
|
||||||
|
<Setter Property="Foreground" Value="#666666" />
|
||||||
|
</Style>
|
||||||
|
<Style Selector="Border.kpi > StackPanel > TextBlock.value">
|
||||||
|
<Setter Property="FontSize" Value="18" />
|
||||||
|
<Setter Property="FontWeight" Value="SemiBold" />
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<!-- Werkzeugleiste oben in jedem Fenster (Ersatz fuer ToolStrip). -->
|
||||||
|
<Style Selector="Border.toolbar">
|
||||||
|
<Setter Property="Background" Value="#FAFAFA" />
|
||||||
|
<Setter Property="BorderBrush" Value="#DDDDDD" />
|
||||||
|
<Setter Property="BorderThickness" Value="0,0,0,1" />
|
||||||
|
<Setter Property="Padding" Value="6,4" />
|
||||||
|
</Style>
|
||||||
|
<Style Selector="Border.toolbar Button">
|
||||||
|
<Setter Property="Margin" Value="0,0,6,0" />
|
||||||
|
<Setter Property="Padding" Value="10,4" />
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<!-- Statusleiste unten (Ersatz fuer StatusStrip). -->
|
||||||
|
<Style Selector="Border.statusbar">
|
||||||
|
<Setter Property="Background" Value="#FAFAFA" />
|
||||||
|
<Setter Property="BorderBrush" Value="#DDDDDD" />
|
||||||
|
<Setter Property="BorderThickness" Value="0,1,0,0" />
|
||||||
|
<Setter Property="Padding" Value="8,4" />
|
||||||
|
</Style>
|
||||||
|
</Application.Styles>
|
||||||
|
|
||||||
|
</Application>
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using PolyTrader.App.Avalonia.Shell;
|
||||||
|
using PolyTrader.App.Avalonia.Views;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Avalonia-Anwendungsobjekt. Hält die Verbindung zwischen dem bereits laufenden Generic Host
|
||||||
|
/// (Trading-Services, Module, Persistenz) und der Oberfläche: beim Start wird der Launcher
|
||||||
|
/// erzeugt und die Views von Core und Modulen werden bei der Shell registriert.
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : global::Avalonia.Application
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wird von <see cref="Program"/> vor <c>StartWithClassicDesktopLifetime</c> gesetzt.
|
||||||
|
/// Bewusst statisch: Avalonia erzeugt die Application-Instanz selbst, ein Konstruktor-
|
||||||
|
/// Parameter ist daher nicht möglich.
|
||||||
|
/// </summary>
|
||||||
|
public static IServiceProvider? Services { get; set; }
|
||||||
|
|
||||||
|
public override void Initialize() => AvaloniaXamlLoader.Load(this);
|
||||||
|
|
||||||
|
public override void OnFrameworkInitializationCompleted()
|
||||||
|
{
|
||||||
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop && Services != null)
|
||||||
|
{
|
||||||
|
var uiHost = Services.GetRequiredService<AvaloniaUiHost>();
|
||||||
|
|
||||||
|
CoreViews.Register(uiHost, Services);
|
||||||
|
foreach (var module in Services.GetServices<Core.Modularity.IPolyTraderModule>())
|
||||||
|
module.RegisterUi(uiHost, Services);
|
||||||
|
ViewIcons.AssignDefaults(uiHost);
|
||||||
|
|
||||||
|
var launcher = new LauncherWindow(uiHost, Services);
|
||||||
|
uiHost.SetMainWindow(launcher);
|
||||||
|
desktop.MainWindow = launcher;
|
||||||
|
|
||||||
|
// Schliessen des Launchers laeuft ueber die Sicherheitsabfrage (wie bisher das X).
|
||||||
|
desktop.ShutdownMode = global::Avalonia.Controls.ShutdownMode.OnMainWindowClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnFrameworkInitializationCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:shell="using:PolyTrader.App.Avalonia.Shell"
|
||||||
|
x:Class="PolyTrader.App.Avalonia.Controls.WindowMenuBar"
|
||||||
|
x:DataType="shell:WindowMenuModel">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Gemeinsame Fenster-Menüleiste, die auf JEDEM PolyTrader-Fenster oben sitzt.
|
||||||
|
Alle Fenster stehen nebeneinander (nicht in einem Untermenü versteckt), das aktuelle
|
||||||
|
fett, offene mit Haken. Die rechte Aktion ist kontextabhängig.
|
||||||
|
|
||||||
|
Vollständig deklarativ: die Einträge kommen als Datenmodell aus WindowMenuModel.Entries,
|
||||||
|
hier wird nur beschrieben, wie ein Eintrag aussieht. Kein Aufbau zur Laufzeit im Code.
|
||||||
|
(Avalonia kennt kein ToolStripItemAlignment.Right — die rechte Ausrichtung entsteht
|
||||||
|
dadurch, dass der letzte Eintrag im DockPanel rechts angedockt wird.)
|
||||||
|
-->
|
||||||
|
<Border Background="#F3F3F3" BorderBrush="#DDDDDD" BorderThickness="0,0,0,1" Padding="4,2">
|
||||||
|
<ItemsControl ItemsSource="{Binding Entries}">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal" />
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="shell:WindowMenuEntry">
|
||||||
|
<Button Command="{Binding Command}"
|
||||||
|
Background="Transparent"
|
||||||
|
BorderThickness="0"
|
||||||
|
Padding="8,4"
|
||||||
|
Margin="0,0,2,0">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="6">
|
||||||
|
<Image Source="{Binding Icon}"
|
||||||
|
Width="20" Height="20"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
IsVisible="{Binding Icon, Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||||
|
<TextBlock Text="{Binding CheckMark}"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Foreground="#2E7D32" />
|
||||||
|
<TextBlock Text="{Binding Title}"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
FontWeight="{Binding FontWeight}" />
|
||||||
|
</StackPanel>
|
||||||
|
</Button>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using PolyTrader.App.Avalonia.Shell;
|
||||||
|
using PolyTrader.Core.Modularity;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia.Controls
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Code-Behind der Fenster-Menüleiste: nur Verdrahtung, kein Layout (siehe Layout-Regel).
|
||||||
|
/// Jedes Fenster ruft <see cref="Attach"/> auf und bekommt damit dieselbe Leiste.
|
||||||
|
/// </summary>
|
||||||
|
public partial class WindowMenuBar : UserControl
|
||||||
|
{
|
||||||
|
private WindowMenuModel? _model;
|
||||||
|
|
||||||
|
public WindowMenuBar() => AvaloniaXamlLoader.Load(this);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verbindet die Leiste mit der Shell. <paramref name="currentViewId"/> ist <c>null</c> für den
|
||||||
|
/// Launcher (rechte Aktion „Beenden"), sonst die View-ID (rechte Aktion „Fenster schließen").
|
||||||
|
/// Die Event-Registrierung wird beim Entladen wieder gelöst – kein Leak.
|
||||||
|
/// </summary>
|
||||||
|
public void Attach(IModuleUiHost host, string? currentViewId, Window owner)
|
||||||
|
{
|
||||||
|
_model = new WindowMenuModel(host, currentViewId, owner.Close);
|
||||||
|
DataContext = _model;
|
||||||
|
owner.Closed += (_, _) => _model?.Detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<!-- Plattformneutral: dieselbe Anwendung laeuft unter Windows und Linux. Loest schrittweise
|
||||||
|
PolyTrader.App (WinForms, net10.0-windows) ab; der letzte WinForms-Stand liegt im
|
||||||
|
Git-Tag winforms-final, die UI-Beschreibung in docs/UI-SPEZIFIKATION-WinForms.md. -->
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<AssemblyName>PolyTrader.App.Avalonia</AssemblyName>
|
||||||
|
<RootNamespace>PolyTrader.App.Avalonia</RootNamespace>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
<!-- Avalonia-Previewer und XAML-Compiler: Layout wird deklarativ in .axaml gebaut,
|
||||||
|
nicht zur Laufzeit im Code (Layout-Regel des Projekts). -->
|
||||||
|
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Avalonia" Version="12.1.1" />
|
||||||
|
<PackageReference Include="Avalonia.Desktop" Version="12.1.1" />
|
||||||
|
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.1.1" />
|
||||||
|
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.1.1" />
|
||||||
|
<PackageReference Include="Avalonia.Controls.DataGrid" Version="12.1.1" />
|
||||||
|
<!-- Diagramme (Entscheidung: LiveCharts2 statt ScottPlot, aus optischen Gruenden). -->
|
||||||
|
<PackageReference Include="LiveChartsCore.SkiaSharpView.Avalonia" Version="2.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PolyTrader.Core\PolyTrader.Core.csproj" />
|
||||||
|
<ProjectReference Include="..\PolyTrader.Modules.CopyTrading\PolyTrader.Modules.CopyTrading.csproj" />
|
||||||
|
<ProjectReference Include="..\PolyTrader.Modules.ResolutionFarming\PolyTrader.Modules.ResolutionFarming.csproj" />
|
||||||
|
<ProjectReference Include="..\PolyTrader.Modules.Supervisor\PolyTrader.Modules.Supervisor.csproj" />
|
||||||
|
<ProjectReference Include="..\PolyTrader.Modules.Accounting\PolyTrader.Modules.Accounting.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- Symbole der bisherigen UI unveraendert weiterverwenden (siehe Shell/ViewIcons.cs). -->
|
||||||
|
<AvaloniaResource Include="..\..\Resources\*.png" Link="Assets\%(Filename)%(Extension)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
<None Update="appsettings.Local.json" Condition="Exists('appsettings.Local.json')" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,251 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Avalonia;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using PolyTrader.App.Avalonia.Shell;
|
||||||
|
using PolyTrader.Core.Configuration;
|
||||||
|
using PolyTrader.Core.DependencyInjection;
|
||||||
|
using PolyTrader.Core.Modularity;
|
||||||
|
using PolyTrader.Core.Notifications;
|
||||||
|
using PolyTrader.Core.Security;
|
||||||
|
using PolyTrader.Modules.Accounting;
|
||||||
|
using PolyTrader.Modules.CopyTrading;
|
||||||
|
using PolyTrader.Modules.ResolutionFarming;
|
||||||
|
using PolyTrader.Modules.Supervisor;
|
||||||
|
using PolyTraderSharp;
|
||||||
|
using PolyTraderSharp.Models;
|
||||||
|
using PolyTraderSharp.Services;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Einstiegspunkt der plattformneutralen PolyTrader-Anwendung.
|
||||||
|
///
|
||||||
|
/// <para>Der Aufbau ist bewusst zweigeteilt: <see cref="BuildHost"/> stellt den Generic Host mit
|
||||||
|
/// Persistenz, Diensten und Modulen zusammen – ohne jeden Bezug zur Oberfläche. Erst
|
||||||
|
/// <see cref="Main"/> hängt Avalonia daran. Damit lässt sich derselbe Host später ohne Umbau
|
||||||
|
/// für den kopflosen Linux-Betrieb starten (Schalter <c>--headless</c>, Stufe L2).</para>
|
||||||
|
/// </summary>
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
private const string ServerSettingsPath = "server_settings.xml";
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
public static int Main(string[] args)
|
||||||
|
{
|
||||||
|
bool headless = args.Any(a => string.Equals(a, "--headless", StringComparison.OrdinalIgnoreCase));
|
||||||
|
bool smoke = args.Any(a => string.Equals(a, "--smoke-ui", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
var host = BuildHost(out var bootLog);
|
||||||
|
|
||||||
|
// Konstruktionspruefung der Fenster: Host NICHT starten. Sonst laufen Trading-Engine,
|
||||||
|
// WSS-Clients und Jobs gegen die echten Boersen-Endpunkte an - fuer einen reinen
|
||||||
|
// UI-Test unerwuenscht (und auf einem Build-Server schlicht falsch).
|
||||||
|
if (smoke)
|
||||||
|
{
|
||||||
|
try { return RunSmokeUi(host, bootLog); }
|
||||||
|
finally { host.Dispose(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
host.Start();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (headless)
|
||||||
|
{
|
||||||
|
bootLog.Info("Kopfloser Betrieb: keine Oberfläche, Trading-Dienste laufen. Beenden mit Strg+C.");
|
||||||
|
host.WaitForShutdown();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
App.Services = host.Services;
|
||||||
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Geordnetes Herunterfahren der Module – erst nach dem Ende der Oberfläche.
|
||||||
|
host.StopAsync(TimeSpan.FromSeconds(30)).GetAwaiter().GetResult();
|
||||||
|
host.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Von Avalonia (auch vom XAML-Previewer) erwartete Fabrikmethode.</summary>
|
||||||
|
public static AppBuilder BuildAvaloniaApp() =>
|
||||||
|
AppBuilder.Configure<App>()
|
||||||
|
.UsePlatformDetect()
|
||||||
|
.WithInterFont()
|
||||||
|
.LogToTrace();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Baut den Anwendungs-Host: Konfiguration, Master-Key, Persistenz, Core-Dienste und die
|
||||||
|
/// aktiven Module. Kennt die Oberfläche nicht.
|
||||||
|
/// </summary>
|
||||||
|
private static IHost BuildHost(out TerminalLogger bootLog)
|
||||||
|
{
|
||||||
|
var serverSettings = ServerSettings.Load(ServerSettingsPath);
|
||||||
|
var logger = new TerminalLogger();
|
||||||
|
bootLog = logger;
|
||||||
|
|
||||||
|
ConfigureSecretProtection(logger);
|
||||||
|
|
||||||
|
var allModules = new List<IPolyTraderModule>
|
||||||
|
{
|
||||||
|
new CopyTradingModule(),
|
||||||
|
new ResolutionFarmingModule(),
|
||||||
|
new SupervisorModule(),
|
||||||
|
new AccountingModule()
|
||||||
|
};
|
||||||
|
var disabled = new HashSet<string>(serverSettings.DisabledModules, StringComparer.OrdinalIgnoreCase);
|
||||||
|
var modules = allModules.Where(m => !disabled.Contains(m.Name)).ToList();
|
||||||
|
|
||||||
|
return Host.CreateDefaultBuilder()
|
||||||
|
.UseContentRoot(AppContext.BaseDirectory)
|
||||||
|
.ConfigureAppConfiguration((_, config) =>
|
||||||
|
config.AddJsonFile("appsettings.Local.json", optional: true, reloadOnChange: false))
|
||||||
|
.ConfigureServices((context, services) =>
|
||||||
|
{
|
||||||
|
var databaseOptions = new DatabaseOptions
|
||||||
|
{
|
||||||
|
MySqlConnectionString = context.Configuration["Database:MySqlConnectionString"] ?? string.Empty
|
||||||
|
};
|
||||||
|
services.Configure<DatabaseOptions>(context.Configuration.GetSection(DatabaseOptions.SectionName));
|
||||||
|
services.AddCorePersistence(databaseOptions);
|
||||||
|
|
||||||
|
services.AddSingleton(serverSettings);
|
||||||
|
services.AddSingleton(logger);
|
||||||
|
services.AddSingleton<TradingState>();
|
||||||
|
services.AddSingleton<JobManager>();
|
||||||
|
services.AddSingleton<MullvadVpnService>();
|
||||||
|
services.AddHttpClient();
|
||||||
|
|
||||||
|
// Polymarket-Zugriffe teilen sich einen langlebigen Verbindungspool.
|
||||||
|
services.AddSingleton(sp => new PolymarketApiService(
|
||||||
|
sp.GetRequiredService<TerminalLogger>(), CreatePolymarketHttpClient()));
|
||||||
|
services.AddSingleton(sp => new PolymarketClobClient(
|
||||||
|
sp.GetRequiredService<TerminalLogger>(), CreatePolymarketHttpClient()));
|
||||||
|
|
||||||
|
// Benachrichtigungen: neutrale Senke, bis RocketChat/Telegram angebunden sind.
|
||||||
|
services.AddSingleton<INotificationSink>(
|
||||||
|
sp => new LogNotificationSink(sp.GetRequiredService<TerminalLogger>()));
|
||||||
|
|
||||||
|
services.AddSingleton(sp => new WatchdogHeartbeatService(sp.GetRequiredService<TerminalLogger>()));
|
||||||
|
|
||||||
|
// MUSS vor den Modulen registriert werden: hydriert die Accounts, bevor die
|
||||||
|
// Trading-Dienste anlaufen (Reihenfolge = Registrierungsreihenfolge).
|
||||||
|
services.AddHostedService<CoreStateHydrationService>();
|
||||||
|
|
||||||
|
foreach (var module in modules)
|
||||||
|
{
|
||||||
|
services.AddSingleton(module);
|
||||||
|
module.RegisterServices(services, context.Configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
services.AddHostedService<MarketSyncService>();
|
||||||
|
services.AddHostedService(sp => sp.GetRequiredService<MullvadVpnService>());
|
||||||
|
services.AddHostedService(sp => sp.GetRequiredService<WatchdogHeartbeatService>());
|
||||||
|
|
||||||
|
// Shell-Zustand (Fensterverwaltung). Auch im kopflosen Betrieb harmlos.
|
||||||
|
services.AddSingleton<AvaloniaUiHost>();
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Kopflose Konstruktionsprüfung aller registrierten Fenster – Nachfolger des
|
||||||
|
/// <c>--smoke-ui</c>-Laufs der WinForms-App, der Konstruktionsfehler zuverlässig gefangen hat.
|
||||||
|
/// Läuft ohne Fenster und ohne Message-Loop.
|
||||||
|
/// </summary>
|
||||||
|
private static int RunSmokeUi(IHost host, TerminalLogger logger)
|
||||||
|
{
|
||||||
|
// Avalonia muss initialisiert sein, damit Fenster konstruiert werden koennen.
|
||||||
|
BuildAvaloniaApp().SetupWithoutStarting();
|
||||||
|
App.Services = host.Services;
|
||||||
|
|
||||||
|
var uiHost = host.Services.GetRequiredService<AvaloniaUiHost>();
|
||||||
|
CoreViews.Register(uiHost, host.Services);
|
||||||
|
foreach (var module in host.Services.GetServices<IPolyTraderModule>())
|
||||||
|
module.RegisterUi(uiHost, host.Services);
|
||||||
|
ViewIcons.AssignDefaults(uiHost);
|
||||||
|
|
||||||
|
int failures = 0;
|
||||||
|
Console.WriteLine("=== Smoke-UI: Fenster-Konstruktion (Avalonia) ===");
|
||||||
|
foreach (var view in uiHost.Views)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = view.CreateView();
|
||||||
|
Console.WriteLine($"[OK] {view.Id} ({view.Title})");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
failures++;
|
||||||
|
Console.WriteLine($"[FEHLER] {view.Id}: {ex.GetType().Name}: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = new Views.LauncherWindow(uiHost, host.Services);
|
||||||
|
Console.WriteLine("[OK] LauncherWindow konstruiert");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
failures++;
|
||||||
|
Console.WriteLine($"[FEHLER] LauncherWindow: {ex.GetType().Name}: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = new Views.ShutdownConfirmWindow();
|
||||||
|
Console.WriteLine("[OK] ShutdownConfirmWindow konstruiert");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
failures++;
|
||||||
|
Console.WriteLine($"[FEHLER] ShutdownConfirmWindow: {ex.GetType().Name}: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine(failures == 0 ? "=== Smoke-UI OK ===" : $"=== Smoke-UI: {failures} Fehler ===");
|
||||||
|
return failures == 0 ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// HttpClient für die Polymarket-APIs: langlebiger Verbindungspool und die Header, die die
|
||||||
|
/// Gegenstelle erwartet (identisch zur bisherigen WinForms-Zusammenstellung).
|
||||||
|
/// </summary>
|
||||||
|
private static System.Net.Http.HttpClient CreatePolymarketHttpClient() =>
|
||||||
|
new(new System.Net.Http.SocketsHttpHandler
|
||||||
|
{
|
||||||
|
PooledConnectionLifetime = TimeSpan.FromMinutes(2),
|
||||||
|
MaxConnectionsPerServer = 100
|
||||||
|
})
|
||||||
|
{
|
||||||
|
DefaultRequestHeaders = { { "User-Agent", "py_clob_client" }, { "Accept", "*/*" } }
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lädt den Master-Key (Umgebungsvariable, sonst gitignorierte <c>master.key</c>) und aktiviert
|
||||||
|
/// die at-rest-Verschlüsselung. Muss VOR jeder Credential-Entschlüsselung laufen.
|
||||||
|
/// </summary>
|
||||||
|
private static void ConfigureSecretProtection(TerminalLogger logger)
|
||||||
|
{
|
||||||
|
string? masterKey = Environment.GetEnvironmentVariable("POLYTRADER_MASTER_KEY");
|
||||||
|
if (string.IsNullOrWhiteSpace(masterKey))
|
||||||
|
{
|
||||||
|
string keyFile = Path.Combine(AppContext.BaseDirectory, "master.key");
|
||||||
|
if (File.Exists(keyFile)) masterKey = File.ReadAllText(keyFile).Trim();
|
||||||
|
}
|
||||||
|
SecretProtection.Configure(masterKey);
|
||||||
|
|
||||||
|
if (SecretProtection.IsConfigured)
|
||||||
|
logger.Info("🔐 Secret-Verschlüsselung aktiv – Account-Credentials werden at-rest verschlüsselt (AES-256-GCM).");
|
||||||
|
else
|
||||||
|
logger.Warning("⚠️ SICHERHEIT: Kein POLYTRADER_MASTER_KEY gesetzt – Account-Credentials liegen UNVERSCHLÜSSELT in der DB.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using PolyTrader.Core.Modularity;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia.Shell
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Avalonia-Umsetzung von <see cref="IModuleUiHost"/>. Verhält sich wie der frühere
|
||||||
|
/// WinForms-<c>ShellUiHost</c>: je View höchstens ein Fenster, ein bereits offenes wird nach vorn
|
||||||
|
/// geholt, alle Fenster öffnen maximiert.
|
||||||
|
///
|
||||||
|
/// <para>Der Core-Contract ist toolkit-neutral (<see cref="ModuleView.CreateView"/> liefert
|
||||||
|
/// <see cref="object"/>) – hier wird auf <see cref="Window"/> gecastet. Ein falscher Typ ist ein
|
||||||
|
/// Programmierfehler und soll laut scheitern, nicht still ein leeres Fenster erzeugen.</para>
|
||||||
|
/// </summary>
|
||||||
|
public sealed class AvaloniaUiHost : IModuleUiHost
|
||||||
|
{
|
||||||
|
private readonly List<ModuleView> _views = new();
|
||||||
|
private readonly Dictionary<string, Window> _open = new();
|
||||||
|
private Window? _mainWindow;
|
||||||
|
private bool _shutdownDialogOpen;
|
||||||
|
|
||||||
|
/// <summary>True, sobald das Herunterfahren über die Sicherheitsabfrage bestätigt wurde.</summary>
|
||||||
|
public bool ShutdownConfirmed { get; private set; }
|
||||||
|
|
||||||
|
public event Action? OpenStateChanged;
|
||||||
|
|
||||||
|
public IReadOnlyList<ModuleView> Views => _views;
|
||||||
|
|
||||||
|
public void RegisterView(ModuleView view) => _views.Add(view);
|
||||||
|
|
||||||
|
/// <summary>Setzt das Hauptfenster (Launcher) – Ziel für <see cref="ActivateMain"/>.</summary>
|
||||||
|
public void SetMainWindow(Window main) => _mainWindow = main;
|
||||||
|
|
||||||
|
public bool IsOpen(string viewId) => _open.ContainsKey(viewId);
|
||||||
|
|
||||||
|
public void ActivateMain()
|
||||||
|
{
|
||||||
|
if (_mainWindow == null) return;
|
||||||
|
if (_mainWindow.WindowState == WindowState.Minimized)
|
||||||
|
_mainWindow.WindowState = WindowState.Maximized;
|
||||||
|
_mainWindow.Activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenView(string viewId)
|
||||||
|
{
|
||||||
|
var view = _views.FirstOrDefault(v => v.Id == viewId);
|
||||||
|
if (view != null) OpenView(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenView(ModuleView view)
|
||||||
|
{
|
||||||
|
if (_open.TryGetValue(view.Id, out var existing))
|
||||||
|
{
|
||||||
|
if (existing.WindowState == WindowState.Minimized)
|
||||||
|
existing.WindowState = WindowState.Normal;
|
||||||
|
existing.Activate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var window = (Window)view.CreateView();
|
||||||
|
if (string.IsNullOrEmpty(window.Title)) window.Title = view.Title;
|
||||||
|
|
||||||
|
// Vorgabe aus der WinForms-Oberflaeche uebernommen: alle Fenster maximiert (Full-HD-Ziel).
|
||||||
|
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||||
|
window.WindowState = WindowState.Maximized;
|
||||||
|
|
||||||
|
_open[view.Id] = window;
|
||||||
|
window.Closed += (_, _) =>
|
||||||
|
{
|
||||||
|
_open.Remove(view.Id);
|
||||||
|
OpenStateChanged?.Invoke();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.Show();
|
||||||
|
OpenStateChanged?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Zeigt die Sicherheitsabfrage (Beenden-Schaltfläche 10 s gesperrt) und fährt bei Bestätigung
|
||||||
|
/// herunter. Aus jedem Fenster aufrufbar – auch aus Modul-Fenstern, die die App nicht kennen.
|
||||||
|
/// </summary>
|
||||||
|
public async void RequestShutdown()
|
||||||
|
{
|
||||||
|
if (ShutdownConfirmed || _shutdownDialogOpen) return;
|
||||||
|
_shutdownDialogOpen = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dlg = new Views.ShutdownConfirmWindow();
|
||||||
|
bool confirmed = _mainWindow != null
|
||||||
|
? await dlg.ShowDialog<bool>(_mainWindow)
|
||||||
|
: await dlg.ShowDialog<bool>(new Window());
|
||||||
|
if (!confirmed) return;
|
||||||
|
|
||||||
|
ShutdownConfirmed = true;
|
||||||
|
if (global::Avalonia.Application.Current?.ApplicationLifetime
|
||||||
|
is global::Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
|
{
|
||||||
|
desktop.Shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_shutdownDialogOpen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using PolyTrader.Core.Modularity;
|
||||||
|
using PolyTraderSharp.Services;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia.Shell
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Registriert die Fenster, die der Core selbst beisteuert (Dashboard, Einstellungen,
|
||||||
|
/// Terminal, Jobs). Gegenstück zur entsprechenden Registrierung im WinForms-Program.cs –
|
||||||
|
/// die View-IDs sind bewusst identisch, damit Symbole und Reihenfolge unverändert greifen.
|
||||||
|
/// </summary>
|
||||||
|
public static class CoreViews
|
||||||
|
{
|
||||||
|
public static void Register(IModuleUiHost host, IServiceProvider services)
|
||||||
|
{
|
||||||
|
host.RegisterView(new ModuleView
|
||||||
|
{
|
||||||
|
Id = "core.jobs",
|
||||||
|
Title = "Server Jobs",
|
||||||
|
Group = "Core",
|
||||||
|
Order = 30,
|
||||||
|
CreateView = () => new Views.JobsWindow(host, services.GetRequiredService<JobManager>())
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO Portierung: core.dashboard (Order 10), core.settings (Order 20) und
|
||||||
|
// core.terminal (Order 40) folgen. Aufbau siehe docs/UI-SPEZIFIKATION-WinForms.md,
|
||||||
|
// Originalcode im Git-Tag winforms-final.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Avalonia.Media.Imaging;
|
||||||
|
using Avalonia.Platform;
|
||||||
|
using PolyTrader.Core.Modularity;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia.Shell
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Löst die toolkit-neutralen <see cref="ModuleView.IconKey"/>-Schlüssel gegen die
|
||||||
|
/// Avalonia-Bildressourcen auf. Gegenstück zum gleichnamigen Helfer der WinForms-Shell –
|
||||||
|
/// <b>dieselben Schlüssel, dieselben PNG-Dateien</b>, sodass Core und Module unverändert bleiben.
|
||||||
|
/// </summary>
|
||||||
|
public static class ViewIcons
|
||||||
|
{
|
||||||
|
/// <summary>Symbol-Schlüssel → Dateiname in <c>Resources/</c> (als Avalonia-Asset eingebettet).</summary>
|
||||||
|
private static readonly Dictionary<string, string> FileByKey = new()
|
||||||
|
{
|
||||||
|
["dashboard"] = "dashboard.png",
|
||||||
|
["settings"] = "setting_tools.png",
|
||||||
|
["terminal"] = "error_log.png",
|
||||||
|
["jobs"] = "system_time.png",
|
||||||
|
["accounting"] = "coins_in_hand.png",
|
||||||
|
["copytrading"] = "cross_reference.png",
|
||||||
|
["resolutionfarming"] = "file_start_workflow.png",
|
||||||
|
["supervisor"] = "emotion_batman.png",
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>Standard-Symbolschlüssel je View-ID – identisch zur WinForms-Shell.</summary>
|
||||||
|
private static readonly Dictionary<string, string> DefaultKeyByViewId = new()
|
||||||
|
{
|
||||||
|
["core.dashboard"] = "dashboard",
|
||||||
|
["core.settings"] = "settings",
|
||||||
|
["core.terminal"] = "terminal",
|
||||||
|
["core.jobs"] = "jobs",
|
||||||
|
["accounting.main"] = "accounting",
|
||||||
|
["copytrading.main"] = "copytrading",
|
||||||
|
["resolutionfarming.main"] = "resolutionfarming",
|
||||||
|
["supervisor.main"] = "supervisor",
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly ConcurrentDictionary<string, Bitmap?> Cache = new();
|
||||||
|
|
||||||
|
/// <summary>Bild zum Schlüssel, oder <c>null</c> (kein Symbol / Datei fehlt).</summary>
|
||||||
|
public static Bitmap? Resolve(string? iconKey)
|
||||||
|
{
|
||||||
|
if (iconKey == null || !FileByKey.TryGetValue(iconKey, out var file)) return null;
|
||||||
|
|
||||||
|
return Cache.GetOrAdd(iconKey, _ =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var uri = new Uri($"avares://PolyTrader.App.Avalonia/Assets/{file}");
|
||||||
|
using var stream = AssetLoader.Open(uri);
|
||||||
|
return new Bitmap(stream);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Ein fehlendes Symbol darf die Oberflaeche nie aufhalten – Menueeintrag bleibt Text-only.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Setzt bei allen registrierten Views den Standard-Symbolschlüssel, falls noch keiner gesetzt ist.</summary>
|
||||||
|
public static void AssignDefaults(IModuleUiHost uiHost)
|
||||||
|
{
|
||||||
|
foreach (var view in uiHost.Views)
|
||||||
|
if (view.IconKey == null && DefaultKeyByViewId.TryGetValue(view.Id, out var key))
|
||||||
|
view.IconKey = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Avalonia.Media.Imaging;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using PolyTrader.Core.Modularity;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia.Shell
|
||||||
|
{
|
||||||
|
/// <summary>Schlanker Befehl ohne MVVM-Fremdbibliothek.</summary>
|
||||||
|
public sealed class RelayCommand : ICommand
|
||||||
|
{
|
||||||
|
private readonly Action _execute;
|
||||||
|
public RelayCommand(Action execute) => _execute = execute;
|
||||||
|
public bool CanExecute(object? parameter) => true;
|
||||||
|
public void Execute(object? parameter) => _execute();
|
||||||
|
public event EventHandler? CanExecuteChanged { add { } remove { } }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Ein Eintrag der Fenster-Menüleiste (Launcher, eine View, oder die rechte Aktion).</summary>
|
||||||
|
public sealed class WindowMenuEntry
|
||||||
|
{
|
||||||
|
public string Title { get; init; } = "";
|
||||||
|
public Bitmap? Icon { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Aktuelles Fenster – wird fett dargestellt.</summary>
|
||||||
|
public bool IsCurrent { get; init; }
|
||||||
|
|
||||||
|
/// <summary>Fenster ist offen (oder das aktuelle) – bekommt einen Haken.</summary>
|
||||||
|
public bool IsChecked { get; init; }
|
||||||
|
|
||||||
|
public ICommand Command { get; init; } = new RelayCommand(() => { });
|
||||||
|
|
||||||
|
// Von den Bindungen im XAML genutzt (kein Konverter nötig).
|
||||||
|
public string FontWeight => IsCurrent ? "Bold" : "Normal";
|
||||||
|
public string CheckMark => IsChecked ? "✓ " : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Datenmodell der gemeinsamen Fenster-Menüleiste, die auf JEDEM PolyTrader-Fenster erscheint.
|
||||||
|
///
|
||||||
|
/// <para><b>Umsetzung der neuen Layout-Regel:</b> Die WinForms-Fassung baute das Menü zur Laufzeit
|
||||||
|
/// auf (<c>menu.Items.Clear()</c> + dynamisch erzeugte <c>ToolStripMenuItem</c>). Hier liefert das
|
||||||
|
/// Modell nur noch <see cref="Entries"/>; das Layout steht deklarativ in
|
||||||
|
/// <c>Controls/WindowMenuBar.axaml</c>.</para>
|
||||||
|
/// </summary>
|
||||||
|
public sealed class WindowMenuModel : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
private readonly IModuleUiHost _host;
|
||||||
|
private readonly string? _currentViewId;
|
||||||
|
private readonly Action _closeThisWindow;
|
||||||
|
|
||||||
|
public ObservableCollection<WindowMenuEntry> Entries { get; } = new();
|
||||||
|
|
||||||
|
/// <param name="currentViewId">
|
||||||
|
/// <c>null</c> für den Launcher (dort heisst die rechte Aktion „Beenden"), sonst die View-ID
|
||||||
|
/// des Fensters (dann „Fenster schließen").
|
||||||
|
/// </param>
|
||||||
|
public WindowMenuModel(IModuleUiHost host, string? currentViewId, Action closeThisWindow)
|
||||||
|
{
|
||||||
|
_host = host;
|
||||||
|
_currentViewId = currentViewId;
|
||||||
|
_closeThisWindow = closeThisWindow;
|
||||||
|
|
||||||
|
Rebuild();
|
||||||
|
_host.OpenStateChanged += OnOpenStateChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Registrierung lösen, wenn das Fenster geht – kein Event-Leak über die Host-Lebensdauer.</summary>
|
||||||
|
public void Detach() => _host.OpenStateChanged -= OnOpenStateChanged;
|
||||||
|
|
||||||
|
private void OnOpenStateChanged()
|
||||||
|
{
|
||||||
|
if (Dispatcher.UIThread.CheckAccess()) Rebuild();
|
||||||
|
else Dispatcher.UIThread.Post(Rebuild);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Rebuild()
|
||||||
|
{
|
||||||
|
Entries.Clear();
|
||||||
|
|
||||||
|
Entries.Add(new WindowMenuEntry
|
||||||
|
{
|
||||||
|
Title = "Launcher",
|
||||||
|
IsCurrent = _currentViewId == null,
|
||||||
|
IsChecked = _currentViewId == null,
|
||||||
|
Command = new RelayCommand(_host.ActivateMain)
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var view in _host.Views.OrderBy(v => v.Order).ThenBy(v => v.Title))
|
||||||
|
{
|
||||||
|
string id = view.Id;
|
||||||
|
bool isCurrent = id == _currentViewId;
|
||||||
|
Entries.Add(new WindowMenuEntry
|
||||||
|
{
|
||||||
|
Title = view.Title,
|
||||||
|
Icon = ViewIcons.Resolve(view.IconKey),
|
||||||
|
IsCurrent = isCurrent,
|
||||||
|
IsChecked = isCurrent || _host.IsOpen(id),
|
||||||
|
Command = new RelayCommand(() => _host.OpenView(id))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kontextabhaengige rechte Aktion – wie in der WinForms-Fassung: nur der Launcher darf die
|
||||||
|
// App beenden (mit Sicherheitsabfrage), jedes andere Fenster schliesst nur sich selbst.
|
||||||
|
Entries.Add(_currentViewId == null
|
||||||
|
? new WindowMenuEntry { Title = "Beenden", Command = new RelayCommand(_host.RequestShutdown) }
|
||||||
|
: new WindowMenuEntry { Title = "Fenster schließen", Command = new RelayCommand(_closeThisWindow) });
|
||||||
|
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Entries)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:controls="using:PolyTrader.App.Avalonia.Controls"
|
||||||
|
xmlns:models="using:PolyTraderSharp.Models"
|
||||||
|
x:Class="PolyTrader.App.Avalonia.Views.JobsWindow"
|
||||||
|
Title="Server Jobs"
|
||||||
|
Width="1429" Height="833">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Ansicht der Hintergrund-Jobs (JobManager).
|
||||||
|
Spaltenreihenfolge, Überschriften, Breiten und Zeitformat entsprechen der bisherigen
|
||||||
|
WinForms-Ansicht (docs/UI-SPEZIFIKATION-WinForms.md, Abschnitt JobsView).
|
||||||
|
Feste Pixelbreiten wurden dabei absichtlich in Sternbreiten übersetzt, damit das Fenster
|
||||||
|
auf anderen Auflösungen mitwächst — die Proportionen bleiben erhalten.
|
||||||
|
-->
|
||||||
|
<DockPanel>
|
||||||
|
<controls:WindowMenuBar Name="menuBar" DockPanel.Dock="Top" />
|
||||||
|
|
||||||
|
<Border Classes="toolbar" DockPanel.Dock="Top">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button Name="btnRefresh" Content="Aktualisieren" />
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<DataGrid Name="gridJobs" x:DataType="models:JobStatusRow">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="Job Name" Width="150"
|
||||||
|
Binding="{Binding JobName}" />
|
||||||
|
<DataGridTextColumn Header="Status" Width="150"
|
||||||
|
Binding="{Binding StatusText}" />
|
||||||
|
<DataGridTextColumn Header="Zuletzt ausgeführt" Width="130"
|
||||||
|
Binding="{Binding LastRun, StringFormat=\{0:HH:mm:ss\}}" />
|
||||||
|
<DataGridTextColumn Header="Nächster Lauf" Width="130"
|
||||||
|
Binding="{Binding NextRun, StringFormat=\{0:HH:mm:ss\}}" />
|
||||||
|
<DataGridCheckBoxColumn Header="Aktiv" Width="60" IsReadOnly="False"
|
||||||
|
Binding="{Binding IsEnabled}" />
|
||||||
|
<DataGridTemplateColumn Header="Aktion" Width="90">
|
||||||
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
|
<DataTemplate x:DataType="models:JobStatusRow">
|
||||||
|
<Button Content="Run Now"
|
||||||
|
Margin="2"
|
||||||
|
Padding="6,2"
|
||||||
|
Click="OnRunNowClick"
|
||||||
|
IsEnabled="{Binding ManualTriggerAction, Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
|
</DataGridTemplateColumn>
|
||||||
|
<DataGridTextColumn Header="Beschreibung" Width="*"
|
||||||
|
Binding="{Binding Description}" />
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
</DockPanel>
|
||||||
|
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using PolyTrader.Core.Modularity;
|
||||||
|
using PolyTraderSharp.Models;
|
||||||
|
using PolyTraderSharp.Services;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia.Views
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Hintergrund-Jobs (JobManager). Verhalten wie bisher: „Run Now" löst den ManualTrigger aus,
|
||||||
|
/// „Aktiv" schaltet den Job über die Bindung. Layout vollständig in JobsWindow.axaml.
|
||||||
|
/// </summary>
|
||||||
|
public partial class JobsWindow : Window
|
||||||
|
{
|
||||||
|
public JobsWindow() => AvaloniaXamlLoader.Load(this);
|
||||||
|
|
||||||
|
public JobsWindow(IModuleUiHost host, JobManager jobManager) : this()
|
||||||
|
{
|
||||||
|
this.FindControl<Controls.WindowMenuBar>("menuBar")!.Attach(host, "core.jobs", this);
|
||||||
|
|
||||||
|
var grid = this.FindControl<DataGrid>("gridJobs")!;
|
||||||
|
grid.ItemsSource = jobManager.Jobs;
|
||||||
|
|
||||||
|
this.FindControl<Button>("btnRefresh")!.Click += (_, _) =>
|
||||||
|
{
|
||||||
|
// Die Zeilen aktualisieren sich über INotifyPropertyChanged von selbst; der Knopf
|
||||||
|
// erzwingt lediglich ein Neuzeichnen (wie das frühere dgvJobs.Refresh()).
|
||||||
|
grid.InvalidateVisual();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Manuellen Lauf anstoßen – bewusst im Hintergrund, damit die Oberfläche nicht blockiert.</summary>
|
||||||
|
private void OnRunNowClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is Button { DataContext: JobStatusRow job } && job.ManualTriggerAction != null)
|
||||||
|
_ = Task.Run(() => job.ManualTriggerAction.Invoke());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:controls="using:PolyTrader.App.Avalonia.Controls"
|
||||||
|
xmlns:shell="using:PolyTrader.App.Avalonia.Shell"
|
||||||
|
x:Class="PolyTrader.App.Avalonia.Views.LauncherWindow"
|
||||||
|
Title="PolyTrader"
|
||||||
|
Width="1600" Height="700"
|
||||||
|
WindowState="Maximized">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
„Startleiste" der Anwendung. Entspricht der bisherigen LauncherForm:
|
||||||
|
oben die gemeinsame Fenster-Menüleiste, darunter die Schnellaktionen (Trading-Modi),
|
||||||
|
dann die Fenster-Buttons, unten die Statusleiste.
|
||||||
|
|
||||||
|
Die Fenster-Buttons sind bewusst datengebunden (ItemsControl über die registrierten Views)
|
||||||
|
statt einzeln im Layout festgeschrieben: die WinForms-Fassung hatte je Modul einen fest
|
||||||
|
verdrahteten Button, der bei fehlendem Modul deaktiviert wurde. Über die Bindung erscheinen
|
||||||
|
genau die Fenster, die es wirklich gibt — das ist robuster und bleibt trotzdem deklarativ.
|
||||||
|
-->
|
||||||
|
<DockPanel>
|
||||||
|
<controls:WindowMenuBar Name="menuBar" DockPanel.Dock="Top" />
|
||||||
|
|
||||||
|
<Border Classes="toolbar" DockPanel.Dock="Top">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="4">
|
||||||
|
<Button Name="btnLiveTrading" Content="LiveTrading (—)" MinWidth="170" />
|
||||||
|
<Button Name="btnDemoTrading" Content="DemoTrading (—)" MinWidth="170" />
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<Border Classes="statusbar" DockPanel.Dock="Bottom">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="24">
|
||||||
|
<TextBlock Name="lblTrading" Text="Trading: —" />
|
||||||
|
<TextBlock Name="lblModules" Text="Module: —" />
|
||||||
|
<TextBlock Name="lblRatelimit" Text="API: —" />
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<ScrollViewer>
|
||||||
|
<StackPanel Margin="12" Spacing="16">
|
||||||
|
<TextBlock Text="Fenster" FontSize="14" FontWeight="SemiBold" />
|
||||||
|
|
||||||
|
<ItemsControl Name="windowButtons">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<WrapPanel Orientation="Horizontal" />
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="shell:WindowMenuEntry">
|
||||||
|
<Button Command="{Binding Command}"
|
||||||
|
MinWidth="190" MinHeight="56"
|
||||||
|
Margin="0,0,8,8"
|
||||||
|
HorizontalContentAlignment="Left">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="10">
|
||||||
|
<Image Source="{Binding Icon}" Width="28" Height="28"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
IsVisible="{Binding Icon, Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||||
|
<StackPanel VerticalAlignment="Center">
|
||||||
|
<TextBlock Text="{Binding Title}" FontWeight="{Binding FontWeight}" />
|
||||||
|
<TextBlock Text="{Binding CheckMark}" FontSize="11" Foreground="#2E7D32" />
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Button>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
|
||||||
|
<TextBlock Name="lblPortInfo"
|
||||||
|
Foreground="#996600"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
Text="Portierung läuft: Dashboard, Terminal, Einstellungen und die Modul-Fenster werden noch auf Avalonia umgestellt. Die Trading-Dienste laufen davon unabhängig." />
|
||||||
|
</StackPanel>
|
||||||
|
</ScrollViewer>
|
||||||
|
</DockPanel>
|
||||||
|
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using PolyTrader.App.Avalonia.Shell;
|
||||||
|
using PolyTrader.Core.Modularity;
|
||||||
|
using PolyTraderSharp;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia.Views
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// „Startleiste" der Anwendung – Gegenstück zur bisherigen LauncherForm. Öffnet die Fenster,
|
||||||
|
/// spiegelt deren Offen-Status und zeigt die Kernkennzahlen in der Statusleiste.
|
||||||
|
/// Layout vollständig in LauncherWindow.axaml.
|
||||||
|
/// </summary>
|
||||||
|
public partial class LauncherWindow : Window
|
||||||
|
{
|
||||||
|
private readonly AvaloniaUiHost _uiHost;
|
||||||
|
private readonly IServiceProvider _services;
|
||||||
|
private readonly TradingState _state;
|
||||||
|
private readonly DispatcherTimer _statusTimer = new() { Interval = TimeSpan.FromSeconds(1) };
|
||||||
|
private readonly ObservableCollection<WindowMenuEntry> _windowButtons = new();
|
||||||
|
|
||||||
|
public LauncherWindow() => AvaloniaXamlLoader.Load(this);
|
||||||
|
|
||||||
|
public LauncherWindow(AvaloniaUiHost uiHost, IServiceProvider services) : this()
|
||||||
|
{
|
||||||
|
_uiHost = uiHost;
|
||||||
|
_services = services;
|
||||||
|
_state = services.GetRequiredService<TradingState>();
|
||||||
|
|
||||||
|
// currentViewId == null => dies ist der Launcher (rechte Menueaktion "Beenden").
|
||||||
|
this.FindControl<Controls.WindowMenuBar>("menuBar")!.Attach(uiHost, null, this);
|
||||||
|
|
||||||
|
this.FindControl<ItemsControl>("windowButtons")!.ItemsSource = _windowButtons;
|
||||||
|
RebuildWindowButtons();
|
||||||
|
_uiHost.OpenStateChanged += OnOpenStateChanged;
|
||||||
|
|
||||||
|
this.FindControl<Button>("btnLiveTrading")!.Click += (_, _) =>
|
||||||
|
{
|
||||||
|
_state.LiveTradingMode = Next(_state.LiveTradingMode);
|
||||||
|
UpdateTradingToggles();
|
||||||
|
};
|
||||||
|
this.FindControl<Button>("btnDemoTrading")!.Click += (_, _) =>
|
||||||
|
{
|
||||||
|
_state.DemoTradingMode = Next(_state.DemoTradingMode);
|
||||||
|
UpdateTradingToggles();
|
||||||
|
};
|
||||||
|
|
||||||
|
_statusTimer.Tick += (_, _) => UpdateStatus();
|
||||||
|
_statusTimer.Start();
|
||||||
|
UpdateStatus();
|
||||||
|
|
||||||
|
// Schliessen des Launchers laeuft ueber dieselbe Sicherheitsabfrage wie "Beenden".
|
||||||
|
Closing += (_, e) =>
|
||||||
|
{
|
||||||
|
if (_uiHost.ShutdownConfirmed) return;
|
||||||
|
e.Cancel = true;
|
||||||
|
Dispatcher.UIThread.Post(_uiHost.RequestShutdown);
|
||||||
|
};
|
||||||
|
Closed += (_, _) =>
|
||||||
|
{
|
||||||
|
_statusTimer.Stop();
|
||||||
|
_uiHost.OpenStateChanged -= OnOpenStateChanged;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Dreistufiger Wechsel wie bisher: Inactive -> SellOnly -> Active -> Inactive.</summary>
|
||||||
|
private static TradingMode Next(TradingMode mode) => mode switch
|
||||||
|
{
|
||||||
|
TradingMode.Inactive => TradingMode.SellOnly,
|
||||||
|
TradingMode.SellOnly => TradingMode.Active,
|
||||||
|
_ => TradingMode.Inactive
|
||||||
|
};
|
||||||
|
|
||||||
|
private void OnOpenStateChanged()
|
||||||
|
{
|
||||||
|
if (Dispatcher.UIThread.CheckAccess()) RebuildWindowButtons();
|
||||||
|
else Dispatcher.UIThread.Post(RebuildWindowButtons);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RebuildWindowButtons()
|
||||||
|
{
|
||||||
|
_windowButtons.Clear();
|
||||||
|
foreach (var view in _uiHost.Views.OrderBy(v => v.Order).ThenBy(v => v.Title))
|
||||||
|
{
|
||||||
|
string id = view.Id;
|
||||||
|
bool open = _uiHost.IsOpen(id);
|
||||||
|
_windowButtons.Add(new WindowMenuEntry
|
||||||
|
{
|
||||||
|
Title = view.Title,
|
||||||
|
Icon = ViewIcons.Resolve(view.IconKey),
|
||||||
|
IsCurrent = open,
|
||||||
|
IsChecked = open,
|
||||||
|
Command = new RelayCommand(() => _uiHost.OpenView(id))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateTradingToggles()
|
||||||
|
{
|
||||||
|
Apply(this.FindControl<Button>("btnLiveTrading")!, "LiveTrading", _state.LiveTradingMode);
|
||||||
|
Apply(this.FindControl<Button>("btnDemoTrading")!, "DemoTrading", _state.DemoTradingMode);
|
||||||
|
|
||||||
|
// Farbgebung aus der WinForms-Oberflaeche uebernommen (LightGreen/Orange/IndianRed).
|
||||||
|
static void Apply(Button btn, string label, TradingMode mode)
|
||||||
|
{
|
||||||
|
(string text, Color color) = mode switch
|
||||||
|
{
|
||||||
|
TradingMode.Active => ($"{label} (AKTIV)", Colors.LightGreen),
|
||||||
|
TradingMode.SellOnly => ($"{label} (SELL-ONLY)", Colors.Orange),
|
||||||
|
_ => ($"{label} (DEAKTIVIERT)", Colors.IndianRed)
|
||||||
|
};
|
||||||
|
btn.Content = text;
|
||||||
|
btn.Background = new SolidColorBrush(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateStatus()
|
||||||
|
{
|
||||||
|
string trading = _state.GlobalTradingPaused
|
||||||
|
? "Pausiert"
|
||||||
|
: $"Live={_state.LiveTradingMode} / Demo={_state.DemoTradingMode}";
|
||||||
|
this.FindControl<TextBlock>("lblTrading")!.Text = $"Trading: {trading}";
|
||||||
|
|
||||||
|
int moduleCount = _services.GetServices<IPolyTraderModule>().Count();
|
||||||
|
this.FindControl<TextBlock>("lblModules")!.Text = $"Module: {moduleCount}";
|
||||||
|
|
||||||
|
this.FindControl<TextBlock>("lblRatelimit")!.Text =
|
||||||
|
$"API: {(_state.IsAlchemyHealthy ? "WSS aktiv" : "Polling")}";
|
||||||
|
|
||||||
|
UpdateTradingToggles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
x:Class="PolyTrader.App.Avalonia.Views.ShutdownConfirmWindow"
|
||||||
|
Title="PolyTrader beenden"
|
||||||
|
Width="480" SizeToContent="Height"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
CanResize="False"
|
||||||
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
|
<!-- Entspricht dem bisherigen ShutdownConfirmDialog: Beenden ist 10 Sekunden gesperrt,
|
||||||
|
Countdown im Text, Abbrechen jederzeit möglich. -->
|
||||||
|
<StackPanel Margin="20" Spacing="12">
|
||||||
|
<TextBlock Text="PolyTrader sicher beenden?"
|
||||||
|
FontSize="16" FontWeight="SemiBold" />
|
||||||
|
|
||||||
|
<TextBlock TextWrapping="Wrap"
|
||||||
|
Text="Offene Orders und laufende Jobs werden geordnet heruntergefahren. Das kann einen Moment dauern. Die Schaltfläche ist kurz gesperrt, damit das Beenden nicht versehentlich ausgelöst wird." />
|
||||||
|
|
||||||
|
<TextBlock Name="lblCountdown"
|
||||||
|
Foreground="#B71C1C"
|
||||||
|
Text="Beenden möglich in 10 s …" />
|
||||||
|
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
|
||||||
|
<Button Name="btnCancel" Content="Abbrechen" Padding="16,6" IsCancel="True" />
|
||||||
|
<Button Name="btnShutdown" Content="Beenden (10 s)" Padding="16,6" IsEnabled="False" />
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
</Window>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
namespace PolyTrader.App.Avalonia.Views
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sicherheitsabfrage vor dem Beenden. Die Beenden-Schaltfläche ist bewusst
|
||||||
|
/// <see cref="LockSeconds"/> Sekunden gesperrt (Verhalten aus der WinForms-Oberfläche
|
||||||
|
/// übernommen), Abbrechen ist jederzeit möglich. Liefert <c>true</c>, wenn bestätigt wurde.
|
||||||
|
/// </summary>
|
||||||
|
public partial class ShutdownConfirmWindow : Window
|
||||||
|
{
|
||||||
|
private const int LockSeconds = 10;
|
||||||
|
|
||||||
|
private readonly DispatcherTimer _timer = new() { Interval = TimeSpan.FromSeconds(1) };
|
||||||
|
private int _remaining = LockSeconds;
|
||||||
|
|
||||||
|
public ShutdownConfirmWindow()
|
||||||
|
{
|
||||||
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
|
||||||
|
var countdown = this.FindControl<TextBlock>("lblCountdown")!;
|
||||||
|
var shutdown = this.FindControl<Button>("btnShutdown")!;
|
||||||
|
var cancel = this.FindControl<Button>("btnCancel")!;
|
||||||
|
|
||||||
|
shutdown.Click += (_, _) => Close(true);
|
||||||
|
cancel.Click += (_, _) => Close(false);
|
||||||
|
|
||||||
|
_timer.Tick += (_, _) =>
|
||||||
|
{
|
||||||
|
_remaining--;
|
||||||
|
if (_remaining > 0)
|
||||||
|
{
|
||||||
|
countdown.Text = $"Beenden möglich in {_remaining} s …";
|
||||||
|
shutdown.Content = $"Beenden ({_remaining} s)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_timer.Stop();
|
||||||
|
countdown.Text = "Beenden ist jetzt möglich.";
|
||||||
|
shutdown.Content = "Beenden";
|
||||||
|
shutdown.IsEnabled = true;
|
||||||
|
};
|
||||||
|
_timer.Start();
|
||||||
|
|
||||||
|
Closed += (_, _) => _timer.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<assemblyIdentity version="1.0.0.0" name="PolyTrader.App.Avalonia"/>
|
||||||
|
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<windowsSettings>
|
||||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
|
||||||
|
</windowsSettings>
|
||||||
|
</application>
|
||||||
|
</assembly>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"Database": {
|
||||||
|
"_comment": "MySqlConnectionString liegt in der gitignorierten appsettings.Local.json.",
|
||||||
|
"MySqlConnectionString": ""
|
||||||
|
},
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.EntityFrameworkCore": "Warning",
|
||||||
|
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using PolyTrader.Core.Persistence;
|
||||||
|
using PolyTraderSharp.Models;
|
||||||
|
|
||||||
|
namespace PolyTraderSharp.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Hydriert den Core-<see cref="TradingState"/> EINMALIG beim Start: Accounts und – bei
|
||||||
|
/// Demo-Konten – deren offene Positionen. Muss als ERSTER IHostedService laufen, damit die
|
||||||
|
/// Trading-BackgroundServices nicht gegen einen leeren State anlaufen (Startup-Race).
|
||||||
|
///
|
||||||
|
/// <para>Zuvor erledigte das der modulübergreifende <c>StartupHydrationService</c> der WinForms-App.
|
||||||
|
/// Der ist mit der Linux-Portierung aufgeteilt worden: Der Core-Anteil steht jetzt hier, der
|
||||||
|
/// Copytrading-Anteil im Modul (<c>CopyTradingHydrationService</c>). Das behebt nebenbei einen
|
||||||
|
/// latenten Fehler – bei deaktiviertem Copytrading-Modul wären die Accounts vorher gar nicht
|
||||||
|
/// mehr hydriert worden, obwohl sie zum Core gehören.</para>
|
||||||
|
/// </summary>
|
||||||
|
public sealed class CoreStateHydrationService : IHostedService
|
||||||
|
{
|
||||||
|
private readonly TradingState _state;
|
||||||
|
private readonly IAccountRepository _accountRepo;
|
||||||
|
private readonly IPositionRepository _positionRepo;
|
||||||
|
private readonly TerminalLogger _logger;
|
||||||
|
|
||||||
|
public CoreStateHydrationService(TradingState state, IAccountRepository accountRepo,
|
||||||
|
IPositionRepository positionRepo, TerminalLogger logger)
|
||||||
|
{
|
||||||
|
_state = state;
|
||||||
|
_accountRepo = accountRepo;
|
||||||
|
_positionRepo = positionRepo;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var acc in _accountRepo.GetAll())
|
||||||
|
{
|
||||||
|
if (acc.IsDemo)
|
||||||
|
foreach (var pos in _positionRepo.GetDemo(acc.AccountId))
|
||||||
|
acc.OpenPositions.TryAdd(pos.TokenId, pos);
|
||||||
|
|
||||||
|
_state.Accounts[acc.AccountId] = acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Info($"Core-Hydration abgeschlossen: {_state.Accounts.Count} Accounts geladen.");
|
||||||
|
}
|
||||||
|
catch (System.Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error($"Core-Hydration fehlgeschlagen: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,20 @@
|
|||||||
using System.ComponentModel;
|
using System.Collections.ObjectModel;
|
||||||
using PolyTraderSharp.Models;
|
using PolyTraderSharp.Models;
|
||||||
|
|
||||||
namespace PolyTraderSharp.Services
|
namespace PolyTraderSharp.Services
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Registrierung der Hintergrund-Jobs für die Jobs-Ansicht.
|
||||||
|
///
|
||||||
|
/// <para><see cref="ObservableCollection{T}"/> statt des früheren <c>BindingList</c>: Avalonia-
|
||||||
|
/// Steuerelemente werten <c>INotifyCollectionChanged</c> aus, das <c>BindingList</c> nicht
|
||||||
|
/// implementiert – neu registrierte Jobs wären in der Oberfläche sonst unsichtbar geblieben.
|
||||||
|
/// Die Zeilen selbst melden Änderungen weiterhin über <c>INotifyPropertyChanged</c>
|
||||||
|
/// (<see cref="JobStatusRow"/>).</para>
|
||||||
|
/// </summary>
|
||||||
public class JobManager
|
public class JobManager
|
||||||
{
|
{
|
||||||
public BindingList<JobStatusRow> Jobs { get; } = new BindingList<JobStatusRow>();
|
public ObservableCollection<JobStatusRow> Jobs { get; } = new();
|
||||||
|
|
||||||
public void RegisterJob(JobStatusRow job)
|
public void RegisterJob(JobStatusRow job)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ namespace PolyTrader.Modules.CopyTrading
|
|||||||
// K2 – Neustart-Reconciliation: MUSS als erster Modul-HostedService laufen (nach der
|
// K2 – Neustart-Reconciliation: MUSS als erster Modul-HostedService laufen (nach der
|
||||||
// State-Hydration, vor TraderMonitor/Engine), damit verwaiste CLOB-Orders vom vorherigen
|
// State-Hydration, vor TraderMonitor/Engine), damit verwaiste CLOB-Orders vom vorherigen
|
||||||
// Lauf storniert sind, bevor das erste Signal verarbeitet wird.
|
// Lauf storniert sind, bevor das erste Signal verarbeitet wird.
|
||||||
|
// Muss vor den Trading-Diensten des Moduls laufen (Settings + Trader in den State).
|
||||||
|
services.AddHostedService<CopyTradingHydrationService>();
|
||||||
services.AddHostedService<StartupOrderReconciliationService>();
|
services.AddHostedService<StartupOrderReconciliationService>();
|
||||||
|
|
||||||
// Modul-Services (Signalquelle, Ausführung, Analytics)
|
// Modul-Services (Signalquelle, Ausführung, Analytics)
|
||||||
|
|||||||
+12
-36
@@ -3,7 +3,6 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using PolyTrader.Core.Persistence;
|
|
||||||
using PolyTrader.Modules.CopyTrading.Logic;
|
using PolyTrader.Modules.CopyTrading.Logic;
|
||||||
using PolyTrader.Modules.CopyTrading.Persistence;
|
using PolyTrader.Modules.CopyTrading.Persistence;
|
||||||
using PolyTraderSharp.Models;
|
using PolyTraderSharp.Models;
|
||||||
@@ -11,35 +10,27 @@ using PolyTraderSharp.Models;
|
|||||||
namespace PolyTraderSharp.Services
|
namespace PolyTraderSharp.Services
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hydriert den TradingState (Accounts, Demo-Positionen, Trader) EINMALIG beim App-Start.
|
/// Hydriert den Copytrading-Zustand beim Start: Account-Settings (legt fehlende Default-Einträge
|
||||||
/// Registriert als erster IHostedService, damit die Hydration abgeschlossen ist, bevor die
|
/// an) und die verfolgten Master-Trader. Läuft nach <see cref="CoreStateHydrationService"/>,
|
||||||
/// Trading-BackgroundServices (TraderMonitor, CopyTradingEngine, ...) ihre ExecuteAsync
|
/// weil er die dort geladenen Accounts braucht – die Reihenfolge ergibt sich aus der
|
||||||
/// starten. Behebt den Startup-Race, bei dem Services gegen einen leeren State anliefen
|
/// Registrierungsreihenfolge (Core zuerst, dann Module).
|
||||||
/// (früher lag diese Logik in frm_main.LoadDatabaseAndState und lief erst NACH AppHost.Start()).
|
///
|
||||||
|
/// <para>Zuvor Teil des modulübergreifenden <c>StartupHydrationService</c> der WinForms-App.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class StartupHydrationService : IHostedService
|
public sealed class CopyTradingHydrationService : IHostedService
|
||||||
{
|
{
|
||||||
private readonly TradingState _state;
|
private readonly TradingState _state;
|
||||||
private readonly CopyTradingState _copyState;
|
private readonly CopyTradingState _copyState;
|
||||||
private readonly IAccountRepository _accountRepo;
|
|
||||||
private readonly IPositionRepository _positionRepo;
|
|
||||||
private readonly ICopyTradingAccountSettingsRepository _accountSettingsRepo;
|
private readonly ICopyTradingAccountSettingsRepository _accountSettingsRepo;
|
||||||
private readonly ITrackedTraderRepository _traderRepo;
|
private readonly ITrackedTraderRepository _traderRepo;
|
||||||
private readonly TerminalLogger _logger;
|
private readonly TerminalLogger _logger;
|
||||||
|
|
||||||
public StartupHydrationService(
|
public CopyTradingHydrationService(TradingState state, CopyTradingState copyState,
|
||||||
TradingState state,
|
|
||||||
CopyTradingState copyState,
|
|
||||||
IAccountRepository accountRepo,
|
|
||||||
IPositionRepository positionRepo,
|
|
||||||
ICopyTradingAccountSettingsRepository accountSettingsRepo,
|
ICopyTradingAccountSettingsRepository accountSettingsRepo,
|
||||||
ITrackedTraderRepository traderRepo,
|
ITrackedTraderRepository traderRepo, TerminalLogger logger)
|
||||||
TerminalLogger logger)
|
|
||||||
{
|
{
|
||||||
_state = state;
|
_state = state;
|
||||||
_copyState = copyState;
|
_copyState = copyState;
|
||||||
_accountRepo = accountRepo;
|
|
||||||
_positionRepo = positionRepo;
|
|
||||||
_accountSettingsRepo = accountSettingsRepo;
|
_accountSettingsRepo = accountSettingsRepo;
|
||||||
_traderRepo = traderRepo;
|
_traderRepo = traderRepo;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@@ -49,31 +40,16 @@ namespace PolyTraderSharp.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var accounts = _accountRepo.GetAll();
|
HydrateAccountSettings(_state.Accounts.Values.ToList());
|
||||||
foreach (var acc in accounts)
|
|
||||||
{
|
|
||||||
if (acc.IsDemo)
|
|
||||||
{
|
|
||||||
foreach (var pos in _positionRepo.GetDemo(acc.AccountId))
|
|
||||||
{
|
|
||||||
acc.OpenPositions.TryAdd(pos.TokenId, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_state.Accounts[acc.AccountId] = acc;
|
|
||||||
}
|
|
||||||
|
|
||||||
HydrateAccountSettings(accounts);
|
|
||||||
|
|
||||||
foreach (var trd in _traderRepo.GetAll())
|
foreach (var trd in _traderRepo.GetAll())
|
||||||
{
|
|
||||||
_copyState.Traders[trd.Id] = trd;
|
_copyState.Traders[trd.Id] = trd;
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info($"Startup-Hydration abgeschlossen: {_state.Accounts.Count} Accounts, {_copyState.Traders.Count} Trader geladen.");
|
_logger.Info($"Copytrading-Hydration abgeschlossen: {_copyState.Traders.Count} Trader geladen.");
|
||||||
}
|
}
|
||||||
catch (System.Exception ex)
|
catch (System.Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Error($"Startup-Hydration fehlgeschlagen: {ex.Message}");
|
_logger.Error($"Copytrading-Hydration fehlgeschlagen: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
Reference in New Issue
Block a user