├── test ├── JCE.Tools.QrCode.ZXing.Test │ ├── UnitTest1.cs │ ├── TestBase.cs │ └── JCE.Tools.QrCode.ZXing.Test.csproj ├── JCE.Utils.Encrypts.Test │ ├── TestBase.cs │ ├── JCE.Utils.Encrypts.Test.csproj │ ├── Base64CryptorTest.cs │ ├── Symmetric │ │ └── DESCryptorTest.cs │ └── Hash │ │ ├── MD5CryptorTest.cs │ │ └── SHACryptorTest.cs ├── JCE.Utils.Test │ ├── TestBase.cs │ ├── JCE.Utils.Test.csproj │ └── Helpers │ │ ├── IdTest.cs │ │ └── WebTest.cs ├── JCE.Tests │ ├── TestBase.cs │ ├── UnitTest1.cs │ ├── JCE.Tests.csproj │ ├── Datas │ │ └── UnitOfWorks │ │ │ └── UnitOfWorkManagerTest.cs │ └── XUnitHelpers │ │ └── AssertHelper.cs └── JCE.ComputerInfo.Test │ ├── TestBase.cs │ ├── JCE.ComputerInfo.Test.csproj │ └── CpuInfoTest.cs ├── src ├── JCE.Logs.NLog │ ├── README.md │ ├── JCE.Logs.NLog.csproj │ ├── LogProviderFactory.cs │ └── ServiceCollectionExtensions.cs ├── JCE.Tools.QrCode │ ├── JCE.Tools.QrCode.csproj │ ├── IQrCodeFactory.cs │ ├── QrSize.cs │ ├── ErrorCorrectionLevel.cs │ └── IQrCodeService.cs ├── JCE │ ├── Dependency │ │ ├── IDependency.cs │ │ ├── IConfig.cs │ │ ├── ConfigBase.cs │ │ ├── IScopeDependency.cs │ │ ├── ISingletonDependency.cs │ │ ├── ITransientDependency.cs │ │ ├── IDependencyRegistrar.cs │ │ ├── IScope.cs │ │ ├── AopExtensions.cs │ │ └── Scope.cs │ ├── Aspects │ │ ├── Base │ │ │ ├── InterceptorBase.cs │ │ │ └── ParameterInterceptorBase.cs │ │ ├── IgnoreAttribute.cs │ │ ├── NotNullAttribute.cs │ │ └── NotEmptyAttribute.cs │ ├── Applications │ │ ├── Dtos │ │ │ ├── IResponse.cs │ │ │ ├── IDto.cs │ │ │ ├── IRequest.cs │ │ │ ├── IKey.cs │ │ │ ├── DtoBase.cs │ │ │ └── RequestBase.cs │ │ └── Commands │ │ │ ├── ICommandFactory.cs │ │ │ └── ICommand.cs │ ├── Domains │ │ ├── Entities │ │ │ ├── IDomainObject.cs │ │ │ ├── IVersion.cs │ │ │ ├── ISoftDelete.cs │ │ │ ├── Tenants │ │ │ │ └── ITenant.cs │ │ │ ├── IKey.cs │ │ │ ├── Auditing │ │ │ │ ├── IAudited.cs │ │ │ │ ├── ICreationAudited.cs │ │ │ │ └── IModificationAudited.cs │ │ │ ├── ICompareChange.cs │ │ │ ├── IAggregateRoot.cs │ │ │ ├── IEntity.cs │ │ │ ├── AggregateRoot.cs │ │ │ ├── ChangeValueCollection.cs │ │ │ └── ChangeValue.cs │ │ └── Repositories │ │ │ ├── ICriteria.cs │ │ │ ├── IPagerBase.cs │ │ │ ├── IQueryBase.cs │ │ │ └── IPager.cs │ ├── Validations │ │ ├── IValidation.cs │ │ ├── IValidationHandler.cs │ │ ├── IValidationRule.cs │ │ ├── Handlers │ │ │ ├── NothingHandler.cs │ │ │ ├── ThrowHandler.cs │ │ │ └── DefaultValidationHandler.cs │ │ ├── DataAnnotationValidation.cs │ │ └── Aspects │ │ │ └── ValidAttribute.cs │ ├── Datas │ │ ├── Queries │ │ │ ├── IQueryParameter.cs │ │ │ ├── Boundary.cs │ │ │ ├── QueryParameter.cs │ │ │ ├── OrderByItem.cs │ │ │ ├── Criterias │ │ │ │ ├── DefaultCriteria.cs │ │ │ │ ├── OrCriteria.cs │ │ │ │ ├── AndCriteria.cs │ │ │ │ ├── IntSegmentCriteria.cs │ │ │ │ ├── DoubleSegmentCriteria.cs │ │ │ │ ├── DecimalSegmentCriteria.cs │ │ │ │ └── DateTimeSegmentCriteria.cs │ │ │ ├── OrderByBuilder.cs │ │ │ └── Internal │ │ │ │ └── Helper.cs │ │ ├── Persistence │ │ │ └── IPersistentObject.cs │ │ └── UnitOfWorks │ │ │ ├── IUnitOfWork.cs │ │ │ ├── IUnitOfWorkManager.cs │ │ │ └── UnitOfWorkManager.cs │ ├── Logs │ │ ├── Abstractions │ │ │ ├── ILogConvert.cs │ │ │ ├── ILogFormat.cs │ │ │ ├── ILogProviderFactory.cs │ │ │ ├── ILogProvider.cs │ │ │ ├── ILogContext.cs │ │ │ └── ILogContent.cs │ │ ├── Core │ │ │ ├── NullLogFormat.cs │ │ │ └── NullLogContext.cs │ │ ├── Internal │ │ │ └── LogContextInfo.cs │ │ └── Extensions │ │ │ ├── LogContentExtensions.cs │ │ │ └── LogExtensions.cs │ ├── Events │ │ ├── IEvent.cs │ │ ├── IEventBus.cs │ │ ├── Messages │ │ │ ├── IMessageEventBus.cs │ │ │ ├── IMessageEvent.cs │ │ │ └── MessageEvent.cs │ │ ├── Handlers │ │ │ ├── IEventHandlerFactory.cs │ │ │ └── IEventHandler.cs │ │ └── Event.cs │ ├── Contexts │ │ ├── IUserContext.cs │ │ ├── NullUserContext.cs │ │ ├── IContext.cs │ │ └── UserContext.cs │ ├── GlobalConfigs │ │ └── Models │ │ │ ├── UserContextConfig.cs │ │ │ ├── JCEConfig.cs │ │ │ └── LogConfig.cs │ ├── Reflections │ │ ├── WebAppTypeFinder.cs │ │ └── ITypeFinder.cs │ ├── ServiceCollectionExtensions.cs │ └── JCE.csproj ├── JCE.Utils.Encrypts │ ├── Symmetric │ │ ├── TripleDESCryptor.cs │ │ └── OutType.cs │ ├── Asymmetric │ │ ├── RsaSize.cs │ │ └── RsaType.cs │ ├── JCE.Utils.Encrypts.csproj │ ├── Const.cs │ └── Base64Cryptor.cs ├── JCE.Security │ ├── JCE.Security.csproj │ └── UserContextExtensions.cs ├── JCE.Utils.AutoMapper │ └── JCE.Utils.AutoMapper.csproj ├── JCE.Datas.EntityFramework.MySql │ ├── IMap.cs │ ├── EntityMap.cs │ ├── JCE.Datas.EntityFramework.MySql.csproj │ ├── AggregateRootMap.cs │ └── ServiceCollectionExtensions.cs ├── JCE.Datas.EntityFramework.SqlServer │ ├── IMap.cs │ ├── EntityMap.cs │ ├── JCE.Datas.EntityFramework.SqlServer.csproj │ ├── AggregateRootMap.cs │ └── ServiceCollectionExtensions.cs ├── JCE.ComputerInfo │ ├── JCE.ComputerInfo.csproj │ └── DiskInfo.cs ├── JCE.Logs │ ├── Contents │ │ └── ICaption.cs │ ├── Aspects │ │ ├── DebugLogAttribute.cs │ │ ├── TraceLogAttribute.cs │ │ └── ErrorLogAttribute.cs │ ├── Extensions │ │ ├── ExceptionExtensions.cs │ │ └── AspectExtensions.cs │ ├── JCE.Logs.csproj │ └── Formats │ │ └── FormatProvider.cs ├── JCE.Applications │ ├── Aspects │ │ ├── ICommitAfter.cs │ │ └── UnitOfWorkAttribute.cs │ └── JCE.Applications.csproj ├── JCE.Utils │ ├── Randoms │ │ ├── IRandomGenerator.cs │ │ └── GuidRandomGenerator.cs │ ├── IdGenerators │ │ └── IGuidGenerator.cs │ ├── JCE.Utils.csproj.DotSettings │ ├── IO │ │ ├── IFileStore.cs │ │ ├── Paths │ │ │ ├── IPathGenerator.cs │ │ │ └── DefaultPathGenerator.cs │ │ └── DefaultFileStore.cs │ ├── Extensions │ │ └── Common │ │ │ ├── Extensions.String.cs │ │ │ └── Extensions.File.cs │ ├── Helpers │ │ ├── Common.cs │ │ ├── Thread.cs │ │ ├── Str.cs │ │ ├── Id.cs │ │ ├── Sys.cs │ │ └── Async.cs │ ├── Webs │ │ └── Clients │ │ │ ├── HttpContentType.cs │ │ │ └── FileParamter.cs │ ├── ExtensionMethodSetting.cs │ ├── Json │ │ └── JsonExtensions.cs │ ├── Operator.cs │ ├── Item.cs │ ├── Configs │ │ └── ConfigUtil.cs │ ├── Expressions │ │ └── ParameterRebinder.cs │ └── JCE.Utils.csproj ├── JCE.Datas.EntityFramework │ ├── Configs │ │ ├── EfConfig.cs │ │ └── EfLogLevel.cs │ ├── Core │ │ └── IMap.cs │ ├── JCE.Datas.EntityFramework.csproj │ ├── UnitOfWorkExtensions.cs │ ├── Logs │ │ ├── NullLogger.cs │ │ └── EfLogProvider.cs │ ├── QueryableExtensions.cs │ └── ServiceCollectionExtensions.cs ├── JCE.Logs.Log4Net │ ├── JCE.Logs.Log4Net.csproj │ ├── LogProviderFactory.cs │ └── ServiceCollectionExtensions.cs ├── JCE.Logs.Exceptionless │ ├── JCE.Logs.Exceptionless.csproj │ ├── LogProviderFactory.cs │ ├── LogContext.cs │ └── ServiceCollectionExtensions.cs ├── JCE.Tools.QrCode.QrCoder │ ├── JCE.Tools.QrCode.QrCoder.csproj │ └── QrCodeFactory.cs ├── JCE.Webs │ ├── JCE.Webs.csproj │ ├── Extensions │ │ └── MiddlewareExtensions.cs │ └── Middlewares │ │ ├── Internals │ │ ├── NullToEmptyStringResolver.cs │ │ └── NullToEmptyStringValueProvider.cs │ │ ├── ErrorLogMiddleware.cs │ │ └── WebApiResultMiddleware.cs ├── JCE.Events │ ├── JCE.Events.csproj │ ├── Default │ │ ├── EventHandlerFactory.cs │ │ └── ServiceCollectionExtensions.cs │ └── Cap │ │ ├── ServiceCollectionExtensions.cs │ │ └── MessageEventBus.cs └── JCE.Tools.QrCode.ZXing │ ├── JCE.Tools.QrCode.ZXing.csproj │ └── QrCodeFactory.cs ├── sample ├── JCE.Samples.Webs │ ├── JCEConfig.json │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── nlog.config │ ├── Controllers │ │ ├── ValuesController.cs │ │ ├── WebPathController.cs │ │ └── TestController.cs │ └── JCE.Samples.Webs.csproj └── JCE.Samples.Services │ ├── Impl │ └── TestService.cs │ ├── ITestService.cs │ └── JCE.Samples.Services.csproj ├── README.md └── demo └── Demo.Domains └── Demo.Domains.csproj /test/JCE.Tools.QrCode.ZXing.Test/UnitTest1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jianxuanbing/JCE.AspNetCore/HEAD/test/JCE.Tools.QrCode.ZXing.Test/UnitTest1.cs -------------------------------------------------------------------------------- /src/JCE.Logs.NLog/README.md: -------------------------------------------------------------------------------- 1 | # NLogger 特点(200行代码的日志组件) 2 | - 不依赖第三方插件和支持.net2.0 3 | - 支持多线程高并发 4 | - 支持读写双缓存队列 5 | - 自定义日志缓冲区大小 6 | - 支持即时触发刷盘机制 7 | - 先按日期再按文件大小RollingFile日志 8 | - 支持日志存储位置,日志文件前缀的个性化定义 9 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/JCEConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logger": { 3 | "Type": "File", 4 | "Level": "DEBUG", 5 | "ProjectName": "JCE", 6 | "EnabledDebug": true, 7 | "EnabledTrace": true 8 | } 9 | } -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode/JCE.Tools.QrCode.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/JCE/Dependency/IDependency.cs: -------------------------------------------------------------------------------- 1 | namespace JCE.Dependency 2 | { 3 | /// 4 | /// 依赖注入接口,表示该接口的实现类将自动注册到IOC容器中 5 | /// 6 | public interface IDependency 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/JCE/Dependency/IConfig.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Core; 2 | 3 | namespace JCE.Dependency 4 | { 5 | /// 6 | /// 依赖配置 7 | /// 8 | public interface IConfig:IModule 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/JCE/Dependency/ConfigBase.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | 3 | namespace JCE.Dependency 4 | { 5 | /// 6 | /// 配置 7 | /// 8 | public abstract class ConfigBase:Module,IConfig 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/JCE.Utils.Encrypts/Symmetric/TripleDESCryptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.Encrypts.Symmetric 6 | { 7 | class TripleDESCryptor 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/JCE/Dependency/IScopeDependency.cs: -------------------------------------------------------------------------------- 1 | namespace JCE.Dependency 2 | { 3 | /// 4 | /// 依赖注入接口,实现该接口将自动注册到IOC容器,生命周期为每次请求创建一个实例 5 | /// 6 | public interface IScopeDependency:IDependency 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/JCE/Dependency/ISingletonDependency.cs: -------------------------------------------------------------------------------- 1 | namespace JCE.Dependency 2 | { 3 | /// 4 | /// 依赖注入接口,实现该接口将自动注册到IOC容器,生命周期为单例 5 | /// 6 | public interface ISingletonDependency:IDependency 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/JCE/Dependency/ITransientDependency.cs: -------------------------------------------------------------------------------- 1 | namespace JCE.Dependency 2 | { 3 | /// 4 | /// 依赖注入接口,实现该接口将自动注册到IOC容器,生命周期为每次创建一个新实例 5 | /// 6 | public interface ITransientDependency:IDependency 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/JCE/Aspects/Base/InterceptorBase.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace JCE.Aspects.Base 4 | { 5 | /// 6 | /// 拦截器基类 7 | /// 8 | public abstract class InterceptorBase:AbstractInterceptorAttribute 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/JCE/Applications/Dtos/IResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Applications.Dtos 6 | { 7 | /// 8 | /// 响应对象 9 | /// 10 | public interface IResponse 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/JCE.Security/JCE.Security.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/JCE/Applications/Dtos/IDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Applications.Dtos 6 | { 7 | /// 8 | /// 数据传输对象 9 | /// 10 | public interface IDto:IKey,IRequest,IResponse 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JCE.AspNetCore 2 | JCE.AspNetCore是基于.net core 2.0的工具库,旨在提升团队的开发输出能力,由常用公共操作类(工具类、帮助类)、分层架构基类,第三方组件封装,第三方业务接口封装等组成。 3 | 4 | ## 开发环境以及类库依赖 5 | 6 | 以下是我们在项目开发和不熟时使用的工具和组件,这个列表会经常更新。 7 | 8 | > 如果没有标注版本号,则采取最新版本。 9 | 10 | 1. 开发工具 11 | - Visual Studio 2017 15.3 12 | - Resharper 2017.2 13 | 14 | 2. 15 | -------------------------------------------------------------------------------- /demo/Demo.Domains/Demo.Domains.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/JCE.Utils.AutoMapper/JCE.Utils.AutoMapper.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/JCE/Aspects/IgnoreAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Aspects 6 | { 7 | /// 8 | /// 忽略拦截 属性 9 | /// 10 | public class IgnoreAttribute:AspectCore.DynamicProxy.NonAspectAttribute 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/JCE/Applications/Dtos/IRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Validations; 5 | 6 | namespace JCE.Applications.Dtos 7 | { 8 | /// 9 | /// 请求对象 10 | /// 11 | public interface IRequest:IValidation 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.MySql/IMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Datas.EntityFramework.MySql 6 | { 7 | /// 8 | /// 映射 9 | /// 10 | public interface IMap : JCE.Datas.EntityFramework.Core.IMap 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/IDomainObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Validations; 5 | 6 | namespace JCE.Domains.Entities 7 | { 8 | /// 9 | /// 领域对象 10 | /// 11 | public interface IDomainObject:IValidation 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.SqlServer/IMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Datas.EntityFramework.SqlServer 6 | { 7 | /// 8 | /// 映射 9 | /// 10 | public interface IMap:JCE.Datas.EntityFramework.Core.IMap 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/JCE.ComputerInfo/JCE.ComputerInfo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Services/Impl/TestService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Samples.Services.Impl 6 | { 7 | public class TestService:ITestService 8 | { 9 | public void WriteOtherLog(string content) 10 | { 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/JCE.Utils.Encrypts/Asymmetric/RsaSize.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.Encrypts.Asymmetric 6 | { 7 | /// 8 | /// Rsa 长度 9 | /// 10 | public enum RsaSize 11 | { 12 | R1024=1024, 13 | R2048=2048, 14 | R4096=4096 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Services/ITestService.cs: -------------------------------------------------------------------------------- 1 | using JCE.Dependency; 2 | using JCE.Logs.Aspects; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace JCE.Samples.Services 8 | { 9 | public interface ITestService: IScopeDependency 10 | { 11 | [DebugLog] 12 | void WriteOtherLog(string content); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/JCE.Logs/Contents/ICaption.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Logs.Contents 6 | { 7 | /// 8 | /// 标题 9 | /// 10 | public interface ICaption 11 | { 12 | /// 13 | /// 标题 14 | /// 15 | string Caption { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/JCE/Applications/Dtos/IKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Applications.Dtos 6 | { 7 | /// 8 | /// 标识 9 | /// 10 | public interface IKey 11 | { 12 | /// 13 | /// 标识 14 | /// 15 | string Id { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/JCE/Aspects/Base/ParameterInterceptorBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using AspectCore.DynamicProxy.Parameters; 5 | 6 | namespace JCE.Aspects.Base 7 | { 8 | /// 9 | /// 参数拦截器基类 10 | /// 11 | public abstract class ParameterInterceptorBase:ParameterInterceptorAttribute 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/JCE.Utils.Encrypts.Test/TestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using Xunit.Abstractions; 4 | 5 | namespace JCE.Utils.Encrypts.Test 6 | { 7 | public class TestBase 8 | { 9 | protected readonly ITestOutputHelper Output; 10 | 11 | public TestBase(ITestOutputHelper output) 12 | { 13 | Output = output; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Services/JCE.Samples.Services.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/IVersion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities 6 | { 7 | /// 8 | /// 乐观锁 9 | /// 10 | public interface IVersion 11 | { 12 | /// 13 | /// 版本号 14 | /// 15 | byte[] Version { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/JCE.Utils.Test/TestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Xunit; 4 | using Xunit.Abstractions; 5 | 6 | namespace JCE.Utils.Test 7 | { 8 | public class TestBase 9 | { 10 | protected readonly ITestOutputHelper Output; 11 | 12 | public TestBase(ITestOutputHelper output) 13 | { 14 | Output = output; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/ISoftDelete.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities 6 | { 7 | /// 8 | /// 逻辑删除 9 | /// 10 | public interface ISoftDelete 11 | { 12 | /// 13 | /// 是否删除 14 | /// 15 | bool IsDeleted { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/JCE.Tests/TestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Xunit.Abstractions; 5 | 6 | namespace JCE.Tests 7 | { 8 | public class TestBase 9 | { 10 | protected readonly ITestOutputHelper Output; 11 | 12 | public TestBase(ITestOutputHelper output) 13 | { 14 | Output = output; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/JCE.Applications/Aspects/ICommitAfter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Applications.Aspects 6 | { 7 | /// 8 | /// 提交工作单元后操作 9 | /// 10 | public interface ICommitAfter 11 | { 12 | /// 13 | /// 提交后操作 14 | /// 15 | void CommitAfter(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/Tenants/ITenant.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities.Tenants 6 | { 7 | /// 8 | /// 租户 9 | /// 10 | public interface ITenant 11 | { 12 | /// 13 | /// 租户编号 14 | /// 15 | string TenantId { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/JCE.ComputerInfo.Test/TestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Xunit; 4 | using Xunit.Abstractions; 5 | 6 | namespace JCE.ComputerInfo.Test 7 | { 8 | public class TestBase 9 | { 10 | protected readonly ITestOutputHelper Output; 11 | 12 | public TestBase(ITestOutputHelper output) 13 | { 14 | Output = output; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/JCE.Utils/Randoms/IRandomGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.Randoms 6 | { 7 | /// 8 | /// 随机数生成器 9 | /// 10 | public interface IRandomGenerator 11 | { 12 | /// 13 | /// 生成随机数 14 | /// 15 | /// 16 | string Generate(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/IKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities 6 | { 7 | /// 8 | /// 标识 9 | /// 10 | /// 标识类型 11 | public interface IKey 12 | { 13 | /// 14 | /// 标识 15 | /// 16 | TKey Id { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/JCE/Validations/IValidation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Validations 6 | { 7 | /// 8 | /// 验证操作 9 | /// 10 | public interface IValidation 11 | { 12 | /// 13 | /// 验证 14 | /// 15 | /// 16 | ValidationResultCollection Validate(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/JCE.Tools.QrCode.ZXing.Test/TestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Xunit.Abstractions; 5 | 6 | namespace JCE.Tools.QrCode.ZXing.Test 7 | { 8 | public class TestBase 9 | { 10 | protected readonly ITestOutputHelper Output; 11 | 12 | public TestBase(ITestOutputHelper output) 13 | { 14 | Output = output; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/Configs/EfConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Datas.EntityFramework.Configs 6 | { 7 | /// 8 | /// EF配置 9 | /// 10 | public class EfConfig 11 | { 12 | /// 13 | /// EF日志级别 14 | /// 15 | public static EfLogLevel LogLevel = EfLogLevel.Sql; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/JCE.Utils.Encrypts/JCE.Utils.Encrypts.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/JCE.Utils/IdGenerators/IGuidGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.IdGenerators 6 | { 7 | /// 8 | /// Id生成器 9 | /// 10 | public interface IGuidGenerator 11 | { 12 | /// 13 | /// 创建 Guid 14 | /// 15 | /// 16 | Guid Create(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/IQueryParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Domains.Repositories; 5 | 6 | namespace JCE.Datas.Queries 7 | { 8 | /// 9 | /// 查询参数 10 | /// 11 | public interface IQueryParameter:IPager 12 | { 13 | /// 14 | /// 搜索关键字 15 | /// 16 | string Keyword { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/JCE/Dependency/IDependencyRegistrar.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | namespace JCE.Dependency 4 | { 5 | /// 6 | /// 依赖注册管理器 7 | /// 8 | public interface IDependencyRegistrar 9 | { 10 | /// 11 | /// 注册依赖 12 | /// 13 | /// 服务集合 14 | void Register(IServiceCollection services); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/JCE/Logs/Abstractions/ILogConvert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils; 5 | 6 | namespace JCE.Logs.Abstractions 7 | { 8 | /// 9 | /// 日志转换器 10 | /// 11 | public interface ILogConvert 12 | { 13 | /// 14 | /// 转换 15 | /// 16 | /// 17 | List To(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE/Datas/Persistence/IPersistentObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Dependency; 5 | using JCE.Domains.Entities; 6 | 7 | namespace JCE.Datas.Persistence 8 | { 9 | /// 10 | /// 持久化对象 11 | /// 12 | /// 13 | public interface IPersistentObject:IKey,IScopeDependency,IVersion 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.MySql/EntityMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Datas.EntityFramework.Core; 5 | 6 | namespace JCE.Datas.EntityFramework.MySql 7 | { 8 | /// 9 | /// 实体映射配置 10 | /// 11 | /// 实体类型 12 | public abstract class EntityMap : MapBase, IMap where TEntity : class 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.SqlServer/EntityMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Datas.EntityFramework.Core; 5 | 6 | namespace JCE.Datas.EntityFramework.SqlServer 7 | { 8 | /// 9 | /// 实体映射配置 10 | /// 11 | /// 实体类型 12 | public abstract class EntityMap:MapBase,IMap where TEntity:class 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/JCE.Utils/JCE.Utils.csproj.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True -------------------------------------------------------------------------------- /src/JCE.Logs.Log4Net/JCE.Logs.Log4Net.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/JCE.Logs.NLog/JCE.Logs.NLog.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/JCE/Validations/IValidationHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Validations 6 | { 7 | /// 8 | /// 验证处理器 9 | /// 10 | public interface IValidationHandler 11 | { 12 | /// 13 | /// 处理验证错误 14 | /// 15 | /// 验证结果集合 16 | void Handle(ValidationResultCollection results); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/JCE/Events/IEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Events 6 | { 7 | /// 8 | /// 事件 9 | /// 10 | public interface IEvent 11 | { 12 | /// 13 | /// 事件标识 14 | /// 15 | string Id { get; set; } 16 | 17 | /// 18 | /// 事件时间 19 | /// 20 | DateTime Time { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/JCE/Validations/IValidationRule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Text; 5 | 6 | namespace JCE.Validations 7 | { 8 | /// 9 | /// 验证规则 10 | /// 11 | public interface IValidationRule 12 | { 13 | /// 14 | /// 验证 15 | /// 16 | /// 17 | ValidationResult Validate(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE.Logs.Exceptionless/JCE.Logs.Exceptionless.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/JCE/Contexts/IUserContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Contexts 6 | { 7 | /// 8 | /// 用户上下文 9 | /// 10 | public interface IUserContext 11 | { 12 | /// 13 | /// 用户编号 14 | /// 15 | string UserId { get; } 16 | 17 | /// 18 | /// 用户名 19 | /// 20 | string UserName { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/JCE/Logs/Abstractions/ILogFormat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Logs.Abstractions 6 | { 7 | /// 8 | /// 日志格式化器 9 | /// 10 | public interface ILogFormat 11 | { 12 | /// 13 | /// 格式化 14 | /// 15 | /// 日志内容 16 | /// 17 | string Format(ILogContent content); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/Core/IMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.EntityFrameworkCore; 5 | 6 | namespace JCE.Datas.EntityFramework.Core 7 | { 8 | /// 9 | /// 映射 10 | /// 11 | public interface IMap 12 | { 13 | /// 14 | /// 映射配置 15 | /// 16 | /// 模型生成器 17 | void Map(ModelBuilder builder); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode/IQrCodeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Tools.QrCode 6 | { 7 | /// 8 | /// 二维码服务 工厂 9 | /// 10 | public interface IQrCodeFactory 11 | { 12 | /// 13 | /// 创建二维码服务 14 | /// 15 | /// 二维码文件存储目录 16 | /// 17 | IQrCodeService Create(string path); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE/Applications/Dtos/DtoBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | using System.Text; 5 | 6 | namespace JCE.Applications.Dtos 7 | { 8 | /// 9 | /// 数据传输对象 10 | /// 11 | [DataContract] 12 | public abstract class DtoBase:RequestBase,IDto 13 | { 14 | /// 15 | /// 标识 16 | /// 17 | [DataMember] 18 | public string Id { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/JCE/Events/IEventBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Events 6 | { 7 | /// 8 | /// 事件总线 9 | /// 10 | public interface IEventBus 11 | { 12 | /// 13 | /// 发布事件 14 | /// 15 | /// 事件类型 16 | /// 事件 17 | void Publish(TEvent @event) where TEvent : IEvent; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.MySql/JCE.Datas.EntityFramework.MySql.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode.QrCoder/JCE.Tools.QrCode.QrCoder.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/JCE.Webs/JCE.Webs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.SqlServer/JCE.Datas.EntityFramework.SqlServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/JCE/GlobalConfigs/Models/UserContextConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace JCE.GlobalConfigs.Models 7 | { 8 | /// 9 | /// 用户上下文 配置 10 | /// 11 | public class UserContextConfig 12 | { 13 | /// 14 | /// 是否启用用户名,用于设置审计创建人以及修改人 15 | /// 16 | [DisplayName("是否启用用户名")] 17 | public bool EnabledUserName { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE.Utils.Encrypts/Symmetric/OutType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace JCE.Utils.Encrypts.Symmetric 7 | { 8 | /// 9 | /// 输出类型 10 | /// 11 | public enum OutType 12 | { 13 | /// 14 | /// Base64字符串 15 | /// 16 | Base64, 17 | /// 18 | /// 16进制字符串 19 | /// 20 | Hex 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode/QrSize.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Tools.QrCode 6 | { 7 | /// 8 | /// 二维码尺寸 9 | /// 10 | public enum QrSize 11 | { 12 | /// 13 | /// 小 14 | /// 15 | Small=5, 16 | /// 17 | /// 中 18 | /// 19 | Middle=10, 20 | /// 21 | /// 大 22 | /// 23 | Large=20 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/JCE/Contexts/NullUserContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Contexts 6 | { 7 | /// 8 | /// 空用户上下文 9 | /// 10 | public class NullUserContext:IUserContext 11 | { 12 | /// 13 | /// 用户编号 14 | /// 15 | public string UserId => string.Empty; 16 | 17 | /// 18 | /// 用户名 19 | /// 20 | public string UserName => string.Empty; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/JCE/Validations/Handlers/NothingHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Validations.Handlers 6 | { 7 | /// 8 | /// 验证失败,不做任何处理 9 | /// 10 | public class NothingHandler : IValidationHandler 11 | { 12 | /// 13 | /// 处理验证错误 14 | /// 15 | /// 验证结果集合 16 | public void Handle(ValidationResultCollection results) 17 | { 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/JCE/Events/Messages/IMessageEventBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Events.Messages 6 | { 7 | /// 8 | /// 消息事件总线 9 | /// 10 | public interface IMessageEventBus 11 | { 12 | /// 13 | /// 发布事件 14 | /// 15 | /// 事件类型 16 | /// 事件 17 | void Publish(TEvent @event) where TEvent : IMessageEvent; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE.Applications/JCE.Applications.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/JCE/Domains/Repositories/ICriteria.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | 6 | namespace JCE.Domains.Repositories 7 | { 8 | /// 9 | /// 查询条件 10 | /// 11 | /// 实体类型 12 | public interface ICriteria 13 | { 14 | /// 15 | /// 获取查询条件 16 | /// 17 | /// 18 | Expression> GetPredicate(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/JCE/Events/Handlers/IEventHandlerFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Events.Handlers 6 | { 7 | /// 8 | /// 事件处理器工厂 9 | /// 10 | public interface IEventHandlerFactory 11 | { 12 | /// 13 | /// 获取事件处理器列表 14 | /// 15 | /// 事件类型 16 | /// 17 | List> GetHandlers() where TEvent : IEvent; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JCE.Utils/IO/IFileStore.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.IO 6 | { 7 | /// 8 | /// 文件存储服务 9 | /// 10 | public interface IFileStore 11 | { 12 | /// 13 | /// 保存文件,返回完整文件路径 14 | /// 15 | /// 文件流 16 | /// 文件名,必须包含扩展名,如果仅传入扩展名则生成随机文件名 17 | /// 18 | string Save(byte[] stream, string fileName); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/JCE.Events/JCE.Events.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/Auditing/IAudited.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities.Auditing 6 | { 7 | /// 8 | /// 操作审计 9 | /// 10 | public interface IAudited:ICreationAudited,IModificationAudited 11 | { 12 | } 13 | 14 | /// 15 | /// 操作审计 16 | /// 17 | /// 操作人编号类型 18 | public interface IAudited : ICreationAudited, IModificationAudited 19 | { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/JCE.Datas.EntityFramework.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/ICompareChange.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities 6 | { 7 | /// 8 | /// 通过对象比较获取变更属性集 9 | /// 10 | /// 领域对象类型 11 | public interface ICompareChange where T:IDomainObject 12 | { 13 | /// 14 | /// 获取变更属性 15 | /// 16 | /// 其它领域对象 17 | /// 18 | ChangeValueCollection GetChanges(T other); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/JCE.Utils.Encrypts/Asymmetric/RsaType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace JCE.Utils.Encrypts.Asymmetric 7 | { 8 | /// 9 | /// Rsa 算法类型 10 | /// 11 | public enum RsaType 12 | { 13 | /// 14 | /// SHA1 15 | /// 16 | [Description("SHA1")] 17 | Rsa, 18 | /// 19 | /// RSA2 密钥长度至少为2048,SHA256 20 | /// 21 | [Description("SHA256")] 22 | Rsa2 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/JCE/Logs/Abstractions/ILogProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Logs.Abstractions 6 | { 7 | /// 8 | /// 日志提供程序工厂 9 | /// 10 | public interface ILogProviderFactory 11 | { 12 | /// 13 | /// 创建日志提供程序 14 | /// 15 | /// 日志名称 16 | /// 日志格式化器 17 | /// 18 | ILogProvider Create(string logName, ILogFormat format = null); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/Configs/EfLogLevel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Datas.EntityFramework.Configs 6 | { 7 | /// 8 | /// Ef日志级别 9 | /// 10 | public enum EfLogLevel 11 | { 12 | /// 13 | /// 输出全部日志,包括连接数据库,提交事务等大量信息 14 | /// 15 | All, 16 | /// 17 | /// 仅输出Sql 18 | /// 19 | Sql, 20 | /// 21 | /// 关闭日志 22 | /// 23 | Off 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/JCE/Dependency/IScope.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JCE.Dependency 4 | { 5 | /// 6 | /// 作用域 7 | /// 8 | public interface IScope:IDisposable 9 | { 10 | /// 11 | /// 创建实例 12 | /// 13 | /// 实例类型 14 | /// 15 | T Create(); 16 | 17 | /// 18 | /// 创建对象 19 | /// 20 | /// 对象类型 21 | /// 22 | object Create(Type type); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/JCE.Tests/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | using JCE.Aspects.Base; 4 | using Xunit; 5 | using Xunit.Abstractions; 6 | 7 | namespace JCE.Tests 8 | { 9 | public class UnitTest1:TestBase 10 | { 11 | public UnitTest1(ITestOutputHelper output) : base(output) 12 | { 13 | } 14 | 15 | [Fact] 16 | public void Test1() 17 | { 18 | Output.WriteLine(typeof(NonAspectAttribute).MetadataToken.ToString()); 19 | Output.WriteLine(typeof(InterceptorBase).MetadataToken.ToString()); 20 | } 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Boundary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Datas.Queries 6 | { 7 | /// 8 | /// 查询边界 9 | /// 10 | public enum Boundary 11 | { 12 | /// 13 | /// 包含左边 14 | /// 15 | Left, 16 | /// 17 | /// 包含右边 18 | /// 19 | Right, 20 | /// 21 | /// 包含两边 22 | /// 23 | Both, 24 | /// 25 | /// 不包含 26 | /// 27 | Neither 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/JCE/Domains/Repositories/IPagerBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Repositories 6 | { 7 | /// 8 | /// 分页 9 | /// 10 | public interface IPagerBase 11 | { 12 | /// 13 | /// 页数,即第几页,从1开始 14 | /// 15 | int Page { get; set; } 16 | 17 | /// 18 | /// 每页显示行数 19 | /// 20 | int PageSize { get; set; } 21 | 22 | /// 23 | /// 总行数 24 | /// 25 | int TotalCount { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/JCE/Events/Messages/IMessageEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Events.Messages 6 | { 7 | /// 8 | /// 消息事件 9 | /// 10 | public interface IMessageEvent:IEvent 11 | { 12 | /// 13 | /// 事件数据 14 | /// 15 | object Data { get; set; } 16 | 17 | /// 18 | /// 发送目标 19 | /// 20 | string Target { get; set; } 21 | 22 | /// 23 | /// 回调 24 | /// 25 | string Callback { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/JCE.Utils/Randoms/GuidRandomGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Helpers; 5 | 6 | namespace JCE.Utils.Randoms 7 | { 8 | /// 9 | /// Guid随机数生成器,每次创建一个新的Guid字符串,去掉了Guid的分隔符 10 | /// 11 | public class GuidRandomGenerator:IRandomGenerator 12 | { 13 | /// 14 | /// 生成随机数 15 | /// 16 | /// 17 | public string Generate() 18 | { 19 | return Id.Guid(); 20 | } 21 | 22 | public static readonly IRandomGenerator Instance=new GuidRandomGenerator(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/JCE.Utils.Encrypts.Test/JCE.Utils.Encrypts.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode/ErrorCorrectionLevel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Tools.QrCode 6 | { 7 | /// 8 | /// 容错级别 9 | /// 10 | public enum ErrorCorrectionLevel 11 | { 12 | /// 13 | /// 可以纠正最大7%的错误 14 | /// 15 | L, 16 | /// 17 | /// 可以纠正最大15%的错误 18 | /// 19 | M, 20 | /// 21 | /// 可以纠正最大25%的错误 22 | /// 23 | Q, 24 | /// 25 | /// 可以纠正最大30%的错误 26 | /// 27 | H 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/JCE/Events/Handlers/IEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Events.Handlers 6 | { 7 | /// 8 | /// 事件处理器 9 | /// 10 | public interface IEventHandler 11 | { 12 | } 13 | 14 | /// 15 | /// 事件处理器 16 | /// 17 | /// 事件类型 18 | public interface IEventHandler : IEventHandler where TEvent : IEvent 19 | { 20 | /// 21 | /// 处理事件 22 | /// 23 | /// 事件 24 | void Handle(TEvent @event); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/JCE/Domains/Repositories/IQueryBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Repositories 6 | { 7 | /// 8 | /// 查询对象 9 | /// 10 | /// 实体类型 11 | public interface IQueryBase:ICriteria where TEntity:class 12 | { 13 | /// 14 | /// 获取排序条件 15 | /// 16 | /// 17 | string GetOrder(); 18 | 19 | /// 20 | /// 获取分页参数 21 | /// 22 | /// 23 | IPager GetPager(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/JCE.Tests/JCE.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/JCE.Events/Default/EventHandlerFactory.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections.Generic; 4 | using JCE.Events.Handlers; 5 | using JCE.Helpers; 6 | 7 | namespace JCE.Events.Default 8 | { 9 | /// 10 | /// 事件处理器工厂 11 | /// 12 | public class EventHandlerFactory:IEventHandlerFactory 13 | { 14 | /// 15 | /// 获取事件处理器列表 16 | /// 17 | /// 事件类型 18 | /// 19 | public List> GetHandlers() where TEvent : IEvent 20 | { 21 | return Ioc.CreateList>(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/JCE/Datas/UnitOfWorks/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using JCE.Aspects; 6 | using JCE.Dependency; 7 | 8 | namespace JCE.Datas.UnitOfWorks 9 | { 10 | /// 11 | /// 工作单元 12 | /// 13 | [Ignore] 14 | public interface IUnitOfWork:IDisposable 15 | { 16 | /// 17 | /// 提交,返回影响的行数 18 | /// 19 | /// 20 | int Commit(); 21 | 22 | /// 23 | /// 提交,返回影响的行数 24 | /// 25 | /// 26 | Task CommitAsync(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode.QrCoder/QrCodeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.IO; 5 | using JCE.Utils.IO.Paths; 6 | 7 | namespace JCE.Tools.QrCode.QrCoder 8 | { 9 | /// 10 | /// QRCoder 二维码服务工厂 11 | /// 12 | public class QrCodeFactory:IQrCodeFactory 13 | { 14 | /// 15 | /// 创建二维码服务 16 | /// 17 | /// 二维码文件存储目录 18 | /// 19 | public IQrCodeService Create(string path) 20 | { 21 | return new QrCoderService(new DefaultFileStore(new DefaultPathGenerator(path))); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/JCE.Utils/Extensions/Common/Extensions.String.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.Extensions 6 | { 7 | /// 8 | /// 系统扩展 - 字符串 9 | /// 10 | public static partial class Extensions 11 | { 12 | /// 13 | /// 返回与 Web 服务器上的指定虚拟路径相对应的物理文件路径。 14 | /// 15 | /// 基础路径 16 | /// 相对路径 17 | /// 18 | public static string MapPath(this string basePath, string path) 19 | { 20 | return System.IO.Path.Combine(basePath, path); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/QueryParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Domains.Repositories; 5 | 6 | namespace JCE.Datas.Queries 7 | { 8 | /// 9 | /// 查询参数 10 | /// 11 | public class QueryParameter:Pager,IQueryParameter 12 | { 13 | /// 14 | /// 搜索关键字 15 | /// 16 | public string Keyword { get; set; } 17 | 18 | /// 19 | /// 添加描述 20 | /// 21 | protected override void AddDescriptions() 22 | { 23 | base.AddDescriptions(); 24 | AddDescription("Keyword",Keyword); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/JCE/Reflections/WebAppTypeFinder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | using Microsoft.Extensions.PlatformAbstractions; 6 | 7 | namespace JCE.Reflections 8 | { 9 | /// 10 | /// Web应用类型查找器 11 | /// 12 | public class WebAppTypeFinder:AppDomainTypeFinder 13 | { 14 | /// 15 | /// 获取程序集列表 16 | /// 17 | /// 18 | public override List GetAssemblies() 19 | { 20 | LoadAssemblies(PlatformServices.Default.Application.ApplicationBasePath); 21 | return base.GetAssemblies(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/JCE.Logs.NLog/LogProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Logs.Abstractions; 5 | 6 | namespace JCE.Logs.NLog 7 | { 8 | /// 9 | /// NLog日志提供程序工厂 10 | /// 11 | public class LogProviderFactory : ILogProviderFactory 12 | { 13 | /// 14 | /// 创建日志提供程序 15 | /// 16 | /// 日志名称 17 | /// 日志格式化器 18 | /// 19 | public ILogProvider Create(string logName, ILogFormat format = null) 20 | { 21 | return new NLogProvider(logName, format); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace JCE.Samples.Webs 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/JCE.Logs.Log4Net/LogProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Logs.Abstractions; 5 | 6 | namespace JCE.Logs.Log4Net 7 | { 8 | /// 9 | /// Log4Net日志提供程序工厂 10 | /// 11 | public class LogProviderFactory:ILogProviderFactory 12 | { 13 | /// 14 | /// 创建日志提供程序 15 | /// 16 | /// 日志名称 17 | /// 日志格式化器 18 | /// 19 | public ILogProvider Create(string logName, ILogFormat format = null) 20 | { 21 | return new Log4NetProvider(logName,format); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode.ZXing/JCE.Tools.QrCode.ZXing.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | JCE.Tools.QrCode.ZXing 6 | JCE.Tools.QrCode.ZXing 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/JCE.Webs/Extensions/MiddlewareExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Webs.Middlewares; 5 | using Microsoft.AspNetCore.Builder; 6 | 7 | namespace JCE.Webs.Extensions 8 | { 9 | /// 10 | /// 中间件扩展 11 | /// 12 | public static partial class MiddlewareExtensions 13 | { 14 | /// 15 | /// 注册错误日志管道 16 | /// 17 | /// 应用程序生成器 18 | /// 19 | public static IApplicationBuilder UseErrorLog(this IApplicationBuilder builder) 20 | { 21 | return builder.UseMiddleware(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/JCE.ComputerInfo.Test/JCE.ComputerInfo.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/JCE.Logs.Exceptionless/LogProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Logs.Abstractions; 5 | 6 | namespace JCE.Logs.Exceptionless 7 | { 8 | /// 9 | /// Exceptionless日志提供程序工厂 10 | /// 11 | public class LogProviderFactory:ILogProviderFactory 12 | { 13 | /// 14 | /// 创建日志提供程序 15 | /// 16 | /// 日志名称 17 | /// 日志格式化器 18 | /// 19 | public ILogProvider Create(string logName, ILogFormat format = null) 20 | { 21 | return new ExceptionlessProvider(logName); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/JCE.Utils/Helpers/Common.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.Helpers 6 | { 7 | /// 8 | /// 常用公共操作 9 | /// 10 | public static class Common 11 | { 12 | /// 13 | /// 获取类型 14 | /// 15 | /// 类型 16 | /// 17 | public static Type GetType() 18 | { 19 | var type = typeof(T); 20 | return Nullable.GetUnderlyingType(type) ?? type; 21 | } 22 | 23 | /// 24 | /// 换行符 25 | /// 26 | public static string Line => Environment.NewLine; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/JCE/Logs/Core/NullLogFormat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Logs.Abstractions; 5 | 6 | namespace JCE.Logs.Core 7 | { 8 | /// 9 | /// 空日志格式器 10 | /// 11 | public class NullLogFormat : ILogFormat 12 | { 13 | /// 14 | /// 空日志格式器实例 15 | /// 16 | public static readonly ILogFormat Instance = new NullLogFormat(); 17 | 18 | /// 19 | /// 格式化 20 | /// 21 | /// 日志内容 22 | /// 23 | public string Format(ILogContent content) 24 | { 25 | return ""; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/JCE/Applications/Commands/ICommandFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Applications.Dtos; 5 | 6 | namespace JCE.Applications.Commands 7 | { 8 | /// 9 | /// 命令工厂 10 | /// 11 | public interface ICommandFactory 12 | { 13 | /// 14 | /// 创建命令 15 | /// 16 | /// 请求类型 17 | /// 响应类型 18 | /// 命令名称 19 | /// 20 | ICommand Create(string name) 21 | where TRequest : IRequest where TResponse : IResponse; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/JCE/Validations/Handlers/ThrowHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using JCE.Utils.Exceptions; 6 | 7 | namespace JCE.Validations.Handlers 8 | { 9 | /// 10 | /// 验证失败,抛出异常 - 默认验证处理器 11 | /// 12 | public class ThrowHandler : IValidationHandler 13 | { 14 | /// 15 | /// 处理验证错误 16 | /// 17 | /// 验证错误集合 18 | public void Handle(ValidationResultCollection results) 19 | { 20 | if (results.IsValid) 21 | { 22 | return; 23 | } 24 | throw new Warning(results.First().ErrorMessage); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/Auditing/ICreationAudited.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities.Auditing 6 | { 7 | /// 8 | /// 创建操作审计 9 | /// 10 | public interface ICreationAudited:ICreationAudited 11 | { 12 | } 13 | 14 | /// 15 | /// 创建操作审计 16 | /// 17 | /// 创建人编号类型 18 | public interface ICreationAudited 19 | { 20 | /// 21 | /// 创建时间 22 | /// 23 | DateTime? CreationTime { get; set; } 24 | 25 | /// 26 | /// 创建人编号 27 | /// 28 | TKey CreatorId { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/JCE.Utils.Encrypts/Const.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.Encrypts 6 | { 7 | /// 8 | /// 内部常量 9 | /// 10 | internal class Const 11 | { 12 | /// 13 | /// 公钥 14 | /// 15 | internal const string PublicKeyFormat = 16 | @"{0}{1}"; 17 | 18 | /// 19 | /// 私钥 20 | /// 21 | internal const string PrivateKeyFormat = 22 | @"{0}{1}

{2}

{3}{4}{5}{6}{7}
"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/JCE.Utils/IO/Paths/IPathGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.IO.Paths 6 | { 7 | /// 8 | /// 路径生成器 9 | /// 10 | public interface IPathGenerator 11 | { 12 | /// 13 | /// 添加路径参数 14 | /// 15 | /// 键 16 | /// 值 17 | /// 18 | IPathGenerator Data(string key, string value); 19 | 20 | /// 21 | /// 生成完整路径 22 | /// 23 | /// 文件名,必须包含扩展名,如果仅传入扩展名则生成随机文件名 24 | /// 25 | string Generate(string fileName); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/JCE.Utils.Test/JCE.Utils.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/JCE.Events/Default/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Events.Handlers; 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | namespace JCE.Events.Default 8 | { 9 | /// 10 | /// 事件总线 扩展 11 | /// 12 | public static partial class ServiceCollectionExtensions 13 | { 14 | /// 15 | /// 注册事件总线服务 16 | /// 17 | /// 服务集合 18 | public static void AddEventBus(this IServiceCollection services) 19 | { 20 | services.AddSingleton(); 21 | services.AddSingleton(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/JCE/Datas/UnitOfWorks/IUnitOfWorkManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using JCE.Dependency; 6 | 7 | namespace JCE.Datas.UnitOfWorks 8 | { 9 | /// 10 | /// 工作单元管理器 11 | /// 12 | public interface IUnitOfWorkManager:IScopeDependency 13 | { 14 | /// 15 | /// 提交 16 | /// 17 | void Commit(); 18 | 19 | /// 20 | /// 提交 21 | /// 22 | /// 23 | Task CommitAsync(); 24 | 25 | /// 26 | /// 注册工作单元 27 | /// 28 | /// 工作单元 29 | void Register(IUnitOfWork unitOfWork); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/Auditing/IModificationAudited.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities.Auditing 6 | { 7 | /// 8 | /// 修改操作审计 9 | /// 10 | public interface IModificationAudited: IModificationAudited 11 | { 12 | } 13 | 14 | /// 15 | /// 修改操作审计 16 | /// 17 | /// 最后修改人编号类型 18 | public interface IModificationAudited 19 | { 20 | /// 21 | /// 最后修改时间 22 | /// 23 | DateTime? LastModificationTime { get; set; } 24 | 25 | /// 26 | /// 最后修改人编号 27 | /// 28 | TKey LastModifierId { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/JCE/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Dependency; 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | namespace JCE 8 | { 9 | /// 10 | /// 系统扩展 - 基础设施扩展 11 | /// 12 | public static partial class ServiceCollectionExtensions 13 | { 14 | /// 15 | /// 注册JCE基础设施服务 16 | /// 17 | /// 服务集合 18 | /// 依赖配置 19 | /// 20 | public static IServiceProvider AddJce(this IServiceCollection services, params IConfig[] configs) 21 | { 22 | return new DependencyConfiguration(services,configs).Config(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/UnitOfWorkExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using JCE.Datas.UnitOfWorks; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | namespace JCE.Datas.EntityFramework 9 | { 10 | /// 11 | /// EF工作单元 扩展 12 | /// 13 | public static partial class UnitOfWorkExtensions 14 | { 15 | /// 16 | /// 清空缓存 17 | /// 18 | /// 工作单元 19 | public static void ClearCache(this IUnitOfWork unitOfWork) 20 | { 21 | var dbContext = unitOfWork as DbContext; 22 | dbContext?.ChangeTracker.Entries().ToList().ForEach(entry=>entry.State=EntityState.Detached); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/JCE/Validations/Handlers/DefaultValidationHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace JCE.Validations.Handlers 8 | { 9 | /// 10 | /// 默认验证处理器,直接抛出异常 11 | /// 12 | public class DefaultValidationHandler : IValidationHandler 13 | { 14 | /// 15 | /// 处理验证错误 16 | /// 17 | /// 验证结果集合 18 | public void Handle(ValidationResultCollection results) 19 | { 20 | if (results.IsValid) 21 | { 22 | return; 23 | } 24 | throw new ValidationException(results.First().ErrorMessage); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/JCE.Logs/Aspects/DebugLogAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Logs.Aspects 6 | { 7 | /// 8 | /// 调试日志 9 | /// 10 | public class DebugLogAttribute:LogAttributeBase 11 | { 12 | /// 13 | /// 写日志 14 | /// 15 | /// 日志操作 16 | protected override void WriteLog(ILog log) 17 | { 18 | log.Debug(); 19 | } 20 | 21 | /// 22 | /// 是否启用 23 | /// 24 | /// 日志操作 25 | /// 26 | protected override bool Enabled(ILog log) 27 | { 28 | return log.IsDebugEnabled; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE.Logs/Aspects/TraceLogAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Logs.Aspects 6 | { 7 | /// 8 | /// 跟踪日志 9 | /// 10 | public class TraceLogAttribute:LogAttributeBase 11 | { 12 | /// 13 | /// 写日志 14 | /// 15 | /// 日志操作 16 | protected override void WriteLog(ILog log) 17 | { 18 | log.Trace(); 19 | } 20 | 21 | /// 22 | /// 是否启用 23 | /// 24 | /// 日志操作 25 | /// 26 | protected override bool Enabled(ILog log) 27 | { 28 | return log.IsTraceEnabled; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE.Logs/Extensions/ExceptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Exceptions; 5 | 6 | namespace JCE.Logs.Extensions 7 | { 8 | /// 9 | /// 异常扩展 10 | /// 11 | public static partial class ExceptionExtensions 12 | { 13 | /// 14 | /// 写日志 15 | /// 16 | /// 异常 17 | /// 日志 18 | public static void Log(this Exception exception, ILog log) 19 | { 20 | if (!(exception is Warning warning)) 21 | { 22 | log.Exception(exception).Error(); 23 | return; 24 | } 25 | log.Exception(exception,warning.Code).Warn(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/JCE.Tools.QrCode.ZXing.Test/JCE.Tools.QrCode.ZXing.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/JCE.ComputerInfo/DiskInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.ComputerInfo 6 | { 7 | /// 8 | /// 硬盘信息 9 | /// 10 | public struct DiskInfo 11 | { 12 | /// 13 | /// 硬盘名 14 | /// 15 | public string Name { get; } 16 | 17 | /// 18 | /// 容量大小,单位:字节 19 | /// 20 | public long Size { get; } 21 | 22 | /// 23 | /// 初始化一个类型的实例 24 | /// 25 | /// 硬盘名 26 | /// 容量大小,单位:字节 27 | public DiskInfo(string name, long size) 28 | { 29 | Name = name; 30 | Size = size; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/JCE.Utils/Webs/Clients/HttpContentType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace JCE.Utils.Webs.Clients 7 | { 8 | /// 9 | /// Http 内容类型 10 | /// 11 | public enum HttpContentType 12 | { 13 | /// 14 | /// Form格式:application/x-www-form-urlencoded 15 | /// 16 | [Description("application/x-www-form-urlencoded")] 17 | FormUrlEncoded, 18 | /// 19 | /// JSON格式:application/json 20 | /// 21 | [Description("application/json")] 22 | Json, 23 | /// 24 | /// 表单文件上传:multipart/form-data 25 | /// 26 | [Description("multipart/form-data")] 27 | FormData 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:22205/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "JCE.Samples.Webs": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:22206/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/JCE/Aspects/NotNullAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using AspectCore.DynamicProxy.Parameters; 6 | using JCE.Aspects.Base; 7 | 8 | namespace JCE.Aspects 9 | { 10 | /// 11 | /// 验证不能为null 12 | /// 13 | [AttributeUsage(AttributeTargets.Parameter)] 14 | public class NotNullAttribute:ParameterInterceptorBase 15 | { 16 | /// 17 | /// 执行 18 | /// 19 | public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next) 20 | { 21 | if (context.Parameter.Value == null) 22 | { 23 | throw new ArgumentNullException(context.Parameter.Name); 24 | } 25 | return next(context); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/JCE.Logs/JCE.Logs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | True 15 | True 16 | LogResource.resx 17 | 18 | 19 | 20 | 21 | 22 | PublicResXFileCodeGenerator 23 | LogResource.Designer.cs 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/JCE/Aspects/NotEmptyAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using AspectCore.DynamicProxy.Parameters; 6 | using JCE.Aspects.Base; 7 | using JCE.Utils.Extensions; 8 | 9 | namespace JCE.Aspects 10 | { 11 | /// 12 | /// 验证不能为空 13 | /// 14 | public class NotEmptyAttribute:ParameterInterceptorBase 15 | { 16 | /// 17 | /// 执行 18 | /// 19 | public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next) 20 | { 21 | if (string.IsNullOrWhiteSpace(context.Parameter.Value.SafeString())) 22 | { 23 | throw new ArgumentNullException(context.Parameter.Name); 24 | } 25 | return next(context); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/JCE/GlobalConfigs/Models/JCEConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.GlobalConfigs.Models 6 | { 7 | /// 8 | /// 框架配置信息实体 9 | /// 10 | // ReSharper disable once InconsistentNaming 11 | public class JCEConfig 12 | { 13 | /// 14 | /// 日志 相关 15 | /// 16 | public LogConfig Logger { get; set; } 17 | 18 | /// 19 | /// 用户上下文 相关 20 | /// 21 | public UserContextConfig UserContext { get; set; } 22 | 23 | /// 24 | /// 初始化一个类型的实例 25 | /// 26 | public JCEConfig() 27 | { 28 | Logger=new LogConfig(); 29 | UserContext = new UserContextConfig(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/JCE.Utils.Encrypts.Test/Base64CryptorTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Xunit; 5 | using Xunit.Abstractions; 6 | 7 | namespace JCE.Utils.Encrypts.Test 8 | { 9 | public class Base64CryptorTest:TestBase 10 | { 11 | public Base64CryptorTest(ITestOutputHelper output) : base(output) 12 | { 13 | } 14 | 15 | [Fact] 16 | public void Test_Encrypt() 17 | { 18 | var result = Base64Cryptor.Encrypt("JCE"); 19 | Output.WriteLine(result); 20 | Assert.Equal("SkNF",result); 21 | } 22 | 23 | [Fact] 24 | public void Test_Decrypt() 25 | { 26 | var result = Base64Cryptor.Decrypt("SkNF"); 27 | Output.WriteLine(result); 28 | Assert.Equal("JCE", result); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.SqlServer/AggregateRootMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Datas.EntityFramework.Core; 5 | using JCE.Domains.Entities; 6 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 7 | 8 | namespace JCE.Datas.EntityFramework.SqlServer 9 | { 10 | /// 11 | /// 聚合根映射配置 12 | /// 13 | /// 实体类型 14 | public abstract class AggregateRootMap:MapBase,IMap where TEntity:class,IVersion 15 | { 16 | /// 17 | /// 映射乐观离线锁 18 | /// 19 | /// 实体类型生成器 20 | protected override void MapVersion(EntityTypeBuilder builder) 21 | { 22 | builder.Property(t => t.Version).IsRowVersion(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.MySql/AggregateRootMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Datas.EntityFramework.Core; 5 | using JCE.Domains.Entities; 6 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 7 | 8 | namespace JCE.Datas.EntityFramework.MySql 9 | { 10 | /// 11 | /// 聚合根映射配置 12 | /// 13 | /// 实体类型 14 | public abstract class AggregateRootMap : MapBase, IMap where TEntity : class, IVersion 15 | { 16 | /// 17 | /// 映射乐观离线锁 18 | /// 19 | /// 实体类型生成器 20 | protected override void MapVersion(EntityTypeBuilder builder) 21 | { 22 | builder.Property(t => t.Version).IsConcurrencyToken(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/IAggregateRoot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities 6 | { 7 | /// 8 | /// 聚合根 9 | /// 10 | public interface IAggregateRoot:IEntity,IVersion 11 | { 12 | } 13 | 14 | /// 15 | /// 聚合根 16 | /// 17 | /// 标识类型 18 | public interface IAggregateRoot : IEntity, IAggregateRoot 19 | { 20 | } 21 | 22 | /// 23 | /// 聚合根 24 | /// 25 | /// 实体类型 26 | /// 标识类型 27 | public interface IAggregateRoot : IEntity, IAggregateRoot 28 | where TEntity : IAggregateRoot 29 | { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE.Utils/ExtensionMethodSetting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Text; 5 | 6 | namespace JCE.Utils 7 | { 8 | /// 9 | /// 扩展方法设置 10 | /// 11 | public class ExtensionMethodSetting 12 | { 13 | /// 14 | /// 初始化静态实例 15 | /// 16 | static ExtensionMethodSetting() 17 | { 18 | DefaultEncoding=Encoding.UTF8; 19 | DefaultCulture=CultureInfo.CurrentCulture; 20 | } 21 | 22 | /// 23 | /// 默认编码 24 | /// 25 | public static Encoding DefaultEncoding { get; set; } 26 | 27 | /// 28 | /// 默认区域设置 29 | /// 30 | public static CultureInfo DefaultCulture { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/JCE.Utils/Extensions/Common/Extensions.File.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace JCE.Utils.Extensions 7 | { 8 | /// 9 | /// 系统扩展 - 文件或流相关扩展 10 | /// 11 | public static partial class Extensions 12 | { 13 | /// 14 | /// 将字节流写入文件 15 | /// 16 | /// 文件流 17 | /// 文件绝对路径 18 | public static void ToFile(this byte[] stream, string filePath) 19 | { 20 | var directoryPath = Path.GetDirectoryName(filePath); 21 | if (Directory.Exists(directoryPath) == false) 22 | { 23 | Directory.CreateDirectory(directoryPath); 24 | } 25 | File.WriteAllBytes(filePath,stream); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/JCE.Utils/Helpers/Thread.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | namespace JCE.Utils.Helpers 7 | { 8 | /// 9 | /// 线程操作 10 | /// 11 | public static class Thread 12 | { 13 | /// 14 | /// 执行多个操作,多个操作将同时执行 15 | /// 16 | /// 操作集合 17 | public static void WaitAll(params Action[] actions) 18 | { 19 | if (actions == null) 20 | { 21 | return; 22 | } 23 | List tasks=new List(); 24 | foreach (var action in actions) 25 | { 26 | tasks.Add(Task.Factory.StartNew(action, TaskCreationOptions.None)); 27 | } 28 | Task.WaitAll(tasks.ToArray()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE.Webs/Middlewares/Internals/NullToEmptyStringResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Newtonsoft.Json; 6 | using Newtonsoft.Json.Serialization; 7 | 8 | namespace JCE.Webs.Middlewares.Internals 9 | { 10 | /// 11 | /// Json Null 值替换为空字符串 解析器 12 | /// 13 | public class NullToEmptyStringResolver:DefaultContractResolver 14 | { 15 | // 重写创建属性方法 16 | protected override IList CreateProperties(Type type, MemberSerialization memberSerialization) 17 | { 18 | return type.GetProperties().Select(p => 19 | { 20 | var jp = base.CreateProperty(p, memberSerialization); 21 | jp.ValueProvider = new NullToEmptyStringValueProvider(p); 22 | return jp; 23 | }).ToList(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/JCE/Applications/Dtos/RequestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | using System.Text; 6 | using JCE.Utils.Exceptions; 7 | using JCE.Validations; 8 | 9 | namespace JCE.Applications.Dtos 10 | { 11 | /// 12 | /// 请求对象 13 | /// 14 | [DataContract] 15 | public abstract class RequestBase:IRequest 16 | { 17 | /// 18 | /// 验证 19 | /// 20 | /// 21 | public virtual ValidationResultCollection Validate() 22 | { 23 | var result = DataAnnotationValidation.Validate(this); 24 | if (result.IsValid) 25 | { 26 | return ValidationResultCollection.Success; 27 | } 28 | throw new Warning(result.First().ErrorMessage); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities 6 | { 7 | /// 8 | /// 实体 9 | /// 10 | public interface IEntity:IDomainObject 11 | { 12 | /// 13 | /// 初始化 14 | /// 15 | void Init(); 16 | } 17 | 18 | /// 19 | /// 实体 20 | /// 21 | /// 标识类型 22 | public interface IEntity : IKey, IEntity 23 | { 24 | } 25 | 26 | /// 27 | /// 实体 28 | /// 29 | /// 实体类型 30 | /// 标识类型 31 | public interface IEntity : ICompareChange, IEntity where TEntity : IEntity 32 | { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/JCE/Logs/Abstractions/ILogProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace JCE.Logs.Abstractions 7 | { 8 | /// 9 | /// 日志提供程序 10 | /// 11 | public interface ILogProvider 12 | { 13 | /// 14 | /// 日志名称 15 | /// 16 | string LogName { get; } 17 | 18 | /// 19 | /// 调试级别是否启用 20 | /// 21 | bool IsDebugEnabled { get; } 22 | 23 | /// 24 | /// 跟踪级别是否启用 25 | /// 26 | bool IsTraceEnabled { get; } 27 | 28 | /// 29 | /// 写日志 30 | /// 31 | /// 日志等级 32 | /// 日志内容 33 | void WriteLog(LogLevel level, ILogContent content); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/JCE/Contexts/IContext.cs: -------------------------------------------------------------------------------- 1 | namespace JCE.Contexts 2 | { 3 | /// 4 | /// 上下文 5 | /// 6 | public interface IContext 7 | { 8 | /// 9 | /// 跟踪号 10 | /// 11 | string TraceId { get; } 12 | 13 | /// 14 | /// 添加对象 15 | /// 16 | /// 对象类型 17 | /// 键名 18 | /// 对象 19 | void Add(string key, T value); 20 | 21 | /// 22 | /// 获取对象 23 | /// 24 | /// 对象类型 25 | /// 键名 26 | /// 27 | T Get(string key); 28 | 29 | /// 30 | /// 移除对象 31 | /// 32 | /// 键名 33 | void Remove(string key); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode.ZXing/QrCodeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.IO; 5 | using JCE.Utils.IO.Paths; 6 | 7 | namespace JCE.Tools.QrCode.ZXing 8 | { 9 | /// 10 | /// ZXing.Net 二维码服务工厂 11 | /// 12 | public class QrCodeFactory:IQrCodeFactory 13 | { 14 | ///// 15 | ///// 文件存储服务 16 | ///// 17 | //private IFileStore _fileStore; 18 | 19 | ///// 20 | ///// 初始化一个 21 | ///// 22 | ///// 23 | //public QrCodeServiceFactory(IFileStore fileStore) 24 | //{ 25 | // _fileStore = fileStore; 26 | //} 27 | 28 | 29 | public IQrCodeService Create(string path) 30 | { 31 | return new ZXingQrCodeService(new DefaultFileStore(new DefaultPathGenerator(path))); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/JCE/Applications/Commands/ICommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using JCE.Applications.Dtos; 6 | 7 | namespace JCE.Applications.Commands 8 | { 9 | /// 10 | /// 命令 11 | /// 12 | /// 请求类型 13 | /// 响应类型 14 | public interface ICommand where TRequest : IRequest where TResponse : IResponse 15 | { 16 | /// 17 | /// 执行 18 | /// 19 | /// 请求参数 20 | /// 21 | TResponse Execute(TRequest request); 22 | 23 | /// 24 | /// 执行 25 | /// 26 | /// 请求参数 27 | /// 28 | Task ExecuteAsync(TRequest request); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/nlog.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/JCE.Logs.NLog/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Logs.Abstractions; 5 | using JCE.Logs.Formats; 6 | using Microsoft.Extensions.DependencyInjection; 7 | 8 | namespace JCE.Logs.NLog 9 | { 10 | /// 11 | /// 日志服务 扩展 12 | /// 13 | public static partial class ServiceCollectionExtensions 14 | { 15 | /// 16 | /// 注册NLog日志操作 17 | /// 18 | /// 服务集合 19 | /// 20 | public static void AddNLog(this IServiceCollection services) 21 | { 22 | services.AddScoped(); 23 | services.AddSingleton(); 24 | services.AddScoped(); 25 | services.AddScoped(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/JCE/Logs/Abstractions/ILogContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | 6 | namespace JCE.Logs.Abstractions 7 | { 8 | /// 9 | /// 日志上下文 10 | /// 11 | public interface ILogContext 12 | { 13 | /// 14 | /// 跟踪号 15 | /// 16 | string TraceId { get; } 17 | 18 | /// 19 | /// 计时器 20 | /// 21 | Stopwatch Stopwatch { get; } 22 | 23 | /// 24 | /// IP 25 | /// 26 | string Ip { get; } 27 | 28 | /// 29 | /// 主机 30 | /// 31 | string Host { get; } 32 | 33 | /// 34 | /// 浏览器 35 | /// 36 | string Browser { get; } 37 | 38 | /// 39 | /// 请求地址 40 | /// 41 | string Url { get; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/JCE/Domains/Repositories/IPager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Repositories 6 | { 7 | /// 8 | /// 分页 9 | /// 10 | public interface IPager:IPagerBase 11 | { 12 | /// 13 | /// 排序条件 14 | /// 15 | string Order { get; set; } 16 | 17 | /// 18 | /// 获取总页数 19 | /// 20 | /// 21 | int GetPageCount(); 22 | 23 | /// 24 | /// 获取跳过的行数 25 | /// 26 | /// 27 | int GetSkipCount(); 28 | 29 | /// 30 | /// 获取起始行数 31 | /// 32 | /// 33 | int GetStartNumber(); 34 | 35 | /// 36 | /// 获取结束行数 37 | /// 38 | /// 39 | int GetEndNumber(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/JCE/Contexts/UserContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Contexts 6 | { 7 | /// 8 | /// 用户上下文 9 | /// 10 | public class UserContext:IUserContext 11 | { 12 | /// 13 | /// 用户编号 14 | /// 15 | public string UserId { get; } 16 | 17 | /// 18 | /// 用户名 19 | /// 20 | public string UserName { get; } 21 | 22 | /// 23 | /// 空用户上下文 24 | /// 25 | public static readonly IUserContext Null=new NullUserContext(); 26 | 27 | /// 28 | /// 初始化一个类型的实例 29 | /// 30 | /// 用户ID 31 | /// 用户名 32 | public UserContext(string userId,string userName) 33 | { 34 | UserId = userId; 35 | UserName = userName; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/JCE.Events/Cap/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using DotNetCore.CAP; 5 | using JCE.Events.Default; 6 | using JCE.Events.Handlers; 7 | using JCE.Events.Messages; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace JCE.Events.Cap 11 | { 12 | /// 13 | /// 事件总线 扩展 14 | /// 15 | public static partial class ServiceCollectionExtensions 16 | { 17 | /// 18 | /// 注册事件总线服务 19 | /// 20 | /// 服务集合 21 | /// 配置操作 22 | public static void AddEventBus(this IServiceCollection services, Action action) 23 | { 24 | services.AddCap(action); 25 | services.AddSingleton(); 26 | services.AddSingleton(); 27 | services.AddSingleton(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/JCE/Reflections/ITypeFinder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | 6 | namespace JCE.Reflections 7 | { 8 | /// 9 | /// 类型查找器 10 | /// 11 | public interface ITypeFinder 12 | { 13 | /// 14 | /// 获取程序集列表 15 | /// 16 | /// 17 | List GetAssemblies(); 18 | 19 | /// 20 | /// 查找类型列表 21 | /// 22 | /// 查找类型 23 | /// 在指定的程序集列表中查找 24 | /// 25 | List Find(List assemblies = null); 26 | 27 | /// 28 | /// 查找类型列表 29 | /// 30 | /// 查找类型 31 | /// 在指定的程序集列表中查找 32 | /// 33 | List Find(Type findType, List assemblies = null); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/JCE.Logs.Exceptionless/LogContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Contexts; 5 | using JCE.Logs.Internal; 6 | using JCE.Utils.Helpers; 7 | 8 | namespace JCE.Logs.Exceptionless 9 | { 10 | /// 11 | /// Exceptionless日志上下文 12 | /// 13 | public class LogContext : JCE.Logs.Core.LogContext 14 | { 15 | /// 16 | /// 初始化一个类型的实例 17 | /// 18 | /// 上下文 19 | public LogContext(IContext context) : base(context) 20 | { 21 | } 22 | 23 | /// 24 | /// 创建日志上下文信息 25 | /// 26 | /// 27 | protected override LogContextInfo CreateInfo() 28 | { 29 | return new LogContextInfo() 30 | { 31 | TraceId = Guid.NewGuid().ToString(), 32 | Stopwatch = GetStopwatch(), 33 | Url = Web.Url 34 | }; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/JCE.Logs.Log4Net/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.IO; 3 | using System.Xml; 4 | using JCE.Logs.Abstractions; 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | namespace JCE.Logs.Log4Net 8 | { 9 | /// 10 | /// 日志服务 扩展 11 | /// 12 | public static partial class ServiceCollectionExtensions 13 | { 14 | /// 15 | /// 注册Log4Net日志操作 16 | /// 17 | /// 服务集合 18 | /// log4net配置文件 19 | public static void AddLog4Net(this IServiceCollection services, string log4NetConfigFile="log4net.config") 20 | { 21 | services.AddScoped(); 22 | services.AddScoped(); 23 | services.AddScoped(); 24 | services.AddScoped(); 25 | 26 | Log4NetProvider.InitRepository(log4NetConfigFile); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /test/JCE.Utils.Test/Helpers/IdTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Extensions; 5 | using JCE.Utils.Helpers; 6 | using JCE.Utils.IdGenerators; 7 | using Xunit; 8 | using Xunit.Abstractions; 9 | 10 | namespace JCE.Utils.Test.Helpers 11 | { 12 | public class IdTest:TestBase 13 | { 14 | public IdTest(ITestOutputHelper output) : base(output) 15 | { 16 | } 17 | 18 | [Fact] 19 | public void TestGenerateId() 20 | { 21 | for (int i = 0; i < 100; i++) 22 | { 23 | var id = Id.ObjectId(); 24 | Output.WriteLine(id); 25 | Output.WriteLine(new Guid(id).ToString()); 26 | } 27 | } 28 | 29 | [Fact] 30 | public void TestGuid() 31 | { 32 | for (int i = 0; i < 100; i++) 33 | { 34 | Output.WriteLine(SequentialGuidGenerator.Instance.Create(SequentialGuidType.SequentialAsBinary).ToString()); 35 | } 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/JCE/Logs/Internal/LogContextInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | 6 | namespace JCE.Logs.Internal 7 | { 8 | /// 9 | /// 日志上下文信息 10 | /// 11 | public class LogContextInfo 12 | { 13 | #region 属性 14 | /// 15 | /// 跟踪号 16 | /// 17 | public string TraceId { get; set; } 18 | 19 | /// 20 | /// 计时器 21 | /// 22 | public Stopwatch Stopwatch { get; set; } 23 | 24 | /// 25 | /// IP 26 | /// 27 | public string Ip { get; set; } 28 | 29 | /// 30 | /// 主机 31 | /// 32 | public string Host { get; set; } 33 | 34 | /// 35 | /// 浏览器 36 | /// 37 | public string Browser { get; set; } 38 | 39 | /// 40 | /// 请求地址 41 | /// 42 | public string Url { get; set; } 43 | #endregion 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/JCE.Utils.Encrypts.Test/Symmetric/DESCryptorTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Encrypts.Symmetric; 5 | using Xunit; 6 | using Xunit.Abstractions; 7 | 8 | namespace JCE.Utils.Encrypts.Test.Symmetric 9 | { 10 | public class DESCryptorTest:TestBase 11 | { 12 | /// 13 | /// 秘钥 14 | /// 15 | private const string Key = "waP1AF5u"; 16 | 17 | public DESCryptorTest(ITestOutputHelper output) : base(output) 18 | { 19 | } 20 | 21 | [Fact] 22 | public void Test_Encrypt() 23 | { 24 | var result = DESCryptor.Encrypt("测试一下内容先", Key); 25 | Output.WriteLine(result); 26 | Assert.Equal("W4Xfcp0fM+aKGhBwYvfcPTUkRL0JQVsH", result); 27 | } 28 | 29 | [Fact] 30 | public void Test_Decrypt() 31 | { 32 | var result = DESCryptor.Decrypt("W4Xfcp0fM+aKGhBwYvfcPTUkRL0JQVsH", Key).Trim(); 33 | Output.WriteLine(result); 34 | Assert.Equal("测试一下内容先", result); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace JCE.Samples.Webs.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/Logs/NullLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace JCE.Datas.EntityFramework.Logs 7 | { 8 | /// 9 | /// 空日志记录器 10 | /// 11 | public class NullLogger:ILogger 12 | { 13 | /// 14 | /// 空日志记录器实例 15 | /// 16 | public static readonly ILogger Instance=new NullLogger(); 17 | 18 | /// 19 | /// 日志记录 20 | /// 21 | public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) 22 | { 23 | } 24 | 25 | /// 26 | /// 是否启用 27 | /// 28 | public bool IsEnabled(LogLevel logLevel) 29 | { 30 | return false; 31 | } 32 | 33 | /// 34 | /// 起始范围 35 | /// 36 | public IDisposable BeginScope(TState state) 37 | { 38 | return null; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/OrderByItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Datas.Queries 6 | { 7 | /// 8 | /// 排序项 9 | /// 10 | public class OrderByItem 11 | { 12 | /// 13 | /// 排序属性 14 | /// 15 | public string Name { get; set; } 16 | 17 | /// 18 | /// 是否降序 19 | /// 20 | public bool Desc { get; set; } 21 | 22 | /// 23 | /// 初始化一个类型的实例 24 | /// 25 | /// 排序属性 26 | /// 是否降序 27 | public OrderByItem(string name, bool desc) 28 | { 29 | Name = name; 30 | Desc = desc; 31 | } 32 | 33 | /// 34 | /// 创建排序字符串 35 | /// 36 | /// 37 | public string Generate() 38 | { 39 | if (Desc) 40 | { 41 | return $"{Name} desc"; 42 | } 43 | return Name; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/JCE.Utils/IO/Paths/DefaultPathGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using JCE.Utils.Randoms; 6 | 7 | namespace JCE.Utils.IO.Paths 8 | { 9 | /// 10 | /// 默认路径生成器 11 | /// 12 | public class DefaultPathGenerator:PathGeneratorBase 13 | { 14 | /// 15 | /// 基础路径 16 | /// 17 | private readonly string _basePath; 18 | 19 | /// 20 | /// 初始化路径生成器 21 | /// 22 | /// 基础路径 23 | /// 随机数生成器 24 | public DefaultPathGenerator(string basePath,IRandomGenerator randomGenerator=null) : base(randomGenerator) 25 | { 26 | _basePath = basePath; 27 | } 28 | 29 | /// 30 | /// 创建完整路径 31 | /// 32 | /// 被处理过的安全有效的文件名 33 | /// 34 | protected override string GeneratePath(string fileName) 35 | { 36 | return Path.Combine(_basePath, fileName); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Criterias/DefaultCriteria.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | using JCE.Domains.Repositories; 6 | 7 | namespace JCE.Datas.Queries.Criterias 8 | { 9 | /// 10 | /// 默认查询条件 11 | /// 12 | /// 实体类型 13 | public class DefaultCriteria:ICriteria where TEntity:class 14 | { 15 | /// 16 | /// 初始化一个类型的实例 17 | /// 18 | /// 查询条件 19 | public DefaultCriteria(Expression> predicate) 20 | { 21 | Predicate = predicate; 22 | } 23 | 24 | /// 25 | /// 查询条件 26 | /// 27 | protected Expression> Predicate { get; set; } 28 | 29 | /// 30 | /// 获取查询条件 31 | /// 32 | /// 33 | public virtual Expression> GetPredicate() 34 | { 35 | return Predicate; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/JCE.Utils.Encrypts.Test/Hash/MD5CryptorTest.cs: -------------------------------------------------------------------------------- 1 | using JCE.Utils.Encrypts.Hash; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using Xunit; 6 | using Xunit.Abstractions; 7 | 8 | namespace JCE.Utils.Encrypts.Test.Hash 9 | { 10 | public class MD5CryptorTest:TestBase 11 | { 12 | public MD5CryptorTest(ITestOutputHelper output) : base(output) 13 | { 14 | } 15 | 16 | [Fact] 17 | public void Test_Encrypt16() 18 | { 19 | var result = MD5Cryptor.Encrypt16("JCE"); 20 | Output.WriteLine(result); 21 | Assert.Equal("94BA44A879194C4B", result); 22 | } 23 | 24 | [Fact] 25 | public void Test_Encrypt32() 26 | { 27 | var result = MD5Cryptor.Encrypt32("JCE"); 28 | Output.WriteLine(result); 29 | Assert.Equal("B89293A694BA44A879194C4BF027AB6B",result); 30 | } 31 | 32 | [Fact] 33 | public void Test_Encrypt64() 34 | { 35 | var result = MD5Cryptor.Encrypt64("JCE"); 36 | Output.WriteLine(result); 37 | Assert.Equal("uJKTppS6RKh5GUxL8Ceraw==",result); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/JCE.Events/Cap/MessageEventBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using DotNetCore.CAP; 5 | using JCE.Events.Messages; 6 | 7 | namespace JCE.Events.Cap 8 | { 9 | /// 10 | /// Cap消息事件总线 11 | /// 12 | public class MessageEventBus:IMessageEventBus 13 | { 14 | /// 15 | /// Cap事件发布器 16 | /// 17 | private readonly ICapPublisher _publisher; 18 | 19 | /// 20 | /// 初始化一个类型的实例 21 | /// 22 | /// Cap事件发布器 23 | public MessageEventBus(ICapPublisher publisher) 24 | { 25 | _publisher = publisher ?? throw new ArgumentNullException(nameof(publisher)); 26 | } 27 | 28 | /// 29 | /// 发布事件 30 | /// 31 | /// 事件类型 32 | /// 事件 33 | public void Publish(TEvent @event) where TEvent : IMessageEvent 34 | { 35 | _publisher.Publish(@event.Target,@event.Data,@event.Callback); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/JCE/Events/Event.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using JCE.Utils.Timing; 4 | 5 | namespace JCE.Events 6 | { 7 | /// 8 | /// 事件 9 | /// 10 | public class Event:IEvent 11 | { 12 | /// 13 | /// 事件标识 14 | /// 15 | public string Id { get; set; } 16 | 17 | /// 18 | /// 事件时间 19 | /// 20 | public DateTime Time { get; } 21 | 22 | /// 23 | /// 初始化一个类型的实例 24 | /// 25 | public Event() 26 | { 27 | Id = Guid.NewGuid().ToString(); 28 | Time=DateTime.Now; 29 | } 30 | 31 | /// 32 | /// 输出日志 33 | /// 34 | /// 35 | public override string ToString() 36 | { 37 | StringBuilder result=new StringBuilder(); 38 | result.AppendLine($"事件标识: {Id}"); 39 | result.AppendLine($"事件时间: {Time.ToMillisecondString()}"); 40 | result.AppendLine($"事件数据: {JCE.Utils.Json.JsonUtil.ToJson(this)}"); 41 | return result.ToString(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/JCE/Validations/DataAnnotationValidation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Text; 5 | 6 | namespace JCE.Validations 7 | { 8 | /// 9 | /// DataAnnotaions 验证操作 10 | /// 11 | public static class DataAnnotationValidation 12 | { 13 | /// 14 | /// 验证 15 | /// 16 | /// 验证目标 17 | /// 18 | public static ValidationResultCollection Validate(object target) 19 | { 20 | if (target == null) 21 | { 22 | throw new ArgumentNullException(nameof(target)); 23 | } 24 | var result = new ValidationResultCollection(); 25 | var validationResults = new List(); 26 | var context = new ValidationContext(target, null, null); 27 | var isValid = Validator.TryValidateObject(target, context, validationResults, true); 28 | if (!isValid) 29 | { 30 | result.AddList(validationResults); 31 | } 32 | return result; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/JCE.Webs/Middlewares/Internals/NullToEmptyStringValueProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | using Newtonsoft.Json.Serialization; 6 | 7 | namespace JCE.Webs.Middlewares.Internals 8 | { 9 | /// 10 | /// Json Null 值替换为空字符串 提供程序 11 | /// 12 | public class NullToEmptyStringValueProvider:IValueProvider 13 | { 14 | /// 15 | /// 属性信息 16 | /// 17 | private PropertyInfo _propertyInfo; 18 | 19 | /// 20 | /// 初始化一个类型的实例 21 | /// 22 | /// 属性信息 23 | public NullToEmptyStringValueProvider(PropertyInfo propertyInfo) 24 | { 25 | _propertyInfo = propertyInfo; 26 | } 27 | 28 | public void SetValue(object target, object value) 29 | { 30 | _propertyInfo.SetValue(target,value); 31 | } 32 | 33 | public object GetValue(object target) 34 | { 35 | object result = _propertyInfo.GetValue(target) ?? ""; 36 | return result; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/JCE.Logs.Exceptionless/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Exceptionless; 5 | using JCE.Logs.Abstractions; 6 | using JCE.Logs.Core; 7 | using Microsoft.Extensions.DependencyInjection; 8 | 9 | namespace JCE.Logs.Exceptionless 10 | { 11 | /// 12 | /// 日志服务 扩展 13 | /// 14 | public static partial class ServiceCollectionExtensions 15 | { 16 | /// 17 | /// 注册Exceptionless日志操作 18 | /// 19 | /// 服务集合 20 | /// 配置操作 21 | public static void AddExceptionless(this IServiceCollection services, 22 | Action configAction) 23 | { 24 | services.AddScoped(); 25 | services.AddSingleton(typeof(ILogFormat), t => NullLogFormat.Instance); 26 | services.AddScoped(); 27 | services.AddScoped(); 28 | configAction?.Invoke(ExceptionlessClient.Default.Configuration); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE.Utils/IO/DefaultFileStore.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Extensions; 5 | using JCE.Utils.IO.Paths; 6 | 7 | namespace JCE.Utils.IO 8 | { 9 | /// 10 | /// 本地文件存储服务 11 | /// 12 | public class DefaultFileStore:IFileStore 13 | { 14 | /// 15 | /// 路径生成器 16 | /// 17 | private readonly IPathGenerator _generator; 18 | 19 | /// 20 | /// 初始化一个类型的实例 21 | /// 22 | /// 路径生成器 23 | public DefaultFileStore(IPathGenerator pathGenerator) 24 | { 25 | _generator = pathGenerator; 26 | } 27 | 28 | /// 29 | /// 保存文件,返回完整文件路径 30 | /// 31 | /// 文件流 32 | /// 文件名,包含扩展名 33 | /// 34 | public string Save(byte[] stream, string fileName) 35 | { 36 | var path = _generator.Generate(fileName); 37 | stream.ToFile(path); 38 | return path; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/JCE/Logs/Core/NullLogContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | using JCE.Logs.Abstractions; 6 | 7 | namespace JCE.Logs.Core 8 | { 9 | /// 10 | /// 空日志上下文 11 | /// 12 | public class NullLogContext:ILogContext 13 | { 14 | /// 15 | /// 跟踪号 16 | /// 17 | public string TraceId => string.Empty; 18 | 19 | /// 20 | /// 计时器 21 | /// 22 | public Stopwatch Stopwatch => new Stopwatch(); 23 | 24 | /// 25 | /// IP 26 | /// 27 | public string Ip => string.Empty; 28 | 29 | /// 30 | /// 主机 31 | /// 32 | public string Host => string.Empty; 33 | 34 | /// 35 | /// 浏览器 36 | /// 37 | public string Browser => string.Empty; 38 | 39 | /// 40 | /// 请求地址 41 | /// 42 | public string Url => string.Empty; 43 | 44 | /// 45 | /// 空日志上下文实例 46 | /// 47 | public static readonly ILogContext Instance=new NullLogContext(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/JCE/GlobalConfigs/Models/LogConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace JCE.GlobalConfigs.Models 7 | { 8 | /// 9 | /// 日志 配置 10 | /// 11 | public class LogConfig 12 | { 13 | /// 14 | /// 日志实现方式:File,Log4net,NLog,Exceptionless,MongoDB 15 | /// 16 | [DisplayName("日志实现方式:File,Log4net,NLog,Exceptionless,MongoDB")] 17 | public string Type { get; set; } 18 | 19 | /// 20 | /// 日志级别:DEBUG|INFO|WARN|ERROR|FATAL|OFF 21 | /// 22 | [DisplayName("日志级别:DEBUG|INFO|WARN|ERROR|FATAL|OFF")] 23 | public string Level { get; set; } 24 | 25 | /// 26 | /// 日志记录的项目名称 27 | /// 28 | [DisplayName("日志记录的项目名称")] 29 | public string ProjectName { get; set; } 30 | 31 | /// 32 | /// 是否启用调试 33 | /// 34 | [DisplayName("是否启用调试")] 35 | public bool EnabledDebug { get; set; } 36 | 37 | /// 38 | /// 是否启用跟踪 39 | /// 40 | [DisplayName("是否启用跟踪")] 41 | public bool EnabledTrace { get; set; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Criterias/OrCriteria.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | using JCE.Domains.Repositories; 6 | using JCE.Utils.Extensions; 7 | 8 | namespace JCE.Datas.Queries.Criterias 9 | { 10 | /// 11 | /// 或查询条件 12 | /// 13 | /// 实体类型 14 | public class OrCriteria:ICriteria where TEntity:class 15 | { 16 | /// 17 | /// 初始化一个类型的实例 18 | /// 19 | /// 查询条件1 20 | /// 查询条件2 21 | public OrCriteria(Expression> left, Expression> right) 22 | { 23 | Predicate = left.Or(right); 24 | } 25 | 26 | /// 27 | /// 查询条件 28 | /// 29 | protected Expression> Predicate { get; set; } 30 | 31 | /// 32 | /// 获取查询条件 33 | /// 34 | /// 35 | public virtual Expression> GetPredicate() 36 | { 37 | return Predicate; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Criterias/AndCriteria.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | using JCE.Domains.Repositories; 6 | using JCE.Utils.Extensions; 7 | 8 | namespace JCE.Datas.Queries.Criterias 9 | { 10 | /// 11 | /// 与查询条件 12 | /// 13 | /// 实体类型 14 | public class AndCriteria:ICriteria where TEntity:class 15 | { 16 | /// 17 | /// 初始化一个类型的实例 18 | /// 19 | /// 查询条件1 20 | /// 查询条件2 21 | public AndCriteria(Expression> left, Expression> right) 22 | { 23 | Predicate = left.And(right); 24 | } 25 | 26 | /// 27 | /// 查询条件 28 | /// 29 | protected Expression> Predicate { get; set; } 30 | 31 | /// 32 | /// 获取查询条件 33 | /// 34 | /// 35 | public virtual Expression> GetPredicate() 36 | { 37 | return Predicate; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/JCE.Utils/Json/JsonExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace JCE.Utils.Json 2 | { 3 | /// 4 | /// Json辅助扩展操作 5 | /// 6 | public static class JsonExtensions 7 | { 8 | #region ToObject(将Json字符串转换为对象) 9 | /// 10 | /// 将Json字符串转换为对象 11 | /// 12 | /// 实体类型 13 | /// Json字符串 14 | /// 15 | public static T ToObject(this string json) 16 | { 17 | return JsonUtil.ToObject(json); 18 | } 19 | #endregion 20 | 21 | #region ToJson(将对象转换为Json字符串) 22 | 23 | /// 24 | /// 将对象转换为Json字符串 25 | /// 26 | /// 目标对象 27 | /// 是否将双引号转换成单引号 28 | /// 是否驼峰式命名 29 | /// 是否缩进 30 | /// 31 | public static string ToJson(this object target, bool isConvertToSingleQuotes = false, bool camelCase = false, bool indented = false) 32 | { 33 | return JsonUtil.ToJson(target, isConvertToSingleQuotes, camelCase, indented); 34 | } 35 | #endregion 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/Controllers/WebPathController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using JCE.GlobalConfigs; 6 | using JCE.GlobalConfigs.Models; 7 | using JCE.Utils.Helpers; 8 | using Microsoft.AspNetCore.Mvc; 9 | using JCE.Utils.Configs; 10 | 11 | // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 12 | 13 | namespace JCE.Samples.Webs.Controllers 14 | { 15 | [Route("api/[controller]")] 16 | public class WebPathController : Controller 17 | { 18 | [HttpGet("[action]")] 19 | public string GetWebRootPath() 20 | { 21 | return Web.HostingEnvironment.WebRootPath; 22 | } 23 | 24 | [HttpGet("[action]")] 25 | public string GetContentRootPath() 26 | { 27 | return Web.HostingEnvironment.ContentRootPath; 28 | } 29 | 30 | [HttpGet("[action]")] 31 | public string GetConsoleLogLevel() 32 | { 33 | return ConfigUtil.GetJsonConfig().GetSection("Logging:Console:LogLevel:Default").Value; 34 | } 35 | 36 | [HttpGet("[action]")] 37 | public JCEConfig GetGloalConfig() 38 | { 39 | return ConfigManager.Config; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/JCE/Dependency/AopExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using AspectCore.DynamicProxy; 5 | using AspectCore.DynamicProxy.Parameters; 6 | using AspectCore.Extensions.AspectScope; 7 | using AspectCore.Extensions.Autofac; 8 | using Autofac; 9 | 10 | namespace JCE.Dependency 11 | { 12 | /// 13 | /// AspectCore扩展 14 | /// 15 | public static class AopExtensions 16 | { 17 | /// 18 | /// 启用Aop 19 | /// 20 | /// 容器生成器 21 | public static void EnableAop(this ContainerBuilder builder) 22 | { 23 | builder.RegisterDynamicProxy(config => config.EnableParameterAspect()); 24 | builder.EnableAspectScoped(); 25 | } 26 | 27 | /// 28 | /// 启用Aop作用域 29 | /// 30 | /// 容器生成器 31 | public static void EnableAspectScoped(this ContainerBuilder builder) 32 | { 33 | builder.AddSingleton(); 34 | builder.AddSingleton(); 35 | builder.AddScoped(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/QueryableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using JCE.Domains.Repositories; 7 | using Microsoft.EntityFrameworkCore; 8 | 9 | namespace JCE.Datas.EntityFramework 10 | { 11 | /// 12 | /// 扩展 13 | /// 14 | public static class QueryableExtensions 15 | { 16 | /// 17 | /// 转换为分页列表 18 | /// 19 | /// 实体类型 20 | /// 数据源 21 | /// 分页对象 22 | /// 23 | public static async Task> ToPagerListAsync(this IQueryable source, 24 | IPager pager) 25 | { 26 | if (source == null) 27 | { 28 | throw new ArgumentNullException(nameof(source)); 29 | } 30 | if (pager == null) 31 | { 32 | throw new ArgumentNullException(nameof(pager)); 33 | } 34 | var result=new PagerList(pager); 35 | result.AddRange(await source.ToListAsync()); 36 | return result; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/JCE.Utils/Helpers/Str.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.Helpers 6 | { 7 | /// 8 | /// 字符串操作 - 工具 9 | /// 10 | public partial class Str 11 | { 12 | #region Join(将集合连接为带分隔符的字符串) 13 | /// 14 | /// 将集合连接为带分隔符的字符串 15 | /// 16 | /// 集合元素类型 17 | /// 集合 18 | /// 引号,默认不带引号,范例:单引号"'" 19 | /// 分隔符,默认使用逗号分隔 20 | /// 21 | public static string Join(IEnumerable list, string quotes = "", string separator = ",") 22 | { 23 | if (list == null) 24 | { 25 | return string.Empty; 26 | } 27 | var result = new StringBuilder(); 28 | foreach (var each in list) 29 | { 30 | result.AppendFormat("{0}{1}{0}{2}", quotes, each, separator); 31 | } 32 | if (separator == "") 33 | { 34 | return result.ToString(); 35 | } 36 | return result.ToString().TrimEnd(separator.ToCharArray()); 37 | } 38 | 39 | #endregion 40 | 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/OrderByBuilder.cs: -------------------------------------------------------------------------------- 1 | using JCE.Utils.Extensions; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace JCE.Datas.Queries 6 | { 7 | /// 8 | /// 排序生成器 9 | /// 10 | public class OrderByBuilder 11 | { 12 | /// 13 | /// 排序项列表 14 | /// 15 | private readonly List _items; 16 | 17 | /// 18 | /// 初始化一个类型的实例 19 | /// 20 | public OrderByBuilder() 21 | { 22 | _items=new List(); 23 | } 24 | 25 | /// 26 | /// 添加排序 27 | /// 28 | /// 排序属相 29 | /// 是否降序 30 | public void Add(string name, bool desc = false) 31 | { 32 | if (string.IsNullOrWhiteSpace(name)) 33 | { 34 | return; 35 | } 36 | _items.Add(new OrderByItem(name,desc)); 37 | } 38 | 39 | /// 40 | /// 生成排序字符串 41 | /// 42 | /// 43 | public string Generate() 44 | { 45 | return _items.Select(t => t.Generate()).ToList().Join(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/JCE/Dependency/Scope.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using System; 3 | 4 | namespace JCE.Dependency 5 | { 6 | /// 7 | /// 作用域 8 | /// 9 | internal class Scope:IScope 10 | { 11 | /// 12 | /// autofac作用域 13 | /// 14 | private readonly ILifetimeScope _scope; 15 | 16 | /// 17 | /// 初始化一个类型的实例 18 | /// 19 | /// autofac作用域 20 | public Scope(ILifetimeScope scope) 21 | { 22 | _scope = scope; 23 | } 24 | 25 | /// 26 | /// 释放对象 27 | /// 28 | public void Dispose() 29 | { 30 | _scope.Dispose(); 31 | } 32 | 33 | /// 34 | /// 创建实例 35 | /// 36 | /// 实例类型 37 | /// 38 | public T Create() 39 | { 40 | return _scope.Resolve(); 41 | } 42 | 43 | /// 44 | /// 创建对象 45 | /// 46 | /// 对象类型 47 | /// 48 | public object Create(Type type) 49 | { 50 | return _scope.Resolve(type); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/AggregateRoot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities 6 | { 7 | /// 8 | /// 聚合根 9 | /// 10 | /// 实体类型 11 | /// 标识类型 12 | public abstract class AggregateRoot:EntityBase,IAggregateRootwhere TEntity:IAggregateRoot 13 | { 14 | /// 15 | /// 初始化一个类型的实例 16 | /// 17 | /// 标识 18 | protected AggregateRoot(TKey id) : base(id) 19 | { 20 | } 21 | 22 | /// 23 | /// 版本号(乐观锁) 24 | /// 25 | public byte[] Version { get; set; } 26 | } 27 | 28 | /// 29 | /// 聚合根 30 | /// 31 | /// 实体类型 32 | public abstract class AggregateRoot : AggregateRoot where TEntity : IAggregateRoot 33 | { 34 | /// 35 | /// 初始化一个类型的实例 36 | /// 37 | /// 标识 38 | protected AggregateRoot(Guid id) : base(id) 39 | { 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/JCE.Utils/Helpers/Id.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Utils.Helpers 6 | { 7 | /// 8 | /// Id生成器 9 | /// 10 | public static class Id 11 | { 12 | /// 13 | /// Id 14 | /// 15 | private static string _id; 16 | 17 | /// 18 | /// 设置Id 19 | /// 20 | /// Id 21 | public static void SetId(string id) 22 | { 23 | _id = id; 24 | } 25 | 26 | /// 27 | /// 重置Id 28 | /// 29 | public static void Reset() 30 | { 31 | _id = null; 32 | } 33 | 34 | /// 35 | /// 创建Id 36 | /// 37 | /// 38 | public static string ObjectId() 39 | { 40 | return string.IsNullOrWhiteSpace(_id) ? JCE.Utils.Helpers.Internal.ObjectId.GenerateNewStringId() : _id; 41 | } 42 | 43 | /// 44 | /// 用Guid创建Id,去掉分隔符 45 | /// 46 | /// 47 | public static string Guid() 48 | { 49 | return string.IsNullOrWhiteSpace(_id) ? System.Guid.NewGuid().ToString("N") : _id; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/JCE.Applications/Aspects/UnitOfWorkAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using AspectCore.DynamicProxy; 6 | using AspectCore.Extensions.AspectScope; 7 | using JCE.Aspects.Base; 8 | using JCE.Datas.UnitOfWorks; 9 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace JCE.Applications.Aspects 12 | { 13 | /// 14 | /// 工作单元拦截器 15 | /// 16 | public class UnitOfWorkAttribute:InterceptorBase,IScopeInterceptor 17 | { 18 | /// 19 | /// 作用域,当嵌套使用工作单元拦截器时,设置为Scope.Aspect,只有最外层工作单元拦截器生效 20 | /// 21 | public Scope Scope { get; set; } 22 | 23 | /// 24 | /// 执行 25 | /// 26 | /// 27 | public override async Task Invoke(AspectContext context, AspectDelegate next) 28 | { 29 | await next(context); 30 | var manager = context.ServiceProvider.GetService(); 31 | if (manager == null) 32 | { 33 | return; 34 | } 35 | await manager.CommitAsync(); 36 | if (context.Implementation is ICommitAfter service) 37 | { 38 | service.CommitAfter(); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/JCE.Tools.QrCode/IQrCodeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Tools.QrCode 6 | { 7 | /// 8 | /// 二维码 服务 9 | /// 10 | public interface IQrCodeService 11 | { 12 | /// 13 | /// 设置二维码尺寸 14 | /// 15 | /// 二维码尺寸 16 | /// 17 | IQrCodeService Size(QrSize size); 18 | 19 | /// 20 | /// 设置二维码尺寸 21 | /// 22 | /// 二维码尺寸 23 | /// 24 | IQrCodeService Size(int size); 25 | 26 | /// 27 | /// 容错处理 28 | /// 29 | /// 容错级别 30 | /// 31 | IQrCodeService Correction(ErrorCorrectionLevel level); 32 | 33 | /// 34 | /// 设置二维码Logo 35 | /// 36 | /// Logo文件路径 37 | /// 38 | IQrCodeService Logo(string filePath); 39 | 40 | /// 41 | /// 生成二维码并保存到指定位置,返回二维码图片完整路径 42 | /// 43 | /// 内容 44 | /// 45 | string Save(string content); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/ChangeValueCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection.PortableExecutable; 4 | using System.Text; 5 | 6 | namespace JCE.Domains.Entities 7 | { 8 | /// 9 | /// 变更值集合 10 | /// 11 | public class ChangeValueCollection:List 12 | { 13 | /// 14 | /// 添加 15 | /// 16 | /// 属性名 17 | /// 描述 18 | /// 旧值 19 | /// 新值 20 | public void Add(string propertyName, string description, string oldValue, string newValue) 21 | { 22 | if (string.IsNullOrWhiteSpace(propertyName)) 23 | { 24 | return; 25 | } 26 | Add(new ChangeValue(propertyName,description,oldValue,newValue)); 27 | } 28 | 29 | /// 30 | /// 输出变更信息 31 | /// 32 | /// 33 | public override string ToString() 34 | { 35 | var result=new StringBuilder(); 36 | foreach (var item in this) 37 | { 38 | result.AppendLine(item.ToString()); 39 | } 40 | return result.ToString(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Datas.EntityFramework.Configs; 5 | using JCE.Datas.EntityFramework.Core; 6 | using JCE.Datas.UnitOfWorks; 7 | using Microsoft.EntityFrameworkCore; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace JCE.Datas.EntityFramework 11 | { 12 | /// 13 | /// 数据服务 扩展 14 | /// 15 | public static partial class ServiceCollectionExtensions 16 | { 17 | /// 18 | /// 注册工作单元服务 19 | /// 20 | /// 工作单元接口类型 21 | /// 工作单元实现类型 22 | /// 服务集合 23 | /// 配置操作 24 | /// 25 | public static IServiceCollection AddUnitOfWork(this IServiceCollection services, 26 | Action configAction) 27 | where TService : class, IUnitOfWork 28 | where TImplementation : UnitOfWorkBase, TService 29 | { 30 | services.AddDbContext(configAction); 31 | services.AddScoped(); 32 | return services; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/JCE.Tests/Datas/UnitOfWorks/UnitOfWorkManagerTest.cs: -------------------------------------------------------------------------------- 1 | using JCE.Datas.UnitOfWorks; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using JCE.Tests.XUnitHelpers; 6 | using NSubstitute; 7 | using Xunit; 8 | 9 | namespace JCE.Tests.Datas.UnitOfWorks 10 | { 11 | /// 12 | /// 工作单元管理器测试 13 | /// 14 | public class UnitOfWorkManagerTest 15 | { 16 | /// 17 | /// 工作单元 18 | /// 19 | private readonly IUnitOfWork _unitOfWork; 20 | 21 | /// 22 | /// 工作单元2 23 | /// 24 | private readonly IUnitOfWork _unitOfWork2; 25 | 26 | /// 27 | /// 工作单元管理器 28 | /// 29 | private readonly UnitOfWorkManager _manager; 30 | 31 | /// 32 | /// 测试初始化 33 | /// 34 | public UnitOfWorkManagerTest() 35 | { 36 | _unitOfWork = Substitute.For(); 37 | _unitOfWork2 = Substitute.For(); 38 | _manager=new UnitOfWorkManager(); 39 | } 40 | 41 | /// 42 | /// 注册一个空工作单元 43 | /// 44 | [Fact] 45 | public void TestRegister_Null() 46 | { 47 | AssertHelper.Throws(() => _manager.Register(null)); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/JCE.Utils.Test/Helpers/WebTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Helpers; 5 | using JCE.Utils.Webs.Clients; 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | 9 | namespace JCE.Utils.Test.Helpers 10 | { 11 | 12 | public class WebTest:TestBase 13 | { 14 | public WebTest(ITestOutputHelper output) : base(output) 15 | { 16 | } 17 | 18 | [Fact] 19 | public void UploadTest() 20 | { 21 | var result = Web.Client() 22 | .Post("http://localhost:28774/api/Common/UploadImg") 23 | .ContentType(HttpContentType.FormData) 24 | .Header("Authorization", 25 | "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyaWQiOiI0OTM4ZGMwMy1kZTYzLTQ2MTYtYjc3Yy01MmE3Zjk4Y2M1ZjIiLCJ1c2VybmFtZSI6Inp5bCIsInNjb3BlIjoiYWRtaW4iLCJsb2dpbiI6IntcIk1lcmNoYW50SWRcIjpcIjg4ODg4ODg4LTg4ODgtODg4OC04ODg4LTg4ODg4ODg4ODg4OFwiLFwiTG9naW5cIjpcInp5bFwiLFwiTmFtZVwiOlwi57O757uf566h55CG5ZGYXCIsXCJSb2xlVHlwZVwiOjEsXCJVc2VySWRcIjpcIjQ5MzhkYzAzLWRlNjMtNDYxNi1iNzdjLTUyYTdmOThjYzVmMlwifSIsImlzcyI6Imx4enlsIiwiYXVkIjoiQW55IiwiZXhwIjoxNTA5MDUwNzIxLCJuYmYiOjE1MDkwMjkxMjF9.RNIwQz66rgDOusuk9-q2v-UnN3p8F5dYupAKzobBQC8") 26 | .FileData("file", @"C:\Users\jianx\Pictures\逗逼卡.jpg") 27 | .Result(); 28 | Output.WriteLine(result); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/JCE.Utils/Operator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace JCE.Utils 7 | { 8 | /// 9 | /// 查询操作符 10 | /// 11 | public enum Operator 12 | { 13 | /// 14 | /// 等于 15 | /// 16 | [Description("等于")] 17 | Equal, 18 | /// 19 | /// 不等于 20 | /// 21 | [Description("不等于")] 22 | NotEqual, 23 | /// 24 | /// 大于 25 | /// 26 | [Description("大于")] 27 | Greater, 28 | /// 29 | /// 大于等于 30 | /// 31 | [Description("大于等于")] 32 | GreaterEqual, 33 | /// 34 | /// 小于 35 | /// 36 | [Description("小于")] 37 | Less, 38 | /// 39 | /// 小于等于 40 | /// 41 | [Description("小于等于")] 42 | LessEqual, 43 | /// 44 | /// 头匹配 45 | /// 46 | [Description("头匹配")] 47 | Starts, 48 | /// 49 | /// 尾匹配 50 | /// 51 | [Description("尾匹配")] 52 | Ends, 53 | /// 54 | /// 模糊匹配 55 | /// 56 | [Description("模糊匹配")] 57 | Contains 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Criterias/IntSegmentCriteria.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | 6 | namespace JCE.Datas.Queries.Criterias 7 | { 8 | /// 9 | /// 整数范围过滤条件 10 | /// 11 | /// 实体类型 12 | /// 属性类型 13 | public class IntSegmentCriteria:SegmentCriteriaBase where TEntity : class 14 | { 15 | /// 16 | /// 初始化一个类型的实例 17 | /// 18 | /// 属性表达式 19 | /// 最小值 20 | /// 最大值 21 | /// 包含边界 22 | public IntSegmentCriteria(Expression> propertyExpression, int? min, int? max, 23 | Boundary boundary = Boundary.Both) : base(propertyExpression, min, max, boundary) 24 | { 25 | } 26 | 27 | /// 28 | /// 最小值是否大于最大值 29 | /// 30 | /// 最小值 31 | /// 最大值 32 | /// 33 | protected override bool IsMinGreaterMax(int? min, int? max) 34 | { 35 | return min > max; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Criterias/DoubleSegmentCriteria.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | 6 | namespace JCE.Datas.Queries.Criterias 7 | { 8 | /// 9 | /// double范围过滤条件 10 | /// 11 | /// 实体类型 12 | /// 属性类型 13 | public class DoubleSegmentCriteria:SegmentCriteriaBase where TEntity:class 14 | { 15 | /// 16 | /// 初始化一个类型的实例 17 | /// 18 | /// 属性表达式 19 | /// 最小值 20 | /// 最大值 21 | /// 包含边界 22 | public DoubleSegmentCriteria(Expression> propertyExpression, double? min, double? max, 23 | Boundary boundary = Boundary.Both) : base(propertyExpression, min, max, boundary) 24 | { 25 | } 26 | 27 | /// 28 | /// 最小值是否大于最大值 29 | /// 30 | /// 最小值 31 | /// 最大值 32 | /// 33 | protected override bool IsMinGreaterMax(double? min, double? max) 34 | { 35 | return min > max; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Criterias/DecimalSegmentCriteria.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | 6 | namespace JCE.Datas.Queries.Criterias 7 | { 8 | /// 9 | /// decimal范围过滤条件 10 | /// 11 | /// 实体类型 12 | /// 属性类型 13 | public class DecimalSegmentCriteria:SegmentCriteriaBase where TEntity:class 14 | { 15 | /// 16 | /// 初始化一个类型的实例 17 | /// 18 | /// 属性表达式 19 | /// 最小值 20 | /// 最大值 21 | /// 包含边界 22 | public DecimalSegmentCriteria(Expression> propertyExpression, decimal? min, 23 | decimal? max, Boundary boundary = Boundary.Both) : base(propertyExpression, min, max, boundary) 24 | { 25 | } 26 | 27 | /// 28 | /// 最小值是否大于最大值 29 | /// 30 | /// 最小值 31 | /// 最大值 32 | /// 33 | protected override bool IsMinGreaterMax(decimal? min, decimal? max) 34 | { 35 | return min > max; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/JCE.Tests/XUnitHelpers/AssertHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using AspectCore.DynamicProxy; 5 | using Xunit; 6 | 7 | namespace JCE.Tests.XUnitHelpers 8 | { 9 | /// 10 | /// 断言操作 11 | /// 12 | public class AssertHelper 13 | { 14 | /// 15 | /// 抛出异常,并从异常消息中搜索特定关键字 16 | /// 17 | /// 异常类型 18 | /// 操作 19 | /// 关键字 20 | public static TException Throws(Action action, string keyword = "") where TException : Exception 21 | { 22 | var exception = GetException(action); 23 | if (!string.IsNullOrWhiteSpace(keyword)) 24 | Assert.Contains(keyword, exception.Message); 25 | return exception; 26 | } 27 | 28 | /// 29 | /// 获取异常 30 | /// 31 | private static TException GetException(Action action) where TException : Exception 32 | { 33 | try 34 | { 35 | var exception = Assert.Throws(action); 36 | return (TException)exception.InnerException; 37 | } 38 | catch 39 | { 40 | return Assert.Throws(action); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Criterias/DateTimeSegmentCriteria.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | 6 | namespace JCE.Datas.Queries.Criterias 7 | { 8 | /// 9 | /// 日期范围过滤条件 - 包含时间 10 | /// 11 | /// 实体类型 12 | /// 属性类型 13 | public class DateTimeSegmentCriteria:SegmentCriteriaBasewhere TEntity:class 14 | { 15 | /// 16 | /// 初始化一个类型的实例 17 | /// 18 | /// 属性表达式 19 | /// 最小值 20 | /// 最大值 21 | /// 包含边界 22 | public DateTimeSegmentCriteria(Expression> propertyExpression, DateTime? min, 23 | DateTime? max, Boundary boundary = Boundary.Both) : base(propertyExpression, min, max, boundary) 24 | { 25 | } 26 | 27 | /// 28 | /// 最小值是否大于最大值 29 | /// 30 | /// 最小值 31 | /// 最大值 32 | /// 33 | protected override bool IsMinGreaterMax(DateTime? min, DateTime? max) 34 | { 35 | return min > max; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/JCE/Events/Messages/MessageEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Timing; 5 | 6 | namespace JCE.Events.Messages 7 | { 8 | /// 9 | /// 消息事件 10 | /// 11 | public class MessageEvent:Event,IMessageEvent 12 | { 13 | /// 14 | /// 事件数据 15 | /// 16 | public object Data { get; set; } 17 | 18 | /// 19 | /// 发送目标 20 | /// 21 | public string Target { get; set; } 22 | 23 | /// 24 | /// 回调 25 | /// 26 | public string Callback { get; set; } 27 | 28 | /// 29 | /// 输出日志 30 | /// 31 | /// 32 | public override string ToString() 33 | { 34 | StringBuilder result=new StringBuilder(); 35 | result.AppendLine($"事件标识: {Id}"); 36 | result.AppendLine($"事件时间: {Time.ToMillisecondString()}"); 37 | if (string.IsNullOrWhiteSpace(Target) == false) 38 | { 39 | result.AppendLine($"发送目标: {Target}"); 40 | } 41 | if (string.IsNullOrWhiteSpace(Callback) == false) 42 | { 43 | result.AppendLine($"回调: {Callback}"); 44 | } 45 | result.Append($"事件数据: {JCE.Utils.Json.JsonUtil.ToJson(Data)}"); 46 | return result.ToString(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/JCE/Datas/Queries/Internal/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | using JCE.Properties; 6 | using JCE.Utils.Extensions; 7 | using JCE.Utils.Helpers; 8 | 9 | namespace JCE.Datas.Queries.Internal 10 | { 11 | /// 12 | /// 查询工具类 13 | /// 14 | internal static class Helper 15 | { 16 | /// 17 | /// 获取查询条件表达式 18 | /// 19 | /// 实体类型 20 | /// 查询条件,如果参数值为空,则忽略该查询条件,范例:t => t.Name == "",该查询条件被忽略。 21 | /// 注意:一次仅能添加一个条件,范例:t => t.Name == "a" && t.Mobile == "123",不支持,将抛出异常 22 | /// 23 | public static Expression> GetWhereIfNotEmptyExpression( 24 | Expression> predicate) where TEntity : class 25 | { 26 | if (predicate == null) 27 | { 28 | return null; 29 | } 30 | if (Lambda.GetConditionCount(predicate) > 1) 31 | { 32 | throw new InvalidOperationException(string.Format(LibraryResource.OnlyOnePredicate, predicate)); 33 | } 34 | var value = predicate.Value(); 35 | if (string.IsNullOrWhiteSpace(value.SafeString())) 36 | { 37 | return null; 38 | } 39 | return predicate; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/JCE.Security/UserContextExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Contexts; 5 | 6 | namespace JCE.Security 7 | { 8 | /// 9 | /// 用户上下文 扩展 10 | /// 11 | public static partial class UserContextExtensions 12 | { 13 | /// 14 | /// 获取当前应用程序 15 | /// 16 | /// 用户上下文 17 | /// 18 | public static string GetApplication(this IUserContext context) 19 | { 20 | return ""; 21 | } 22 | 23 | /// 24 | /// 获取当前租户 25 | /// 26 | /// 用户上下文 27 | /// 28 | public static string GetTenant(this IUserContext context) 29 | { 30 | return ""; 31 | } 32 | 33 | /// 34 | /// 获取当前操作姓名 35 | /// 36 | /// 用户上下文 37 | /// 38 | public static string GetFullName(this IUserContext context) 39 | { 40 | return ""; 41 | } 42 | 43 | /// 44 | /// 获取当前操作人角色名 45 | /// 46 | /// 用户上下文 47 | /// 48 | public static string GetRoleName(this IUserContext context) 49 | { 50 | return ""; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/JCE.Logs/Extensions/AspectExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using AspectCore.DynamicProxy.Parameters; 6 | using JCE.Utils.Extensions; 7 | using JCE.Utils.Helpers; 8 | 9 | namespace JCE.Logs.Extensions 10 | { 11 | /// 12 | /// Aop扩展 13 | /// 14 | public static partial class AspectExtensions 15 | { 16 | /// 17 | /// 添加日志参数 18 | /// 19 | /// 参数 20 | /// 日志 21 | public static void AppendTo(this Parameter parameter, ILog log) 22 | { 23 | log.Params(parameter.ParameterInfo.ParameterType.FullName, parameter.Name, GetParameterValue(parameter)); 24 | } 25 | 26 | /// 27 | /// 获取参数值 28 | /// 29 | /// 参数 30 | /// 31 | private static string GetParameterValue(Parameter parameter) 32 | { 33 | if (Reflection.IsGenericCollection(parameter.RawType) == false) 34 | { 35 | return parameter.Value.SafeString(); 36 | } 37 | if (!(parameter.Value is IEnumerable)) 38 | { 39 | return parameter.Value.SafeString(); 40 | } 41 | return ((IEnumerable)parameter).Select(t => t.SafeString()).Join(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.MySql/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Datas.EntityFramework.Configs; 5 | using JCE.Datas.EntityFramework.Core; 6 | using JCE.Datas.UnitOfWorks; 7 | using Microsoft.EntityFrameworkCore; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace JCE.Datas.EntityFramework.MySql 11 | { 12 | /// 13 | /// 数据服务 扩展 14 | /// 15 | public static partial class ServiceCollectionExtensions 16 | { 17 | /// 18 | /// 注册MySql工作单元服务 19 | /// 20 | /// 工作单元接口类型 21 | /// 工作单元实现类型 22 | /// 服务集合 23 | /// 连接字符串 24 | /// EF日志级别 25 | /// 26 | public static IServiceCollection AddSqlServerUnitOfWork( 27 | this IServiceCollection services, 28 | string connection, EfLogLevel level = EfLogLevel.Sql) 29 | where TService : class, IUnitOfWork 30 | where TImplementation : UnitOfWorkBase, TService 31 | { 32 | EfConfig.LogLevel = level; 33 | return services.AddUnitOfWork(builder => 34 | { 35 | builder.UseMySql(connection); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework.SqlServer/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Datas.EntityFramework.Configs; 5 | using JCE.Datas.EntityFramework.Core; 6 | using JCE.Datas.UnitOfWorks; 7 | using Microsoft.EntityFrameworkCore; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace JCE.Datas.EntityFramework.SqlServer 11 | { 12 | /// 13 | /// 数据服务 扩展 14 | /// 15 | public static partial class ServiceCollectionExtensions 16 | { 17 | /// 18 | /// 注册SqlServer工作单元服务 19 | /// 20 | /// 工作单元接口类型 21 | /// 工作单元实现类型 22 | /// 服务集合 23 | /// 连接字符串 24 | /// EF日志级别 25 | /// 26 | public static IServiceCollection AddSqlServerUnitOfWork( 27 | this IServiceCollection services, 28 | string connection, EfLogLevel level = EfLogLevel.Sql) 29 | where TService : class, IUnitOfWork 30 | where TImplementation : UnitOfWorkBase, TService 31 | { 32 | EfConfig.LogLevel = level; 33 | return services.AddUnitOfWork(builder => 34 | { 35 | builder.UseSqlServer(connection); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/JCE.Utils/Helpers/Sys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using JCE.Utils.Extensions; 6 | 7 | namespace JCE.Utils.Helpers 8 | { 9 | /// 10 | /// 系统操作 11 | /// 12 | public static class Sys 13 | { 14 | #region GetPhysicalPath(获取物理路径) 15 | /// 16 | /// 获取物理路径 17 | /// 18 | /// 相对路径 19 | /// 20 | public static string GetPhysicalPath(string relativePath) 21 | { 22 | if (string.IsNullOrWhiteSpace(relativePath)) 23 | { 24 | return string.Empty; 25 | } 26 | if (Web.HttpContext == null) 27 | { 28 | if (relativePath.StartsWith("~")) 29 | { 30 | relativePath = relativePath.Remove(0, 2); 31 | } 32 | return Path.GetFullPath(relativePath); 33 | } 34 | if (relativePath.StartsWith("~")) 35 | { 36 | return Web.HostingEnvironment.ContentRootPath.MapPath(relativePath); 37 | } 38 | if (relativePath.StartsWith("/") || relativePath.StartsWith("\\")) 39 | { 40 | return Web.HostingEnvironment.ContentRootPath.MapPath("~" + relativePath); 41 | } 42 | return Web.HostingEnvironment.ContentRootPath.MapPath("~/" + relativePath); 43 | } 44 | #endregion 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/JCE.Samples.Webs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Always 38 | 39 | 40 | Always 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/JCE.Logs/Aspects/ErrorLogAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using AspectCore.DynamicProxy; 6 | using AspectCore.DynamicProxy.Parameters; 7 | using JCE.Aspects.Base; 8 | using JCE.Logs.Extensions; 9 | 10 | namespace JCE.Logs.Aspects 11 | { 12 | /// 13 | /// 错误日志 14 | /// 15 | public class ErrorLogAttribute:InterceptorBase 16 | { 17 | /// 18 | /// 执行 19 | /// 20 | public override async Task Invoke(AspectContext context, AspectDelegate next) 21 | { 22 | var methodName = GetMethodName(context); 23 | var log = Log.GetLog(methodName); 24 | try 25 | { 26 | await next(context); 27 | } 28 | catch (Exception ex) 29 | { 30 | log.Class(context.ServiceMethod.DeclaringType.FullName).Method(methodName).Exception(ex); 31 | foreach (var parameter in context.GetParameters()) 32 | { 33 | parameter.AppendTo(log); 34 | } 35 | log.Error(); 36 | throw; 37 | } 38 | } 39 | 40 | /// 41 | /// 获取方法名 42 | /// 43 | /// Aspect上下文 44 | /// 45 | private string GetMethodName(AspectContext context) 46 | { 47 | return $"{context.ServiceMethod.DeclaringType.FullName}.{context.ServiceMethod.Name}"; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sample/JCE.Samples.Webs/Controllers/TestController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using JCE.Logs; 6 | using JCE.Logs.Extensions; 7 | using JCE.Samples.Services; 8 | using Microsoft.AspNetCore.Mvc; 9 | 10 | namespace JCE.Samples.Webs.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | public class TestController:Controller 14 | { 15 | /// 16 | /// 日志操作 17 | /// 18 | public ILog Log { get; set; } 19 | 20 | private ITestService _testService; 21 | 22 | public TestController(ILog log,ITestService testService) 23 | { 24 | Log = log; 25 | _testService = testService; 26 | } 27 | 28 | [HttpPost("[action]")] 29 | public void SendInfo() 30 | { 31 | Log.BussinessId(Guid.NewGuid().ToString()) 32 | .Module("订单") 33 | .Method("PlaceOrder") 34 | .Caption("有人下单了") 35 | .Params("int", "a", "1") 36 | .Params("string", "b", "c") 37 | .Content($"购买商品数量:{100}") 38 | .Content($"购买商品总额:{200}") 39 | .Sql("select * from Users") 40 | .Sql("select * from Orders") 41 | .SqlParams($"@a={1},@b={2}") 42 | .SqlParams($"@userId={ Guid.NewGuid().ToString()}") 43 | .Info(); 44 | } 45 | 46 | [HttpPost("[action]")] 47 | public void SendContent(string content) 48 | { 49 | _testService.WriteOtherLog(content); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/JCE/Logs/Extensions/LogContentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Logs.Abstractions; 5 | using JCE.Utils.Extensions; 6 | 7 | namespace JCE.Logs.Extensions 8 | { 9 | /// 10 | /// 日志内容 扩展 11 | /// 12 | public static class LogContentExtensions 13 | { 14 | /// 15 | /// 追加内容 16 | /// 17 | /// 日志内容 18 | /// 拼接字符串 19 | /// 值 20 | public static void Append(this ILogContent content, StringBuilder result, string value) 21 | { 22 | if (value.IsEmpty()) 23 | { 24 | return; 25 | } 26 | result.Append(" "); 27 | result.AppendFormat(value); 28 | } 29 | 30 | /// 31 | /// 追加内容并换行 32 | /// 33 | /// 日志内容 34 | /// 拼接字符串 35 | /// 值 36 | public static void AppendLine(this ILogContent content, StringBuilder result, string value) 37 | { 38 | content.Append(result, value); 39 | result.AppendLine(); 40 | } 41 | 42 | /// 43 | /// 设置内容并换行 44 | /// 45 | /// 日志内容 46 | /// 值 47 | public static void Content(this ILogContent content, string value) 48 | { 49 | content.AppendLine(content.Content, value); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/JCE.Utils/Helpers/Async.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using Nito.AsyncEx; 6 | 7 | namespace JCE.Utils.Helpers 8 | { 9 | /// 10 | /// 异步操作 11 | /// 12 | public static class Async 13 | { 14 | /// 15 | /// 执行 16 | /// 17 | /// 操作,范例:Async.Run(async () => await SendAsync() ); 18 | public static void Run(Action action) 19 | { 20 | AsyncContext.Run(action); 21 | } 22 | 23 | /// 24 | /// 执行 25 | /// 26 | /// 操作,范例:Async.Run(async () => await SendAsync() ); 27 | public static void Run(Func action) 28 | { 29 | AsyncContext.Run(action); 30 | } 31 | 32 | /// 33 | /// 执行 34 | /// 35 | /// 返回类型 36 | /// 操作,范例:Async.Run(async () => await SendAsync() ); 37 | /// 38 | public static TResult Run(Func action) 39 | { 40 | return AsyncContext.Run(action); 41 | } 42 | 43 | /// 44 | /// 执行 45 | /// 46 | /// 返回类型 47 | /// 操作,范例:Async.Run(async () => await SendAsync() ); 48 | /// 49 | public static TResult Run(Func> action) 50 | { 51 | return AsyncContext.Run(action); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/JCE/Logs/Extensions/LogExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Logs.Abstractions; 5 | 6 | namespace JCE.Logs.Extensions 7 | { 8 | /// 9 | /// 日志操作 扩展 10 | /// 11 | public static class LogExtensions 12 | { 13 | /// 14 | /// 设置内容 15 | /// 16 | /// 日志操作 17 | /// 18 | public static ILog Content(this ILog log) 19 | { 20 | return log.Set(content => content.Content("")); 21 | } 22 | 23 | /// 24 | /// 设置内容并换行 25 | /// 26 | /// 日志操作 27 | /// 值 28 | /// 变量值 29 | /// 30 | public static ILog Content(this ILog log, string value) 31 | { 32 | return log.Set(content => content.Content(value)); 33 | } 34 | 35 | /// 36 | /// 设置内容 37 | /// 38 | /// 日志操作 39 | /// 字典 40 | /// 41 | public static ILog Content(this ILog log, IDictionary dictionary) 42 | { 43 | if (dictionary == null) 44 | { 45 | return log; 46 | } 47 | foreach (var keyValue in dictionary) 48 | { 49 | log.Set(content => content.Content($"{keyValue.Key} : {keyValue.Value}")); 50 | } 51 | return log; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/JCE.Utils.Encrypts.Test/Hash/SHACryptorTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Encrypts.Hash; 5 | using Xunit; 6 | using Xunit.Abstractions; 7 | 8 | namespace JCE.Utils.Encrypts.Test.Hash 9 | { 10 | public class SHACryptorTest:TestBase 11 | { 12 | private const string Source = "MD201711011120370001"; 13 | public SHACryptorTest(ITestOutputHelper output) : base(output) 14 | { 15 | } 16 | 17 | [Fact] 18 | public void Test_Sha1() 19 | { 20 | var result = SHACryptor.Sha1(Source); 21 | Output.WriteLine(result); 22 | Assert.Equal("29288e3dd3bc4e2de7676817df387164dde1af39",result); 23 | } 24 | 25 | [Fact] 26 | public void Test_Sha256() 27 | { 28 | var result = SHACryptor.Sha256(Source); 29 | Output.WriteLine(result); 30 | Assert.Equal("bb359fa9532e95ec9e09283dac96943c17206c007f89afdf2c00fc7c41930a9e",result); 31 | } 32 | 33 | [Fact] 34 | public void Test_Sha384() 35 | { 36 | var result = SHACryptor.Sha384(Source); 37 | Output.WriteLine(result); 38 | Assert.Equal("551d245291a875146cbcd640a0fbc8d9eaf447cd4cba272834444a4f401f436dad7654035e473dd82389382ddb646d61", result); 39 | } 40 | 41 | [Fact] 42 | public void Test_Sha512() 43 | { 44 | var result = SHACryptor.Sha512(Source); 45 | Output.WriteLine(result); 46 | Assert.Equal("29443332fe291c69edbce0b9060f0ddd4c912009772a468d52731f4b41867eb666b6bc9ff766180a06352061643abd666b9c6bdbad302c230aac68668b98eaf9", result); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/JCE.Datas.EntityFramework/Logs/EfLogProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Datas.EntityFramework.Core; 5 | using JCE.Logs; 6 | using Microsoft.Extensions.Logging; 7 | 8 | namespace JCE.Datas.EntityFramework.Logs 9 | { 10 | /// 11 | /// EF日志提供器 12 | /// 13 | public class EfLogProvider:ILoggerProvider 14 | { 15 | /// 16 | /// 日志操作 17 | /// 18 | private readonly ILog _log; 19 | 20 | /// 21 | /// 工作单元 22 | /// 23 | private readonly UnitOfWorkBase _unitOfWork; 24 | 25 | /// 26 | /// 初始化一个类型的实例 27 | /// 28 | /// 日志操作 29 | /// 工作单元 30 | public EfLogProvider(ILog log, UnitOfWorkBase unitOfWork) 31 | { 32 | _log = log ?? throw new ArgumentNullException(nameof(log)); 33 | _unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork)); 34 | } 35 | 36 | /// 37 | /// 释放 38 | /// 39 | public void Dispose() 40 | { 41 | } 42 | 43 | /// 44 | /// 初始化EF日志提供器 45 | /// 46 | /// 日志分类 47 | /// 48 | public ILogger CreateLogger(string category) 49 | { 50 | return category.StartsWith("Microsoft.EntityFrameworkCore") 51 | ? new EfLog(_log, _unitOfWork, category) 52 | : NullLogger.Instance; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/JCE.Utils/Item.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JCE.Utils 4 | { 5 | /// 6 | /// 列表项 7 | /// 8 | public class Item : IComparable 9 | { 10 | /// 11 | /// 文本 12 | /// 13 | public string Text { get; set; } 14 | 15 | /// 16 | /// 值 17 | /// 18 | public string Value { get; set; } 19 | 20 | /// 21 | /// 排序号 22 | /// 23 | public int SortId { get; set; } 24 | 25 | /// 26 | /// 初始化一个类型的实例 27 | /// 28 | public Item() 29 | { 30 | } 31 | 32 | /// 33 | /// 初始化一个类型的实例 34 | /// 35 | /// 文本 36 | /// 值 37 | public Item(string text, string value) : this(text, value, 0) 38 | { 39 | } 40 | 41 | /// 42 | /// 初始化一个类型的实例 43 | /// 44 | /// 文本 45 | /// 值 46 | /// 排序号 47 | public Item(string text, string value, int sortId) 48 | { 49 | Text = text; 50 | Value = value; 51 | SortId = sortId; 52 | } 53 | 54 | /// 55 | /// 比较 56 | /// 57 | /// 其他列表项 58 | /// 59 | public int CompareTo(Item other) 60 | { 61 | return string.Compare(Text, other.Text, StringComparison.CurrentCulture); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/JCE.Utils/Webs/Clients/FileParamter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace JCE.Utils.Webs.Clients 7 | { 8 | /// 9 | /// 文件参数 10 | /// 11 | public struct FileParamter 12 | { 13 | /// 14 | /// 参数名称 15 | /// 16 | public string Name; 17 | 18 | /// 19 | /// 读写操作流,返回的是写入的字节流长度 20 | /// 21 | public Action Writer; 22 | 23 | /// 24 | /// 文件名 25 | /// 26 | public string FileName; 27 | 28 | /// 29 | /// 文件类型 30 | /// 31 | public string ContentType; 32 | 33 | /// 34 | /// 初始化一个类型的实例 35 | /// 36 | /// 参数名称 37 | /// 文件流,调用方会自动释放 38 | /// 文件名 39 | /// 文件类型 40 | public FileParamter(string name, Stream fileStream, string fileName, string contentType) 41 | { 42 | this.Writer = x => 43 | { 44 | var buffer = new byte[1024]; 45 | using (fileStream) 46 | { 47 | int readCount = 0; 48 | while ((readCount = fileStream.Read(buffer, 0, buffer.Length)) != 0) 49 | { 50 | x.Write(buffer, 0, readCount); 51 | } 52 | } 53 | }; 54 | this.FileName = fileName; 55 | this.ContentType = contentType; 56 | this.Name = name; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/JCE/Domains/Entities/ChangeValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace JCE.Domains.Entities 6 | { 7 | /// 8 | /// 变更值 9 | /// 10 | public class ChangeValue 11 | { 12 | /// 13 | /// 属性名 14 | /// 15 | public string PropertyName { get; } 16 | 17 | /// 18 | /// 描述 19 | /// 20 | public string Description { get; } 21 | 22 | /// 23 | /// 旧值 24 | /// 25 | public string OldValue { get; } 26 | 27 | /// 28 | /// 新值 29 | /// 30 | public string NewValue { get; } 31 | 32 | /// 33 | /// 初始化一个类型的实例 34 | /// 35 | /// 属性名 36 | /// 描述 37 | /// 旧值 38 | /// 新值 39 | public ChangeValue(string propertyName, string description, string oldValue, string newValue) 40 | { 41 | PropertyName = propertyName; 42 | Description = description; 43 | OldValue = oldValue; 44 | NewValue = newValue; 45 | } 46 | 47 | /// 48 | /// 输出变更信息 49 | /// 50 | /// 51 | public override string ToString() 52 | { 53 | var result=new StringBuilder(); 54 | result.AppendFormat("{0}({1}),", PropertyName, Description); 55 | result.AppendFormat("旧值:{0},新值:{1}", OldValue, NewValue); 56 | return result.ToString(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/JCE/Validations/Aspects/ValidAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using AspectCore.DynamicProxy.Parameters; 6 | using JCE.Aspects.Base; 7 | using JCE.Utils.Helpers; 8 | 9 | namespace JCE.Validations.Aspects 10 | { 11 | /// 12 | /// 验证拦截器 13 | /// 14 | public class ValidAttribute : ParameterInterceptorBase 15 | { 16 | /// 17 | /// 执行 18 | /// 19 | /// 20 | /// 21 | /// 22 | public override async Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next) 23 | { 24 | Validate(context.Parameter); 25 | await next(context); 26 | } 27 | 28 | /// 29 | /// 验证 30 | /// 31 | private void Validate(Parameter parameter) 32 | { 33 | if (Reflection.IsGenericCollection(parameter.RawType)) 34 | { 35 | ValidateCollection(parameter); 36 | return; 37 | } 38 | IValidation validation = parameter.Value as IValidation; 39 | validation?.Validate(); 40 | } 41 | 42 | /// 43 | /// 验证集合 44 | /// 45 | private void ValidateCollection(Parameter parameter) 46 | { 47 | var validations = parameter.Value as IEnumerable; 48 | if (validations == null) 49 | { 50 | return; 51 | } 52 | foreach (var validation in validations) 53 | { 54 | validation.Validate(); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/JCE.ComputerInfo.Test/CpuInfoTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Xunit; 5 | using Xunit.Abstractions; 6 | 7 | namespace JCE.ComputerInfo.Test 8 | { 9 | public class CpuInfoTest:TestBase 10 | { 11 | public CpuInfoTest(ITestOutputHelper output) : base(output) 12 | { 13 | } 14 | 15 | [Fact] 16 | public void Test_GetCpuName() 17 | { 18 | var result = CpuInfo.GetName(); 19 | Output.WriteLine(result); 20 | } 21 | 22 | [Fact] 23 | public void Test_GetProcessorId() 24 | { 25 | var result = CpuInfo.GetProcessorId(); 26 | Output.WriteLine(result); 27 | } 28 | 29 | [Fact] 30 | public void Test_GetManufacturer() 31 | { 32 | var result = CpuInfo.GetManufacturer(); 33 | Output.WriteLine(result); 34 | } 35 | 36 | [Fact] 37 | public void Test_GetCurrentMhz() 38 | { 39 | var result = CpuInfo.GetCurrentMhz(); 40 | foreach (var item in result) 41 | { 42 | Output.WriteLine(item); 43 | } 44 | } 45 | 46 | [Fact] 47 | public void Test_GetMaxMhz() 48 | { 49 | var result = CpuInfo.GetMaxMhz(); 50 | Output.WriteLine(result); 51 | } 52 | 53 | [Fact] 54 | public void Test_GetExtMhz() 55 | { 56 | var result = CpuInfo.GetExtMhz(); 57 | Output.WriteLine(result); 58 | } 59 | 60 | [Fact] 61 | public void Test_GetCurrentVoltage() 62 | { 63 | var result = CpuInfo.GetCurrentVoltage(); 64 | Output.WriteLine(result); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/JCE/JCE.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | JCE 6 | JCE 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.ComponentModel.Annotations.dll 29 | 30 | 31 | 32 | 33 | 34 | True 35 | True 36 | LibraryResource.resx 37 | 38 | 39 | 40 | 41 | 42 | ResXFileCodeGenerator 43 | LibraryResource.Designer.cs 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/JCE.Webs/Middlewares/ErrorLogMiddleware.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using JCE.Logs; 6 | using JCE.Logs.Extensions; 7 | using Microsoft.AspNetCore.Http; 8 | 9 | namespace JCE.Webs.Middlewares 10 | { 11 | /// 12 | /// 错误日志中间件 13 | /// 14 | public class ErrorLogMiddleware 15 | { 16 | /// 17 | /// 方法 18 | /// 19 | private readonly RequestDelegate _next; 20 | 21 | /// 22 | /// 初始化一个类型的实例 23 | /// 24 | /// 方法 25 | public ErrorLogMiddleware(RequestDelegate next) 26 | { 27 | _next = next; 28 | } 29 | 30 | /// 31 | /// 执行方法 32 | /// 33 | /// Http上下文 34 | /// 35 | public async Task Invoke(HttpContext context) 36 | { 37 | try 38 | { 39 | await _next(context); 40 | } 41 | catch (Exception ex) 42 | { 43 | WriteLog(context,ex); 44 | throw; 45 | } 46 | } 47 | 48 | /// 49 | /// 记录错误日志 50 | /// 51 | /// Http上下文 52 | /// 异常 53 | private void WriteLog(HttpContext context, Exception ex) 54 | { 55 | if (context == null) 56 | { 57 | return; 58 | } 59 | var log = Log.GetLog().Caption("全局异常捕获").Content($"状态码:{context.Response.StatusCode}"); 60 | ex.Log(log); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/JCE.Utils/Configs/ConfigUtil.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using Microsoft.Extensions.FileProviders; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Text; 7 | 8 | namespace JCE.Utils.Configs 9 | { 10 | /// 11 | /// 配置辅助操作类 12 | /// 13 | public static class ConfigUtil 14 | { 15 | /// 16 | /// 获取Json配置文件 17 | /// 18 | /// 配置文件名,默认:appsettings.json 19 | /// 基路径 20 | /// 21 | public static IConfigurationRoot GetJsonConfig(string configFileName="appsettings.json",string basePath = "") 22 | { 23 | basePath = string.IsNullOrWhiteSpace(basePath) ? Directory.GetCurrentDirectory() : basePath; 24 | 25 | var builder = new ConfigurationBuilder().SetBasePath(basePath).AddJsonFile(configFileName); 26 | return builder.Build(); 27 | } 28 | 29 | /// 30 | /// 获取Xml配置文件 31 | /// 32 | /// 配置文件名,默认:appsettings.xml 33 | /// 基路径 34 | /// 35 | public static IConfigurationRoot GetXmlConfig(string configFileName="appsettings.xml",string basePath = "") 36 | { 37 | basePath = string.IsNullOrWhiteSpace(basePath) ? Directory.GetCurrentDirectory() : basePath; 38 | 39 | var builder = new ConfigurationBuilder().AddXmlFile(config=> 40 | { 41 | config.Path = configFileName; 42 | config.FileProvider = new PhysicalFileProvider(basePath); 43 | }); 44 | return builder.Build(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/JCE.Logs/Formats/FormatProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Logs.Abstractions; 5 | 6 | namespace JCE.Logs.Formats 7 | { 8 | /// 9 | /// 日志格式化提供程序 10 | /// 11 | public class FormatProvider : IFormatProvider, ICustomFormatter 12 | { 13 | /// 14 | /// 日志格式化器 15 | /// 16 | private readonly ILogFormat _format; 17 | 18 | /// 19 | /// 初始化一个类型的实例 20 | /// 21 | /// 日志格式化器 22 | public FormatProvider(ILogFormat format) 23 | { 24 | if (format == null) 25 | { 26 | throw new ArgumentNullException(nameof(format)); 27 | } 28 | _format = format; 29 | } 30 | 31 | /// 32 | /// 获取格式化器 33 | /// 34 | /// 格式化器类型 35 | /// 36 | public object GetFormat(Type formatType) 37 | { 38 | return formatType == typeof(ICustomFormatter) ? this : null; 39 | } 40 | 41 | /// 42 | /// 格式化 43 | /// 44 | /// 包含格式规范的格式字符串。 45 | /// 要设置格式的对象。 46 | /// 一个对象,它提供有关当前实例的格式信息。 47 | /// 48 | public string Format(string format, object arg, IFormatProvider formatProvider) 49 | { 50 | var content = arg as ILogContent; 51 | if (content == null) 52 | { 53 | return string.Empty; 54 | } 55 | return _format.Format(content); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/JCE/Datas/UnitOfWorks/UnitOfWorkManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using System.Transactions; 6 | 7 | namespace JCE.Datas.UnitOfWorks 8 | { 9 | /// 10 | /// 工作单元管理器 11 | /// 12 | public class UnitOfWorkManager:IUnitOfWorkManager 13 | { 14 | /// 15 | /// 工作单元集合 16 | /// 17 | private readonly List _unitOfWorks; 18 | 19 | /// 20 | /// 初始化一个类型的实例 21 | /// 22 | public UnitOfWorkManager() 23 | { 24 | _unitOfWorks=new List(); 25 | } 26 | 27 | /// 28 | /// 提交 29 | /// 30 | public void Commit() 31 | { 32 | foreach (var unitOfWork in _unitOfWorks) 33 | { 34 | unitOfWork.Commit(); 35 | } 36 | } 37 | 38 | /// 39 | /// 提交 40 | /// 41 | /// 42 | public async Task CommitAsync() 43 | { 44 | foreach (var unitOfWork in _unitOfWorks) 45 | { 46 | await unitOfWork.CommitAsync(); 47 | } 48 | } 49 | 50 | /// 51 | /// 注册工作单元 52 | /// 53 | /// 工作单元 54 | public void Register(IUnitOfWork unitOfWork) 55 | { 56 | if (unitOfWork == null) 57 | { 58 | throw new ArgumentNullException(nameof(unitOfWork)); 59 | } 60 | if (_unitOfWorks.Contains(unitOfWork) == false) 61 | { 62 | _unitOfWorks.Add(unitOfWork); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/JCE/Logs/Abstractions/ILogContent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Exceptions; 5 | 6 | namespace JCE.Logs.Abstractions 7 | { 8 | /// 9 | /// 日志内容 10 | /// 11 | public interface ILogContent 12 | { 13 | /// 14 | /// 日志名称 15 | /// 16 | string LogName { get; set; } 17 | 18 | /// 19 | /// 日志级别 20 | /// 21 | string Level { get; set; } 22 | 23 | /// 24 | /// 跟踪号 25 | /// 26 | string TraceId { get; set; } 27 | 28 | /// 29 | /// 操作时间 30 | /// 31 | string OperationTime { get; set; } 32 | 33 | /// 34 | /// 持续时间 35 | /// 36 | string Duration { get; set; } 37 | 38 | /// 39 | /// IP 40 | /// 41 | string Ip { get; set; } 42 | 43 | /// 44 | /// 主机 45 | /// 46 | string Host { get; set; } 47 | 48 | /// 49 | /// 线程号 50 | /// 51 | string ThreadId { get; set; } 52 | 53 | /// 54 | /// 浏览器 55 | /// 56 | string Browser { get; set; } 57 | 58 | /// 59 | /// 请求地址 60 | /// 61 | string Url { get; set; } 62 | 63 | /// 64 | /// 操作人编号 65 | /// 66 | string UserId { get; set; } 67 | 68 | /// 69 | /// 内容 70 | /// 71 | StringBuilder Content { get; set; } 72 | 73 | /// 74 | /// 异常消息 75 | /// 76 | Warning Exception { get; set; } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/JCE.Utils/Expressions/ParameterRebinder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | 6 | namespace JCE.Utils.Expressions 7 | { 8 | /// 9 | /// 参数重绑定操作 10 | /// 11 | public class ParameterRebinder : ExpressionVisitor 12 | { 13 | /// 14 | /// 参数字典 15 | /// 16 | private readonly Dictionary _map; 17 | 18 | /// 19 | /// 初始化一个类型的实例 20 | /// 21 | /// 参数字典 22 | public ParameterRebinder(Dictionary map) 23 | { 24 | _map = map ?? new Dictionary(); 25 | } 26 | 27 | /// 28 | /// 替换参数 29 | /// 30 | /// 参数字典 31 | /// 表达式 32 | /// 33 | public static Expression ReplaceParameters(Dictionary map, 34 | Expression exp) 35 | { 36 | return new ParameterRebinder(map).Visit(exp); 37 | } 38 | 39 | /// 40 | /// 访问参数 41 | /// 42 | /// 参数表达式 43 | /// 44 | protected override Expression VisitParameter(ParameterExpression parameterExpression) 45 | { 46 | ParameterExpression replacement; 47 | if (_map.TryGetValue(parameterExpression, out replacement)) 48 | { 49 | parameterExpression = replacement; 50 | } 51 | return base.VisitParameter(parameterExpression); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/JCE.Webs/Middlewares/WebApiResultMiddleware.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Webs.Middlewares.Internals; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.Filters; 7 | using Newtonsoft.Json; 8 | 9 | namespace JCE.Webs.Middlewares 10 | { 11 | /// 12 | /// WebApi结果处理中间件,处理空值为空字符串。 13 | /// 参考地址:http://www.cnblogs.com/xishuai/p/asp-net-core-webapi-json-convert-empty-string-instead-of-null.html 14 | /// 15 | public class WebApiResultMiddleware:ActionFilterAttribute 16 | { 17 | public override void OnResultExecuting(ResultExecutingContext context) 18 | { 19 | if (context.HttpContext.Request.Path.HasValue) 20 | { 21 | if (context.HttpContext.Request.Path.Value.ToLower().IndexOf(".inside.", StringComparison.Ordinal) < 0) 22 | { 23 | if (context.Result is FileContentResult || context.Result is EmptyResult) 24 | { 25 | return; 26 | } 27 | if (context.Result is ObjectResult) 28 | { 29 | var objectResult = context.Result as ObjectResult; 30 | var settings = new JsonSerializerSettings() 31 | { 32 | ContractResolver = new NullToEmptyStringResolver(), 33 | DateFormatString = "yyyy-MM-dd HH:mm:ss" 34 | }; 35 | context.Result=new JsonResult(new {data=objectResult.Value},settings); 36 | } 37 | else 38 | { 39 | context.Result = new ObjectResult(new {data = new { }}); 40 | } 41 | } 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/JCE.Utils.Encrypts/Base64Cryptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using JCE.Utils.Extensions; 5 | 6 | namespace JCE.Utils.Encrypts 7 | { 8 | /// 9 | /// Base64 加密 10 | /// 11 | public class Base64Cryptor 12 | { 13 | #region Encrypt(加密) 14 | 15 | /// 16 | /// 加密,返回Base64字符串 17 | /// 18 | /// 明文 19 | /// 20 | public static string Encrypt(string data) 21 | { 22 | return Encrypt(data, Encoding.UTF8); 23 | } 24 | 25 | /// 26 | /// 加密,返回Base64字符串 27 | /// 28 | /// 明文 29 | /// 编码方式 30 | /// 31 | public static string Encrypt(string data, Encoding encoding) 32 | { 33 | data.CheckNotNullOrEmpty(nameof(data)); 34 | return Convert.ToBase64String(encoding.GetBytes(data)); 35 | } 36 | 37 | #endregion 38 | 39 | #region Decrypt(解密) 40 | 41 | /// 42 | /// 解密 43 | /// 44 | /// 密文 45 | /// 46 | public static string Decrypt(string data) 47 | { 48 | return Decrypt(data, Encoding.UTF8); 49 | } 50 | 51 | /// 52 | /// 解密 53 | /// 54 | /// 密文 55 | /// 编码方式 56 | /// 57 | public static string Decrypt(string data, Encoding encoding) 58 | { 59 | data.CheckNotNullOrEmpty(nameof(data)); 60 | return encoding.GetString(Convert.FromBase64String(data)); 61 | } 62 | 63 | #endregion 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/JCE.Utils/JCE.Utils.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | True 34 | True 35 | R.resx 36 | 37 | 38 | 39 | 40 | 41 | ResXFileCodeGenerator 42 | R.Designer.cs 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | --------------------------------------------------------------------------------