Exemplo n.º 1
0
        private InterceptorInfo[] CreateInterceptors(string categoryName)
        {
            var interceptors = new InterceptorInfo[_providers.Count];

            for (int i = 0; i < _providers.Count; i++)
            {
                SetInterceptorInfo(ref interceptors[i], _providers[i], categoryName);
            }

            return(interceptors);
        }
Exemplo n.º 2
0
        public void Add(IInterceptor interceptor, string name, InterceptorRulesBuilder rulesBuilder = null)
        {
            Check.NotNull(interceptor, nameof(interceptor));
            Check.NotEmpty(name, nameof(name));

            if (Interceptors.ContainsKey(name))
            {
                throw new InterceptionException($"Интерсептор '{name}' уже зарегистрирован.");
            }

            var info = new InterceptorInfo {
                Name = name, Interceptor = interceptor, Rules = rulesBuilder?.GetRules()
            };

            _interceptors.Add(name, info);
        }
Exemplo n.º 3
0
        private bool CanExecute(InterceptorInfo info, object sender)
        {
            if (sender is IInterceptable == false)
            {
                return(false);
            }

            if (info.Rules == null || info.Rules.Count == 0)
            {
                return(true);
            }

            var interceptable = (IInterceptable)sender;
            var types         = interceptable.Info.StackTraceTypes;
            var rule          = FindRule(types, info.Rules, sender);

            return(rule == null || rule.RuleType == RuleType.Enable);
        }
Exemplo n.º 4
0
 private void SetInterceptorInfo(ref InterceptorInfo interceptorInfo, IInterceptorProvider provider,
                                 string categoryName)
 {
     interceptorInfo.Interceptor  = provider.CreateInterceptor(categoryName);
     interceptorInfo.ProviderType = provider.GetType();
 }