InvokeOnError() private method

private InvokeOnError ( object o, StreamingContext context, Newtonsoft.Json.Serialization.ErrorContext errorContext ) : void
o object
context System.Runtime.Serialization.StreamingContext
errorContext Newtonsoft.Json.Serialization.ErrorContext
return void
Exemplo n.º 1
0
        protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, IJsonLineInfo lineInfo, [Nullable(1)] string path, [Nullable(1)] Exception ex)
        {
            ErrorContext errorContext = this.GetErrorContext(currentObject, keyValue, path, ex);

            if (this.TraceWriter != null && this.TraceWriter.LevelFilter >= TraceLevel.Error && !errorContext.Traced)
            {
                errorContext.Traced = true;
                string text = (base.GetType() == typeof(JsonSerializerInternalWriter)) ? "Error serializing" : "Error deserializing";
                if (contract != null)
                {
                    string str            = text;
                    string str2           = " ";
                    Type   underlyingType = contract.UnderlyingType;
                    text = str + str2 + ((underlyingType != null) ? underlyingType.ToString() : null);
                }
                text = text + ". " + ex.Message;
                if (!(ex is JsonException))
                {
                    text = JsonPosition.FormatMessage(lineInfo, path, text);
                }
                this.TraceWriter.Trace(TraceLevel.Error, text, ex);
            }
            if (contract != null && currentObject != null)
            {
                contract.InvokeOnError(currentObject, this.Serializer.Context, errorContext);
            }
            if (!errorContext.Handled)
            {
                this.Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));
            }
            return(errorContext.Handled);
        }
Exemplo n.º 2
0
        protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, IJsonLineInfo lineInfo, string path, Exception ex)
        {
            ErrorContext errorContext = this.GetErrorContext(currentObject, keyValue, path, ex);

            if (this.TraceWriter != null && this.TraceWriter.LevelFilter >= TraceLevel.Error && !errorContext.Traced)
            {
                errorContext.Traced = true;
                string text = this._serializing ? "Error serializing" : "Error deserializing";
                if (contract != null)
                {
                    text = text + " " + contract.UnderlyingType;
                }
                text = text + ". " + ex.Message;
                if (!(ex is JsonException))
                {
                    text = JsonPosition.FormatMessage(lineInfo, path, text);
                }
                this.TraceWriter.Trace(TraceLevel.Error, text, ex);
            }
            if (contract != null && currentObject != null)
            {
                contract.InvokeOnError(currentObject, this.Serializer.Context, errorContext);
            }
            if (!errorContext.Handled)
            {
                this.Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));
            }
            return(errorContext.Handled);
        }
        protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, IJsonLineInfo lineInfo, string path, Exception ex)
        {
            ErrorContext errorContext = this.GetErrorContext(currentObject, keyValue, path, ex);

            if (this.TraceWriter != null && this.TraceWriter.LevelFilter >= TraceLevel.Error && !errorContext.Traced)
            {
                errorContext.Traced = true;
                string str = (this.GetType() == typeof(JsonSerializerInternalWriter) ? "Error serializing" : "Error deserializing");
                if (contract != null)
                {
                    str = string.Concat(str, " ", contract.UnderlyingType);
                }
                str = string.Concat(str, ". ", ex.Message);
                if (!(ex is JsonException))
                {
                    str = JsonPosition.FormatMessage(lineInfo, path, str);
                }
                this.TraceWriter.Trace(TraceLevel.Error, str, ex);
            }
            if (contract != null && currentObject != null)
            {
                contract.InvokeOnError(currentObject, this.Serializer.Context, errorContext);
            }
            if (!errorContext.Handled)
            {
                this.Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));
            }
            return(errorContext.Handled);
        }
        protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, IJsonLineInfo lineInfo, string path, Exception ex)
        {
            ErrorContext errorContext = this.GetErrorContext(currentObject, keyValue, path, ex);

            if (((this.TraceWriter != null) && (this.TraceWriter.LevelFilter >= TraceLevel.Error)) && !errorContext.Traced)
            {
                errorContext.Traced = true;
                string message = (base.GetType() == typeof(JsonSerializerInternalWriter)) ? "Error serializing" : "Error deserializing";
                if (contract != null)
                {
                    message = message + " " + contract.UnderlyingType;
                }
                message = message + ". " + ex.Message;
                if (!(ex is JsonException))
                {
                    message = JsonPosition.FormatMessage(lineInfo, path, message);
                }
                this.TraceWriter.Trace(TraceLevel.Error, message, ex);
            }
            if ((contract != null) && (currentObject != null))
            {
                contract.InvokeOnError(currentObject, this.Serializer.Context, errorContext);
            }
            if (!errorContext.Handled)
            {
                this.Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));
            }
            return(errorContext.Handled);
        }
    protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, Exception ex)
    {
      ErrorContext errorContext = GetErrorContext(currentObject, keyValue, ex);
      contract.InvokeOnError(currentObject, Serializer.Context, errorContext);

      if (!errorContext.Handled)
        Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));

      return errorContext.Handled;
    }
Exemplo n.º 6
0
        protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, Exception ex)
        {
            ErrorContext errorContext = GetErrorContext(currentObject, keyValue, ex);

            contract.InvokeOnError(currentObject, Serializer.Context, errorContext);
            if (!errorContext.Handled)
            {
                Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));
            }
            return(errorContext.Handled);
        }
Exemplo n.º 7
0
        protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, string path, Exception ex)
        {
            ErrorContext errorContext = this.GetErrorContext(currentObject, keyValue, path, ex);

            if (contract != null)
            {
                contract.InvokeOnError(currentObject, this.Serializer.Context, errorContext);
            }
            if (!errorContext.Handled)
            {
                this.Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));
            }
            return(errorContext.Handled);
        }
Exemplo n.º 8
0
        protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, IJsonLineInfo lineInfo, string path, Exception ex)
        {
            ErrorContext errorContext = GetErrorContext(currentObject, keyValue, path, ex);

#if HAVE_TRACE_WRITER
            if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Error && !errorContext.Traced)
            {
                // only write error once
                errorContext.Traced = true;

                // kind of a hack but meh. might clean this up later
                string message = (GetType() == typeof(JsonSerializerInternalWriter)) ? "Error serializing" : "Error deserializing";
                if (contract != null)
                {
                    message += " " + contract.UnderlyingType;
                }
                message += ". " + ex.Message;

                // add line information to non-json.net exception message
                if (!(ex is JsonException))
                {
                    message = JsonPosition.FormatMessage(lineInfo, path, message);
                }

                TraceWriter.Trace(TraceLevel.Error, message, ex);
            }
#endif
#if HAVE_RUNTIME_SERIALIZATION
            // attribute method is non-static so don't invoke if no object
            if (contract != null && currentObject != null)
            {
                contract.InvokeOnError(currentObject, Serializer.Context, errorContext);
            }
#endif

            if (!errorContext.Handled)
            {
                Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));
            }

            return(errorContext.Handled);
        }
        protected bool IsErrorHandled(object currentObject, JsonContract contract, object keyValue, IJsonLineInfo lineInfo, string path, Exception ex)
        {
            ErrorContext errorContext = GetErrorContext(currentObject, keyValue, path, ex);

            if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Error && !errorContext.Traced)
            {
                // only write error once
                errorContext.Traced = true;

                string message = (_serializing) ? "Error serializing" : "Error deserializing";
                if (contract != null)
                {
                    message += " " + contract.UnderlyingType;
                }
                message += ". " + ex.Message;

                // add line information to non-json.net exception message
                if (!(ex is JsonException))
                {
                    message = JsonPosition.FormatMessage(lineInfo, path, message);
                }

                TraceWriter.Trace(TraceLevel.Error, message, ex);
            }

            // attribute method is non-static so don't invoke if no object
            if (contract != null && currentObject != null)
            {
                contract.InvokeOnError(currentObject, Serializer.Context, errorContext);
            }

            if (!errorContext.Handled)
            {
                Serializer.OnError(new ErrorEventArgs(currentObject, errorContext));
            }

            return(errorContext.Handled);
        }