Skip to content

Commit

Permalink
v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed Jan 17, 2024
1 parent e990144 commit fb8b3ac
Show file tree
Hide file tree
Showing 55 changed files with 422 additions and 817 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ PM> NuGet\Install-Package Tynab.YANLib
```

### EXTENSION
- Numeric
- Text
- Bool
- Bytes
- DateTime
- Nullable
- Model
- JSON
- Enum
- Enumerable
- Random
- JSON
- Numeric
- Text
- Object
- Nullable
- Process
- Random
- Task
- Bytes

### OTHER
- Password

[See wiki for more details](https://github.com/Tynab/YANLib/wiki)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BenchmarkDotNet.Attributes;
using YANLib.Benchmarks.Models;
using YANLib.Core;
using static Newtonsoft.Json.JsonConvert;
using static System.Guid;
using static System.Threading.Tasks.Parallel;
using static Newtonsoft.Json.JsonConvert;

namespace YANLib.Benchmarks.Process.Library;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using BenchmarkDotNet.Attributes;
using YANLib.Benchmarks.Models;
using YANLib.Core;
using static Newtonsoft.Json.JsonConvert;
using static System.Guid;
using static System.Threading.Tasks.Parallel;
using static Newtonsoft.Json.JsonConvert;

namespace YANLib.Benchmarks.Process.Library;

Expand All @@ -21,7 +21,7 @@ public class JsonSerializeBenchmark
};

[Benchmark(Baseline = true)]
public void YANLib_Json() => For(0, Size, index => _model.Serialize());
public void YANLib_Json() => For(0, Size, index => _model.StandardSerialize());

[Benchmark]
public void Newtonsoft_Json() => For(0, Size, index => SerializeObject(_model));
Expand Down
4 changes: 4 additions & 0 deletions console/YANLib.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@
}
#endif

#if DEBUG
using static System.Console;

_ = ReadLine();
#endif
5 changes: 4 additions & 1 deletion host/YANLib.HttpApi.Host/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace YANLib.Controllers;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;

namespace YANLib.Controllers;

public class HomeController : AbpController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace YANLib.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace YANLib.EntityFrameworkCore;

public class YANLibHttpApiHostMigrationsDbContext(DbContextOptions<YANLibHttpApiHostMigrationsDbContext> options) : AbpDbContext<YANLibHttpApiHostMigrationsDbContext>(options)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
namespace YANLib.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using static System.IO.Directory;

namespace YANLib.EntityFrameworkCore;

public class YANLibHttpApiHostMigrationsDbContextFactory : IDesignTimeDbContextFactory<YANLibHttpApiHostMigrationsDbContext>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
namespace YANLib.Middlewares;
using Microsoft.AspNetCore.Http;
using System;
using System.IO;
using System.Threading.Tasks;
using YANLib.Core;
using static Microsoft.AspNetCore.Http.StatusCodes;
using static Serilog.Log;
using static System.Net.HttpStatusCode;

namespace YANLib.Middlewares;

public class UnauthorizedHandlerMiddleware(RequestDelegate next)
{
Expand Down
10 changes: 9 additions & 1 deletion host/YANLib.HttpApi.Host/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
namespace YANLib;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using System;
using System.Threading.Tasks;
using static Microsoft.AspNetCore.Builder.WebApplication;

namespace YANLib;

public class Program
{
Expand Down
5 changes: 4 additions & 1 deletion host/YANLib.HttpApi.Host/YANLibBrandingProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace YANLib;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Ui.Branding;

namespace YANLib;

[Dependency(ReplaceServices = true)]
public class YANLibBrandingProvider : DefaultBrandingProvider
Expand Down
56 changes: 51 additions & 5 deletions host/YANLib.HttpApi.Host/YANLibHttpApiHostModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@

#if !DEBUG
using DotNetCore.CAP;
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.EntityFrameworkCore;
using Elastic.Apm.NetCoreAll;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Serilog;
using Volo.Abp.Autofac;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.EventBus.Azure;
using Volo.Abp.EventBus.RabbitMq;
using Volo.Abp.Http.Client;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Swashbuckle;
using YANLib.Core;
using YANLib.EntityFrameworkCore;
using YANLib.Utilities;
using static Elastic.Apm.Agent;
using static HealthChecks.UI.Client.UIResponseWriter;
using static Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerDefaults;
using static Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus;
using static System.Convert;
using static System.StringSplitOptions;

#if DEBUG
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Http;
using YANLib.Middlewares;
using static Microsoft.OpenApi.Models.ParameterLocation;
using static Microsoft.OpenApi.Models.SecuritySchemeType;
using static System.Net.HttpStatusCode;
using static System.Threading.Tasks.Task;
#endif

namespace YANLib;
Expand Down Expand Up @@ -75,7 +121,7 @@ private static void ConfigureAuthentication(ServiceConfigurationContext context,
o.RequireHttpsMetadata = ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
o.Audience = configuration["AuthServer:ApiName"];

#if !DEBUG
#if DEBUG
o.Events = new JwtBearerEvents
{
OnMessageReceived = async c =>
Expand Down Expand Up @@ -119,7 +165,7 @@ private static void ConfigureSwaggerServices(ServiceConfigurationContext context
Version = "test"
});

#if !DEBUG
#if DEBUG
o.AddSecurityDefinition("Authorization", new OpenApiSecurityScheme
{
In = Header,
Expand Down Expand Up @@ -249,7 +295,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex

_ = app.UseCapDashboard();

#if !DEBUG
#if DEBUG
_ = app.UseMiddleware<UnauthorizedHandlerMiddleware>();
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace YANLib.Application.Redis.ConnectionFactory;
using StackExchange.Redis;

namespace YANLib.Application.Redis.ConnectionFactory;

public interface IRedisConnectionFactory
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
namespace YANLib.Application.Redis.ConnectionFactory.Implements;
using Microsoft.Extensions.Options;
using StackExchange.Redis;
using Volo.Abp.DependencyInjection;
using static StackExchange.Redis.ConnectionMultiplexer;

namespace YANLib.Application.Redis.ConnectionFactory.Implements;

public class RedisConnectionFactory : IRedisConnectionFactory, ISingletonDependency
{
#region Fields
private readonly RedisOptions _option;
private readonly Lazy<ConnectionMultiplexer> _connection;
#endregion

#region Constructors
public RedisConnectionFactory(IOptions<RedisOptions> options)
{
_option = options.Value;
_connection = new Lazy<ConnectionMultiplexer>(() => Connect(_option.RedisConnectionString ?? string.Empty));
}
#endregion

#region Implements
public ConnectionMultiplexer Connection() => _connection.Value;

public string ConnectionString() => (_option.RedisConnectionString ?? ",").Split(',')[0];
#endregion
}
4 changes: 3 additions & 1 deletion src/YANLib.Application.Redis/Services/IRedisService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace YANLib.Application.Redis.Services;
using Volo.Abp.Application.Services;

namespace YANLib.Application.Redis.Services;

public interface IRedisService<T> : IApplicationService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
using YANLib.Application.Redis.ConnectionFactory;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using Volo.Abp;
using YANLib.Application.Redis.ConnectionFactory;
using YANLib.Core;
using YANLib.RedisDtos;
using static System.Text.Encoding;
using static System.Threading.Tasks.Task;
using static YANLib.YANLibConsts.RedisConstant;
using static YANLib.YANLibDomainErrorCodes;

namespace YANLib.Application.Redis.Services.Implements;

public class DeveloperTypeRedisService : IRedisService<DeveloperTypeRedisDto>
{
#region Fields
private readonly ILogger<DeveloperTypeRedisService> _logger;
private readonly IRedisConnectionFactory _connectionFactory;
private readonly ConnectionMultiplexer _connectionMultiplexer;
private readonly IDatabase _database;
#endregion

#region Constructors
public DeveloperTypeRedisService(ILogger<DeveloperTypeRedisService> logger, IRedisConnectionFactory connectionFactory)
{
_logger = logger;
_connectionFactory = connectionFactory;
_connectionMultiplexer = _connectionFactory.Connection();
_database = _connectionMultiplexer.GetDatabase();
}
#endregion

#region Implements
public async ValueTask<DeveloperTypeRedisDto?> Get(string group, string key)
{
try
Expand Down Expand Up @@ -295,9 +299,7 @@ public async ValueTask<bool> DeleteGroup(string groupPreffix)
throw;
}
}
#endregion

#region Methods
private async ValueTask<RedisResult> GetGroupKeys(string groupPreffix)
{
try
Expand All @@ -310,5 +312,4 @@ private async ValueTask<RedisResult> GetGroupKeys(string groupPreffix)
throw;
}
}
#endregion
}
6 changes: 5 additions & 1 deletion src/YANLib.Application.Redis/YANLibApplicationRedisModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using YANLib.Application.Redis.ConnectionFactory;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Modularity;
using YANLib.Application.Redis.ConnectionFactory;
using YANLib.Application.Redis.Services;
using YANLib.Application.Redis.Services.Implements;
using YANLib.RedisDtos;

namespace YANLib.Application.Redis;

Expand Down
17 changes: 12 additions & 5 deletions src/YANLib.Application/EsServices/DeveloperEsService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
using YANLib.Utilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using YANLib.Core;
using YANLib.EsIndices;
using YANLib.Utilities;
using static System.Threading.Tasks.Task;
using static YANLib.YANLibConsts.ElasticsearchIndex;

namespace YANLib.EsServices;

Expand All @@ -7,13 +18,10 @@ public class DeveloperEsService(ILogger<DeveloperEsService> logger,
IConfiguration configuration
) : YANLibAppService, IDeveloperEsService
{
#region Fields
private readonly ILogger<DeveloperEsService> _logger = logger;
private readonly IElasticClient _elasticClient = elasticClient;
private readonly IConfiguration _configuration = configuration;
#endregion

#region Implements
public async ValueTask<DeveloperIndex> Get(string id)
{
try
Expand Down Expand Up @@ -108,5 +116,4 @@ public async ValueTask<IReadOnlyCollection<DeveloperIndex>> SearchByPhone(string
.MatchPhrasePrefix(m => m
.Field(c => c.Phone)
.Query(searchText))))))).Documents;
#endregion
}
14 changes: 9 additions & 5 deletions src/YANLib.Application/Handlers/AdjustCertificateHandler.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
namespace YANLib.Handlers;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using Volo.Abp.EventBus.Distributed;
using YANLib.Core;
using YANLib.RabbitMq.Etos;
using YANLib.Requests;
using YANLib.Services;

namespace YANLib.Handlers;

public class AdjustCertificateHandler(
ILogger<AdjustCertificateHandler> logger,
ICertificateService certificateService
) : YANLibAppService, IDistributedEventHandler<CertificateAdjustEto>
{
#region Fields
private readonly ILogger<AdjustCertificateHandler> _logger = logger;
private readonly ICertificateService _certificateService = certificateService;
#endregion

#region Implements
public async Task HandleEventAsync(CertificateAdjustEto eventData)
{
_logger.LogInformation("AdjustCertificateHandler-Subscribe: {EventData}", eventData.Serialize());
_logger.LogInformation("AdjustCertificateHandler-UpdateCertificateService: {Responses}", await _certificateService.Update(ObjectMapper.Map<CertificateAdjustEto, CertificateRequest>(eventData)));
}
#endregion
}
Loading

0 comments on commit fb8b3ac

Please sign in to comment.