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); }
private Dictionary <string, BaseInput> InitializeInputs(EventQueue queue) { F2BSection config = F2B.Config.Instance; InputCollection inputs = config.Inputs; SelectorCollection selectors = config.Selectors; ProcessorCollection processors = config.Processors; string firstProcName = null; if (processors.Count > 0) { firstProcName = processors[0].Name; } Dictionary <string, BaseInput> ret = new Dictionary <string, BaseInput>(); // create log data sources and selectors foreach (InputElement input in inputs) { Log.Info("input[" + input.Name + "]"); if (string.IsNullOrEmpty(input.Name)) { Log.Warn("input[" + input.Name + "] undefined input name"); continue; } foreach (SelectorElement selector in selectors) { if (!string.IsNullOrEmpty(selector.InputName) && selector.InputName != input.Name) { continue; } if (!string.IsNullOrEmpty(selector.InputType) && selector.InputType != input.Type) { continue; } // create input string clazzName = "F2B.inputs." + input.Type + "Input"; Type clazzType = Type.GetType(clazzName); if (clazzType == null) { Log.Error("input[" + input.Name + "]/selector[" + selector.Name + "]: unable to resolve class \"" + clazzName + "\""); } else { Log.Info("input[" + input.Name + "]/selector[" + selector.Name + "]: creating new " + clazzName + " input"); } ConstructorInfo ctor = clazzType.GetConstructor( new[] { typeof(InputElement), typeof(SelectorElement), typeof(EventQueue) }); BaseInput logInput = (BaseInput)ctor.Invoke(new object[] { input, selector, queue }); ret[input.Name + "/" + selector.Name] = logInput; } } return(ret); }