Removed CommonCore
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,17 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Common.Core.Extensions;
|
||||
|
||||
public static class ConfigurationExtension
|
||||
{
|
||||
public static IConfigurationBuilder Initialize(this IConfigurationBuilder builder)
|
||||
{
|
||||
string env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production";
|
||||
|
||||
return builder
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true)
|
||||
.AddEnvironmentVariables();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
namespace Common.Core.Extensions;
|
||||
|
||||
public static class ServicesExtension
|
||||
{
|
||||
public static TModel? TryGetService<TModel>(this IServiceProvider serviceProvider) where TModel : class
|
||||
{
|
||||
try
|
||||
{
|
||||
return (TModel?)serviceProvider.GetService(typeof(TModel));
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// ignore as we do not care...
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Common.Core;
|
||||
|
||||
public class AppSettings<TOption>
|
||||
{
|
||||
#region Constructors
|
||||
public AppSettings(IConfigurationSection configSection, string? key = null)
|
||||
{
|
||||
ConfigSection = configSection;
|
||||
|
||||
// ReSharper disable once VirtualMemberCallInConstructor
|
||||
GetValue(key);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
protected static AppSettings<TOption>? AppSetting { get; private set; }
|
||||
|
||||
// ReSharper disable once StaticMemberInGenericType
|
||||
protected static IConfigurationSection? ConfigSection { get; private set; }
|
||||
|
||||
public TOption? Value { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
#pragma warning disable CA1000 // Do not declare static members on generic types
|
||||
public static TOption? Current(string section, string? key = null)
|
||||
{
|
||||
AppSetting = GetCurrentSettings(section, key);
|
||||
return AppSetting.Value;
|
||||
}
|
||||
|
||||
|
||||
public static AppSettings<TOption> GetCurrentSettings(string section, string? key = null)
|
||||
#pragma warning restore CA1000 // Do not declare static members on generic types
|
||||
{
|
||||
string env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production";
|
||||
|
||||
IConfigurationBuilder builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true)
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
IConfigurationRoot configuration = builder.Build();
|
||||
|
||||
if (string.IsNullOrEmpty(section))
|
||||
section = "AppSettings"; // default
|
||||
|
||||
AppSettings<TOption> settings = new AppSettings<TOption>(configuration.GetSection(section), key);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
protected virtual void GetValue(string? key)
|
||||
{
|
||||
if (key is null)
|
||||
{
|
||||
// no key, so must be a class/strut object
|
||||
Value = Activator.CreateInstance<TOption>();
|
||||
ConfigSection!.Bind(Value);
|
||||
return;
|
||||
}
|
||||
|
||||
Type optionType = typeof(TOption);
|
||||
|
||||
if ((optionType == typeof(string) ||
|
||||
optionType == typeof(int) ||
|
||||
optionType == typeof(long) ||
|
||||
optionType == typeof(decimal) ||
|
||||
optionType == typeof(float) ||
|
||||
optionType == typeof(double))
|
||||
&& ConfigSection != null)
|
||||
{
|
||||
// we must be retrieving a value
|
||||
Value = ConfigSection.GetValue<TOption>(key);
|
||||
return;
|
||||
}
|
||||
|
||||
// Could not find a supported type
|
||||
throw new InvalidCastException($"Type {typeof(TOption).Name} is invalid");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -45,21 +45,10 @@ public static class LoggerExtensions
|
||||
|
||||
#pragma warning disable CA1848 // Use the LoggerMessage delegates
|
||||
logger.Emit(eventId, LogLevel.Trace, "Trace Test Pattern");
|
||||
#pragma warning restore CA1848 // Use the LoggerMessage delegates
|
||||
#pragma warning disable CA1848 // Use the LoggerMessage delegates
|
||||
logger.Emit(eventId, LogLevel.Debug, "Debug Test Pattern");
|
||||
#pragma warning restore CA1848 // Use the LoggerMessage delegates
|
||||
#pragma warning disable CA1848 // Use the LoggerMessage delegates
|
||||
logger.Emit(eventId, LogLevel.Information, "Information Test Pattern");
|
||||
#pragma warning restore CA1848 // Use the LoggerMessage delegates
|
||||
#pragma warning disable CA1848 // Use the LoggerMessage delegates
|
||||
logger.Emit(eventId, LogLevel.Warning, "Warning Test Pattern");
|
||||
#pragma warning restore CA1848 // Use the LoggerMessage delegates
|
||||
#pragma warning disable CA1848 // Use the LoggerMessage delegates
|
||||
logger.Emit(eventId, LogLevel.Error, "Error Test Pattern", exception);
|
||||
#pragma warning restore CA1848 // Use the LoggerMessage delegates
|
||||
#pragma warning disable CA1848 // Use the LoggerMessage delegates
|
||||
logger.Emit(eventId, LogLevel.Critical, "Critical Test Pattern", exception);
|
||||
#pragma warning restore CA1848 // Use the LoggerMessage delegates
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,4 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Mvvm.Core\Mvvm.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,21 +1,7 @@
|
||||
using Mvvm.Core;
|
||||
namespace LogViewer.Core.ViewModels;
|
||||
|
||||
namespace LogViewer.Core.ViewModels;
|
||||
|
||||
public class LogViewerControlViewModel : ViewModel, ILogDataStoreCore
|
||||
public class LogViewerControlViewModel(ILogDataStore dataStore) : ILogDataStoreCore
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public LogViewerControlViewModel(ILogDataStore dataStore)
|
||||
{
|
||||
DataStore = dataStore;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public ILogDataStore DataStore { get; set; }
|
||||
|
||||
#endregion
|
||||
public ILogDataStore DataStore { get; set; } = dataStore;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user