Ejemplo n.º 1
0
 public RedisInternalConfigurationRepository(CzarOcelotConfiguration options, IFileConfigurationRepository fileConfigurationRepository, IInternalConfigurationCreator internalConfigurationCreator, IOcelotCache <InternalConfiguration> ocelotCache)
 {
     _fileConfigurationRepository  = fileConfigurationRepository;
     _internalConfigurationCreator = internalConfigurationCreator;
     _options     = options;
     _ocelotCache = ocelotCache;
 }
 public CzarClientRateLimitProcessor(CzarOcelotConfiguration options, IClientRateLimitRepository clientRateLimitRepository, IOcelotCache <CzarClientRateLimitCounter?> clientRateLimitCounter, IOcelotCache <ClientRoleModel> ocelotCache, IOcelotCache <RateLimitRuleModel> rateLimitRuleCache)
 {
     _options = options;
     _clientRateLimitRepository = clientRateLimitRepository;
     _clientRateLimitCounter    = clientRateLimitCounter;
     _ocelotCache        = ocelotCache;
     _rateLimitRuleCache = rateLimitRuleCache;
 }
 public CzarClientRateLimitMiddleware(OcelotRequestDelegate next,
                                      IOcelotLoggerFactory loggerFactory,
                                      IClientRateLimitProcessor clientRateLimitProcessor,
                                      CzarOcelotConfiguration options)
     : base(loggerFactory.CreateLogger <CzarClientRateLimitMiddleware>())
 {
     _next = next;
     _clientRateLimitProcessor = clientRateLimitProcessor;
     _options = options;
 }
 public CzarAuthenticationMiddleware(OcelotRequestDelegate next,
                                     IOcelotLoggerFactory loggerFactory,
                                     ICzarAuthenticationProcessor ahphAuthenticationProcessor,
                                     CzarOcelotConfiguration options)
     : base(loggerFactory.CreateLogger <CzarAuthenticationMiddleware>())
 {
     _next = next;
     _ahphAuthenticationProcessor = ahphAuthenticationProcessor;
     _options = options;
 }
Ejemplo n.º 5
0
 public CzarCacheController(IClientAuthenticationRepository clientAuthenticationRepository, CzarOcelotConfiguration options,
                            IFileConfigurationRepository fileConfigurationRepository,
                            IInternalConfigurationCreator internalConfigurationCreator,
                            IClientRateLimitRepository clientRateLimitRepository,
                            IRpcRepository rpcRepository,
                            IMemoryCache cache)
 {
     _clientAuthenticationRepository = clientAuthenticationRepository;
     _options = options;
     _fileConfigurationRepository  = fileConfigurationRepository;
     _internalConfigurationCreator = internalConfigurationCreator;
     _clientRateLimitRepository    = clientRateLimitRepository;
     _rpcRepository = rpcRepository;
     _cache         = cache;
 }
Ejemplo n.º 6
0
 public InRedisCache(CzarOcelotConfiguration options)
 {
     _options = options;
     CSRedis.CSRedisClient csredis;
     if (options.RedisConnectionStrings.Count == 1)
     {
         //普通模式
         csredis = new CSRedis.CSRedisClient(options.RedisConnectionStrings[0]);
     }
     else
     {
         //集群模式
         //实现思路:根据key.GetHashCode() % 节点总数量,确定连向的节点
         //也可以自定义规则(第一个参数设置)
         csredis = new CSRedis.CSRedisClient(null, options.RedisConnectionStrings.ToArray());
     }
     //初始化 RedisHelper
     RedisHelper.Initialization(csredis);
 }
Ejemplo n.º 7
0
 public RedisInternalConfigurationRepository(CzarOcelotConfiguration options, IFileConfigurationRepository fileConfigurationRepository, IInternalConfigurationCreator internalConfigurationCreator)
 {
     _fileConfigurationRepository  = fileConfigurationRepository;
     _internalConfigurationCreator = internalConfigurationCreator;
     _options = options;
     CSRedis.CSRedisClient csredis;
     if (options.RedisConnectionStrings.Count == 1)
     {
         //普通模式
         csredis = new CSRedis.CSRedisClient(options.RedisConnectionStrings[0]);
     }
     else
     {
         //集群模式
         //实现思路:根据key.GetHashCode() % 节点总数量,确定连向的节点
         //也可以自定义规则(第一个参数设置)
         csredis = new CSRedis.CSRedisClient(null, options.RedisConnectionStrings.ToArray());
     }
     //初始化 RedisHelper
     RedisHelper.Initialization(csredis);
 }
        /// <summary>
        /// 添加默认的注入方式,所有需要传入的参数都是用默认值
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IOcelotBuilder AddCzarOcelot(this IOcelotBuilder builder, Action <CzarOcelotConfiguration> option)
        {
            //builder.Services.Configure(option);
            ////配置信息
            //builder.Services.AddSingleton(
            //    resolver => resolver.GetRequiredService<IOptions<CzarOcelotConfiguration>>().Value);
            var options = new CzarOcelotConfiguration();

            builder.Services.AddSingleton(options);
            option?.Invoke(options);
            //配置文件仓储注入
            builder.Services.AddSingleton <IFileConfigurationRepository, SqlServerFileConfigurationRepository>();
            builder.Services.AddSingleton <IClientAuthenticationRepository, SqlServerClientAuthenticationRepository>();
            builder.Services.AddSingleton <IClientRateLimitRepository, SqlServerClientRateLimitRepository>();
            builder.Services.AddSingleton <IRpcRepository, SqlServerRpcRepository>();
            //注册后端服务
            builder.Services.AddHostedService <DbConfigurationPoller>();
            //使用Redis重写缓存
            builder.Services.AddSingleton <IOcelotCache <FileConfiguration>, InRedisCache <FileConfiguration> >();
            builder.Services.AddSingleton <IOcelotCache <CachedResponse>, InRedisCache <CachedResponse> >();
            builder.Services.AddSingleton <IInternalConfigurationRepository, RedisInternalConfigurationRepository>();
            builder.Services.AddSingleton <IOcelotCache <ClientRoleModel>, InRedisCache <ClientRoleModel> >();
            builder.Services.AddSingleton <IOcelotCache <RateLimitRuleModel>, InRedisCache <RateLimitRuleModel> >();
            builder.Services.AddSingleton <IOcelotCache <RemoteInvokeMessage>, InRedisCache <RemoteInvokeMessage> >();
            builder.Services.AddSingleton <IOcelotCache <CzarClientRateLimitCounter?>, InRedisCache <CzarClientRateLimitCounter?> >();
            //注入授权
            builder.Services.AddSingleton <ICzarAuthenticationProcessor, CzarAuthenticationProcessor>();
            //注入限流实现
            builder.Services.AddSingleton <IClientRateLimitProcessor, CzarClientRateLimitProcessor>();

            //重写错误状态码
            builder.Services.AddSingleton <IErrorsToHttpStatusCodeMapper, CzarErrorsToHttpStatusCodeMapper>();

            //http输出转换类
            builder.Services.AddSingleton <IHttpResponder, CzarHttpContextResponder>();

            //Rpc应用
            builder.Services.AddSingleton <ICzarRpcProcessor, CzarRpcProcessor>();
            return(builder);
        }
Ejemplo n.º 9
0
 public CzarMemoryCache(CzarOcelotConfiguration options, IMemoryCache cache)
 {
     _options = options;
     _cache   = cache;
 }
        /// <summary>
        /// 添加默认的注入方式,所有需要传入的参数都是用默认值
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IOcelotBuilder AddCzarOcelot(this IServiceCollection builder, Action <CzarOcelotConfiguration> option)
        {
            var options = new CzarOcelotConfiguration();

            builder.AddSingleton(options);
            option?.Invoke(options);

            //配置文件仓储注入
            builder.AddSingleton <IFileConfigurationRepository, SqlServerFileConfigurationRepository>();
            builder.AddSingleton <IClientAuthenticationRepository, SqlServerClientAuthenticationRepository>();
            builder.AddSingleton <IClientRateLimitRepository, SqlServerClientRateLimitRepository>();

            //注册后端服务
            builder.AddHostedService <DbConfigurationPoller>();
            builder.AddMemoryCache(); //添加本地缓存
            #region 启动Redis缓存,并支持普通模式 官方集群模式  哨兵模式 分区模式
            if (options.ClusterEnvironment)
            {
                //默认使用普通模式
                var csredis = new CSRedis.CSRedisClient(options.RedisConnectionString);
                switch (options.RedisStoreMode)
                {
                case RedisStoreMode.Partition:
                    var NodesIndex = options.RedisSentinelOrPartitionConStr;
                    Func <string, string> nodeRule = null;
                    csredis = new CSRedis.CSRedisClient(nodeRule, options.RedisSentinelOrPartitionConStr);
                    break;

                case RedisStoreMode.Sentinel:
                    csredis = new CSRedis.CSRedisClient(options.RedisConnectionString, options.RedisSentinelOrPartitionConStr);
                    break;
                }
                //初始化 RedisHelper
                RedisHelper.Initialization(csredis);
            }
            #endregion
            builder.AddSingleton <IOcelotCache <FileConfiguration>, CzarMemoryCache <FileConfiguration> >();
            builder.AddSingleton <IOcelotCache <InternalConfiguration>, CzarMemoryCache <InternalConfiguration> >();
            builder.AddSingleton <IOcelotCache <CachedResponse>, CzarMemoryCache <CachedResponse> >();
            builder.AddSingleton <IInternalConfigurationRepository, RedisInternalConfigurationRepository>();
            builder.AddSingleton <IOcelotCache <ClientRoleModel>, CzarMemoryCache <ClientRoleModel> >();
            builder.AddSingleton <IOcelotCache <RateLimitRuleModel>, CzarMemoryCache <RateLimitRuleModel> >();
            builder.AddSingleton <IOcelotCache <RemoteInvokeMessage>, CzarMemoryCache <RemoteInvokeMessage> >();
            builder.AddSingleton <IOcelotCache <CzarClientRateLimitCounter?>, CzarMemoryCache <CzarClientRateLimitCounter?> >();
            //注入授权
            builder.AddSingleton <ICzarAuthenticationProcessor, CzarAuthenticationProcessor>();
            //注入限流实现
            builder.AddSingleton <IClientRateLimitProcessor, CzarClientRateLimitProcessor>();

            //重写错误状态码
            builder.AddSingleton <IErrorsToHttpStatusCodeMapper, CzarErrorsToHttpStatusCodeMapper>();

            //http输出转换类
            builder.AddSingleton <IHttpResponder, CzarHttpContextResponder>();

            var service       = builder.First(x => x.ServiceType == typeof(IConfiguration));
            var configuration = (IConfiguration)service.ImplementationInstance;
            //Rpc应用
            builder.AddSingleton <ICzarRpcProcessor, CzarRpcProcessor>();
            builder.AddSingleton <IRpcRepository, SqlServerRpcRepository>();
            builder.AddLibuvTcpClient(configuration);

            return(new OcelotBuilder(builder, configuration));
        }
Ejemplo n.º 11
0
 public CzarRpcProcessor(IRpcRepository rpcRepository, CzarOcelotConfiguration options, IOcelotCache <RemoteInvokeMessage> ocelotCache)
 {
     _rpcRepository = rpcRepository;
     _options       = options;
     _ocelotCache   = ocelotCache;
 }
Ejemplo n.º 12
0
 public CzarAuthenticationProcessor(IClientAuthenticationRepository clientAuthenticationRepository, CzarOcelotConfiguration options, IOcelotCache <ClientRoleModel> ocelotCache)
 {
     _clientAuthenticationRepository = clientAuthenticationRepository;
     _options     = options;
     _ocelotCache = ocelotCache;
 }
 public MySqlClientRateLimitRepository(CzarOcelotConfiguration option)
 {
     _option = option;
 }
Ejemplo n.º 14
0
 public SqlServerFileConfigurationRepository(CzarOcelotConfiguration option)
 {
     _option = option;
 }
Ejemplo n.º 15
0
 public MySqlFileConfigurationRepository(CzarOcelotConfiguration option)
 {
     _option = option;
 }
Ejemplo n.º 16
0
 public MySqlClientAuthenticationRepository(CzarOcelotConfiguration option)
 {
     _option = option;
 }