Example #1
0
        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);
            }
        }