示例#1
0
        static RequestTrackerRepository()
        {
            ConfigurationContainer.RegisterJsonListener <RequestTrackerContainer>("RequestTrackerData.json", (container) =>
            {
                var requestTrackerStaticData = new RequestTrackerStaticData()
                {
                    Datas = new Dictionary <string, RequestTracker>()
                };

                requestTrackerStaticData.Global = new RequestTracker()
                {
                    ID         = Guid.NewGuid(),
                    MaxNumber  = container.Global.MaxNumber,
                    RequestKey = ""
                };
                requestTrackerStaticData.Global.Extensions.Add("Strategies", container.Global.Strategies);

                foreach (var item in container.Configuration)
                {
                    var newRequestTracker = new RequestTracker()
                    {
                        ID         = Guid.NewGuid(),
                        MaxNumber  = item.Value.MaxNumber,
                        RequestKey = item.Key
                    };
                    newRequestTracker.Extensions.Add("Strategies", item.Value.Strategies);
                    requestTrackerStaticData.Datas.Add(item.Key, newRequestTracker);
                }

                _requestTrackerStaticData = requestTrackerStaticData;
            });
        }
示例#2
0
 public async Task Exit(RequestTracker tracker)
 {
     //获取所有的策略
     await GetAllStrategies(tracker, async (strategy) =>
     {
         //对每一个策略执行Exit
         await strategy.Exit(tracker);
     });
 }
示例#3
0
        public async Task GetAllStrategies(RequestTracker tracker, Func <TrackerStrategy, Task> callback)
        {
            var strategies = (string[])tracker.Extensions["Strategies"];

            foreach (var item in strategies)
            {
                var strategy = await _trackerStrategyRepository.QueryByName(item);

                if (strategy != null)
                {
                    await callback(strategy);
                }
            }

            await Task.FromResult(0);
        }
示例#4
0
        public async Task <ValidateResult> Access(RequestTracker tracker)
        {
            ValidateResult result = new ValidateResult()
            {
                Result = true
            };

            //获取所有的策略
            await GetAllStrategies(tracker, async (strategy) =>
            {
                //对每一个策略执行Access
                var strategyResult = await strategy.Access(tracker);
                if (!strategyResult.Result)
                {
                    result.Result      = false;
                    result.Description = strategyResult.Description;
                }
            });

            return(result);
        }
示例#5
0
 /// <summary>
 /// 请求退出
 /// </summary>
 /// <param name="tracker"></param>
 /// <returns></returns>
 public async Task Exit(RequestTracker tracker)
 {
     await _imp.Exit(this, tracker);
 }
示例#6
0
 /// <summary>
 /// 请求进入
 /// </summary>
 /// <param name="tracker"></param>
 /// <returns></returns>
 public async Task <ValidateResult> Access(RequestTracker tracker)
 {
     return(await _imp.Access(this, tracker));
 }
示例#7
0
        public async Task Exit(TrackerStrategy trackerStrategy, RequestTracker tracker)
        {
            var service = await GetStrategyService(trackerStrategy.Name);

            await service.Exit(tracker);
        }
示例#8
0
        public async Task <ValidateResult> Access(TrackerStrategy trackerStrategy, RequestTracker tracker)
        {
            var service = await GetStrategyService(trackerStrategy.Name);

            return(await service.Access(tracker));
        }