Skip to content

Commit e4db961

Browse files
committed
Refactoring
1 parent f3c0317 commit e4db961

File tree

8 files changed

+69
-21
lines changed

8 files changed

+69
-21
lines changed

src/PainKiller.PowerCommands/PainKiller.PowerCommands.Bootstrap/Configuration/PowerCommandsConfiguration.cs

-9
This file was deleted.

src/PainKiller.PowerCommands/PainKiller.PowerCommands.Bootstrap/PainKiller.PowerCommands.Bootstrap.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ProjectReference Include="..\PainKiller.AzureKeyVault\PainKiller.AzureKeyVault.csproj" />
1111
<ProjectReference Include="..\PainKiller.PowerCommands.Configuration\PainKiller.PowerCommands.Configuration.csproj" />
1212
<ProjectReference Include="..\PainKiller.PowerCommands.Core\PainKiller.PowerCommands.Core.csproj" />
13+
<ProjectReference Include="..\PainKiller.PowerCommands.MyExampleCommands\PainKiller.PowerCommands.MyExampleCommands.csproj" />
1314
<ProjectReference Include="..\PainKiller.PowerCommands.Security\PainKiller.PowerCommands.Security.csproj" />
1415
<ProjectReference Include="..\PainKiller.PowerCommands.Shared\PainKiller.PowerCommands.Shared.csproj" />
1516
<ProjectReference Include="..\PainKiller.SerilogExtensions\PainKiller.SerilogExtensions.csproj" />
@@ -21,4 +22,8 @@
2122
</None>
2223
</ItemGroup>
2324

25+
<ItemGroup>
26+
<Folder Include="Configuration\" />
27+
</ItemGroup>
28+
2429
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using Microsoft.Extensions.Logging;
2-
using PainKiller.PowerCommands.Bootstrap.Configuration;
3-
using PainKiller.PowerCommands.Configuration;
42
using PainKiller.PowerCommands.Configuration.Extensions;
53
using PainKiller.PowerCommands.Core.Managers;
6-
using PainKiller.PowerCommands.Shared.DomainObjects.Configuration;
4+
using PainKiller.PowerCommands.MyExampleCommands.Configuration;
75
using PainKiller.SerilogExtensions.Managers;
86

97
namespace PainKiller.PowerCommands.Bootstrap
@@ -12,24 +10,24 @@ public static class Startup
1210
{
1311
private static PluginManager<PowerCommandsConfiguration>? _pluginManager;
1412

15-
public static BaseCommandsConfiguration Initialize()
13+
public static void Initialize()
1614
{
17-
var configuration = ConfigurationManager.GetConfiguration<PowerCommandsConfiguration>().Configuration;
15+
var configuration = PowerCommandsConfiguration.Instance ?? new PowerCommandsConfiguration();
1816
var logger = GetLoggerManager.GetFileLogger(configuration.Log.FileName.GetSafePathRegardlessHowApplicationStarted("logs"));
17+
1918
logger.LogInformation("Program started, configuration read");
2019

2120
_pluginManager = new PluginManager<PowerCommandsConfiguration>(configuration);
2221
try
2322
{
2423
var validatePlugins = _pluginManager.ValidateConfigurationWithPlugins();
25-
24+
if(!validatePlugins) Console.WriteLine("Some of the components did not pass security check...");
2625
}
2726
catch (Exception ex)
2827
{
2928
logger.LogCritical(ex,"Critical error, program could not start");
3029
throw;
3130
}
32-
return configuration;
3331
}
3432
}
3533
}

src/PainKiller.PowerCommands/PainKiller.PowerCommands.Core/Managers/PluginManager.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Security;
2-
using PainKiller.PowerCommands.Core.Extensions;
1+
using PainKiller.PowerCommands.Core.Extensions;
32
using PainKiller.PowerCommands.Security.DomainObjects;
43
using PainKiller.PowerCommands.Security.Extensions;
54
using PainKiller.PowerCommands.Shared.DomainObjects.Configuration;
@@ -28,16 +27,16 @@ public PluginManager(TConfiguration configuration)
2827

2928
public bool ValidateConfigurationWithPlugins()
3029
{
31-
var retVal = false;
30+
var retVal = true;
3231
var components = typeof(TConfiguration).GetPropertiesOfT<BaseComponentConfiguration>();
3332

3433
foreach (var propertyInfo in components)
3534
{
3635
if (propertyInfo.GetValue(_configuration) is not BaseComponentConfiguration instance) continue;
3736
var fileCheckSum = new FileChecksum(instance.Component);
3837
var validateCheckSum = fileCheckSum.CompareFileChecksum(instance.Checksum);
38+
if(!validateCheckSum) retVal = false;
3939
if(_configuration.ShowDiagnosticInformation) Console.WriteLine($"{instance?.Name ?? "null"} Checksum {fileCheckSum.Mde5Hash} {validateCheckSum}");
40-
retVal = true;
4140
}
4241
return retVal;
4342
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using PainKiller.AzureKeyVault.DomainObjects;
2+
using PainKiller.PowerCommands.Configuration;
3+
using PainKiller.PowerCommands.Shared.DomainObjects.Configuration;
4+
5+
namespace PainKiller.PowerCommands.MyExampleCommands.Configuration;
6+
7+
public class PowerCommandsConfiguration : BaseCommandsConfiguration
8+
{
9+
private static PowerCommandsConfiguration? _instance;
10+
public static PowerCommandsConfiguration? Instance
11+
{
12+
get
13+
{
14+
if(_instance != null) return _instance;
15+
_instance = ConfigurationManager.GetConfiguration<PowerCommandsConfiguration>().Configuration;
16+
return _instance;
17+
18+
}
19+
}
20+
public KeyVaultConfig KeyVault { get; set; } = new();
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Folder Include="Commands\" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\PainKiller.AzureKeyVault\PainKiller.AzureKeyVault.csproj" />
15+
<ProjectReference Include="..\PainKiller.PowerCommands.Configuration\PainKiller.PowerCommands.Configuration.csproj" />
16+
<ProjectReference Include="..\PainKiller.PowerCommands.Shared\PainKiller.PowerCommands.Shared.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\PainKiller.SerilogExtensions\PainKiller.SerilogExtensions.csproj" />
15+
</ItemGroup>
16+
917
</Project>

src/PainKiller.PowerCommands/PainKiller.PowerCommands.sln

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Custom Components", "Custom
2929
EndProject
3030
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PainKiller.AzureKeyVault", "PainKiller.AzureKeyVault\PainKiller.AzureKeyVault.csproj", "{13CC0652-52C9-4675-8E45-0BAEC32D9431}"
3131
EndProject
32+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PainKiller.PowerCommands.MyExampleCommands", "PainKiller.PowerCommands.MyExampleCommands\PainKiller.PowerCommands.MyExampleCommands.csproj", "{C53C0EBD-1FEF-43F3-8AF9-285A4AB2A524}"
33+
EndProject
3234
Global
3335
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3436
Debug|Any CPU = Debug|Any CPU
@@ -71,6 +73,10 @@ Global
7173
{13CC0652-52C9-4675-8E45-0BAEC32D9431}.Debug|Any CPU.Build.0 = Debug|Any CPU
7274
{13CC0652-52C9-4675-8E45-0BAEC32D9431}.Release|Any CPU.ActiveCfg = Release|Any CPU
7375
{13CC0652-52C9-4675-8E45-0BAEC32D9431}.Release|Any CPU.Build.0 = Release|Any CPU
76+
{C53C0EBD-1FEF-43F3-8AF9-285A4AB2A524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77+
{C53C0EBD-1FEF-43F3-8AF9-285A4AB2A524}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{C53C0EBD-1FEF-43F3-8AF9-285A4AB2A524}.Release|Any CPU.ActiveCfg = Release|Any CPU
79+
{C53C0EBD-1FEF-43F3-8AF9-285A4AB2A524}.Release|Any CPU.Build.0 = Release|Any CPU
7480
EndGlobalSection
7581
GlobalSection(SolutionProperties) = preSolution
7682
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)