Beispiel #1
0
        private void CreateHandler(IXDocument doc, DocumentHandlerInfo handlerInfo, List <IDocumentHandler> handlersList)
        {
            var createHandler = false;

            var docType = doc.GetType();

            if (handlerInfo.DocumentTypeFilters == null)
            {
                createHandler = true;
            }
            else
            {
                createHandler = handlerInfo.DocumentTypeFilters.Any(t => t.IsAssignableFrom(docType));
            }

            if (createHandler)
            {
                m_Logger.Log($"Creating document handler '{handlerInfo.HandlerType.FullName}' for document type: {docType}", LoggerMessageSeverity_e.Debug);

                var handler = (IDocumentHandler)handlerInfo.Factory.DynamicInvoke();
                handler.Init(m_App, doc);
                handlersList.Add(handler);
            }
            else
            {
                m_Logger.Log($"Skipping creation of document handler '{handlerInfo.HandlerType.FullName}' for document type: {docType}", LoggerMessageSeverity_e.Debug);
            }
        }
Beispiel #2
0
        public void RegisterHandler <THandler>(Func <THandler> handlerFact) where THandler : IDocumentHandler
        {
            var type = typeof(THandler);

            if (m_Handlers.Any(h => h.HandlerType == type))
            {
                throw new Exception("Handler for this type is already registered");
            }

            Type[] filters = null;

            type.TryGetAttribute <DocumentHandlerFilterAttribute>(a => filters = a.Filters);

            var handlerInfo = new DocumentHandlerInfo(type, filters, handlerFact);

            m_Handlers.Add(handlerInfo);

            foreach (var map in m_DocsMap)
            {
                CreateHandler(map.Key, handlerInfo, map.Value);
            }
        }