Ejemplo n.º 1
0
        private Dictionary <string, BaseProcessor> InitializeProcessors()
        {
            F2BSection          config     = F2B.Config.Instance;
            ProcessorCollection processors = config.Processors;

            Dictionary <string, BaseProcessor> ret = new Dictionary <string, BaseProcessor>();

            // create processors
            for (int i = 0; i < processors.Count; i++)
            {
                ProcessorElement processor = processors[(int)i];

                // test invalid configuration
                if (processor.Name == null || processor.Name == "")
                {
                    throw new Exception("Undefined processor #" + (processors.Count + 1) + " name");
                }
                if (ret.ContainsKey(processor.Name))
                {
                    throw new Exception("Duplicate processor name: " + processor.Name);
                }

                // add reference to next processor name
                if (i < processors.Count - 1)
                {
                    string nextName = processors[(int)(i + 1)].Name;
                    if (processor.Goto.Next == string.Empty)
                    {
                        processor.Goto.Next = nextName;
                    }
                    if (processor.Goto.Error == string.Empty)
                    {
                        if (processor.Goto.OnErrorNext)
                        {
                            processor.Goto.Error = nextName;
                        }
                        else
                        {
                            processor.Goto.Error = null;
                        }
                    }
                    if (processor.Goto.Success == string.Empty)
                    {
                        processor.Goto.Success = nextName;
                    }
                    if (processor.Goto.Failure == string.Empty)
                    {
                        processor.Goto.Failure = nextName;
                    }
                }

                // create processor
                string clazzName = "F2B.processors." + processor.Type + "Processor";
                Type   clazzType = Type.GetType(clazzName); // + "`1[F2B.ProcessorElement]");

                if (clazzType == null)
                {
                    Log.Error("processor[" + processor.Name + "@" + processor.Type
                              + "]: unable to resolve class \"" + clazzName + "\"");
                }
                else if (clazzType.IsSubclassOf(typeof(BoolProcessor)))
                {
                    Log.Info("processor[" + processor.Name + "@" + processor.Type
                             + "]: next->" + processor.Goto.Next
                             + ", error->" + processor.Goto.Error
                             + ", success->" + processor.Goto.Success
                             + ", failure->" + processor.Goto.Failure);
                }
                else
                {
                    Log.Info("processor[" + processor.Name + "@" + processor.Type
                             + "]: next->" + processor.Goto.Next
                             + ", error->" + processor.Goto.Error);
                }

                //ConstructorInfo ctor = clazzType.GetConstructor(new[] { typeof(ProcessorElement), typeof(Action<EventEntry, string, bool>) });
                //ret[processor.Name] = (BaseProcessor)ctor.Invoke(new object[] { processor, Delegate.CreateDelegate(GetType(), this, "Produce") });
                ConstructorInfo ctor = clazzType.GetConstructor(new[] { typeof(ProcessorElement), GetType() });
                ret[processor.Name] = (BaseProcessor)ctor.Invoke(new object[] { processor, this });
            }

            return(ret);
        }
Ejemplo n.º 2
0
        protected override object GetElementKey(ConfigurationElement element)
        {
            ProcessorElement pe = element as ProcessorElement;

            return(pe.Name);
        }