本文整理汇总了C#中IDataService.InternalHandleException方法的典型用法代码示例。如果您正苦于以下问题:C# IDataService.InternalHandleException方法的具体用法?C# IDataService.InternalHandleException怎么用?C# IDataService.InternalHandleException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataService
的用法示例。
在下文中一共展示了IDataService.InternalHandleException方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleBatchProcessException
/// <summary>Handles an exception when processing a batch response.</summary>
/// <param name='service'>Data service doing the processing.</param>
/// <param name="host">host to which we need to write the exception message</param>
/// <param name='exception'>Exception thrown.</param>
/// <param name='writer'>Output writer for the batch.</param>
internal static void HandleBatchProcessException(IDataService service, DataServiceHostWrapper host, Exception exception, StreamWriter writer)
{
Debug.Assert(service != null, "service != null");
Debug.Assert(host != null, "host != null");
Debug.Assert(exception != null, "exception != null");
Debug.Assert(writer != null, "writer != null");
Debug.Assert(service.Configuration != null, "service.Configuration != null");
Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");
string contentType;
Encoding encoding;
TryGetResponseFormatForError(host, out contentType, out encoding);
HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, service.Configuration.UseVerboseErrors);
service.InternalHandleException(args);
host.ResponseVersion = XmlConstants.DataServiceVersion1Dot0 + ";";
host.ProcessException(args);
writer.Flush();
Action<Stream> errorWriter = ProcessBenignException(exception, service);
if (errorWriter == null)
{
errorWriter = CreateErrorSerializer(args, encoding);
}
errorWriter(writer.BaseStream);
writer.WriteLine();
}
示例2: HandleBatchInStreamError
internal static void HandleBatchInStreamError(IDataService service, Exception exception, ODataBatchWriter batchWriter, Stream responseStream)
{
string str;
Encoding encoding;
string str2;
Version version;
DataServiceHostWrapper host = (service.OperationContext == null) ? null : service.OperationContext.Host;
TryGetResponseFormatForError(service, host, RequestDescription.DataServiceDefaultResponseVersion, out str, out encoding, out str2, out version);
HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, service.Configuration.UseVerboseErrors);
service.InternalHandleException(args);
batchWriter.Flush();
using (XmlWriter writer = XmlUtil.CreateXmlWriterAndWriteProcessingInstruction(responseStream, encoding))
{
ODataError error = CreateODataErrorFromExceptionArgs(args);
ErrorUtils.WriteXmlError(writer, error, args.UseVerboseErrors, 100);
}
}
示例3: HandleBatchOperationError
internal static void HandleBatchOperationError(IDataService service, DataServiceHostWrapper host, Exception exception, ODataBatchWriter batchWriter, Stream responseStream, Version defaultResponseVersion)
{
string str;
Encoding encoding;
string str2;
Version version;
TryGetResponseFormatForError(service, host, defaultResponseVersion, out str, out encoding, out str2, out version);
HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, service.Configuration.UseVerboseErrors);
service.InternalHandleException(args);
Action<Stream> action = null;
if (host != null)
{
host.ResponseVersion = version.ToString(2) + ";";
host.ProcessException(args);
action = ProcessBenignException(exception, service);
}
if (action == null)
{
ODataBatchOperationResponseMessage operationResponseMessage;
if (host != null)
{
operationResponseMessage = host.BatchServiceHost.GetOperationResponseMessage();
WebUtil.SetResponseHeadersForBatchRequests(operationResponseMessage, host.BatchServiceHost);
}
else
{
operationResponseMessage = batchWriter.CreateOperationResponseMessage();
operationResponseMessage.StatusCode = args.ResponseStatusCode;
}
using (ODataMessageWriter writer = ResponseBodyWriter.CreateMessageWriter(null, service, version, operationResponseMessage, str, null))
{
SerializeODataError(args, writer, responseStream, encoding);
}
}
}
示例4: HandleDuringWritingException
internal static void HandleDuringWritingException(Exception exception, IDataService service, string contentType, ODataMessageWriter messageWriter, Stream responseStream, Encoding encoding)
{
HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);
service.InternalHandleException(args);
service.OperationContext.Host.ProcessException(args);
SerializeODataError(args, messageWriter, responseStream, encoding);
}
示例5: HandleBeforeWritingException
internal static Action<Stream> HandleBeforeWritingException(Exception exception, IDataService service)
{
string str;
Encoding encoding;
string str2;
Version responseVersion = null;
DataServiceHostWrapper host = service.OperationContext.Host;
TryGetResponseFormatForError(service, host, RequestDescription.DataServiceDefaultResponseVersion, out str, out encoding, out str2, out responseVersion);
bool verboseResponse = (service.Configuration != null) ? service.Configuration.UseVerboseErrors : false;
HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, verboseResponse);
service.InternalHandleException(args);
host.ResponseVersion = responseVersion.ToString(2) + ";";
host.ProcessException(args);
Action<Stream> action = ProcessBenignException(exception, service);
ODataFormat atom = ODataFormat.Atom;
if (WebUtil.GetContentFormat(str) == ContentFormat.VerboseJson)
{
atom = ODataFormat.VerboseJson;
}
return (action ?? CreateErrorSerializer(atom, args, encoding));
}
示例6: HandleBatchRequestException
/// <summary>Handles an exception when processing a batch request.</summary>
/// <param name='service'>Data service doing the processing.</param>
/// <param name='exception'>Exception thrown.</param>
/// <param name='writer'>Output writer for the batch.</param>
internal static void HandleBatchRequestException(IDataService service, Exception exception, StreamWriter writer)
{
Debug.Assert(service != null, "service != null");
Debug.Assert(exception != null, "exception != null");
Debug.Assert(writer != null, "writer != null");
Debug.Assert(service.Configuration != null, "service.Configuration != null - it should have been initialized by now");
Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception) - ");
string contentType;
Encoding encoding;
DataServiceHostWrapper host = service.OperationContext == null ? null : service.OperationContext.Host;
TryGetResponseFormatForError(host, out contentType, out encoding);
encoding = writer.Encoding;
HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, service.Configuration.UseVerboseErrors);
service.InternalHandleException(args);
writer.Flush();
Action<Stream> errorWriter = CreateErrorSerializer(args, encoding);
errorWriter(writer.BaseStream);
writer.WriteLine();
}
示例7: HandleDuringWritingException
/// <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);
}
示例8: HandleBeforeWritingException
/// <summary>Handles an exception before the response has been written out.</summary>
/// <param name='exception'>Exception thrown.</param>
/// <param name='service'>Data service doing the processing.</param>
/// <param name='accept'>'Accept' header value; possibly null.</param>
/// <param name='acceptCharset'>'Accept-Charset' header; possibly null.</param>
/// <returns>An action that can serialize the exception into a stream.</returns>
internal static Action<Stream> HandleBeforeWritingException(Exception exception, IDataService service, string accept, string acceptCharset)
{
Debug.Assert(WebUtil.IsCatchableExceptionType(exception), "WebUtil.IsCatchableExceptionType(exception)");
Debug.Assert(exception != null, "exception != null");
Debug.Assert(service != null, "service != null");
string contentType;
Encoding encoding;
TryGetResponseFormatForError(accept, acceptCharset, out contentType, out encoding);
bool verbose = (service.Configuration != null) ? service.Configuration.UseVerboseErrors : false;
HandleExceptionArgs args = new HandleExceptionArgs(exception, false, contentType, verbose);
service.InternalHandleException(args);
DataServiceHostWrapper host = service.OperationContext.Host;
host.ResponseVersion = XmlConstants.DataServiceVersion1Dot0 + ";";
host.ProcessException(args);
Action<Stream> action = ProcessBenignException(exception, service);
if (action != null)
{
return action;
}
else
{
return CreateErrorSerializer(args, encoding);
}
}
示例9: HandleBatchOperationError
/// <summary>Handles an exception when processing a batch response.</summary>
/// <param name='service'>Data service doing the processing.</param>
/// <param name="requestMessage">requestMessage holding information about the request that caused an error</param>
/// <param name="responseMessage">responseMessage to which we need to write the exception message</param>
/// <param name='exception'>Exception thrown.</param>
/// <param name='batchWriter'>Output writer for the batch.</param>
/// <param name="responseStream">Underlying response stream.</param>
/// <param name="defaultResponseVersion">The data service version to use for response, if it cannot be computed from the requestMessage.</param>
internal static void HandleBatchOperationError(IDataService service, AstoriaRequestMessage requestMessage, IODataResponseMessage responseMessage, Exception exception, ODataBatchWriter batchWriter, Stream responseStream, Version defaultResponseVersion)
{
Debug.Assert(service != null, "service != null");
Debug.Assert(exception != null, "exception != null");
Debug.Assert(batchWriter != null, "batchWriter != null");
Debug.Assert(service.Configuration != null, "service.Configuration != null");
Debug.Assert(CommonUtil.IsCatchableExceptionType(exception), "CommonUtil.IsCatchableExceptionType(exception)");
ErrorHandler handler = CreateHandler(service, requestMessage, exception, defaultResponseVersion);
service.InternalHandleException(handler.exceptionArgs);
if (requestMessage != null && responseMessage != null)
{
responseMessage.SetHeader(XmlConstants.HttpODataVersion, handler.responseVersion.ToString(2) + ";");
requestMessage.ProcessException(handler.exceptionArgs);
// if ProcessBenignException returns anything, we can safely not write to the stream.
if (ProcessBenignException(exception, service) != null)
{
return;
}
}
if (requestMessage != null)
{
responseMessage = requestMessage.BatchServiceHost.GetOperationResponseMessage();
WebUtil.SetResponseHeadersForBatchRequests(responseMessage, requestMessage.BatchServiceHost);
}
else
{
responseMessage = batchWriter.CreateOperationResponseMessage(null);
responseMessage.StatusCode = handler.exceptionArgs.ResponseStatusCode;
}
MessageWriterBuilder messageWriterBuilder = MessageWriterBuilder.ForError(
null,
service,
handler.responseVersion,
responseMessage,
handler.contentType,
null /*acceptCharsetHeaderValue*/);
using (ODataMessageWriter messageWriter = messageWriterBuilder.CreateWriter())
{
ODataError error = handler.exceptionArgs.CreateODataError();
WriteErrorWithFallbackForXml(messageWriter, handler.encoding, responseStream, handler.exceptionArgs, error, messageWriterBuilder);
}
}
示例10: HandleExceptionWhileWriting
/// <summary>
/// Handles an exception that occurred while writing a response.
/// </summary>
/// <param name="service">Data service doing the processing.</param>
/// <param name="exception">The exception that was thrown.</param>
/// <param name="responseMessage">The response message.</param>
/// <param name="messageWriter">The message writer, if null this will fall back to writing a raw XML error to the stream.</param>
/// <param name="encoding">The encoding to while writing the error.</param>
/// <param name="responseStream">The response stream to write the error to.</param>
/// <param name="messageWriterBuilder">MessageWriterBuilder to use in case a new ODataMessageWriter needs to be constructed.</param>
internal static void HandleExceptionWhileWriting(IDataService service, Exception exception, IODataResponseMessage responseMessage, ODataMessageWriter messageWriter, Encoding encoding, Stream responseStream, MessageWriterBuilder messageWriterBuilder)
{
Debug.Assert(service != null, "service != null");
Debug.Assert(service.Configuration != null, "service.Configuration != null");
Debug.Assert(exception != null, "exception != null");
Debug.Assert(CommonUtil.IsCatchableExceptionType(exception), "CommonUtil.IsCatchableExceptionType(exception)");
Debug.Assert(responseMessage != null, "responseMessage != null");
string contentType = responseMessage.GetHeader(XmlConstants.HttpContentType);
HandleExceptionArgs args = new HandleExceptionArgs(exception, true, contentType, service.Configuration.UseVerboseErrors);
service.InternalHandleException(args);
service.OperationContext.RequestMessage.ProcessException(args);
ODataError error = args.CreateODataError();
WriteErrorWithFallbackForXml(messageWriter, encoding, responseStream, args, error, messageWriterBuilder);
}
示例11: HandleBeforeWritingException
/// <summary>Handles an exception before the response has been written out.</summary>
/// <param name='exception'>Exception thrown.</param>
/// <param name='service'>Data service doing the processing.</param>
/// <returns>An action that can serialize the exception into a stream.</returns>
internal static Action<Stream> HandleBeforeWritingException(Exception exception, IDataService service)
{
Debug.Assert(CommonUtil.IsCatchableExceptionType(exception), "CommonUtil.IsCatchableExceptionType(exception)");
Debug.Assert(exception != null, "exception != null");
Debug.Assert(service != null, "service != null");
AstoriaRequestMessage requestMessage = service.OperationContext.RequestMessage;
Debug.Assert(requestMessage != null, "requestMessage != null");
ErrorHandler handler = CreateHandler(service, requestMessage, exception, VersionUtil.DataServiceDefaultResponseVersion);
service.InternalHandleException(handler.exceptionArgs);
service.OperationContext.ResponseMessage.SetHeader(XmlConstants.HttpODataVersion, handler.responseVersion.ToString(2) + ";");
requestMessage.ProcessException(handler.exceptionArgs);
Action<Stream> action = ProcessBenignException(exception, service);
if (action != null)
{
return action;
}
MessageWriterBuilder messageWriterBuilder = MessageWriterBuilder.ForError(
service.OperationContext.RequestMessage.AbsoluteServiceUri,
service,
handler.responseVersion,
service.OperationContext.ResponseMessage,
handler.contentType,
service.OperationContext.RequestMessage.GetRequestAcceptCharsetHeader());
ODataMessageWriter messageWriter = messageWriterBuilder.CreateWriter();
ODataUtils.SetHeadersForPayload(messageWriter, ODataPayloadKind.Error);
return stream =>
{
service.OperationContext.ResponseMessage.SetStream(stream);
ODataError error = handler.exceptionArgs.CreateODataError();
WriteErrorWithFallbackForXml(messageWriter, handler.encoding, stream, handler.exceptionArgs, error, messageWriterBuilder);
};
}
示例12: HandleBatchInStreamError
/// <summary>Handles an exception when processing a batch request.</summary>
/// <param name='service'>Data service doing the processing.</param>
/// <param name='exception'>Exception thrown.</param>
/// <param name='batchWriter'>Output writer for the batch.</param>
/// <param name="responseStream">Underlying response stream.</param>
internal static void HandleBatchInStreamError(IDataService service, Exception exception, ODataBatchWriter batchWriter, Stream responseStream)
{
Debug.Assert(service != null, "service != null");
Debug.Assert(exception != null, "exception != null");
Debug.Assert(responseStream != null, "responseStream != null");
Debug.Assert(service.Configuration != null, "service.Configuration != null - it should have been initialized by now");
Debug.Assert(CommonUtil.IsCatchableExceptionType(exception), "CommonUtil.IsCatchableExceptionType(exception) - ");
AstoriaRequestMessage requestMessage = service.OperationContext == null ? null : service.OperationContext.RequestMessage;
ErrorHandler handler = CreateHandler(service, requestMessage, exception, VersionUtil.DataServiceDefaultResponseVersion);
service.InternalHandleException(handler.exceptionArgs);
// Make sure to flush the batch writer before we write anything to the underlying stream
batchWriter.Flush();
// Note the OData protocol spec did not defined the behavior when an exception is encountered outside of a batch operation.
// The batch writer in ODataLib doesn't allow WriteError in this case.
// Unfortunately the shipped behavior on the server is we serialize out an error payload in XML format. We need to keep the
// existing behavior. The batch client doesn't know how to deserialize an error payload outside of a batch operation however.
using (XmlWriter xmlWriter = XmlUtil.CreateXmlWriterAndWriteProcessingInstruction(responseStream, handler.encoding))
{
ODataError error = handler.exceptionArgs.CreateODataError();
ErrorUtils.WriteXmlError(xmlWriter, error, handler.exceptionArgs.UseVerboseErrors, MaxInnerErrorDepth);
}
}