├── .gitignore ├── Document ├── 工程结构图.xmind └── 工程结构架构图.png ├── Test ├── Ccshis.ConsulExtend.Test │ ├── ComponentServiceExtendUnitTest.cs │ ├── Ccshis.ServiceDiscovery.ConsulExtend.Test.csproj.user │ ├── Ccshis.ServiceDiscovery.ConsulExtend.Test.csproj │ └── DefaultConfiguationServiceTest.cs ├── BaseTest │ ├── BaseTestClass.cs │ └── BaseTest.csproj └── Ccshis.Information.Sms.Ali.Test │ └── Ccshis.Information.Sms.Ali.Test.csproj ├── Infrastructure ├── Component │ ├── Ccshis.Aliyun │ │ └── Ccshis.Aliyun.LogExtend │ │ │ ├── AliyunLogSetting.cs │ │ │ ├── AliYunLogAppend.cs │ │ │ ├── Ccshis.Aliyun.LogExtend.csproj │ │ │ └── ComponentServiceExtend.cs │ ├── Ccshis.ConsulExtend │ │ ├── IConsulServices.cs │ │ ├── Ccshis.ConsulComponent.csproj │ │ ├── IConsulSetting.cs │ │ ├── ConsulServerSetting.cs │ │ ├── MicServerSetting.cs │ │ ├── ConsulConfigurationService.cs │ │ ├── HealthCheckSetting.cs │ │ └── ComponentServiceExtend.cs │ ├── Ccshis.Component │ │ ├── Information │ │ │ ├── EmaiInformation.cs │ │ │ ├── IEmailSenderService.cs │ │ │ └── ComponentServiceExtend.cs │ │ ├── IFileConfigurationService.cs │ │ ├── Cluster │ │ │ ├── ServerMember.cs │ │ │ └── ClusterService.cs │ │ ├── Ccshis.Component.csproj │ │ ├── Util │ │ │ └── IdentifiedGenerateService.cs │ │ ├── ComponentServiceExtend.cs │ │ ├── ComponentService.cs │ │ ├── ComponentContainer.cs │ │ └── DefaultConfigurationService.cs │ ├── Ccshis.QuzrtzExtend │ │ └── Ccshis.QuzrtzExtend.csproj │ ├── Ccshis.ExceptionlessExtend │ │ ├── ExceptionlessSetting.cs │ │ ├── Ccshis.ExceptionlessExtend.csproj │ │ ├── ComponentServiceExtend.cs │ │ └── log4net.config │ └── Ccshis.Information │ │ └── Ccshis.Information.Sms.Ali │ │ ├── ISmsSender.cs │ │ ├── AliApiResult.cs │ │ ├── Ccshis.Information.Sms.Ali.csproj │ │ ├── SmsInformation.cs │ │ ├── ComponentServiceExtend.cs │ │ └── SmsSender.cs ├── SmsSender │ ├── SmsSender.cs │ ├── SmsSender.csproj │ └── Program.cs ├── Ccshis │ ├── IServices.cs │ ├── ISetting.cs │ ├── Job │ │ ├── IJob.cs │ │ └── IJobService.cs │ ├── Util │ │ ├── Ensure.cs │ │ ├── IIdentifiedGenerate.cs │ │ ├── LocalizationUtil.cs │ │ └── StringUtil.cs │ ├── Security │ │ └── Authorize │ │ │ ├── IRole.cs │ │ │ ├── IUser.cs │ │ │ ├── IHotel.cs │ │ │ ├── Identity.cs │ │ │ ├── IOpeartion.cs │ │ │ ├── IResource.cs │ │ │ └── IPermission.cs │ ├── Information │ │ ├── IInformation.cs │ │ └── IInformationSender.cs │ ├── Ccshis.csproj │ ├── SystemConst.cs │ ├── IConfigurationService.cs │ ├── IAggregateRoot.cs │ ├── Cluster │ │ ├── Virtualization.cs │ │ ├── IClusterService.cs │ │ └── IServerMember.cs │ ├── IPager.cs │ ├── AggregateRoot.cs │ ├── SysException.cs │ ├── BizException.cs │ ├── DataException.cs │ ├── AuthorizeExcpetion.cs │ ├── CoreException.cs │ └── IComponentService.cs └── Infrastructure.sln ├── Shared ├── Ccshis.Shared │ ├── Topics.cs │ ├── Ccshis.Shared.csproj │ ├── Settings │ │ ├── AliYunApiSetting.cs │ │ └── Cluster │ │ │ └── ServerMemberSetting.cs │ ├── SettingsPath.cs │ └── Localization.cs └── Shared.sln └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | .vs 4 | package -------------------------------------------------------------------------------- /Document/工程结构图.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheetahing/Ccshis/HEAD/Document/工程结构图.xmind -------------------------------------------------------------------------------- /Document/工程结构架构图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheetahing/Ccshis/HEAD/Document/工程结构架构图.png -------------------------------------------------------------------------------- /Test/Ccshis.ConsulExtend.Test/ComponentServiceExtendUnitTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cheetahing/Ccshis/HEAD/Test/Ccshis.ConsulExtend.Test/ComponentServiceExtendUnitTest.cs -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Aliyun/Ccshis.Aliyun.LogExtend/AliyunLogSetting.cs: -------------------------------------------------------------------------------- 1 | namespace Ccshis.Aliyun.LogExtend 2 | { 3 | public class AliyunLogSetting 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /Infrastructure/SmsSender/SmsSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SmsSender 6 | { 7 | class SmsSender 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/IServices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | public interface IServices 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/ISetting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | public interface ISetting 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Job/IJob.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Job 6 | { 7 | public interface IJob 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Util/Ensure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Util 6 | { 7 | public class Ensure 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Job/IJobService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Job 6 | { 7 | public interface IJobService 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Security/Authorize/IRole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Security.Authorize 6 | { 7 | public class IRole 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/SmsSender/SmsSender.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Security/Authorize/IUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Security.Authorize 6 | { 7 | public interface IUser 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Security/Authorize/IHotel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Security.Authorize 6 | { 7 | public interface IHotel 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Security/Authorize/Identity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Security.Authorize 6 | { 7 | public interface Identity 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Security/Authorize/IOpeartion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Security.Authorize 6 | { 7 | public interface IOpeartion 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Security/Authorize/IResource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Security.Authorize 6 | { 7 | public interface IResource 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Security/Authorize/IPermission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Security.Authorize 6 | { 7 | public interface IPermission 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ConsulExtend/IConsulServices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.ConsulComponent 6 | { 7 | interface IConsulServices 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/Information/EmaiInformation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Ccshis.Information.Email 4 | { 5 | public class EmaiInformation : IInformation 6 | { 7 | public string Body { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Infrastructure/SmsSender/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SmsSender 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Information/IInformation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Information 6 | { 7 | public interface IInformation 8 | { 9 | string Body { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Util/IIdentifiedGenerate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Util 6 | { 7 | public interface IIdentifiedGenerateService 8 | { 9 | long GetIdentified(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Ccshis.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Test/Ccshis.ConsulExtend.Test/Ccshis.ServiceDiscovery.ConsulExtend.Test.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/SystemConst.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | public static class SystemConst 8 | { 9 | public const string ValueIsEmpty = "Empty"; 10 | 11 | public const string EmptyString = ""; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.QuzrtzExtend/Ccshis.QuzrtzExtend.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Shared/Ccshis.Shared/Topics.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | /// 8 | /// 消息队列订阅主题 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// date:2019-5-20 13 | /// 14 | public class Topics 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Shared/Ccshis.Shared/Ccshis.Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | Ccshis 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/IConfigurationService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | namespace Ccshis 7 | { 8 | public interface IConfigurationService 9 | { 10 | Task GetAsync(string key) where T : class, ISetting; 11 | 12 | Task GetAsync(string key); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/Information/IEmailSenderService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | namespace Ccshis.Information.Email 7 | { 8 | public interface IEmailSenderService 9 | { 10 | Task SendAsync(List receivers, EmaiInformation information); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/IAggregateRoot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ENode.Domain; 5 | 6 | namespace Ccshis 7 | { 8 | /// 9 | /// 聚合根接口 10 | /// 直接引用enode框架聚合根接口 11 | /// 12 | /// 13 | /// 14 | public interface IAggregateRoot:ENode.Domain.IAggregateRoot 15 | { 16 | } 17 | } -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Cluster/Virtualization.cs: -------------------------------------------------------------------------------- 1 | namespace Ccshis.Cluster 2 | { 3 | /// 4 | /// 虚拟化类型 5 | /// 6 | public enum Virtualization 7 | { 8 | /// 9 | /// docker容器 10 | /// 11 | Docker=0, 12 | 13 | /// 14 | /// 实体服务器或虚拟机 15 | /// 16 | Machine=1 17 | } 18 | } -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Aliyun/Ccshis.Aliyun.LogExtend/AliYunLogAppend.cs: -------------------------------------------------------------------------------- 1 | using log4net.Appender; 2 | using log4net.Core; 3 | using System; 4 | 5 | namespace Ccshis.Aliyun.LogExtend 6 | { 7 | public class AliYunLogAppend : AppenderSkeleton 8 | { 9 | protected override void Append(LoggingEvent loggingEvent) 10 | { 11 | //todo 写入阿里云日志 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Information/IInformationSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | namespace Ccshis.Information 7 | { 8 | public interface IInformationSenderService 9 | { 10 | Task SendAsync(List receivers, T information) where T:IInformation; 11 | Task SendAsync(string oneReceiver, T information); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/IPager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Ccshis 4 | { 5 | /// 6 | /// 分页数据接口 7 | /// 8 | /// 9 | /// author:catdemon 10 | /// data:2019-05-15 11 | /// opt:create 12 | /// 13 | public interface IPager 14 | { 15 | int pageIndex { get; set; } 16 | 17 | int PageSize { get; set; } 18 | 19 | int Totle { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Cluster/IClusterService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Cluster 6 | { 7 | public interface IClusterService 8 | { 9 | IServerMember ServerMember { get; } 10 | 11 | IServerMember JoinCluster(string clusterServerIp, IServerMember serverMember); 12 | 13 | IServerMember QuitCluster(string clusterServerIp, IServerMember serverMember); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Aliyun/Ccshis.Aliyun.LogExtend/Ccshis.Aliyun.LogExtend.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/AggregateRoot.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | /// 8 | /// 框架领域聚合根 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// data:2019-05-14 13 | /// opt:create 14 | /// remark:框架使用雪花算法id,要求使用long作为聚合根id 15 | /// 16 | public class AggregateRoot:ENode.Domain.AggregateRoot,IAggregateRoot 17 | { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Shared/Ccshis.Shared/Settings/AliYunApiSetting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Settings 6 | { 7 | /// 8 | /// 阿里去配制 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// date;2019-5-22 13 | /// 14 | public class AliYunApiSetting:ISetting 15 | { 16 | public string accessKeyId { get; set; } 17 | public string secret { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Test/BaseTest/BaseTestClass.cs: -------------------------------------------------------------------------------- 1 | using Ccshis; 2 | using NUnit.Framework; 3 | using System; 4 | 5 | namespace BaseTest 6 | { 7 | public class BaseTestClass 8 | { 9 | 10 | protected IComponentService componentService; 11 | 12 | [SetUp] 13 | public void SetUp() 14 | { 15 | componentService = ComponentService.Create(); 16 | componentService 17 | .UseAutofac() 18 | .UseCommonComponent(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Test/BaseTest/BaseTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Shared/Ccshis.Shared/SettingsPath.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Ccshis 4 | { 5 | /// 6 | /// 配置文件路径 7 | /// 8 | /// 9 | /// author:catdemon 10 | /// date:2019-5-20 11 | /// 12 | public static class SettingsPath 13 | { 14 | /// 15 | /// 服务器节点成员配置文件路径 16 | /// 17 | public const string ServerMemberSettingPath = "/Cluster/ServerMemberSetting.json"; 18 | 19 | public const string AliYunApiSettingPath = "AliYunApiSetting.json"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ConsulExtend/Ccshis.ConsulComponent.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | Ccshis.ConsulComponent 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/IFileConfigurationService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | namespace Ccshis 7 | { 8 | /// 9 | /// 文件配置服务 10 | /// 11 | /// 12 | /// author:catdemon 13 | /// date:2019-5-21 14 | /// reamark: 15 | /// 16 | public interface IFileConfigurationService:IConfigurationService 17 | { 18 | Task SetAsync(string key,T value) where T:class,ISetting; 19 | Task SetAsync(string key, string value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Shared/Ccshis.Shared/Settings/Cluster/ServerMemberSetting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Settings.Cluster 6 | { 7 | /// 8 | /// 服务器配置成员,注册到集群后,集群会分配一个服务器节点id给到当前节点 9 | /// 当前节点会存储集群分配的节点,并使用该节点作为雪花算法的服务器节点id 10 | /// 11 | /// 12 | /// authro:catdemon 13 | /// date:2019-5-21 14 | /// 15 | public class ServerMemberSetting:ISetting 16 | { 17 | /// 18 | /// 服务器节点,在集群中全局唯一 19 | /// 20 | public long Id { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ExceptionlessExtend/ExceptionlessSetting.cs: -------------------------------------------------------------------------------- 1 | namespace Ccshis.ExceptionlessExtend 2 | { 3 | /// 4 | /// Exceptionless配制项 5 | /// 6 | /// 7 | /// author:catdemon 8 | /// data:2019-05-15 9 | /// opt:create 10 | /// 11 | public class ExceptionlessSetting : ISetting 12 | { 13 | /// 14 | /// 服务器地址 15 | /// 16 | public string ServerUrl { get; set; } 17 | 18 | /// 19 | /// apikey 20 | /// 21 | public string ApiKey { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/Cluster/ServerMember.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Text; 5 | 6 | namespace Ccshis.Cluster 7 | { 8 | public class ServerMember : IServerMember 9 | { 10 | public long Id { get; set; } 11 | 12 | public Virtualization Virtualization { get; set; } 13 | 14 | public IPAddress IPAddress { get; set; } 15 | 16 | public string Name { get; set; } 17 | 18 | public string GroupName { get; set; } 19 | 20 | public string[] Tags { get; set; } 21 | 22 | public string Remark { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Information/Ccshis.Information.Sms.Ali/ISmsSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | namespace Ccshis.Information.Sms.Ali 7 | { 8 | /// 9 | /// 阿里云短信发送 10 | /// 11 | /// /// 12 | /// author:catdemon 13 | /// data:2019-05-15 14 | /// opt:create 15 | /// 16 | interface ISmsSender 17 | { 18 | Task SendAsync(string[] receivers, SmsInformation information); 19 | 20 | Task SendAsync(string receivers, SmsInformation information); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ConsulExtend/IConsulSetting.cs: -------------------------------------------------------------------------------- 1 | using Consul; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Ccshis.ServiceDiscovery.ConsulExtend 7 | { 8 | public interface IConsulSetting 9 | { 10 | 11 | /// 12 | /// 服务发现中间件配置 13 | /// 14 | ConsulServerSetting ConsulServerSetting { get; } 15 | 16 | /// 17 | /// 微服务配置 18 | /// 19 | MicServerSetting MicServerSetting { get; } 20 | 21 | /// 22 | /// 健康检查 23 | /// 24 | HealthCheckSetting HealthCheckSetting { get;} 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ExceptionlessExtend/Ccshis.ExceptionlessExtend.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | PreserveNewest 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/Ccshis.Component.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | Ccshis 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Information/Ccshis.Information.Sms.Ali/AliApiResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Information.Sms.Ali 6 | { 7 | /// 8 | /// 阿里云短信调用结果 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// date:2019-5-23 13 | /// opt:create 14 | /// 15 | class AliApiResult 16 | { 17 | public string Message { get; set; } 18 | public string RequestId { get; set; } 19 | public string BizId { get; set; } 20 | 21 | /// 22 | /// 返回代码,如果成功返回OK 23 | /// 24 | public string Code { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Information/Ccshis.Information.Sms.Ali/Ccshis.Information.Sms.Ali.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ConsulExtend/ConsulServerSetting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.ConsulComponent 6 | { 7 | /// 8 | /// 服务器发现中间件配置 9 | /// 10 | public class ConsulServerSetting 11 | { 12 | /// 13 | /// 默认端口号 14 | /// 15 | public const int DefaultPort = 8500; 16 | 17 | /// 18 | /// 服务发现地址,例如http://127.0.0.1 19 | /// 20 | public string Url { get; set; } 21 | 22 | /// 23 | /// 服务发现端口,默认8500 24 | /// 25 | public int Port { get; set; } = DefaultPort; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Util/LocalizationUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Linq; 5 | 6 | namespace Ccshis.Util 7 | { 8 | public static class LocalizationUtil 9 | { 10 | /// 11 | /// 构建多语言 12 | /// 13 | /// 14 | /// 15 | public static string Build(Enum[] localization) 16 | { 17 | var result = new StringBuilder(); 18 | 19 | foreach(Enum item in localization) 20 | { 21 | result.Append($"{item.ToString()},"); 22 | } 23 | return result.Remove(result.Length - 1, 1).ToString(); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Aliyun/Ccshis.Aliyun.LogExtend/ComponentServiceExtend.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Aliyun.LogExtend 6 | { 7 | public static class ComponentServiceExtend 8 | { 9 | /// 10 | /// 注册使用阿里云日志 11 | /// 12 | /// IComponentService 13 | /// 发件邮箱配置项 14 | /// 15 | public static IComponentService UseEmail(this IComponentService componentService, AliyunLogSetting aliyunLogSetting) 16 | { 17 | componentService.RegisterAssembly(typeof(ComponentServiceExtend).Assembly); 18 | return componentService; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Test/Ccshis.Information.Sms.Ali.Test/Ccshis.Information.Sms.Ali.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/SysException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | /// 8 | /// 框架级别的错误 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// date:2019-5-23 13 | /// opt:create 14 | /// 15 | public class SysException:CoreException 16 | { 17 | public SysException(string message = SystemConst.EmptyString, string localizationCode = SystemConst.ValueIsEmpty, Exception innerException = null) 18 | : base(message, localizationCode, innerException) 19 | { 20 | 21 | } 22 | 23 | public SysException(Enum[] messageCode, Enum[] localizationCode, Exception innerException = null) 24 | : base(messageCode, localizationCode, innerException) 25 | { 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/BizException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | /// 8 | /// ccshis系统业务异常类 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// data:2019-05-14 13 | /// opt:create 14 | /// 15 | public class BizException:CoreException 16 | { 17 | public BizException(string message = SystemConst.EmptyString, string localizationCode = SystemConst.ValueIsEmpty, Exception innerException = null) 18 | :base(message,localizationCode,innerException) 19 | { 20 | 21 | } 22 | public BizException(Enum[] messageCode = null, Enum[] localizationCode = null, Exception innerException = null) 23 | : base(messageCode, localizationCode, innerException) 24 | { 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/DataException.cs: -------------------------------------------------------------------------------- 1 | using Ccshis.Util; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Ccshis 7 | { 8 | /// 9 | /// ccshis系统数据异常类 10 | /// 11 | /// 12 | /// author:catdemon 13 | /// data:2019-05-14 14 | /// opt:create 15 | /// 16 | public class DataException:CoreException 17 | { 18 | public DataException(string message = SystemConst.EmptyString, string localizationCode = SystemConst.ValueIsEmpty, Exception innerException = null) 19 | : base(message, localizationCode, innerException) 20 | { 21 | } 22 | 23 | public DataException(Enum[] messageCode = null, Enum[] localizationCode = null, Exception innerException = null) 24 | : base(messageCode, localizationCode,innerException) 25 | { 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/Util/IdentifiedGenerateService.cs: -------------------------------------------------------------------------------- 1 | using Ccshis.Cluster; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using Snowflake.Core; 6 | using System.Collections.Concurrent; 7 | using System.Threading.Tasks; 8 | 9 | namespace Ccshis.Util 10 | { 11 | public class IdentifiedGenerateService : IIdentifiedGenerateService 12 | { 13 | IdWorker _idWorker; 14 | 15 | public IdentifiedGenerateService(IClusterService clusterService) 16 | { 17 | if(clusterService==null||clusterService.ServerMember==null) 18 | { 19 | throw new SysException(ExcpetionCode.EX1100000.ToString(), Localization.Sy000000.ToString()); 20 | } 21 | 22 | _idWorker = new IdWorker(clusterService.ServerMember.Id, 1); 23 | } 24 | 25 | public long GetIdentified() 26 | { 27 | return _idWorker.NextId(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ExceptionlessExtend/ComponentServiceExtend.cs: -------------------------------------------------------------------------------- 1 | using ECommon.Configurations; 2 | using Exceptionless; 3 | using System; 4 | 5 | namespace Ccshis.ExceptionlessExtend 6 | { 7 | public static class ComponentServiceExtend 8 | { 9 | public static IComponentService UseExceptionless(this IComponentService componentService, ExceptionlessSetting exceptionlessSetting) 10 | { 11 | initExceptionless(exceptionlessSetting); 12 | 13 | componentService.RegisterAssembly(typeof(ComponentManagerExtend).Assembly); 14 | return componentService; 15 | } 16 | 17 | private static void initExceptionless(ExceptionlessSetting exceptionlessSetting) 18 | { 19 | //TODO这里修改 20 | ExceptionlessClient.Default.Configuration.ApiKey = exceptionlessSetting.ApiKey; 21 | ExceptionlessClient.Default.Configuration.ServerUrl = exceptionlessSetting.ServerUrl; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/Information/ComponentServiceExtend.cs: -------------------------------------------------------------------------------- 1 | namespace Ccshis.Information.Email 2 | { 3 | /// 4 | /// 注册使用电子邮件组件,系统所有发的邮件,都由该组件提供 5 | /// 6 | /// 7 | /// author:catdemon 8 | /// data:2019-05-15 9 | /// opt:create 10 | /// 11 | /// 12 | /// componentService.UseEmail(emailSetting); 13 | /// 14 | public static class ComponentServiceExtend 15 | { 16 | /// 17 | /// 注册使用电子邮件组件 18 | /// 19 | /// IComponentService 20 | /// 发件邮箱配置项 21 | /// 22 | public static IComponentService UseEmail(this IComponentService componentService) 23 | { 24 | componentService.RegisterAssembly(typeof(ComponentServiceExtend).Assembly); 25 | return componentService; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Test/Ccshis.ConsulExtend.Test/Ccshis.ServiceDiscovery.ConsulExtend.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | 6 | false 7 | 8 | Ccshis.ConsulExtend.Test 9 | 10 | Ccshis.ConsulExtend.Test 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ConsulExtend/MicServerSetting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.ConsulComponent 6 | { 7 | 8 | public class MicServerSetting 9 | { 10 | /// 11 | /// 默认端口号 12 | /// 13 | public const int DefaultPort = 80; 14 | 15 | /// 16 | /// 注册id 17 | /// 18 | public long Id { get; set; } 19 | 20 | /// 21 | /// 微服务器健康url地址,例如http://127.0.0.1 22 | /// 23 | public string Url { get; set; } 24 | 25 | /// 26 | /// 端口号,默认60 27 | /// 28 | public int Port { get; set; } = DefaultPort; 29 | 30 | /// 31 | /// 注册服务名 32 | /// 33 | public string Name { get; set; } 34 | 35 | /// 36 | /// 注册标签 37 | /// 38 | public string[] Tags { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 智选云开发平台 ## 2 | 3 | 响应github针对华为,已转到码云,码云地址见下 4 | https://gitee.com/cheetahing2017/ccshis 5 | 6 | **智选云开发平台** 基于ddd(领域驱动设计)+cqrs(命令查询职责分离)+micservice(微服务)的开发框架,在使用该架构时,你需要提前了解以上开发方式。 7 | 8 | ### 架构特点 ### 9 | 10 | - 微服务 11 | - 分布式 12 | - 高并发 13 | - 横向扩容 14 | - saas平台化 15 | - 多租户云化 16 | - iot物联网化 17 | - 容器化 18 | - 平台可监控 19 | - 多语言 20 | 21 | ### 技术要点 ### 22 | - .net core,c#语言 23 | - autoface,ico注入 24 | - castle,aop切面 25 | - docker,部署 26 | - enode,cqrs框架 27 | - equeue,消息队列 28 | - mongodb 29 | - redis 30 | - mysql 31 | - ocelot,微服务网关 32 | - consul,服务发现与配置中心 33 | - Skywalking,调用链路追踪 34 | - Quzrtz.net core,任务管理 35 | - exceptionless,分布式日志 36 | - WebApiClient.JIT,微服务RPC调用 37 | - swagger,API调试组件 38 | - singlR,websocket双向通行 39 | - 阿里云短信sms 40 | - 阿里对象存储oss 41 | - 集成微信公从号 42 | - 集成微信小程序 43 | - 集成微信支付 44 | - 集成阿里支付 45 | - 集成阿里云 46 | 47 | 48 | ### 项目结构图 ### 49 | ![avatar](https://raw.githubusercontent.com/cheetahing/Ccshis/master/Document/%E5%B7%A5%E7%A8%8B%E7%BB%93%E6%9E%84%E6%9E%B6%E6%9E%84%E5%9B%BE.png) 50 | 51 | copyright 智选云® [www.ccshis.com](http://www.ccshis.com) 52 | -------------------------------------------------------------------------------- /Shared/Ccshis.Shared/Localization.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | /// 8 | /// 多语言管理类 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// date:2019-5-20 13 | /// Sy000000-Sy999999为系统级别 14 | /// Fi000000-Fi999999为常用字段名 15 | /// Xx000000-Xx999999为x微服务 16 | /// Xx000000-Xx999999为x微服务 17 | /// Xx000000-Xx999999为x微服务 18 | /// 19 | public enum Localization 20 | { 21 | #region Sy000000-Sy999999为系统级别 22 | /// 23 | /// Yes 是 24 | /// 25 | Sy000000, 26 | 27 | /// 28 | /// No 否 29 | /// 30 | Sy000001, 31 | 32 | /// 33 | /// Ok 确定 34 | /// 35 | Sy000002, 36 | 37 | /// 38 | /// cancel 取消 39 | /// 40 | Sy000003 41 | #endregion 42 | 43 | #region Fi000000-Fi999999为常用字段名 44 | 45 | #endregion 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Cluster/IServerMember.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Text; 5 | 6 | namespace Ccshis.Cluster 7 | { 8 | /// 9 | /// 服务节点 10 | /// 11 | public interface IServerMember 12 | { 13 | /// 14 | /// 服务器Id 15 | /// 16 | long Id { get; } 17 | 18 | /// 19 | /// 虚拟化类型 20 | /// 21 | Virtualization Virtualization { get; } 22 | 23 | /// 24 | /// 服务器地址 25 | /// 26 | IPAddress IPAddress { get; } 27 | 28 | /// 29 | /// 服务器名称 30 | /// 31 | string Name { get; } 32 | 33 | /// 34 | /// 服务器组 35 | /// 36 | string GroupName { get;} 37 | 38 | /// 39 | /// 服务器标签 40 | /// 41 | string[] Tags { get;} 42 | 43 | /// 44 | /// 备注 45 | /// 46 | string Remark { get; } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Shared/Shared.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28803.452 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ccshis.Shared", "Ccshis.Shared\Ccshis.Shared.csproj", "{DD9E0939-B581-4886-AC36-3D9F34FC0784}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {DD9E0939-B581-4886-AC36-3D9F34FC0784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {DD9E0939-B581-4886-AC36-3D9F34FC0784}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {DD9E0939-B581-4886-AC36-3D9F34FC0784}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {DD9E0939-B581-4886-AC36-3D9F34FC0784}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {08077019-D35E-4E62-B3C9-6DEB071A6040} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/AuthorizeExcpetion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis 6 | { 7 | /// 8 | /// catdemon 2019-5-4 9 | /// 权限身份认证异常 10 | /// 当平台发生权限验证失败时,抛出该异常信息 11 | /// 12 | /// 13 | /// author:catdemon 14 | /// data:2019-05-14 15 | /// opt:create 16 | /// 17 | public class AuthorizeExcpetion:CoreException 18 | { 19 | /// 20 | /// catdemon 2019-5-4 21 | /// 权限身份认证异常 22 | /// 23 | /// 异常消息 24 | /// 多语言编码 25 | /// 内部异常 26 | public AuthorizeExcpetion(string message = SystemConst.EmptyString, string localizationCode = SystemConst.ValueIsEmpty, Exception innerException = null) 27 | : base(message, localizationCode,innerException) 28 | { 29 | 30 | } 31 | public AuthorizeExcpetion(Enum[] messageCode = null, Enum[] localizationCode = null, Exception innerException = null) 32 | : base(messageCode, localizationCode, innerException) 33 | { 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ConsulExtend/ConsulConfigurationService.cs: -------------------------------------------------------------------------------- 1 | using Consul; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Ccshis.ConsulComponent 9 | { 10 | /// 11 | /// 配置中心 12 | /// 13 | public class ConsulConfigurationService : IConfigurationService 14 | { 15 | private IConsulClient _consulClien; 16 | 17 | public ConsulConfigurationService(IConsulClient consulClient) 18 | { 19 | _consulClien = consulClient; 20 | } 21 | 22 | public async Task GetAsync(string key) where T:class,ISetting 23 | { 24 | return JsonConvert.DeserializeObject(await GetAsync(key)); 25 | } 26 | 27 | 28 | public async Task GetAsync(string key) 29 | { 30 | return await GetConfigByConsul(key); 31 | } 32 | 33 | public async Task GetConfigByConsul(string key) 34 | { 35 | var result = await _consulClien.KV.Get(key); 36 | var list = await _consulClien.KV.List("test/"); 37 | return Encoding.UTF8.GetString(result.Response.Value); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Test/Ccshis.ConsulExtend.Test/DefaultConfiguationServiceTest.cs: -------------------------------------------------------------------------------- 1 | using BaseTest; 2 | using ECommon.Components; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.IO; 8 | 9 | namespace Ccshis.ConsulExtend.Test 10 | { 11 | public class DefaultConfiguationServiceTest:BaseTestClass 12 | { 13 | [Test] 14 | public void TestGet() 15 | { 16 | this.componentService 17 | .UseDefaultConfigurationService() 18 | .BuildContainer(); 19 | 20 | var fileName = "test.json"; 21 | var fileContext = "testFielContext"; 22 | //var filePath = Path.Combine(DefaultConfiguationService.DefaultPath,fileName); 23 | 24 | //set configFile 25 | var fileConfigurationService = ObjectContainer.Resolve(); 26 | fileConfigurationService.SetAsync(fileName,fileContext); 27 | 28 | //get configFile 29 | var configurationService=ObjectContainer.Resolve(); 30 | var result=configurationService.GetAsync(fileName).GetAwaiter().GetResult(); 31 | 32 | Assert.AreEqual(fileContext, result); 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Information/Ccshis.Information.Sms.Ali/SmsInformation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Information.Sms.Ali 6 | { 7 | /// 8 | /// 阿里云短信模板 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// data:2019-05-15 13 | /// opt:create 14 | /// 15 | public class SmsInformation:IInformation 16 | { 17 | /// 18 | /// 短信模板编码 19 | /// 20 | public string TemplateCode { get; set; } 21 | 22 | /// 23 | /// 短信签名 24 | /// 25 | public string SignName { get; set; } 26 | 27 | /// 28 | /// 发送信息的内容 29 | /// 30 | string IInformation.Body { get; set; } 31 | 32 | 33 | /// 34 | /// 模板参数,json格式字符串 35 | /// 36 | /// 37 | /// {'cdoe':'12345'} 38 | /// 39 | public string TemplateParam 40 | { 41 | get 42 | { 43 | return (this as IInformation).Body; 44 | } 45 | set 46 | { 47 | (this as IInformation).Body = value; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/CoreException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Linq; 5 | using Ccshis.Util; 6 | 7 | namespace Ccshis 8 | { 9 | /// 10 | /// ccshis系统核心异常类 11 | /// 12 | /// 13 | /// author:catdemon 14 | /// data:2019-05-14 15 | /// opt:create 16 | /// 17 | public class CoreException:Exception 18 | { 19 | /// 20 | /// 多语言编号 21 | /// 22 | public string LocalizationCode { get; private set; } 23 | 24 | /// 25 | /// 核心异常类 26 | /// 27 | /// 28 | /// 异常消息 29 | /// 多语言编码 30 | /// 内部异常 31 | public CoreException(string message= SystemConst.EmptyString, string localizationCode= SystemConst.ValueIsEmpty, Exception innerException=null) 32 | :base(message,innerException) 33 | { 34 | this.LocalizationCode = localizationCode; 35 | } 36 | 37 | public CoreException(Enum[] messageCode=null, Enum[] localizationCode=null, Exception innerException = null) 38 | : base(StringUtil.SplitJoint(messageCode), innerException) 39 | { 40 | LocalizationCode = StringUtil.SplitJoint(localizationCode); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Information/Ccshis.Information.Sms.Ali/ComponentServiceExtend.cs: -------------------------------------------------------------------------------- 1 | using Ccshis.Settings; 2 | using ECommon.Configurations; 3 | 4 | namespace Ccshis.Information.Sms.Ali 5 | { 6 | /// 7 | /// 注册使用阿里云短信 8 | /// 9 | /// 10 | /// author:catdemon 11 | /// data:2019-05-15 12 | /// opt:create 13 | /// 14 | /// 15 | /// componentService.UseAliSms(aliSmsSetting); 16 | /// 17 | public static class ComponentServiceExtend 18 | { 19 | /// 20 | /// 注册使用阿里云短信组件 21 | /// 22 | /// IComponentService 23 | /// 阿里云配置 24 | /// 25 | public static IComponentService UseAliSms(this IComponentService componentService) 26 | { 27 | componentService.SetDefault(); 28 | 29 | componentService.RegisterAssembly(typeof(ComponentServiceExtend).Assembly); 30 | return componentService; 31 | } 32 | 33 | public static IComponentService InitializeAliSms(this IComponentService componentService,AliYunApiSetting aliYunApiSetting) 34 | { 35 | var smsSender=ComponentContainer.Resolve(); 36 | return componentService; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/Util/StringUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.Util 6 | { 7 | /// 8 | /// 字符串处理工具类 9 | /// 10 | /// 11 | /// author:catdemon 12 | /// date:2019-5-23 13 | /// 14 | public static class StringUtil 15 | { 16 | private const string _default_splitChar = ","; 17 | 18 | /// 19 | /// 把数组对象拼接为字符串,使用默认obj.ToString()转为字符串 20 | /// 21 | /// 数组对象 22 | /// 拼接字符串,默认为逗号"," 23 | /// 拼接后字符串 24 | public static string SplitJoint(object[] objArray,string splitChar= _default_splitChar) 25 | { 26 | return SplitJoint(objArray, splitChar, p => p.ToString()); 27 | } 28 | 29 | /// 30 | /// 把数组对象拼接为字符串,使用默认objToStringAction委托把对象转为字符串 31 | /// 32 | /// 数组对象 33 | /// 拼接字符串 34 | /// 返回拼接后字符串 35 | /// 拼接后字符串 36 | public static string SplitJoint(object[] objArray, string splitChar,Func objToStringAction) 37 | { 38 | StringBuilder result = new StringBuilder(); 39 | foreach (var item in objArray) 40 | { 41 | result.Append($"{objToStringAction(item)}{splitChar}"); 42 | } 43 | return result.Remove(result.Length - 1, 1).ToString(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/ComponentServiceExtend.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ECommon.Configurations; 5 | using Ccshis.Cluster; 6 | 7 | namespace Ccshis 8 | { 9 | public static class ComponentServiceExtend 10 | { 11 | /// 12 | /// 使用autofac作为依赖注入组件 13 | /// 14 | /// 15 | /// 16 | public static IComponentService UseAutofac(this IComponentService componentService) 17 | { 18 | var componentServiceImpl = componentService as ComponentService; 19 | componentServiceImpl.ComponentsConfiguration.UseAutofac(); 20 | 21 | return componentService; 22 | } 23 | 24 | /// 25 | /// 使用通用模块 26 | /// 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// author:catdemon 32 | /// date:2019-5-21 33 | /// 34 | public static IComponentService UseCommonComponent(this IComponentService componentService, string defaultPath = DefaultConfiguationService.DefaultPath) 35 | { 36 | //文件配置 37 | componentService.SetDefault(new DefaultConfiguationService(defaultPath)); 38 | 39 | //集群组件 40 | componentService.SetDefault(); 41 | 42 | return componentService; 43 | } 44 | 45 | /// 46 | /// 使用默认配置中心,生产环境不建议使用该方法,请使用配置中心 47 | /// 48 | /// 49 | /// 50 | /// 51 | public static IComponentService UseDefaultConfigurationService(this IComponentService componentService,string defaultPath= DefaultConfiguationService.DefaultPath) 52 | { 53 | //使用默认配置中心 54 | componentService.SetDefault(new DefaultConfiguationService(defaultPath)); 55 | 56 | 57 | return componentService; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ConsulExtend/HealthCheckSetting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Ccshis.ConsulComponent 6 | { 7 | 8 | /// 9 | /// 微服务健康检查,采用http或tcp方式进行健康检查 10 | /// 11 | public class HealthCheckSetting 12 | { 13 | /// 14 | /// 默认健康检查路径,默认值api/ServerHealthCheck 15 | /// 16 | public const string DefaultCheckPath = "api/ServerHealthCheck"; 17 | 18 | /// 19 | /// 默认健康检查端口,默认值80 20 | /// 21 | public const int DefaultPort = 80; 22 | 23 | /// 24 | /// 默认延迟注册到服务中心时间,默认值5秒 25 | /// 26 | public const int DefaultDeregisterCriticalServiceAfter = 5; 27 | 28 | /// 29 | /// 默认健康检查时间间隔,默认值10秒 30 | /// 31 | public const int DefaultHeathInterval = 10; 32 | 33 | /// 34 | /// 默认超时时间,默认值5秒 35 | /// 36 | public const int DefaultTimeOut = 5; 37 | 38 | /// 39 | /// 检查路径,默认api/health 40 | /// 41 | public string CheckPath { get; set; } = DefaultCheckPath; 42 | 43 | /// 44 | /// 端口号 45 | /// 46 | public int Port { get; set; } = DefaultPort; 47 | 48 | /// 49 | /// 健康检查tcp地址,如果不填,默认使用MicServerSetting的http地址 50 | /// 51 | public string TcpAddress { get; set; } 52 | 53 | /// 54 | /// 服务启动后延迟注册秒数,默认5秒后注册 55 | /// 56 | /// 57 | /// 由于启动后,服务不是马上可用,在初始化注册中心后,延迟指定的秒数让服务器有充分的启动时间 58 | /// 59 | public int DeregisterCriticalServiceAfter { get; set; } = DefaultDeregisterCriticalServiceAfter; 60 | 61 | /// 62 | /// 健康检查(心跳)的秒数,单位秒,默认10秒 63 | /// 64 | /// 65 | /// 微服务,每隔一定的时候间隔向注册中心发送心跳,告诉注册中心微服务还可用 66 | /// 67 | public int HeathInterval { get; set; } = DefaultHeathInterval; 68 | 69 | /// 70 | /// 心跳检测地址,例如:http://localhost:51606/api/health 71 | /// 72 | public string HeathUrl { get; set; } 73 | 74 | /// 75 | /// 超时时间,单位秒,默认5秒 76 | /// 77 | public int TimeOut { get; set; } = DefaultTimeOut; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/Cluster/ClusterService.cs: -------------------------------------------------------------------------------- 1 | using Ccshis.Settings.Cluster; 2 | using ECommon.Components; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Ccshis.Cluster 8 | { 9 | [Component] 10 | public class ClusterService : IClusterService 11 | { 12 | /// 13 | /// 当前服务器所在集群内的成员信息 14 | /// 15 | /// 16 | /// author:catdemon 17 | /// date:2019-5-21 18 | /// 19 | public IServerMember ServerMember { get; private set; } 20 | 21 | private IFileConfigurationService _fileConfigurationService; 22 | 23 | public ClusterService(IFileConfigurationService fileConfigurationService) 24 | { 25 | _fileConfigurationService = fileConfigurationService; 26 | } 27 | 28 | /// 29 | /// 加入集群 30 | /// 31 | /// 32 | /// 33 | /// 34 | public IServerMember JoinCluster(string clusterServerIp, IServerMember serverMember) 35 | { 36 | //todo 37 | /* 38 | * 调用集群组件,注册服务,并获取分配到的服务器IServerMember.Id 39 | * IServerMember.Id作为雪花算法的服务器节点id 40 | */ 41 | var serverMemberInstance = serverMember as ServerMember; 42 | 43 | //模拟服务器分配的节点id 44 | var config = _fileConfigurationService.GetAsync(SettingsPath.ServerMemberSettingPath); 45 | if (config == null) 46 | { 47 | #warning 随机分配一个节点id,需要使用集群管理进行分配 48 | /*后期需要修改为,跟服务器通信,然后再分配服务器集群成员id*/ 49 | serverMemberInstance.Id = new System.Random().Next(1000); 50 | } 51 | else 52 | { 53 | serverMemberInstance.Id = config.Id; 54 | } 55 | 56 | ServerMember = serverMemberInstance as IServerMember; 57 | 58 | return ServerMember; 59 | } 60 | 61 | /// 62 | /// 离开集群 63 | /// 64 | /// 65 | /// 66 | /// 67 | public IServerMember QuitCluster(string clusterServerIp, IServerMember member) 68 | { 69 | //todo 退出服务 70 | throw new NotImplementedException(); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/ComponentService.cs: -------------------------------------------------------------------------------- 1 | using ECommon.Components; 2 | using ECommon.Configurations; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace Ccshis 9 | { 10 | /// 11 | /// 组件管理器,用于管理所有第三方组件的引入 12 | /// 13 | /// 14 | /// author:catdemon 15 | /// data:2019-05-16 16 | /// opt:create 17 | /// remark: 18 | /// 使用ecomom的容器管理类,详细参见本类的接口里说明 19 | /// 20 | [Component] 21 | public class ComponentService : IComponentService 22 | { 23 | private List _assembliesList = new List(); 24 | 25 | public static IComponentService SingleInstance; 26 | 27 | /// 28 | /// enode配置组件 29 | /// 30 | public Configuration ComponentsConfiguration { get; set; } 31 | 32 | private ComponentService() { } 33 | 34 | public static IComponentService Create() 35 | { 36 | var componentService = new ComponentService(); 37 | componentService.ComponentsConfiguration = Configuration.Create(); 38 | 39 | SingleInstance = componentService as IComponentService; 40 | return SingleInstance; 41 | } 42 | 43 | public void RegisterAssembly(Assembly assembly) 44 | { 45 | _assembliesList.Add(assembly); 46 | } 47 | 48 | public Configuration BuildContainer() 49 | { 50 | return ComponentsConfiguration.BuildContainer(); 51 | } 52 | public Configuration RegisterCommonComponents() 53 | { 54 | //todo 初始化通用组件 55 | return ComponentsConfiguration.RegisterCommonComponents(); 56 | } 57 | public Configuration RegisterUnhandledExceptionHandler() 58 | { 59 | return ComponentsConfiguration.RegisterUnhandledExceptionHandler(); 60 | } 61 | public Configuration SetDefault(string serviceName = null, LifeStyle life = LifeStyle.Singleton) 62 | where TService : class 63 | where TImplementer : class, TService 64 | { 65 | return ComponentsConfiguration.SetDefault(serviceName, life); 66 | } 67 | public Configuration SetDefault(TImplementer instance, string serviceName = null) 68 | where TService : class 69 | where TImplementer : class, TService 70 | { 71 | return ComponentsConfiguration.SetDefault(instance, serviceName); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Infrastructure/Ccshis/IComponentService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Reflection; 5 | using ECommon.Configurations; 6 | using ECommon.Components; 7 | 8 | namespace Ccshis 9 | { 10 | /// 11 | /// 组件及容器管理器 12 | /// 13 | /// 14 | /// author:catdemon 15 | /// data:2019-5-16 16 | /// opt:create 17 | /// remark: 18 | /// 引入ecommon的ioc容器管理,ecommon ioc容器抽象一层容器管理器无关的配置类。 19 | /// 由于ecommon中容器管理是单例,不允许继承,架构把他的方法重新实现了一遍。 20 | /// 目前整个架构容器管理器默认使用autofac 21 | /// 22 | public interface IComponentService 23 | { 24 | 25 | void RegisterAssembly(Assembly assembly); 26 | 27 | 28 | #region ecommon ioc容器管理的相关方法 29 | /// 30 | /// 造告整个容器 31 | /// 32 | /// 33 | Configuration BuildContainer(); 34 | 35 | /// 36 | /// 注册默认公共组件 37 | /// 38 | /// 39 | /// 40 | /// author:catdemon 41 | /// data:2019-5-16 42 | /// opt:create 43 | /// 44 | Configuration RegisterCommonComponents(); 45 | 46 | Configuration RegisterUnhandledExceptionHandler(); 47 | 48 | /// 49 | /// 设置默认的组件 50 | /// 51 | /// 组件接口 52 | /// 组件实现类 53 | /// 组件名称 54 | /// 生命周期,默认为单例 55 | /// 56 | /// 57 | /// author:catdemon 58 | /// data:2019-5-16 59 | /// opt:create 60 | /// 61 | Configuration SetDefault(string serviceName = null, LifeStyle life = LifeStyle.Singleton) 62 | where TService : class 63 | where TImplementer : class, TService; 64 | 65 | /// 66 | /// 设置默认的组件 67 | /// 68 | /// 组件接口 69 | /// 组件实现类 70 | /// 组件实例 71 | /// 组件名称 72 | /// 73 | /// 74 | /// author:catdemon 75 | /// data:2019-5-16 76 | /// opt:create 77 | /// 78 | Configuration SetDefault(TImplementer instance, string serviceName = null) 79 | where TService : class 80 | where TImplementer : class, TService; 81 | #endregion 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/ComponentContainer.cs: -------------------------------------------------------------------------------- 1 | using ECommon.Components; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Ccshis 7 | { 8 | /// 9 | /// 组件容器 10 | /// 11 | /// 12 | /// author:catdemon 13 | /// date:2019-5-17 14 | /// remark: 15 | /// 引用ecommon的容器管理,ecommon使用了autofac容器管理器 16 | /// 为了避免ecommon的重构或变更引起框架变更,这里做了一层解耦 17 | /// 18 | public class ComponentContainer 19 | { 20 | public static void Build() 21 | { 22 | ObjectContainer.Build(); 23 | } 24 | 25 | public static void RegisterType(Type implementationType, string serviceName = null, LifeStyle life = LifeStyle.Singleton) 26 | { 27 | ObjectContainer.RegisterType(implementationType, serviceName, life); 28 | } 29 | 30 | public static void RegisterType(Type serviceType, Type implementationType, string serviceName = null, LifeStyle life = LifeStyle.Singleton) 31 | { 32 | ObjectContainer.RegisterType(serviceType,implementationType, serviceName,life); 33 | } 34 | 35 | public static TService Resolve() where TService : class 36 | { 37 | return ObjectContainer.Resolve(); 38 | } 39 | 40 | public static object Resolve(Type serviceType) 41 | { 42 | return ObjectContainer.Resolve(serviceType); 43 | } 44 | 45 | public static TService ResolveNamed(string serviceName) where TService : class 46 | { 47 | return ObjectContainer.ResolveNamed(serviceName); 48 | } 49 | 50 | public static object ResolveNamed(string serviceName, Type serviceType) 51 | { 52 | return ObjectContainer.ResolveNamed(serviceName, serviceType); 53 | } 54 | 55 | public static bool TryResolve(out TService instance) where TService : class 56 | { 57 | return ObjectContainer.TryResolve(out instance); 58 | } 59 | 60 | public static bool TryResolve(Type serviceType, out object instance) 61 | { 62 | return ObjectContainer.TryResolve(serviceType, out instance); 63 | } 64 | 65 | public static bool TryResolveNamed(string serviceName, Type serviceType, out object instance) 66 | { 67 | return ObjectContainer.TryResolveNamed(serviceName, serviceType,out instance); 68 | } 69 | 70 | public static void Register(string serviceName, LifeStyle life) 71 | where TService : class 72 | where TImplementer : class, TService 73 | { 74 | ObjectContainer.Register(serviceName, life); 75 | } 76 | 77 | public void RegisterInstance(TImplementer instance, string serviceName) 78 | where TService : class 79 | where TImplementer : class, TService 80 | { 81 | ObjectContainer.RegisterInstance(instance, serviceName); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ExceptionlessExtend/log4net.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.ConsulExtend/ComponentServiceExtend.cs: -------------------------------------------------------------------------------- 1 | using Consul; 2 | using System; 3 | 4 | namespace Ccshis.ConsulComponent 5 | { 6 | public static class ComponentServiceExtend 7 | { 8 | private static ConsulClient _consulClient; 9 | private static ConsulServerSetting _consulServerSetting; 10 | private static MicServerSetting _micServerSetting; 11 | private static HealthCheckSetting _healthCheckSetting; 12 | 13 | 14 | #region consul 15 | public static IComponentService UseConsul(this IComponentService componentService, ConsulServerSetting consulServerSetting) 16 | { 17 | _consulServerSetting = consulServerSetting; 18 | //初始化 19 | initializeConsulClient(componentService); 20 | 21 | //组件注册到容器中 22 | componentService.SetDefault(_consulClient); 23 | 24 | componentService.RegisterAssembly(typeof(ComponentServiceExtend).Assembly); 25 | 26 | return componentService; 27 | } 28 | 29 | /// 30 | /// 初始化consul客户端 31 | /// 32 | /// 33 | private static void initializeConsulClient(IComponentService componentService) 34 | { 35 | /* 36 | * 创建Consul客户端 37 | */ 38 | ConsulClientConfiguration consulClientConfiguration = new ConsulClientConfiguration() 39 | { 40 | Address = new Uri($"{_consulServerSetting.Url}:{_consulServerSetting.Port}") 41 | }; 42 | _consulClient = new ConsulClient(x => x = consulClientConfiguration);//请求注册的 Consul 地址 43 | } 44 | 45 | /// 46 | /// 取消组件注册 47 | /// 48 | /// 49 | /// 50 | public static IComponentService CloseConsul(this IComponentService componentService) 51 | { 52 | _consulClient.Agent.ServiceDeregister(_micServerSetting.Id.ToString()).Wait();//服务停止时取消注册 53 | return componentService; 54 | } 55 | #endregion 56 | 57 | #region 服务发现 58 | /// 59 | /// 初始化服务发现 60 | /// 61 | /// componentService 62 | /// 服务发现配置 63 | /// 64 | public static IComponentService InitializeServiceDiscovery(this IComponentService componentService, MicServerSetting micServerSetting, HealthCheckSetting healthCheckSetting) 65 | { 66 | _micServerSetting = micServerSetting; 67 | _healthCheckSetting = healthCheckSetting; 68 | 69 | /* 70 | * 设置健康检查 71 | */ 72 | var httpCheck = new AgentServiceCheck() 73 | { 74 | DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(_healthCheckSetting.DeregisterCriticalServiceAfter),//服务启动多久后注册 75 | Interval = TimeSpan.FromSeconds(_healthCheckSetting.HeathInterval),//健康检查时间间隔,或者称为心跳间隔 76 | HTTP = $"{_healthCheckSetting.HeathUrl}:{_healthCheckSetting.Port}{_healthCheckSetting.CheckPath}",//健康检查地址 77 | Timeout = TimeSpan.FromSeconds(_healthCheckSetting.TimeOut) 78 | }; 79 | 80 | /* 81 | * 注册微信服信息 82 | */ 83 | var registration = new AgentServiceRegistration() 84 | { 85 | Checks = new[] { httpCheck }, 86 | ID = _micServerSetting.Id.ToString(), 87 | Name = _micServerSetting.Name, 88 | Address = _micServerSetting.Url, 89 | Port = _micServerSetting.Port, 90 | Tags = _micServerSetting.Tags 91 | }; 92 | 93 | _consulClient.Agent.ServiceRegister(registration).Wait();//服务启动时注册,内部实现其实就是使用 Consul API 进行注册(HttpClient发起) 94 | 95 | return componentService; 96 | } 97 | #endregion 98 | 99 | #region 配置中心 100 | /// 101 | /// 初始化配置中心 102 | /// 103 | /// 104 | /// 105 | /// 106 | public static IComponentService UseConsulConfiguationCenter(this IComponentService componentService) 107 | { 108 | //注册ConsulConfigurationService组件 109 | componentService.SetDefault(); 110 | 111 | return componentService; 112 | } 113 | 114 | #endregion 115 | 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Component/DefaultConfigurationService.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Ccshis 9 | { 10 | /// 11 | /// 默认配置服务,默认采用文件配置方式 12 | /// 13 | public class DefaultConfiguationService : IConfigurationService,IFileConfigurationService 14 | { 15 | 16 | public const string DefaultPath = "ConfigurationSetting"; 17 | 18 | private Dictionary _cache = new Dictionary(); 19 | 20 | /// 21 | /// 默认配置路径 22 | /// 23 | private readonly string _filePath; 24 | 25 | /// 26 | /// 默认配置的路径,如果包含盘符则是绝对路径,如果以\开头则表示相对程序路径。所有的配置文件都存在该路径下 27 | /// 28 | /// 文件路径 29 | public DefaultConfiguationService(string filePath) 30 | { 31 | _filePath = filePath; 32 | } 33 | 34 | /// 35 | /// 读取配置文件,key为文件的路径 36 | /// 37 | /// 配置对象 38 | /// 配置相对DefaultPath路径 39 | /// 配置项 40 | /// 41 | /// authro:catdemon 42 | /// date:2019-5-20 43 | /// 44 | public async Task GetAsync(string key) where T : class, ISetting 45 | { 46 | //从缓存获取key 47 | if (_cache.ContainsKey(key)) 48 | { 49 | return _cache[key] as T; 50 | } 51 | 52 | string filePath = getFilePath(key); 53 | 54 | if(!File.Exists(filePath)) 55 | { 56 | return null; 57 | } 58 | 59 | var fileContent = await GetAsync(filePath); 60 | var setting = JsonConvert.DeserializeObject(fileContent); 61 | 62 | _cache[key] = setting; 63 | 64 | return setting; 65 | } 66 | 67 | /// 68 | /// 读取配置文件,key为文件的路径 69 | /// 70 | /// 配置相对DefaultPath路径 71 | /// 配置项 72 | /// 73 | /// authro:catdemon 74 | /// date:2019-5-20 75 | /// 76 | public async Task GetAsync(string key) 77 | { 78 | return await Task.Run(() => 79 | { 80 | return File.ReadAllText(getFilePath(key)); 81 | }); 82 | } 83 | 84 | /// 85 | /// 设置配置 86 | /// 87 | /// 88 | /// 89 | /// 90 | /// 91 | /// 92 | /// author:catdemon 93 | /// date:2019-5-21 94 | /// 95 | public async Task SetAsync(string key, T value) where T:class,ISetting 96 | { 97 | await SetAsync(key, JsonConvert.SerializeObject(value)); 98 | } 99 | 100 | /// 101 | /// 设置配置 102 | /// 103 | /// 104 | /// 105 | /// 106 | /// 107 | /// author:catdemon 108 | /// date:2019-5-21 109 | /// 110 | public async Task SetAsync(string key, string value) 111 | { 112 | var filePath = getFilePath(key); 113 | 114 | await Task.Run(() => 115 | { 116 | createFile(filePath); 117 | 118 | File.WriteAllText(filePath, value); 119 | }); 120 | } 121 | 122 | /// 123 | /// 如果配置文件不存在,则创建配置文件 124 | /// 125 | /// 126 | /// 127 | /// author:catdemon 128 | /// date:2019-5-21 129 | /// 130 | private void createFile(string filePath) 131 | { 132 | if (!File.Exists(filePath)) 133 | { 134 | var dir = Path.GetDirectoryName(filePath); 135 | Directory.CreateDirectory(dir); 136 | using (var filr = File.Create(filePath)) { } 137 | } 138 | } 139 | 140 | /// 141 | /// 获取文件路径 142 | /// 143 | /// 144 | /// 145 | private string getFilePath(string key) 146 | { 147 | return Path.Combine(_filePath, key); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /Infrastructure/Component/Ccshis.Information/Ccshis.Information.Sms.Ali/SmsSender.cs: -------------------------------------------------------------------------------- 1 | using Aliyun.Acs.Core; 2 | using Aliyun.Acs.Core.Exceptions; 3 | using Aliyun.Acs.Core.Http; 4 | using Aliyun.Acs.Core.Profile; 5 | using Ccshis.Settings; 6 | using Ccshis.Util; 7 | using ECommon.Components; 8 | using ECommon.Logging; 9 | using Newtonsoft.Json; 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | using System.Threading.Tasks; 14 | 15 | namespace Ccshis.Information.Sms.Ali 16 | { 17 | [Component] 18 | public class SmsSender : ISmsSender 19 | { 20 | private const string _aliApiDomain = "dysmsapi.aliyuncs.com"; 21 | private const string _aliApiVersion = "2017-05-25"; 22 | private const string _AliApiAction = "SendSms"; 23 | private const string _ApiResult_OK = "OK"; 24 | 25 | private const string _profile_default = "default"; 26 | 27 | private const string _param_PhoneNumbers = "PhoneNumbers"; 28 | private const string _param_SignName = "SignName"; 29 | private const string _param_TemplateCode = "TemplateCode"; 30 | private const string _param_TemplateParam = "TemplateParam"; 31 | 32 | private const string _splitPhoneNumber = ","; 33 | 34 | private ILogger _logger; 35 | private AliYunApiSetting _aliYunApiSetting; 36 | 37 | public SmsSender(ILoggerFactory loggerFactory) 38 | { 39 | _logger = loggerFactory.Create(GetType().FullName); 40 | } 41 | public SmsSender(AliYunApiSetting aliYunApiSetting) 42 | { 43 | _aliYunApiSetting = aliYunApiSetting; 44 | } 45 | 46 | /// 47 | /// 发送短信 48 | /// 49 | /// 接收者手机号码 50 | /// 信息内容 51 | /// 52 | /// author:catdemon 53 | /// data:2019-05-15 54 | /// opt:create 55 | /// 56 | /// 调用网络错误 57 | /// 阿里云授权异常" 58 | /// 业务异常 59 | public async Task SendAsync(string[] receivers, SmsInformation information) 60 | { 61 | await send(receivers, information); 62 | } 63 | 64 | private async Task send(string[] receivers, SmsInformation information) 65 | { 66 | await Task.Run(() => 67 | { 68 | IClientProfile profile = DefaultProfile.GetProfile(_profile_default, _aliYunApiSetting.accessKeyId, _aliYunApiSetting.secret); 69 | DefaultAcsClient client = new DefaultAcsClient(profile); 70 | CommonRequest request = new CommonRequest(); 71 | 72 | request.Method = MethodType.POST; 73 | request.Domain = _aliApiDomain; 74 | request.Version = _aliApiVersion; 75 | request.Action = _AliApiAction; 76 | // request.Protocol = ProtocolType.HTTP; 77 | 78 | string phoneNumbers = StringUtil.SplitJoint(receivers); 79 | 80 | request.AddQueryParameters(_param_PhoneNumbers, phoneNumbers); 81 | request.AddQueryParameters(_param_SignName, information.SignName); 82 | request.AddQueryParameters(_param_TemplateCode, information.TemplateCode); 83 | request.AddQueryParameters(_param_TemplateParam, information.TemplateParam); 84 | 85 | try 86 | { 87 | CommonResponse response = client.GetCommonResponse(request); 88 | var apiResult = JsonConvert.DeserializeObject(response.Data); 89 | 90 | if (apiResult.Code != _ApiResult_OK) 91 | { 92 | sendErrorLog(Localization.Sy000100.ToString(), receivers, information); 93 | } 94 | } 95 | catch (ServerException e) 96 | { 97 | sendErrorLog(e.Message, receivers, information); 98 | } 99 | catch (ClientException e) 100 | { 101 | sendErrorLog(e.Message, receivers, information); 102 | } 103 | }); 104 | } 105 | 106 | private void sendErrorLog(string message,string[] receivers, SmsInformation information) 107 | { 108 | _logger.Error(new 109 | { 110 | message = "发送短信失败", 111 | exception = message, 112 | receivers = receivers, 113 | information = information 114 | }); 115 | } 116 | 117 | /// 118 | /// 发送短信 119 | /// 120 | /// 121 | /// 接收者 122 | /// 信息内容 123 | /// 124 | /// author:catdemon 125 | /// data:2019-05-15 126 | /// opt:create 127 | /// remark:显示实现接口 128 | /// 129 | public async Task SendAsync(string oneReceiver, T information) 130 | { 131 | await send(new[] { oneReceiver }, information as SmsInformation); 132 | } 133 | 134 | async Task ISmsSender.SendAsync(string[] receivers, SmsInformation information) 135 | { 136 | await SendAsync(receivers, information); 137 | } 138 | 139 | async Task ISmsSender.SendAsync(string receivers, SmsInformation information) 140 | { 141 | await SendAsync(receivers, information); 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Infrastructure/Infrastructure.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28803.352 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ccshis", "Ccshis\Ccshis.csproj", "{9E61C65E-89DC-481C-B8DB-E71B3B4C6969}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Component", "Component", "{B6BF8B0F-4FF7-460E-8DB7-43193A1B4621}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Ccshis.Information", "Ccshis.Information", "{6ED96D06-54A7-440B-8BB7-459BE55E542D}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ccshis.Information.Sms.Ali", "Component\Ccshis.Information\Ccshis.Information.Sms.Ali\Ccshis.Information.Sms.Ali.csproj", "{ABA025E2-DC04-4C2D-B0A7-79B960784AFC}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Ccshis.Aliyun", "Ccshis.Aliyun", "{34910088-E455-4E35-B06E-204782A4DD1F}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ccshis.Aliyun.LogExtend", "Component\Ccshis.Aliyun\Ccshis.Aliyun.LogExtend\Ccshis.Aliyun.LogExtend.csproj", "{3329A68E-5792-4321-8E26-E65B543CC46E}" 17 | EndProject 18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ccshis.Component", "Component\Ccshis.Component\Ccshis.Component.csproj", "{975356AB-E2DE-48F1-87A1-1F2E07F629D9}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{3BFCA744-B4CD-42F1-86DB-FB7825454A82}" 21 | EndProject 22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ccshis.ConsulComponent", "Component\Ccshis.ConsulExtend\Ccshis.ConsulComponent.csproj", "{55A70C22-4CA4-453D-9B29-3DF2CFB41696}" 23 | EndProject 24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ccshis.ConsulExtend.Test", "..\Test\Ccshis.ConsulExtend.Test\Ccshis.ConsulExtend.Test.csproj", "{8D378D01-BE06-4CB1-ADA3-23623B8D107C}" 25 | EndProject 26 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaseTest", "..\Test\BaseTest\BaseTest.csproj", "{9A9355B2-6DCE-4105-8F7D-3B962561203A}" 27 | EndProject 28 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{EB784FC0-8258-4FD5-89E8-DBD2FE8C0AB2}" 29 | EndProject 30 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ccshis.Shared", "..\Shared\Ccshis.Shared\Ccshis.Shared.csproj", "{2CDB435A-A984-40C3-A9A5-6A5D8BC3EE91}" 31 | EndProject 32 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ccshis.Test", "..\Test\Ccshis.Test\Ccshis.Test.csproj", "{2F55B276-8452-4E37-B28D-5DC31F83B195}" 33 | EndProject 34 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ccshis.QuzrtzExtend", "Component\Ccshis.QuzrtzExtend\Ccshis.QuzrtzExtend.csproj", "{DD33BECA-4001-41B9-8BB3-77F0BDFA9980}" 35 | EndProject 36 | Global 37 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 38 | Debug|Any CPU = Debug|Any CPU 39 | Release|Any CPU = Release|Any CPU 40 | EndGlobalSection 41 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 42 | {9E61C65E-89DC-481C-B8DB-E71B3B4C6969}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {9E61C65E-89DC-481C-B8DB-E71B3B4C6969}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {9E61C65E-89DC-481C-B8DB-E71B3B4C6969}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {9E61C65E-89DC-481C-B8DB-E71B3B4C6969}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {ABA025E2-DC04-4C2D-B0A7-79B960784AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {ABA025E2-DC04-4C2D-B0A7-79B960784AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {ABA025E2-DC04-4C2D-B0A7-79B960784AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {ABA025E2-DC04-4C2D-B0A7-79B960784AFC}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {3329A68E-5792-4321-8E26-E65B543CC46E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {3329A68E-5792-4321-8E26-E65B543CC46E}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {3329A68E-5792-4321-8E26-E65B543CC46E}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {3329A68E-5792-4321-8E26-E65B543CC46E}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {975356AB-E2DE-48F1-87A1-1F2E07F629D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {975356AB-E2DE-48F1-87A1-1F2E07F629D9}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {975356AB-E2DE-48F1-87A1-1F2E07F629D9}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {975356AB-E2DE-48F1-87A1-1F2E07F629D9}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {55A70C22-4CA4-453D-9B29-3DF2CFB41696}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {55A70C22-4CA4-453D-9B29-3DF2CFB41696}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {55A70C22-4CA4-453D-9B29-3DF2CFB41696}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {55A70C22-4CA4-453D-9B29-3DF2CFB41696}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {8D378D01-BE06-4CB1-ADA3-23623B8D107C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {8D378D01-BE06-4CB1-ADA3-23623B8D107C}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {8D378D01-BE06-4CB1-ADA3-23623B8D107C}.Release|Any CPU.ActiveCfg = Release|Any CPU 65 | {8D378D01-BE06-4CB1-ADA3-23623B8D107C}.Release|Any CPU.Build.0 = Release|Any CPU 66 | {9A9355B2-6DCE-4105-8F7D-3B962561203A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 | {9A9355B2-6DCE-4105-8F7D-3B962561203A}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 | {9A9355B2-6DCE-4105-8F7D-3B962561203A}.Release|Any CPU.ActiveCfg = Release|Any CPU 69 | {9A9355B2-6DCE-4105-8F7D-3B962561203A}.Release|Any CPU.Build.0 = Release|Any CPU 70 | {2CDB435A-A984-40C3-A9A5-6A5D8BC3EE91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 71 | {2CDB435A-A984-40C3-A9A5-6A5D8BC3EE91}.Debug|Any CPU.Build.0 = Debug|Any CPU 72 | {2CDB435A-A984-40C3-A9A5-6A5D8BC3EE91}.Release|Any CPU.ActiveCfg = Release|Any CPU 73 | {2CDB435A-A984-40C3-A9A5-6A5D8BC3EE91}.Release|Any CPU.Build.0 = Release|Any CPU 74 | {2F55B276-8452-4E37-B28D-5DC31F83B195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 75 | {2F55B276-8452-4E37-B28D-5DC31F83B195}.Debug|Any CPU.Build.0 = Debug|Any CPU 76 | {2F55B276-8452-4E37-B28D-5DC31F83B195}.Release|Any CPU.ActiveCfg = Release|Any CPU 77 | {2F55B276-8452-4E37-B28D-5DC31F83B195}.Release|Any CPU.Build.0 = Release|Any CPU 78 | {DD33BECA-4001-41B9-8BB3-77F0BDFA9980}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 79 | {DD33BECA-4001-41B9-8BB3-77F0BDFA9980}.Debug|Any CPU.Build.0 = Debug|Any CPU 80 | {DD33BECA-4001-41B9-8BB3-77F0BDFA9980}.Release|Any CPU.ActiveCfg = Release|Any CPU 81 | {DD33BECA-4001-41B9-8BB3-77F0BDFA9980}.Release|Any CPU.Build.0 = Release|Any CPU 82 | EndGlobalSection 83 | GlobalSection(SolutionProperties) = preSolution 84 | HideSolutionNode = FALSE 85 | EndGlobalSection 86 | GlobalSection(NestedProjects) = preSolution 87 | {6ED96D06-54A7-440B-8BB7-459BE55E542D} = {B6BF8B0F-4FF7-460E-8DB7-43193A1B4621} 88 | {ABA025E2-DC04-4C2D-B0A7-79B960784AFC} = {6ED96D06-54A7-440B-8BB7-459BE55E542D} 89 | {34910088-E455-4E35-B06E-204782A4DD1F} = {B6BF8B0F-4FF7-460E-8DB7-43193A1B4621} 90 | {3329A68E-5792-4321-8E26-E65B543CC46E} = {34910088-E455-4E35-B06E-204782A4DD1F} 91 | {975356AB-E2DE-48F1-87A1-1F2E07F629D9} = {B6BF8B0F-4FF7-460E-8DB7-43193A1B4621} 92 | {55A70C22-4CA4-453D-9B29-3DF2CFB41696} = {B6BF8B0F-4FF7-460E-8DB7-43193A1B4621} 93 | {8D378D01-BE06-4CB1-ADA3-23623B8D107C} = {3BFCA744-B4CD-42F1-86DB-FB7825454A82} 94 | {9A9355B2-6DCE-4105-8F7D-3B962561203A} = {3BFCA744-B4CD-42F1-86DB-FB7825454A82} 95 | {2CDB435A-A984-40C3-A9A5-6A5D8BC3EE91} = {EB784FC0-8258-4FD5-89E8-DBD2FE8C0AB2} 96 | {2F55B276-8452-4E37-B28D-5DC31F83B195} = {3BFCA744-B4CD-42F1-86DB-FB7825454A82} 97 | {DD33BECA-4001-41B9-8BB3-77F0BDFA9980} = {B6BF8B0F-4FF7-460E-8DB7-43193A1B4621} 98 | EndGlobalSection 99 | GlobalSection(ExtensibilityGlobals) = postSolution 100 | SolutionGuid = {707A0CCD-84CF-4EDC-9ED1-D785414DE42E} 101 | EndGlobalSection 102 | EndGlobal 103 | --------------------------------------------------------------------------------