Phase 6 (Stufe 6): MongoDB vollstaendig entfernt
- Legacy-Form stillgelegt: frm_main(.Designer/.resx) + frm_analytics(.Designer/.resx) geloescht, 'Open Legacy'-Menue aus LauncherForm entfernt. - Program.cs: IMongoDatabase-Registrierung + closed_trades-Cleanup weg; Trade-Nummerierung liest jetzt hoechste TradeId aus ICopyTradeLogRepository. - StartupHydrationService: Mongo-/Bson-Fallback entfernt (Settings kommen aus dem Repo; fehlende Accounts erhalten Default-Settings). - Alle Mongo*Repository (Core 4 + Modul 4) geloescht; DI-Zweige auf EF/MySQL reduziert (AddCorePersistence, CopyTradingModule). - ConfigMigrator: Mongo-Pfad (Run/MigrateSettings) entfernt; nur noch RunFromJson + VerifyMySql (kein Mongo-Treiber mehr). - Modelle: [BsonId] entfernt (EF-Keys via HasKey); ObjectId-Defaults -> Guid. - LiteDB-Shim (MongoDbLiteDBShim) geloescht; MongoDB.Driver- + LiteDB-Pakete aus App/Core entfernt; stale usings + user-sichtbare Strings bereinigt. - DatabaseOptions/appsettings.json: Mongo-Provider/Connection-Felder entfernt. - Build gruen; --verify-mysql bestaetigt 3 Accounts/3 Settings/32 Trader/2344 Markets. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d227d24ca8
commit
b951b912f4
+9
-66
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using MongoDB.Driver;
|
||||
using PolyTraderSharp.Extensions;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Channels;
|
||||
using System.Windows.Forms;
|
||||
@@ -26,13 +25,6 @@ internal static class Program
|
||||
[STAThread]
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
// Einmalige Config-Migration Mongo -> MySQL (Phase 6, Stufe 4). Kein UI-Start.
|
||||
if (args.Length > 0 && string.Equals(args[0], "--migrate-config", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
RunConfigMigration();
|
||||
return;
|
||||
}
|
||||
|
||||
// Config-Migration aus mongoexport-JSON (Ordner, Default "MongoDB") -> MySQL.
|
||||
if (args.Length > 0 && string.Equals(args[0], "--migrate-json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
@@ -59,18 +51,9 @@ internal static class Program
|
||||
{
|
||||
var databaseOptions = new DatabaseOptions
|
||||
{
|
||||
Provider = context.Configuration["Database:Provider"] ?? "Mongo",
|
||||
MySqlConnectionString = context.Configuration["Database:MySqlConnectionString"] ?? string.Empty,
|
||||
ConnectionString = context.Configuration["Database:ConnectionString"] ?? "mongodb://localhost:27017",
|
||||
DatabaseName = context.Configuration["Database:DatabaseName"] ?? "PolyTraderDB"
|
||||
MySqlConnectionString = context.Configuration["Database:MySqlConnectionString"] ?? string.Empty
|
||||
};
|
||||
services.Configure<DatabaseOptions>(context.Configuration.GetSection(DatabaseOptions.SectionName));
|
||||
services.AddSingleton<IMongoDatabase>((IServiceProvider sp) =>
|
||||
{
|
||||
var dbOptions = sp.GetRequiredService<IOptions<DatabaseOptions>>().Value;
|
||||
var client = new MongoClient(dbOptions.ConnectionString);
|
||||
return client.GetDatabase(dbOptions.DatabaseName);
|
||||
});
|
||||
services.AddCorePersistence(databaseOptions);
|
||||
services.AddSingleton<IBlockchainWssClientFactory, AlchemyWssClientFactory>();
|
||||
services.AddSingleton((IServiceProvider sp) => ServerSettings.Load("server_settings.xml"));
|
||||
@@ -124,37 +107,19 @@ internal static class Program
|
||||
services.AddHostedService<PolymarketWssClient>();
|
||||
services.AddHostedService((IServiceProvider sp) => sp.GetRequiredService<MullvadVpnService>());
|
||||
services.AddHostedService((IServiceProvider sp) => sp.GetRequiredService<ThreemaService>());
|
||||
services.AddTransient<frm_main>();
|
||||
services.AddSingleton<PolyTraderSharp.Ui.ShellUiHost>();
|
||||
services.AddTransient<PolyTraderSharp.Ui.LauncherForm>();
|
||||
}).Build();
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
var db = AppHost.Services.GetRequiredService<IMongoDatabase>();
|
||||
|
||||
// Einmal-Bereinigung (Alt-Bug): entferne closed_trades mit ObjectId-_id.
|
||||
// Das _id muss die int-TradeId sein; fehlerhafte Auto-ObjectIds werden verworfen.
|
||||
// Läuft jetzt über die konfigurierte DB statt über einen hart codierten Client.
|
||||
try
|
||||
{
|
||||
var cleanupCol = db.GetCollection<MongoDB.Bson.BsonDocument>("closed_trades");
|
||||
cleanupCol.DeleteMany(Builders<MongoDB.Bson.BsonDocument>.Filter.Type("_id", MongoDB.Bson.BsonType.ObjectId));
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Trade-Nummerierung fortsetzen: höchste bestehende TradeId aus dem Log lesen.
|
||||
var copyState = AppHost.Services.GetRequiredService<CopyTradingState>();
|
||||
var maxTradeDoc = db.GetCollection<MongoDB.Bson.BsonDocument>("closed_trades")
|
||||
.Find(Builders<MongoDB.Bson.BsonDocument>.Filter.Empty)
|
||||
.SortByDescending(d => d["_id"])
|
||||
.Limit(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (maxTradeDoc != null && maxTradeDoc.Contains("_id"))
|
||||
{
|
||||
copyState.TotalCopyTrades = maxTradeDoc["_id"].AsInt32;
|
||||
}
|
||||
}
|
||||
var tradeLog = AppHost.Services.GetRequiredService<ICopyTradeLogRepository>();
|
||||
var allTrades = tradeLog.Find(_ => true);
|
||||
if (allTrades.Count > 0)
|
||||
copyState.TotalCopyTrades = allTrades.Max(t => t.TradeId);
|
||||
}
|
||||
catch { }
|
||||
|
||||
AppHost.Start();
|
||||
@@ -232,28 +197,6 @@ internal static class Program
|
||||
AppHost.StopAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private static void RunConfigMigration()
|
||||
{
|
||||
var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
|
||||
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: true)
|
||||
.AddJsonFile("appsettings.Local.json", optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
var mongoConn = config["Database:ConnectionString"] ?? "mongodb://localhost:27017";
|
||||
var mongoDbName = config["Database:DatabaseName"] ?? "PolyTraderDB";
|
||||
var mySql = config["Database:MySqlConnectionString"] ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(mySql))
|
||||
{
|
||||
Console.WriteLine("FEHLER: Database:MySqlConnectionString fehlt (appsettings.Local.json).");
|
||||
return;
|
||||
}
|
||||
|
||||
Services.ConfigMigrator.Run(mongoConn, mongoDbName, mySql);
|
||||
}
|
||||
|
||||
private static void RunConfigMigrationFromJson(string folder)
|
||||
{
|
||||
var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
|
||||
|
||||
Reference in New Issue
Block a user