Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.1"/>
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="9.0.1"/>
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1"/>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3"/>
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.1"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2"/>
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.2"/>
Expand Down
18 changes: 18 additions & 0 deletions ScriptBee.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence.File", "src\Ada
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence.File.Tests", "test\Adapters\Driven\Persistence.File.Tests\Persistence.File.Tests.csproj", "{86A8C10D-0701-4D44-BEAB-0982C0D733A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ports.Plugins", "src\Application\Ports\Driven\Ports.Plugins\Ports.Plugins.csproj", "{FC474598-6399-46E2-8795-394E4F806052}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence.InMemory", "src\Adapters\Driven\Persistence.InMemory\Persistence.InMemory.csproj", "{0426847C-4B33-434E-AC93-7C8C95AB5506}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence.InMemory.Tests", "test\Adapters\Driven\Persistence.InMemory.Tests\Persistence.InMemory.Tests.csproj", "{348FE904-F636-4113-B63E-044B645F64C7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -163,5 +169,17 @@ Global
{86A8C10D-0701-4D44-BEAB-0982C0D733A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86A8C10D-0701-4D44-BEAB-0982C0D733A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86A8C10D-0701-4D44-BEAB-0982C0D733A2}.Release|Any CPU.Build.0 = Release|Any CPU
{FC474598-6399-46E2-8795-394E4F806052}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC474598-6399-46E2-8795-394E4F806052}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC474598-6399-46E2-8795-394E4F806052}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC474598-6399-46E2-8795-394E4F806052}.Release|Any CPU.Build.0 = Release|Any CPU
{0426847C-4B33-434E-AC93-7C8C95AB5506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0426847C-4B33-434E-AC93-7C8C95AB5506}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0426847C-4B33-434E-AC93-7C8C95AB5506}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0426847C-4B33-434E-AC93-7C8C95AB5506}.Release|Any CPU.Build.0 = Release|Any CPU
{348FE904-F636-4113-B63E-044B645F64C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{348FE904-F636-4113-B63E-044B645F64C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{348FE904-F636-4113-B63E-044B645F64C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{348FE904-F636-4113-B63E-044B645F64C7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
11 changes: 0 additions & 11 deletions ScriptBee/Models/Plugin.cs

This file was deleted.

31 changes: 0 additions & 31 deletions ScriptBee/Plugin/IPluginRepository.cs

This file was deleted.

5 changes: 0 additions & 5 deletions ScriptBee/Plugin/Manifest/LinkerPluginExtensionPoint.cs

This file was deleted.

5 changes: 0 additions & 5 deletions ScriptBee/Plugin/Manifest/LoaderPluginExtensionPoint.cs

This file was deleted.

5 changes: 0 additions & 5 deletions ScriptBee/Plugin/Manifest/PluginBundleExtensionPoint.cs

This file was deleted.

81 changes: 0 additions & 81 deletions ScriptBee/Plugin/PluginRepository.cs

This file was deleted.

11 changes: 0 additions & 11 deletions ScriptBeeWebApp/Services/GuidGenerator.cs

This file was deleted.

4 changes: 3 additions & 1 deletion calculation.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ COPY src/Application/Domain/Service.Analysis src/Application/Domain/Service.Anal
COPY src/Application/Ports/Driving/UseCases.Analysis src/Application/Ports/Driving/UseCases.Analysis
COPY src/Application/Ports/Driven/Ports.Analysis src/Application/Ports/Driven/Ports.Analysis
COPY src/Application/Ports/Driven/Ports.Files src/Application/Ports/Driven/Ports.Files
COPY src/Application/Ports/Driven/Ports.Plugins src/Application/Ports/Driven/Ports.Plugins
COPY src/Application/Ports/Driven/Ports.Project src/Application/Ports/Driven/Ports.Project

COPY src/Adapters/Driven/Persistence.Mongodb src/Adapters/Driven/Persistence.Mongodb
COPY src/Adapters/Driven/Persistence.File src/Adapters/Driven/Persistence.File
COPY src/Adapters/Driven/Persistence.InMemory src/Adapters/Driven/Persistence.InMemory
COPY src/Adapters/Driven/Persistence.Mongodb src/Adapters/Driven/Persistence.Mongodb

COPY src/Adapters/Driving/Common.Web src/Adapters/Driving/Common.Web
COPY src/Adapters/Driving/Calculation.Web src/Adapters/Driving/Calculation.Web
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>ScriptBee.Persistence.InMemory</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Application\Ports\Driven\Ports.Plugins\Ports.Plugins.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
</ItemGroup>
</Project>
91 changes: 91 additions & 0 deletions src/Adapters/Driven/Persistence.InMemory/PluginRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Collections.Concurrent;
using DxWorks.ScriptBee.Plugin.Api;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using ScriptBee.Domain.Model.Plugin;
using ScriptBee.Domain.Model.Plugin.Manifest;
using ScriptBee.Ports.Plugins;

namespace ScriptBee.Persistence.InMemory;

public class PluginRepository : IPluginRepository
{
private readonly ConcurrentDictionary<string, Plugin> _plugins = new();
private readonly ConcurrentBag<ServiceDescriptor> _pluginServiceCollection = [];

public void UnRegisterPlugin(string pluginId, string pluginVersion)
{
_plugins.Remove(pluginId, out _);
}

public void RegisterPlugin(Plugin plugin, Type @interface, Type concrete)
{
RegisterPlugin(plugin);

_pluginServiceCollection.Add(
new ServiceDescriptor(@interface, concrete, ServiceLifetime.Singleton)
);
}

public void RegisterPlugin(Plugin plugin)
{
_plugins.AddOrUpdate(
plugin.Id,
plugin,
(_, manifest) => manifest.Version < plugin.Version ? plugin : manifest
);
}

public TService? GetPlugin<TService>(
Func<TService, bool> filter,
IEnumerable<(Type @interface, object instance)>? services = null
)
where TService : IPlugin
{
return GetPlugins<TService>().FirstOrDefault(filter);
}

public IEnumerable<TService> GetPlugins<TService>(
IEnumerable<(Type @interface, object instance)>? services = null
)
where TService : IPlugin
{
var serviceCollection = new ServiceCollection { _pluginServiceCollection };

if (services is not null)
serviceCollection.Add(
services.Select(s => new ServiceDescriptor(s.@interface, s.instance))
);

return serviceCollection.BuildServiceProvider().GetServices<TService>();
}

public IEnumerable<PluginManifest> GetLoadedPluginsManifests()
{
return GetLoadedPlugins().Select(plugin => plugin.Manifest);
}

public IEnumerable<Plugin> GetLoadedPlugins(string kind)
{
return GetLoadedPlugins()
.Where(plugin =>
plugin.Manifest.ExtensionPoints.Any(extensionPoint => extensionPoint.Kind == kind)
);
}

public IEnumerable<T> GetLoadedPluginExtensionPoints<T>()
where T : PluginExtensionPoint
{
return GetLoadedPlugins().SelectMany(p => p.Manifest.ExtensionPoints).OfType<T>();
}

public Version? GetInstalledPluginVersion(string pluginId)
{
return _plugins.TryGetValue(pluginId, out var plugin) ? plugin.Version : null;
}

private IEnumerable<Plugin> GetLoadedPlugins()
{
return _plugins.Values;
}
}
1 change: 1 addition & 0 deletions src/Adapters/Driving/Analysis.Web/Analysis.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\Common\Common.csproj" />
<ProjectReference Include="..\..\Driven\Persistence.InMemory\Persistence.InMemory.csproj" />
<ProjectReference Include="..\Common.Web\Common.Web.csproj"/>
<ProjectReference Include="..\..\..\Application\Domain\Service.Analysis\Service.Analysis.csproj" />
<ProjectReference Include="..\..\..\Application\Ports\Driving\UseCases.Analysis\UseCases.Analysis.csproj"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using ScriptBee.Persistence.InMemory;
using ScriptBee.Ports.Plugins;

namespace ScriptBee.Analysis.Web.Extensions;

public static class PluginsConfigExtensions
{
public static IServiceCollection AddPluginsConfig(this IServiceCollection services)
{
return services.AddSingleton<IPluginRepository, PluginRepository>();
}
}
3 changes: 2 additions & 1 deletion src/Adapters/Driving/Analysis.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
.AddProblemDetailsDefaults()
.AddMongoDb(mongoConnectionString)
.AddCommonServices()
.AddFileConfig(userFolderConfigurationSection);
.AddFileConfig(userFolderConfigurationSection)
.AddPluginsConfig();

builder.Services.AddEndpointDefinitions(
typeof(IEndpointDefinition),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
namespace ScriptBee.Plugin.Manifest;
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public class HelperFunctionsPluginExtensionPoint : PluginExtensionPoint
{
}
public class HelperFunctionsPluginExtensionPoint : PluginExtensionPoint { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public class LinkerPluginExtensionPoint : PluginExtensionPoint { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public class LoaderPluginExtensionPoint : PluginExtensionPoint { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public class PluginBundleExtensionPoint : PluginExtensionPoint { }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ScriptBee.Plugin.Manifest;
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public abstract class PluginExtensionPoint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ScriptBee.Plugin.Manifest;
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public static class PluginKind
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;

namespace ScriptBee.Plugin.Manifest;
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public class PluginManifest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ScriptBee.Plugin.Manifest;
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public class ScriptGeneratorPluginExtensionPoint : PluginExtensionPoint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ScriptBee.Plugin.Manifest;
namespace ScriptBee.Domain.Model.Plugin.Manifest;

public class ScriptRunnerPluginExtensionPoint : PluginExtensionPoint
{
Expand Down
Loading
Loading