remove old references and remove unnecessary code
This commit is contained in:
parent
6358f5f199
commit
f89dd755b1
@ -10,7 +10,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
<PackageReference Include="Core.Blueprint.Logging" Version="0.3.0-alpha0034" />
|
||||
<PackageReference Include="Blueprint.Logging" Version="0.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
|
||||
@ -7,11 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Identity" Version="1.13.1" />
|
||||
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
|
||||
<PackageReference Include="Core.Blueprint.KeyVault" Version="0.3.0-alpha0037" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Blueprint.KeyVault" Version="0.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,50 +0,0 @@
|
||||
using Core.Blueprint.DAL.Logs.Contracts;
|
||||
using Serilog;
|
||||
|
||||
namespace Core.Blueprint.DAL.Logs
|
||||
{
|
||||
public class BlueprintSerilogLogger : IBlueprintSerilogLogger
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
|
||||
public BlueprintSerilogLogger(ILogger logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void LogInformation(string service, params object[] args)
|
||||
{
|
||||
logger.Information("Starting operation in {service} service", service, args);
|
||||
}
|
||||
|
||||
public void LogOperationStarted(string service, params object[] args)
|
||||
{
|
||||
logger.Information("Starting operation in {Service} service with parameters: {@Args}", service, args);
|
||||
}
|
||||
public void LogOperationFinished(string service, params object[] args)
|
||||
{
|
||||
logger.Information("Finishing operation in {Service} service with parameters: {@Args}", service, args);
|
||||
}
|
||||
|
||||
public void LogInformation(string message)
|
||||
{
|
||||
logger.Information(message);
|
||||
}
|
||||
|
||||
public void LogWarning(string message, params object[] args)
|
||||
{
|
||||
logger.Warning(message, args);
|
||||
}
|
||||
|
||||
public void LogError(string service, params object[] args)
|
||||
{
|
||||
logger.Error("An error occurred in `{service}` Exception: {@Args}", service, args);
|
||||
}
|
||||
|
||||
public void LogCritical(Exception exception, string message, params object[] args)
|
||||
{
|
||||
logger.Fatal(exception, message, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
using Core.Blueprint.DAL.Logs.Contracts;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Core.Blueprint.DAL.Logs.Configuration
|
||||
{
|
||||
public static class LogExtensionConfiguration
|
||||
{
|
||||
public static IServiceCollection AddLogLayer(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IBlueprintSerilogLogger, BlueprintSerilogLogger>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
namespace Core.Blueprint.DAL.Logs.Contracts
|
||||
{
|
||||
public interface IBlueprintLogger<T> where T : class, new()
|
||||
{
|
||||
//logger
|
||||
//serilog...
|
||||
//patterns of structuie logging
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
namespace Core.Blueprint.DAL.Logs.Contracts
|
||||
{
|
||||
public interface IBlueprintSerilogLogger
|
||||
{
|
||||
public void LogInformation(string service, params object[] args);
|
||||
public void LogOperationStarted(string service, params object[] args);
|
||||
public void LogOperationFinished(string service, params object[] args);
|
||||
public void LogWarning(string message, params object[] args);
|
||||
public void LogError(string servicee, params object[] args);
|
||||
public void LogCritical(Exception exception, string message, params object[] args);
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
namespace Core.Blueprint.DAL.Logs;
|
||||
public static partial class Log
|
||||
{
|
||||
//[LoggerMessage(
|
||||
// EventId = 1,
|
||||
// Level = LogLevel.Information,
|
||||
// Message = "Starting operation in`{service}` service with parameters: {@Args}"
|
||||
//)]
|
||||
//static partial void OperationStarted(ILogger logger, string service, params object[] args);
|
||||
|
||||
//[LoggerMessage(
|
||||
// EventId = 1,
|
||||
// Level = LogLevel.Information,
|
||||
// Message = "Operation finished in`{service}` service with parameters: {@Args}"
|
||||
//)]
|
||||
//static partial void OperationFinished(ILogger logger, string service, params object[] args);
|
||||
|
||||
//[LoggerMessage(
|
||||
// EventId = 2,
|
||||
// Level = LogLevel.Error,
|
||||
// Message = "An error occurred in `{service}` service"
|
||||
//)]
|
||||
//static partial void OperationFailed(ILogger logger, string service, Exception exception);
|
||||
}
|
||||
@ -7,16 +7,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Identity" Version="1.13.1" />
|
||||
<PackageReference Include="Core.Blueprint.Mongo" Version="0.3.0-alpha0047" />
|
||||
<PackageReference Include="Core.Blueprint.Redis" Version="0.3.0-alpha0032" />
|
||||
<PackageReference Include="Mapster" Version="7.4.1-pre01" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||
<PackageReference Include="Blueprint.Mongo" Version="0.0.1" />
|
||||
<PackageReference Include="Blueprint.Redis" Version="0.0.1" />
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,134 +0,0 @@
|
||||
using Azure.Identity;
|
||||
using Core.Blueprint.DAL.Redis.Contracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StackExchange.Redis;
|
||||
using System.Text.Json;
|
||||
|
||||
|
||||
namespace Core.Blueprint.DAL.Redis
|
||||
{
|
||||
public class CacheService : ICacheService
|
||||
{
|
||||
private IDatabase _cacheDatabase = null!;
|
||||
private readonly ILogger<CacheService> _logger;
|
||||
|
||||
|
||||
public CacheService(string connectionString, ILogger<CacheService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
_cacheDatabase = await GetRedisDatabase(connectionString);
|
||||
}).Wait();
|
||||
}
|
||||
|
||||
private async Task<IDatabase> GetRedisDatabase(string connectionString)
|
||||
{
|
||||
try
|
||||
{
|
||||
var configurationOptions = await ConfigurationOptions.Parse($"{connectionString}")
|
||||
.ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential());
|
||||
|
||||
configurationOptions.AbortOnConnectFail = false;
|
||||
var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions);
|
||||
|
||||
_logger.LogInformation("Successfully connected to Redis.");
|
||||
|
||||
return connectionMultiplexer.GetDatabase();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error establishing Redis connection.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<T> GetAsync<T>(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
var value = await _cacheDatabase.StringGetAsync(key);
|
||||
if (value.IsNullOrEmpty)
|
||||
{
|
||||
_logger.LogInformation($"Cache miss for key: {key}");
|
||||
return default;
|
||||
}
|
||||
|
||||
_logger.LogInformation($"Cache hit for key: {key}");
|
||||
return JsonSerializer.Deserialize<T>(value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error getting cache item with key {key}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetAsync<T>(string key, T value, TimeSpan? expiry = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(value);
|
||||
await _cacheDatabase.StringSetAsync(key, json, expiry);
|
||||
_logger.LogInformation($"Cache item set with key: {key}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error setting cache item with key {key}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemoveAsync(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _cacheDatabase.KeyDeleteAsync(key);
|
||||
_logger.LogInformation($"Cache item removed with key: {key}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error removing cache item with key {key}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> ExistsAsync(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
var exists = await _cacheDatabase.KeyExistsAsync(key);
|
||||
_logger.LogInformation($"Cache item exists check for key: {key} - {exists}");
|
||||
return exists;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error checking existence of cache item with key {key}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RefreshAsync(string key, TimeSpan? expiry = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var value = await _cacheDatabase.StringGetAsync(key);
|
||||
if (!value.IsNullOrEmpty)
|
||||
{
|
||||
await _cacheDatabase.StringSetAsync(key, value, expiry);
|
||||
_logger.LogInformation($"Cache item refreshed with key: {key}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"Cache item with key: {key} does not exist, cannot refresh");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error refreshing cache item with key {key}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
namespace Core.Blueprint.DAL.Redis.Configuration
|
||||
{
|
||||
public class CacheSettings
|
||||
{
|
||||
public int DefaultCacheDurationInMinutes { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
using Core.Blueprint.DAL.Redis.Contracts;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Core.Blueprint.DAL.Redis.Configuration
|
||||
{
|
||||
public static class RedisExtension
|
||||
{
|
||||
public static IServiceCollection AddRedisLayer(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var source = configuration.GetSection("ConnectionStrings");
|
||||
|
||||
var redisConnectionString = source["Redis"]?.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(redisConnectionString))
|
||||
{
|
||||
throw new InvalidOperationException("Redis connection string is not configured.");
|
||||
}
|
||||
|
||||
services.AddSingleton<ICacheService>(provider =>
|
||||
new CacheService(redisConnectionString, provider.GetRequiredService<ILogger<CacheService>>()));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
namespace Core.Blueprint.DAL.Redis.Contracts
|
||||
{
|
||||
public interface ICacheService
|
||||
{
|
||||
Task<T> GetAsync<T>(string key);
|
||||
Task SetAsync<T>(string key, T value, TimeSpan? expiry = null);
|
||||
Task RemoveAsync(string key);
|
||||
Task<bool> ExistsAsync(string key);
|
||||
Task RefreshAsync(string key, TimeSpan? expiry = null);
|
||||
}
|
||||
}
|
||||
@ -7,11 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Identity" Version="1.13.1" />
|
||||
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="2.8.24" />
|
||||
<PackageReference Include="Blueprint.Redis" Version="0.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
using Core.Blueprint.DAL.Redis.Configuration;
|
||||
|
||||
namespace Core.Blueprint.DAL.Redis.Helpers
|
||||
{
|
||||
public static class CacheHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines the cache duration based on specific duration, settings, or a default value.
|
||||
/// </summary>
|
||||
/// <param name="specificCacheDuration">Specific cache duration in minutes, if provided.</param>
|
||||
/// <param name="cacheSettings">General cache settings containing default duration values.</param>
|
||||
/// <returns>The cache duration as a TimeSpan.</returns>
|
||||
public static TimeSpan GetCacheDuration(CacheSettings cacheSettings, int? specificCacheDuration = 0)
|
||||
{
|
||||
var defaultCacheDuration = TimeSpan.FromMinutes(.5);
|
||||
|
||||
if (specificCacheDuration.HasValue && specificCacheDuration.Value > 0)
|
||||
{
|
||||
return TimeSpan.FromMinutes(specificCacheDuration.Value);
|
||||
}
|
||||
|
||||
if (cacheSettings.DefaultCacheDurationInMinutes > 0)
|
||||
{
|
||||
return TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes);
|
||||
}
|
||||
|
||||
return defaultCacheDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Core.Blueprint.DAL.Redis.Helpers
|
||||
{
|
||||
public static class CacheKeyHelper
|
||||
{
|
||||
public static string GenerateCacheKey(object instance, string methodName, params object[] parameters)
|
||||
{
|
||||
var className = instance.GetType().Name;
|
||||
var keyBuilder = new StringBuilder($"{className}.{methodName}");
|
||||
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
string normalizedParam = NormalizeParameter(param);
|
||||
keyBuilder.Append($".{normalizedParam}");
|
||||
}
|
||||
|
||||
return keyBuilder.ToString();
|
||||
}
|
||||
|
||||
private static string NormalizeParameter(object param)
|
||||
{
|
||||
if (param == null)
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
|
||||
string paramString;
|
||||
|
||||
if (param is DateTime dateTime)
|
||||
{
|
||||
paramString = dateTime.ToString("yyyyMMdd");
|
||||
}
|
||||
else
|
||||
{
|
||||
paramString = param.ToString();
|
||||
}
|
||||
|
||||
// Replace special characters with an underscore
|
||||
string normalizedParam = Regex.Replace(paramString, @"[^a-zA-Z0-9]", "_");
|
||||
|
||||
return normalizedParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,13 +7,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Blueprint.Redis" Version="0.3.0-alpha0032" />
|
||||
<PackageReference Include="Core.Blueprint.SQLServer" Version="0.3.0-alpha0030" />
|
||||
<PackageReference Include="Blueprint.Redis" Version="0.0.1" />
|
||||
<PackageReference Include="Blueprint.SQLServer" Version="0.0.1" />
|
||||
<PackageReference Include="Mapster" Version="7.4.1-pre01" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -11,12 +11,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Identity" Version="1.13.1" />
|
||||
<PackageReference Include="Azure.Storage.Blobs" Version="12.23.0" />
|
||||
<PackageReference Include="Core.Blueprint.Storage" Version="0.3.0-alpha0049" />
|
||||
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.9.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Blueprint.Storage" Version="0.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -13,8 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Blueprint.DAL.SQLServe
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Blueprint.DAL.Storage", "Core.Blueprint.DAL.Storage\Core.Blueprint.DAL.Storage.csproj", "{B744C1BC-7EDA-47C5-BC04-91D0FB061985}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Blueprint.DAL.Hangfire", "Core.Blueprint.DAL.Hangfire\Core.Blueprint.DAL.Hangfire.csproj", "{5D3F8418-7BFA-4EA7-ADE7-7285A91FB1D9}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Blueprint.DAL.Mongo", "Core.Blueprint.DAL.Mongo\Core.Blueprint.DAL.Mongo.csproj", "{14F77CBD-952F-40F1-8568-A084EF7D2224}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Blueprint.DAL.Redis", "Core.Blueprint.DAL.Redis\Core.Blueprint.DAL.Redis.csproj", "{CD655B60-8C94-494A-87BA-F689CDD65F2B}"
|
||||
@ -41,10 +39,6 @@ Global
|
||||
{B744C1BC-7EDA-47C5-BC04-91D0FB061985}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B744C1BC-7EDA-47C5-BC04-91D0FB061985}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B744C1BC-7EDA-47C5-BC04-91D0FB061985}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5D3F8418-7BFA-4EA7-ADE7-7285A91FB1D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5D3F8418-7BFA-4EA7-ADE7-7285A91FB1D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5D3F8418-7BFA-4EA7-ADE7-7285A91FB1D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5D3F8418-7BFA-4EA7-ADE7-7285A91FB1D9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{14F77CBD-952F-40F1-8568-A084EF7D2224}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{14F77CBD-952F-40F1-8568-A084EF7D2224}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{14F77CBD-952F-40F1-8568-A084EF7D2224}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@ -69,7 +63,6 @@ Global
|
||||
{D66611EE-2AE0-48B2-8D79-AF10A5E11C91} = {0DD43B65-17E6-4AA2-BE35-F9C7FCB5DD18}
|
||||
{546B418A-2DBD-499D-B7AA-57078231B950} = {4D299A91-3EDD-4ABF-B134-CE4966E8C990}
|
||||
{B744C1BC-7EDA-47C5-BC04-91D0FB061985} = {4D299A91-3EDD-4ABF-B134-CE4966E8C990}
|
||||
{5D3F8418-7BFA-4EA7-ADE7-7285A91FB1D9} = {4D299A91-3EDD-4ABF-B134-CE4966E8C990}
|
||||
{14F77CBD-952F-40F1-8568-A084EF7D2224} = {4D299A91-3EDD-4ABF-B134-CE4966E8C990}
|
||||
{CD655B60-8C94-494A-87BA-F689CDD65F2B} = {4D299A91-3EDD-4ABF-B134-CE4966E8C990}
|
||||
{B91E1D72-FB2E-4532-83E9-3E9EF2231740} = {4D299A91-3EDD-4ABF-B134-CE4966E8C990}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user