private static void ReadRegisterTransform(XmlNode node, RewriterConfiguration config)
        {
            // Type attribute.
            XmlNode typeNode = node.Attributes[Constants.AttrTransform];

            if (typeNode == null)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrTransform), node);
            }

            if (node.ChildNodes.Count > 0)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister), node);
            }

            // Transform type specified.  Create an instance and add it
            // as the mapper handler for this map.
            IRewriteTransform handler = TypeHelper.Activate(typeNode.Value, null) as IRewriteTransform;

            if (handler != null)
            {
                config.TransformFactory.AddTransform(handler);
            }
            else
            {
                // TODO: Error due to type.
            }
        }
Beispiel #2
0
        private static void ReadErrorHandler(XmlNode node, IRewriterConfiguration config)
        {
            var code = node.GetRequiredAttribute(Constants.AttrCode);

            XmlNode typeNode = node.Attributes[Constants.AttrType];
            XmlNode urlNode  = node.Attributes[Constants.AttrUrl];

            if (typeNode == null && urlNode == null)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrUrl), node);
            }

            IRewriteErrorHandler handler;

            if (typeNode != null)
            {
                // <error-handler code="500" url="/oops.aspx" />
                handler = TypeHelper.Activate(typeNode.Value, null) as IRewriteErrorHandler;
                if (handler == null)
                {
                    throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidTypeSpecified, typeNode.Value, typeof(IRewriteErrorHandler)), node);
                }
            }
            else
            {
                handler = new DefaultErrorHandler(urlNode.Value);
            }

            if (!int.TryParse(code, out var statusCode))
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidHttpStatusCode, code), node);
            }

            config.ErrorHandlers.Add(statusCode, handler);
        }
        private static void ReadErrorHandler(XmlNode node, RewriterConfiguration config)
        {
            XmlNode codeNode = node.Attributes[Constants.AttrCode];

            if (codeNode == null)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrCode), node);
            }

            XmlNode typeNode = node.Attributes[Constants.AttrType];
            XmlNode urlNode  = node.Attributes[Constants.AttrUrl];

            if (typeNode == null && urlNode == null)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrUrl), node);
            }

            IRewriteErrorHandler handler = null;

            if (typeNode != null)
            {
                // <error-handler code="500" url="/oops.aspx" />
                handler = TypeHelper.Activate(typeNode.Value, null) as IRewriteErrorHandler;
                if (handler == null)
                {
                    throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidTypeSpecified));
                }
            }
            else
            {
                handler = new DefaultErrorHandler(urlNode.Value);
            }

            config.ErrorHandlers.Add(Convert.ToInt32(codeNode.Value), handler);
        }
        private static void ReadRegisterParser(XmlNode node, RewriterConfiguration config)
        {
            XmlNode typeNode = node.Attributes[Constants.AttrParser];

            if (typeNode == null)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrParser), node);
            }

            if (node.ChildNodes.Count > 0)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister), node);
            }

            object parser = TypeHelper.Activate(typeNode.Value, null);
            IRewriteActionParser actionParser = parser as IRewriteActionParser;

            if (actionParser != null)
            {
                config.ActionParserFactory.AddParser(actionParser);
            }

            IRewriteConditionParser conditionParser = parser as IRewriteConditionParser;

            if (conditionParser != null)
            {
                config.ConditionParserPipeline.AddParser(conditionParser);
            }
        }
        private static void ReadRegisterLogger(XmlNode node, RewriterConfiguration config)
        {
            // Type attribute.
            XmlNode typeNode = node.Attributes[Constants.AttrLogger];

            if (typeNode == null)
            {
                throw new ConfigurationErrorsException(
                          MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrLogger),
                          node);
            }

            if (node.ChildNodes.Count > 0)
            {
                throw new ConfigurationErrorsException(
                          MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister),
                          node);
            }

            // Logger type specified.  Create an instance and add it
            // as the mapper handler for this map.
            var logger = TypeHelper.Activate(typeNode.Value, null) as IRewriteLogger;

            if (logger != null)
            {
                config.Logger = logger;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 手动执行task
        /// </summary>
        /// <param name="item"></param>
        private static void ExcuteJobManaul(SystemTaskOfDailyExcutorEntity item)
        {
            DateTime scheduledTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, item.ExcuteHour, item.ExcuteMinute, 0);

            if (DateTime.Now > scheduledTime)
            {
                IJob job = TypeHelper.Activate <IJob>(item.Type);
                if (job != null)
                {
                    job.Execute(null);
                }
            }
        }
Beispiel #7
0
        private static void ReadRegisterLogger(XmlNode node, IRewriterConfiguration config)
        {
            if (node.ChildNodes.Count > 0)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister), node);
            }

            var type = node.GetRequiredAttribute(Constants.AttrLogger);

            // Logger type specified.  Create an instance and add it
            // as the mapper handler for this map.
            if (TypeHelper.Activate(type, null) is IRewriteLogger logger)
            {
                config.Logger = logger;
            }
        }
Beispiel #8
0
        private static void ReadRegisterTransform(XmlNode node, IRewriterConfiguration config)
        {
            if (node.ChildNodes.Count > 0)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister), node);
            }

            var type = node.GetRequiredAttribute(Constants.AttrTransform);

            // Transform type specified.
            // Create an instance and add it as the mapper handler for this map.
            if (!(TypeHelper.Activate(type, null) is IRewriteTransform transform))
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidTypeSpecified, type, typeof(IRewriteTransform)), node);
            }

            config.TransformFactory.Add(transform);
        }
        public void ActivateTest()
        {
            o = TypeHelper.Activate(GetType().Assembly, typeof(A <int, string>).FullName, null, 1, "2");
            Assert.IsNotNull(o);
            A <int, string> a = o as A <int, string>;

            Assert.IsNotNull(a);
            Assert.AreEqual(1, a.F1);
            Assert.AreEqual("2", a.F2);

            o = TypeHelper.Activate(GetType().Assembly, typeof(A <,>).FullName,
                                    new Type[] { typeof(int), typeof(string) }, 1, "2");
            Assert.IsNotNull(o);
            a = o as A <int, string>;
            Assert.IsNotNull(a);
            Assert.AreEqual(1, a.F1);
            Assert.AreEqual("2", a.F2);
        }
Beispiel #10
0
        private static void ReadRegisterParser(XmlNode node, IRewriterConfiguration config)
        {
            if (node.ChildNodes.Count > 0)
            {
                throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister), node);
            }

            var type = node.GetRequiredAttribute(Constants.AttrParser);

            var parser = TypeHelper.Activate(type, null);

            if (parser is IRewriteActionParser actionParser)
            {
                config.ActionParserFactory.Add(actionParser);
            }

            if (parser is IRewriteConditionParser conditionParser)
            {
                config.ConditionParserPipeline.Add(conditionParser);
            }
        }
        public void CreateDummyTypeTest()
        {
            Type t1 = TypeHelper.CreateDummyType("Test1", typeof(object), false);

            Assert.IsNotNull(t1);
            AssertEx.IsPatternMatch(t1.Name, "Test1*");
            TestLog.Info("t1 name: {0}", t1.GetFullName());

            Type t2 = TypeHelper.CreateDummyType("Test2", typeof(object), false);

            Assert.IsNotNull(t2);
            AssertEx.IsPatternMatch(t2.Name, "Test2*");
            TestLog.Info("t2 name: {0}", t2.GetFullName());

            Assert.AreNotEqual(t1, t2);

            Type  listType = typeof(List <>);
            IList list     = (IList)TypeHelper.Activate(listType.Assembly, listType.FullName, new Type[] { t1 }, null);

            TestLog.Info("List<t1> name: {0}", list.GetType().GetFullName());
        }
 /// <summary>
 /// Adds a parser.
 /// </summary>
 /// <param name="parserType">The parser type.</param>
 public void AddParser(string parserType)
 {
     this.AddParser((IRewriteActionParser)TypeHelper.Activate(parserType, null));
 }
Beispiel #13
0
 /// <summary>
 /// Adds a transform.
 /// </summary>
 /// <param name="transformType">The type of the transform.</param>
 public void AddTransform(string transformType)
 {
     AddTransform((IRewriteTransform)TypeHelper.Activate(transformType, null));
 }