internal PipelineAction SetAction(PipelineAction act) { //PW handled zou ook globaal uitgezet moeten kunnen worden if (!(act is PipelineNopAction)) { ActionFlags |= _ActionFlags.Handled; } Action = act; return(act); }
private PipelineAction[] createSubActions(Pipeline pipeline, XmlNodeList c) { var ret = new PipelineAction[c.Count]; for (int i = 0; i < c.Count; i++) { XmlElement elt = (XmlElement)c[i]; elt.SetAttribute("key", Name); ret[i] = PipelineAction.Create(pipeline, elt); } return(ret); }
public ActionAdmin(String key, int order, PipelineAction action) { this.Key = key.ToLowerInvariant(); this.KeyLen = this.Key.Length; this.Order = order; this.Action = action; var cond = action as PipelineConditionAction; if (cond != null) { IsCondition = true; ActionsToSkipIfCond = cond.ActionsToSkip; } }
private bool checkTemplates(PipelineContext ctx, String key, ref Object lastTemplate) { PipelineAction a = null; String templateExpr = null; int i; for (i = 0; i < templates.Count; i++) { lastTemplate = templates[i]; a = templates[i].OptCreateAction(ctx, key); if (a != null) { goto ADD_TEMPLATE; } } a = new PipelineNopAction(key); actions.Add(new ActionAdmin(a.Name, actions.Count, a)); prepareActions(); return(false); ADD_TEMPLATE: templateExpr = templates[i].Expr; missed[key] = templateExpr; while (true) { a.Start(ctx); actions.Add(new ActionAdmin(a.Name, actions.Count, a)); i++; if (i >= templates.Count) { break; } if (!templates[i].Expr.Equals(templateExpr, StringComparison.InvariantCultureIgnoreCase)) { break; } a = templates[i].OptCreateAction(ctx, key); if (a == null) { break; } } prepareActions(); return(true); }
} //Only needed for NOP action protected PipelineAction(PipelineAction template, String name, Regex regex) : base(name) { this.Debug = template.Debug; this.ConvertersFirst = template.ConvertersFirst; this.pipeline = template.pipeline; this.node = template.node; this.endpointName = optReplace(regex, name, template.endpointName); this.postProcessors = optReplace(regex, name, template.postProcessors); this.convertersName = optReplace(regex, name, template.convertersName); this.scriptName = optReplace(regex, name, template.scriptName); this.clrvarName = optReplace(regex, name, template.clrvarName); if (this.clrvarName == template.clrvarName) { this.VarsToClear = template.VarsToClear; } else { this.VarsToClear = this.clrvarName.SplitStandard(); } if (template.valueSource != null) { String src = optReplace(regex, name, template.valueSource.Input); if (src == template.valueSource.Input) { valueSource = template.valueSource; } else { valueSource = ValueSource.Parse(src); } } this.valExpr = template.valExpr; this.valExprFunc = template.valExprFunc; this.condExpr = template.condExpr; this.condExprFunc = template.condExprFunc; this.scriptBody = template.scriptBody; this.bodyFunc = template.bodyFunc; updateConvertAndCallScriptNeeded(); }
public static PipelineTemplate Create(Pipeline pipeline, XmlNode node) { var act = PipelineAction.GetActionType(node); switch (act) { case _ActionType.Add: return(new PipelineAddTemplate(pipeline, node)); case _ActionType.Clear: return(new PipelineClearTemplate(pipeline, node)); case _ActionType.Nop: return(new PipelineNopTemplate(pipeline, node)); case _ActionType.OrgField: return(new PipelineFieldTemplate(pipeline, node)); case _ActionType.Field: return(new PipelineFieldTemplate2(pipeline, node)); case _ActionType.Emit: return(new PipelineEmitTemplate(pipeline, node)); case _ActionType.Except: return(new PipelineExceptionTemplate(pipeline, node)); case _ActionType.Del: return(new PipelineDeleteTemplate(pipeline, node)); case _ActionType.Cat: return(new PipelineCategorieTemplate(pipeline, node)); case _ActionType.Cond: return(new PipelineConditionTemplate(pipeline, node)); case _ActionType.CheckExist: return(new PipelineCheckExistTemplate(pipeline, node)); case _ActionType.Forward: return(new PipelineForwardTemplate(pipeline, node)); case _ActionType.Split: return(new PipelineSplitTemplate(pipeline, node)); case _ActionType.EmitVars: return(new PipelineEmitVarsTemplate(pipeline, node)); case _ActionType.Remove: return(new PipelineRemoveAction.Template(pipeline, node)); } act.ThrowUnexpected(); return(null); }
public Object HandleValue(PipelineContext ctx, String key, Object value) { Object orgValue = value; Object ret = null; Object lastAction = null; try { ctx.ActionFlags = 0; if ((ctx.ImportFlags & _ImportFlags.TraceValues) != 0) { logger.Log("HandleValue ({0}, {1} [{2}]", key, value, value == null ? "null" : value.GetType().Name); } if (key == null) { goto EXIT_RTN; } String lcKey = key.ToLowerInvariant(); int keyLen = lcKey.Length; if (ctx.SkipUntilKey != null) { ctx.ActionFlags |= _ActionFlags.Skipped; if (ctx.SkipUntilKey.Length == keyLen && lcKey.Equals(ctx.SkipUntilKey, StringComparison.OrdinalIgnoreCase)) { ctx.SkipUntilKey = null; } goto EXIT_RTN; } int ixStart = findAction(lcKey); if (ixStart < 0) { if (templates.Count == 0 || !checkTemplates(ctx, key, ref lastAction)) //templates==0: otherwise checkTemplates() inserts a NOP action... { missed[lcKey] = null; goto EXIT_RTN; } ixStart = findAction(lcKey); if (ixStart < 0) { goto EXIT_RTN; //Should not happen, just to be sure! } } for (int i = ixStart; i < actions.Count; i++) { ActionAdmin a = actions[i]; if (i > ixStart && !a.EqualToPrev) { break; } lastAction = ctx.SetAction(a.Action); Object tmp = a.Action.HandleValue(ctx, key, value); ClearVariables(a.Action.VarsToClear); if (tmp != null) { ret = tmp; } if ((ctx.ActionFlags & (_ActionFlags.SkipRest | _ActionFlags.ConditionMatched)) != 0) { if ((ctx.ActionFlags & _ActionFlags.ConditionMatched) != 0) { if (!a.IsCondition) { throw new BMException("Action [{0}] is not a condition.", a.Key); } i += a.ActionsToSkipIfCond; continue; } break; } } //Make sure the skipUntil can also be set from the last action in a chain... if (ctx.SkipUntilKey != null && ctx.SkipUntilKey.Length == keyLen && lcKey.Equals(ctx.SkipUntilKey, StringComparison.OrdinalIgnoreCase)) { ctx.SkipUntilKey = null; } EXIT_RTN : return(ret); } catch (Exception e) { String type; if (orgValue == value) { type = String.Format("[{0}]", getType(orgValue)); } else { type = String.Format("[{0}] (was [{1}])", getType(value), getType(orgValue)); } ctx.ErrorLog.Log("Exception while handling event. Key={0}, value type={1}, action={2}", key, type, lastAction); ctx.ErrorLog.Log("-- value={0}", value); if (orgValue != value) { ctx.ErrorLog.Log("-- orgvalue={0}", orgValue); } ctx.ErrorLog.Log(e); PipelineAction act = lastAction as PipelineAction; if (act == null) { ctx.ErrorLog.Log("Cannot dump accu: no current action found."); } else { var accu = (JObject)act.Endpoint.GetFieldAsToken(null); ctx.ErrorLog.Log("Dumping content of current accu: fieldcount={0}", accu.Count); String content = accu.ToString(); if (content != null && content.Length > 1000) { content = content.Substring(0, 1000) + "..."; } ctx.ErrorLog.Log(content); } if (MaxAddsExceededException.ContainsMaxAddsExceededException(e)) { throw; } throw new BMException(e, "{0}\r\nKey={1}, valueType={2}.", e.Message, key, type); } }
public Pipeline(ImportEngine engine, XmlNode node) : base(node) { ImportEngine = engine; logger = engine.DebugLog.Clone("pipeline"); ScriptTypeName = node.ReadStr("@script", null); DefaultConverters = node.ReadStr("@converters", null); DefaultPostProcessors = node.ReadStr("@postprocessors", null); DefaultEndpoint = node.ReadStr("@endpoint", null); if (DefaultEndpoint == null) { if (engine.Endpoints.Count == 1) { DefaultEndpoint = engine.Endpoints[0].Name; } else if (engine.Endpoints.GetByName(Name, false) != null) { DefaultEndpoint = Name; } } trace = node.ReadBool("@trace", false); AdminCollection <PipelineAction> rawActions = new AdminCollection <PipelineAction>(node, "action", (x) => PipelineAction.Create(this, x), false); definedActions = new List <ActionAdmin>(); for (int i = 0; i < rawActions.Count; i++) { var action = rawActions[i]; String[] keys = action.Name.SplitStandard(); for (int k = 0; k < keys.Length; k++) { definedActions.Add(new ActionAdmin(keys[k], i, action)); } } definedActions.Sort(cbSortAction); var templNodes = node.SelectNodes("template"); templates = new List <PipelineTemplate>(templNodes.Count); for (int i = 0; i < templNodes.Count; i++) { templates.Add(PipelineTemplate.Create(this, templNodes[i])); } Dump(""); }