Update repo structure

This commit is contained in:
Dennis Reimann 2023-01-25 17:14:40 +01:00
parent 54492b1125
commit 0caa7d7d27
No known key found for this signature in database
GPG Key ID: 5009E1797F03F8D0
21 changed files with 103 additions and 81 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "btcpayserver"]
path = btcpayserver
url = https://github.com/btcpayserver/btcpayserver

View File

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
</PropertyGroup>
<!-- Plugin specific properties -->
<PropertyGroup>
<Product>BTCPay Server Plugin Template</Product>
<Description>A template for your own BTCPay Server plugin.</Description>
<Authors>BTCPay Server</Authors>
<Version>1.0.0</Version>
</PropertyGroup>
<!-- Plugin development properties -->
<PropertyGroup>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PreserveCompilationContext>false</PreserveCompilationContext>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
<!-- This will make sure that referencing BTCPayServer doesn't put any artifact in the published directory -->
<ItemDefinitionGroup>
<ProjectReference>
<Properties>StaticWebAssetsEnabled=false</Properties>
<Private>false</Private>
<ExcludeAssets>runtime;native;build;buildTransitive;contentFiles</ExcludeAssets>
</ProjectReference>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\btcpayserver\BTCPayServer\BTCPayServer.csproj" />
<EmbeddedResource Include="Resources\**" />
</ItemGroup>
</Project>

View File

@ -13,9 +13,9 @@ namespace BTCPayServer.Plugins.Template;
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanViewProfile)]
public class UIPluginController : Controller
{
private readonly PluginService _PluginService;
private readonly MyPluginService _PluginService;
public UIPluginController(PluginService PluginService)
public UIPluginController(MyPluginService PluginService)
{
_PluginService = PluginService;
}

View File

@ -9,11 +9,11 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BTCPayServer.Plugins.Template;
public class PluginDbContext : DbContext
public class MyPluginDbContext : DbContext
{
private readonly bool _designTime;
public PluginDbContext(DbContextOptions<PluginDbContext> options, bool designTime = false)
public MyPluginDbContext(DbContextOptions<MyPluginDbContext> options, bool designTime = false)
: base(options)
{
_designTime = designTime;

View File

@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace BTCPayServer.Plugins.Template.Migrations
{
[DbContext(typeof(PluginDbContext))]
[DbContext(typeof(MyPluginDbContext))]
[Migration("20201117154419_Init")]
public partial class Init : Migration
{

View File

@ -7,8 +7,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BTCPayServer.Plugins.Template.Migrations
{
[DbContext(typeof(PluginDbContext))]
partial class PluginDbContextModelSnapshot : ModelSnapshot
[DbContext(typeof(MyPluginDbContext))]
partial class MyPluginDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{

View File

@ -8,20 +8,21 @@ namespace BTCPayServer.Plugins.Template;
public class Plugin : BaseBTCPayServerPlugin
{
public override string Identifier { get; } = "BTCPayServer.Plugins.Template";
public override string Name { get; } = "Plugin Template";
public override string Description { get; } = "This is the plugin description";
public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = new[]
{
new IBTCPayServerPlugin.PluginDependency { Identifier = nameof(BTCPayServer), Condition = ">=1.7.4" }
};
public override void Execute(IServiceCollection services)
{
services.AddSingleton<IUIExtension>(new UIExtension("TemplatePluginHeaderNav", "header-nav"));
services.AddHostedService<ApplicationPartsLogger>();
services.AddHostedService<PluginMigrationRunner>();
services.AddSingleton<PluginService>();
services.AddSingleton<PluginDbContextFactory>();
services.AddDbContext<PluginDbContext>((provider, o) =>
services.AddSingleton<MyPluginService>();
services.AddSingleton<MyPluginDbContextFactory>();
services.AddDbContext<MyPluginDbContext>((provider, o) =>
{
PluginDbContextFactory factory = provider.GetRequiredService<PluginDbContextFactory>();
MyPluginDbContextFactory factory = provider.GetRequiredService<MyPluginDbContextFactory>();
factory.ConfigureBuilder(o);
});
}

View File

@ -9,15 +9,17 @@ namespace BTCPayServer.Plugins.Template;
public class PluginMigrationRunner : IHostedService
{
private readonly PluginDbContextFactory _PluginDbContextFactory;
private readonly PluginService _PluginService;
private readonly MyPluginDbContextFactory _PluginDbContextFactory;
private readonly MyPluginService _PluginService;
private readonly ISettingsRepository _settingsRepository;
public PluginMigrationRunner(PluginDbContextFactory PluginDbContextFactory, ISettingsRepository settingsRepository,
PluginService PluginService)
public PluginMigrationRunner(
ISettingsRepository settingsRepository,
MyPluginDbContextFactory PluginDbContextFactory,
MyPluginService PluginService)
{
_PluginDbContextFactory = PluginDbContextFactory;
_settingsRepository = settingsRepository;
_PluginDbContextFactory = PluginDbContextFactory;
_PluginService = PluginService;
}
@ -25,16 +27,16 @@ public class PluginMigrationRunner : IHostedService
{
PluginDataMigrationHistory settings = await _settingsRepository.GetSettingAsync<PluginDataMigrationHistory>() ??
new PluginDataMigrationHistory();
await using PluginDbContext ctx = _PluginDbContextFactory.CreateContext();
await using var ctx = _PluginDbContextFactory.CreateContext();
await ctx.Database.MigrateAsync(cancellationToken);
// settings migrations
if (!settings.UpdatedSomething)
{
settings.UpdatedSomething = true;
await _settingsRepository.UpdateSetting(settings);
}
// test record
await _PluginService.AddTestDataRecord();
}

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -0,0 +1,33 @@
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Abstractions.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Options;
namespace BTCPayServer.Plugins.Template;
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<MyPluginDbContext>
{
public MyPluginDbContext CreateDbContext(string[] args)
{
DbContextOptionsBuilder<MyPluginDbContext> builder = new DbContextOptionsBuilder<MyPluginDbContext>();
builder.UseSqlite("Data Source=temp.db");
return new MyPluginDbContext(builder.Options, true);
}
}
public class MyPluginDbContextFactory : BaseDbContextFactory<MyPluginDbContext>
{
public MyPluginDbContextFactory(IOptions<DatabaseOptions> options) : base(options, "BTCPayServer.Plugins.Template")
{
}
public override MyPluginDbContext CreateContext()
{
DbContextOptionsBuilder<MyPluginDbContext> builder = new DbContextOptionsBuilder<MyPluginDbContext>();
ConfigureBuilder(builder);
return new MyPluginDbContext(builder.Options);
}
}

View File

@ -6,18 +6,18 @@ using Microsoft.EntityFrameworkCore;
namespace BTCPayServer.Plugins.Template.Services;
public class PluginService
public class MyPluginService
{
private readonly PluginDbContextFactory _PluginDbContextFactory;
private readonly MyPluginDbContextFactory _PluginDbContextFactory;
public PluginService(PluginDbContextFactory PluginDbContextFactory)
public MyPluginService(MyPluginDbContextFactory PluginDbContextFactory)
{
_PluginDbContextFactory = PluginDbContextFactory;
}
public async Task AddTestDataRecord()
{
await using PluginDbContext context = _PluginDbContextFactory.CreateContext();
await using var context = _PluginDbContextFactory.CreateContext();
await context.PluginRecords.AddAsync(new PluginData { Timestamp = DateTimeOffset.UtcNow });
await context.SaveChangesAsync();
@ -25,7 +25,7 @@ public class PluginService
public async Task<List<PluginData>> Get()
{
await using PluginDbContext context = _PluginDbContextFactory.CreateContext();
await using var context = _PluginDbContextFactory.CreateContext();
return await context.PluginRecords.ToListAsync();
}

View File

@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PreserveCompilationContext>false</PreserveCompilationContext>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<AssemblyVersion>1.0.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<ProjectReference Include="..\BTCPayServer.Abstractions\BTCPayServer.Abstractions.csproj" />
<EmbeddedResource Include="Resources\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017-2023 btcpayserver
Copyright (c) 2023 BTCPay Server
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,33 +0,0 @@
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Abstractions.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Options;
namespace BTCPayServer.Plugins.Template;
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<PluginDbContext>
{
public PluginDbContext CreateDbContext(string[] args)
{
DbContextOptionsBuilder<PluginDbContext> builder = new DbContextOptionsBuilder<PluginDbContext>();
builder.UseSqlite("Data Source=temp.db");
return new PluginDbContext(builder.Options, true);
}
}
public class PluginDbContextFactory : BaseDbContextFactory<PluginDbContext>
{
public PluginDbContextFactory(IOptions<DatabaseOptions> options) : base(options, "BTCPayServer.Plugins.Template")
{
}
public override PluginDbContext CreateContext()
{
DbContextOptionsBuilder<PluginDbContext> builder = new DbContextOptionsBuilder<PluginDbContext>();
ConfigureBuilder(builder);
return new PluginDbContext(builder.Options);
}
}

1
btcpayserver Submodule

@ -0,0 +1 @@
Subproject commit 5089ec98262a05ffb955d918828e53de93e0894b