Beispiel #1
0
        public PipelineConfigItem GetHandlerConfig(Type handlerType)
        {
            handlerType = handlerType ?? throw new ArgumentNullException("Не указан тип обработчика.");

            _cachedHandlerCollection = _cachedHandlerCollection ?? GetConfig() ?? throw new ApplicationException("Не удалось получить конфигурацию.");

            PipelineConfigItem result;

            result = _cachedHandlerCollection.Handlers.FirstOrDefault(h => h.Type == handlerType.AssemblyQualifiedName);
            if (result != null)
            {
                return(result);
            }

            result = _cachedHandlerCollection.Handlers.FirstOrDefault(h => h.Type == handlerType.FullName);
            if (result != null)
            {
                return(result);
            }

            result = _cachedHandlerCollection.Handlers.FirstOrDefault(h => h.Type == handlerType.Name);
            if (result != null)
            {
                return(result);
            }
            throw new ApplicationException($"Не удалось найти конфигурацию для типа {handlerType.AssemblyQualifiedName}");
        }
Beispiel #2
0
        public IHandler GetPipeline()
        {
            var pipeLineHandlres = new List <IHandler>();
            HandlersCollection handlersCollection = _configurationProvider.GetConfig();

            foreach (PipelineConfigItem handler in handlersCollection.Handlers)
            {
                pipeLineHandlres.Add(_handlerFactory.GetHandler(handler));
            }

            if (pipeLineHandlres.Count > 0)
            {
                IHandler pipeline = null;
                pipeLineHandlres.ForEach(h =>
                {
                    if (pipeline != null)
                    {
                        pipeline.Next = h;
                    }
                    pipeline = h;
                });

                return(pipeLineHandlres[0]);
            }
            return(null);
        }
Beispiel #3
0
        public HandlersCollection GetConfig()
        {
            const string fileName = "rules.xml";

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException($"Файл {fileName} не найден.");
            }
            using (var stream = new StreamReader(fileName))
            {
                var serializer = new XmlSerializer(typeof(HandlersCollection));
                _cachedHandlerCollection = (HandlersCollection)serializer.Deserialize(stream);
                return(_cachedHandlerCollection);
            }
        }