コード例 #1
0
        private ExceptionLogManager()
        {
            //Switch the below string to change where your exceptions are logged.
            string logOutputFormat = "html";

            switch (logOutputFormat)
            {
            case "html":
                exceptionWriter = new HTMLExceptionWriter();
                break;

            default:
                exceptionWriter = new HTMLExceptionWriter();
                break;
            }
        }
コード例 #2
0
 /// <summary>
 /// Adds writer
 /// </summary>
 /// <param name="writer">The writer for adding</param>
 public void Add(IExceptionWriter writer)
 {
     write       += writer.Write;
     writeHeader += writer.WriteHeader;
 }
コード例 #3
0
ファイル: ResponseBodyWriter.cs プロジェクト: ash2005/z
        /// <summary>Writes the request body to the specified <see cref="Stream"/>.</summary>
        /// <param name="stream">Stream to write to.</param>
        internal void Write(Stream stream)
        {
            Debug.Assert(stream != null, "stream != null");
            IExceptionWriter exceptionWriter = null;

            try
            {
                switch (this.responseFormat)
                {
                case ContentFormat.Binary:
                    Debug.Assert(
                        this.requestDescription.TargetKind == RequestTargetKind.OpenPropertyValue ||
                        this.requestDescription.TargetKind == RequestTargetKind.PrimitiveValue ||
                        this.requestDescription.TargetKind == RequestTargetKind.MediaResource,
                        this.requestDescription.TargetKind + " is PrimitiveValue or OpenPropertyValue or StreamPropertyValue");

                    BinarySerializer binarySerializer = new BinarySerializer(stream);
                    exceptionWriter = binarySerializer;
                    if (this.requestDescription.TargetKind == RequestTargetKind.MediaResource)
                    {
                        Debug.Assert(this.mediaResourceStream != null, "this.mediaResourceStream != null");

                        binarySerializer.WriteRequest(this.mediaResourceStream, this.service.StreamProvider.StreamBufferSize);
                    }
                    else
                    {
                        binarySerializer.WriteRequest(this.queryResults.Current);
                    }

                    break;

                case ContentFormat.Text:
                    Debug.Assert(
                        this.requestDescription.TargetKind == RequestTargetKind.OpenPropertyValue ||
                        this.requestDescription.TargetKind == RequestTargetKind.PrimitiveValue,
                        this.requestDescription.TargetKind + " is PrimitiveValue or OpenPropertyValue");

                    TextSerializer textSerializer = new TextSerializer(stream, this.encoding);
                    exceptionWriter = textSerializer;
                    textSerializer.WriteRequest(this.queryResults.Current);
                    break;

                case ContentFormat.Atom:
                case ContentFormat.Json:
                case ContentFormat.PlainXml:
                    Debug.Assert(this.requestDescription.TargetKind != RequestTargetKind.PrimitiveValue, "this.requestDescription.TargetKind != RequestTargetKind.PrimitiveValue");
                    Debug.Assert(this.requestDescription.TargetKind != RequestTargetKind.OpenPropertyValue, "this.requestDescription.TargetKind != RequestTargetKind.OpenPropertyValue");
                    Debug.Assert(this.requestDescription.TargetKind != RequestTargetKind.Metadata, "this.requestDescription.TargetKind != RequestTargetKind.Metadata");

                    if (this.requestDescription.TargetKind == RequestTargetKind.ServiceDirectory)
                    {
                        if (this.responseFormat == ContentFormat.Json)
                        {
                            JsonServiceDocumentSerializer serviceSerializer = new JsonServiceDocumentSerializer(stream, this.Provider, this.encoding);
                            exceptionWriter = serviceSerializer;
                            serviceSerializer.WriteRequest();
                            break;
                        }
                        else
                        {
                            AtomServiceDocumentSerializer serviceSerializer = new AtomServiceDocumentSerializer(stream, this.AbsoluteServiceUri, this.Provider, this.encoding);
                            exceptionWriter = serviceSerializer;
                            serviceSerializer.WriteRequest(this.service);
                        }
                    }
                    else
                    {
                        Serializer serializer;
                        if (ContentFormat.Json == this.responseFormat)
                        {
                            serializer = new JsonSerializer(this.requestDescription, stream, this.AbsoluteServiceUri, this.service, this.encoding, this.Host.ResponseETag);
                        }
                        else if (ContentFormat.PlainXml == this.responseFormat)
                        {
                            serializer = new PlainXmlSerializer(this.requestDescription, this.AbsoluteServiceUri, this.service, stream, this.encoding);
                        }
                        else
                        {
                            Debug.Assert(
                                this.requestDescription.TargetKind == RequestTargetKind.OpenProperty ||
                                this.requestDescription.TargetKind == RequestTargetKind.Resource,
                                "TargetKind " + this.requestDescription.TargetKind + " == Resource || OpenProperty -- POX should have handled it otherwise.");
                            serializer = new SyndicationSerializer(
                                this.requestDescription,
                                this.AbsoluteServiceUri,
                                this.service,
                                stream,
                                this.encoding,
                                this.Host.ResponseETag,
                                new Atom10FormatterFactory());
                        }

                        exceptionWriter = serializer;
                        Debug.Assert(exceptionWriter != null, "this.exceptionWriter != null");
                        serializer.WriteRequest(this.queryResults, this.hasMoved);
                    }

                    break;

                default:
                    Debug.Assert(
                        this.responseFormat == ContentFormat.MetadataDocument,
                        "responseFormat(" + this.responseFormat + ") == ContentFormat.MetadataDocument -- otherwise exception should have been thrown before");
                    Debug.Assert(this.requestDescription.TargetKind == RequestTargetKind.Metadata, "this.requestDescription.TargetKind == RequestTargetKind.Metadata");
                    MetadataSerializer metadataSerializer = new MetadataSerializer(stream, this.AbsoluteServiceUri, this.Provider, this.encoding);
                    exceptionWriter = metadataSerializer;
                    metadataSerializer.WriteRequest(this.service);
                    break;
                }
            }
            catch (Exception exception)
            {
                if (!WebUtil.IsCatchableExceptionType(exception))
                {
                    throw;
                }

                // Only JSON and XML are supported.
                string contentType = (this.responseFormat == ContentFormat.Json) ? XmlConstants.MimeApplicationJson : XmlConstants.MimeApplicationXml;
                ErrorHandler.HandleDuringWritingException(exception, this.service, contentType, exceptionWriter);
            }
            finally
            {
                WebUtil.Dispose(this.queryResults);
                WebUtil.Dispose(this.mediaResourceStream);
            }
        }
コード例 #4
0
ファイル: ErrorHandler.cs プロジェクト: nickchal/pash
 internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, IExceptionWriter exceptionWriter)
 {
     HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);
     service.InternalHandleException(args);
     service.OperationContext.Host.ProcessException(args);
     exceptionWriter.WriteException(args);
 }
コード例 #5
0
ファイル: ErrorHandler.cs プロジェクト: dox0/DotNet471RS3
        /// <summary>Handles an exception while the response is being written out.</summary>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name='contentType'>MIME type of output stream.</param>
        /// <param name='exceptionWriter'>Serializer-specific exception writer.</param>
        internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, IExceptionWriter exceptionWriter)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(exceptionWriter != null, "exceptionWriter != null");
            Debug.Assert(service.Configuration != null, "service.Configuration != null");
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");

            HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            service.OperationContext.Host.ProcessException(args);
            exceptionWriter.WriteException(args);
        }
コード例 #6
0
ファイル: ErrorHandler.cs プロジェクト: JianwenSun/cc
        /// <summary>Handles an exception while the response is being written out.</summary>
        /// <param name='exception'>Exception thrown.</param>
        /// <param name='service'>Data service doing the processing.</param>
        /// <param name='contentType'>MIME type of output stream.</param>
        /// <param name='exceptionWriter'>Serializer-specific exception writer.</param>
        internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, IExceptionWriter exceptionWriter)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(exception != null, "exception != null");
            Debug.Assert(exceptionWriter != null, "exceptionWriter != null");
            Debug.Assert(service.Configuration != null, "service.Configuration != null");
            Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");

            HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);
            service.InternalHandleException(args);
            service.OperationContext.Host.ProcessException(args);
            exceptionWriter.WriteException(args);
        }
コード例 #7
0
 public GlobalExceptionHandler(IExceptionWriter exceptionWriter, IAppLogger logger)
 {
     _exceptionWriter = exceptionWriter;
     _logger          = logger;
 }
コード例 #8
0
        internal void Write(Stream stream)
        {
            IExceptionWriter exceptionWriter = null;
            Stream           output          = null;
            Serializer       serializer      = null;

            System.Data.Services.ODataResponseMessage responseMessage = this.responseMessage as System.Data.Services.ODataResponseMessage;
            if (responseMessage != null)
            {
                responseMessage.SetStream(stream);
            }
            try
            {
                BinarySerializer   serializer2;
                MetadataSerializer serializer7;
                switch (this.payloadKind)
                {
                case ODataPayloadKind.Feed:
                case ODataPayloadKind.Entry:
                {
                    EntitySerializer serializer6 = new EntitySerializer(this.requestDescription, this.AbsoluteServiceUri, this.service, this.service.OperationContext.Host.ResponseETag, this.messageWriter, this.contentFormat);
                    serializer = serializer6;
                    serializer6.WriteRequest(this.queryResults, this.hasMoved);
                    return;
                }

                case ODataPayloadKind.Property:
                case ODataPayloadKind.EntityReferenceLink:
                case ODataPayloadKind.EntityReferenceLinks:
                case ODataPayloadKind.Collection:
                {
                    NonEntitySerializer serializer5 = new NonEntitySerializer(this.requestDescription, this.AbsoluteServiceUri, this.service, this.messageWriter);
                    serializer = serializer5;
                    serializer5.WriteRequest(this.queryResults, this.hasMoved);
                    return;
                }

                case ODataPayloadKind.Value:
                    new TextSerializer(this.messageWriter).WriteRequest(this.queryResults.Current);
                    return;

                case ODataPayloadKind.BinaryValue:
                    output          = this.responseMessage.GetStream();
                    serializer2     = new BinarySerializer(output);
                    exceptionWriter = serializer2;
                    if (this.requestDescription.TargetKind != RequestTargetKind.MediaResource)
                    {
                        break;
                    }
                    if (this.mediaResourceStream != null)
                    {
                        serializer2.WriteRequest(this.mediaResourceStream, this.service.StreamProvider.StreamBufferSize);
                    }
                    return;

                case ODataPayloadKind.ServiceDocument:
                    new ServiceDocumentSerializer(this.messageWriter).WriteServiceDocument(this.service.Provider);
                    return;

                default:
                    goto Label_0194;
                }
                serializer2.WriteRequest(this.queryResults.Current);
                return;

                Label_0194:
                serializer7 = new MetadataSerializer(this.messageWriter);
                serializer7.WriteMetadataDocument(this.service);
            }
            catch (Exception exception)
            {
                if (!CommonUtil.IsCatchableExceptionType(exception))
                {
                    throw;
                }
                if (serializer != null)
                {
                    serializer.Flush();
                }
                string contentType = this.responseMessage.GetHeader("Content-Type").StartsWith("application/json", StringComparison.OrdinalIgnoreCase) ? "application/json;odata=verbose" : "application/xml";
                if (this.messageWriter != null)
                {
                    ErrorHandler.HandleDuringWritingException(exception, this.service, contentType, this.messageWriter, stream, this.encoding);
                }
                else
                {
                    ErrorHandler.HandleDuringWritingException(exception, this.service, contentType, exceptionWriter);
                }
            }
            finally
            {
                WebUtil.Dispose(this.messageWriter);
                WebUtil.Dispose(this.queryResults);
                WebUtil.Dispose(this.mediaResourceStream);
                if ((output != null) && (responseMessage == null))
                {
                    output.Dispose();
                }
            }
        }
コード例 #9
0
ファイル: ErrorHandler.cs プロジェクト: modulexcite/pash-1
        internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, IExceptionWriter exceptionWriter)
        {
            HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);

            service.InternalHandleException(args);
            service.OperationContext.Host.ProcessException(args);
            exceptionWriter.WriteException(args);
        }