using Abstractions; using MedusaPluginChargeMachine.Entities; using MedusaPluginChargeMachine.Services; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using System.Text; namespace MedusaPluginChargeMachine; public class ChargeMachinePlugin : IMedusaPlugin { public string Name => "Charge Machine"; public string Version => "1.0.0"; public string Description => "Plugin for the paseli charge machine"; public string GameCode => "LA9"; public int? MinVer => null; public int? MaxVer => null; public Encoding? ForcedEncoding => null; public Delegate DoesProfileExist => () => false; public Task OnBuilderInitialize(WebApplicationBuilder builder) => Task.CompletedTask; public void ConfigurePluginServices(IServiceCollection services) { services.AddSingleton(); services.AddDbContext(o => o.UseSqlite("Data Source=database/ChargeMachine.db;")); } public async Task OnAppInitialize(WebApplication app, IServiceProvider pluginServices) { await using var scope = pluginServices.CreateAsyncScope(); var db = scope.ServiceProvider.GetRequiredService(); await db.Database.MigrateAsync(); await SeedArticleContentsAsync(db); } private static async Task SeedArticleContentsAsync(ChargeMachineDbContext db) { if (await db.ArticleContents.AnyAsync()) return; var defaults = new List { new() { ArticleType = "DOCMT_0000", ArticleDoc = "" }, new() { ArticleType = "DOCMT_0001", ArticleDoc = "PASELI Charge Machine" }, new() { ArticleType = "DOCMT_0002", ArticleDoc = "" }, new() { ArticleType = "DOCMT_0003", ArticleDoc = "" }, new() { ArticleType = "URL_0001_A", ArticleDoc = "https://localhost:5173/" }, new() { ArticleType = "URL_0001_B", ArticleDoc = "https://localhost:5173/" }, new() { ArticleType = "URL_0002_A", ArticleDoc = "https://localhost:5173/" }, new() { ArticleType = "URL_0002_B", ArticleDoc = "https://localhost:5173/" }, new() { ArticleType = "URL_0003_A", ArticleDoc = "https://localhost:5173/" }, new() { ArticleType = "URL_0003_B", ArticleDoc = "https://localhost:5173/" }, new() { ArticleType = "URL_0004_A", ArticleDoc = "https://localhost:5173/" }, new() { ArticleType = "URL_0041_B", ArticleDoc = "https://localhost:5173/" }, new() { ArticleType = "PASELIUNIT", ArticleDoc = "P" }, }; db.ArticleContents.AddRange(defaults); await db.SaveChangesAsync(); } }