Ejemplo n.º 1
0
        public bool HandleException(Exception err, String prefix = "record", bool exceptIfNotHandled = true)
        {
            MaxAddsExceededException mae = err as MaxAddsExceededException;

            if (mae != null)
            {
                throw new MaxAddsExceededException(mae);
            }

            Errors++;
            String pfx = String.IsNullOrEmpty(prefix) ? "_error" : prefix + "/_error";

            Pipeline.HandleValue(this, pfx, err);
            if ((ActionFlags & _ActionFlags.Handled) != 0)
            {
                return(true);
            }

            if (exceptIfNotHandled)
            {
                throw new BMException(err, err.Message);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void Import(PipelineContext ctx)
        {
            Logger importLog  = ctx.ImportLog;
            Logger errorLog   = ctx.ErrorLog;
            bool   stopNeeded = false;

            importLog.Log(_LogType.ltProgress | _LogType.ltTimerStart, "[{0}]: starting import with pipeline {1}, default endpoint={2}, maxadds={3} ", Name, Pipeline.Name, Pipeline.DefaultEndpoint, ctx.MaxAdds);

            Pipeline.Start(ctx);
            Pipeline.HandleValue(ctx, "_datasource/_start", this);
            try
            {
                Datasource.Import(ctx, Pipeline);
                importLog.Log(_LogType.ltProgress | _LogType.ltTimerStop, "[{0}]: raw import ended. Partial stats={1}.", Name, ctx.GetStats());
                stopNeeded = true;
            }

            catch (Exception e)
            {
                ctx.LastError = e;
                if (MaxAddsExceededException.ContainsMaxAddsExceededException(e))
                {
                    stopNeeded      = true;
                    ctx.ErrorState |= _ErrorState.Limited;
                    importLog.Log(_LogType.ltWarning | _LogType.ltTimerStop, "[{0}]: {1}", Name, e.Message);
                    importLog.Log("-- " + ctx.GetStats());
                    if ((ctx.ImportFlags & _ImportFlags.IgnoreLimited) != 0)
                    {
                        importLog.Log(_LogType.ltWarning, "Limited ignored due to importFlags [{0}].", ctx.ImportFlags);
                    }
                    stopNeeded = true;
                }
                else
                {
                    ctx.ErrorState |= _ErrorState.Error;
                    String msg = String.Format("[{0}]: crashed err={1}", Name, e.Message);
                    importLog.Log(_LogType.ltError | _LogType.ltTimerStop, msg);
                    importLog.Log("-- " + ctx.GetStats());
                    errorLog.Log(_LogType.ltError, msg);
                    ctx.ErrorLog.Log(e);
                    if ((ctx.ImportFlags & _ImportFlags.IgnoreErrors) == 0)
                    {
                        throw new BMException(e, "{0}\r\nDatasource={1}.", e.Message, Name);
                    }

                    msg = String.Format("Exception ignored due to importFlags [{0}].", ctx.ImportFlags);
                    importLog.Log(_LogType.ltWarning, msg);
                    errorLog.Log(_LogType.ltWarning, msg);
                    stopNeeded = true;
                }
            }

            finally
            {
                try
                {
                    if (stopNeeded)
                    {
                        ctx.OptSendItemStop();
                        Pipeline.HandleValue(ctx, "_datasource/_stop", this);
                    }
                }
                finally
                {
                    Pipeline.Stop(ctx);
                }
            }
            importLog.Log(_LogType.ltProgress | _LogType.ltTimerStop, "[{0}]: import ended. {1}.", Name, ctx.GetStats());
        }