本文整理汇总了C#中OperationContext.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# OperationContext.ToString方法的具体用法?C# OperationContext.ToString怎么用?C# OperationContext.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationContext
的用法示例。
在下文中一共展示了OperationContext.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
// Routing -> ParameterBinding -> Execute
public async Task<bool> ProcessRequest(IDictionary<string, object> environment)
{
options.Logger.ProcessRequestStart(environment.AsRequestPath());
MemoryStream bufferedRequestStream = null;
var originalRequestStream = environment.AsRequestBody();
if (!originalRequestStream.CanSeek)
{
bufferedRequestStream = new MemoryStream();
if (options.StreamWriteOption == StreamWriteOption.BufferAndAsynchronousWrite)
{
await originalRequestStream.CopyToAsync(bufferedRequestStream); // keep context
}
else
{
originalRequestStream.CopyTo(bufferedRequestStream);
}
bufferedRequestStream.Position = 0;
environment[OwinConstants.RequestBody] = bufferedRequestStream;
}
try
{
var coordinator = options.OperationCoordinatorFactory.Create();
if (!coordinator.OnStartProcessRequest(options, environment))
{
return ReturnNextMiddleware(environment);
}
AcceptVerbs verb;
string ext;
var handler = SelectHandler(environment, coordinator, out verb, out ext);
if (handler == null) return ReturnNextMiddleware(environment);
// Parameter binding
var valueProvider = new ValueProvider(environment, verb);
var methodParameters = ParameterBinder.BindParameter(environment, options, coordinator, valueProvider, handler.Arguments);
if (methodParameters == null) return ReturnNextMiddleware(environment);
// select formatter
var formatter = handler.NegotiateFormat(environment, ext, options, coordinator);
if (formatter == null)
{
if (formatter == null) return ReturnNextMiddleware(environment);
}
try
{
// Operation execute
var context = new OperationContext(environment, handler.ClassName, handler.MethodName, verb)
{
Parameters = methodParameters,
ParameterNames = handler.ParameterNames,
ContentFormatter = formatter,
Attributes = handler.AttributeLookup
};
var executionPath = context.ToString();
options.Logger.ExecuteStart(executionPath);
var sw = Stopwatch.StartNew();
var interrupted = false;
try
{
await handler.Execute(options, context, coordinator).ConfigureAwait(false);
}
catch
{
interrupted = true;
throw;
}
finally
{
sw.Stop();
options.Logger.ExecuteFinished(executionPath, interrupted, sw.Elapsed.TotalMilliseconds);
}
return ReturnNextMiddleware(environment);
}
catch (ReturnStatusCodeException statusException)
{
try
{
if (options.UseOtherMiddleware && options.PassThroughWhenStatusCodesAre != null)
{
var code = (int)statusException.StatusCode;
for (int i = 0; i < options.PassThroughWhenStatusCodesAre.Length; i++)
{
if (code == options.PassThroughWhenStatusCodesAre[i])
{
environment[OwinConstants.ResponseStatusCode] = code; // emit only code.
return ReturnNextMiddleware(environment);
}
}
}
statusException.EmitCode(options, environment);
}
catch (Exception ex)
{
if (IsRethrowOrEmitException(coordinator, options, environment, ex))
{
throw;
//.........这里部分代码省略.........
示例2: ExecuteOperation
public async Task<object> ExecuteOperation(ILightNodeOptions options, OperationContext context, Func<ILightNodeOptions, OperationContext, Task<object>> originalOperation)
{
if (MessageBroker == null || Timer == null) return await originalOperation(options, context);
var timer = Timer;
object result;
var start = timer.Start();
try
{
result = await originalOperation(options, context);
var stop = timer.Stop(start);
var message = new LightNodeExecuteResultMessage()
{
ContractName = context.ContractName,
OperationName = context.OperationName,
Result = result,
Environment = context.Environment,
UsedContentFormatter = context.ContentFormatter,
Options = options,
FromRequestStart = timer.Point().Offset,
Phase = OperationPhase.Operation
}
.AsTimelineMessage(context.ToString(), OperationCategory)
.AsTimedMessage(stop);
MessageBroker.Publish(message);
return result;
}
catch (Exception ex)
{
var stop = timer.Stop(start);
var message = new LightNodeExecuteResultMessage()
{
ContractName = context.ContractName,
OperationName = context.OperationName,
Result = ex.ToString(),
Environment = context.Environment,
UsedContentFormatter = context.ContentFormatter,
Options = options,
FromRequestStart = timer.Point().Offset,
Phase = (ex is ReturnStatusCodeException) ? OperationPhase.ReturnStatusCode : OperationPhase.Exception
}
.AsTimelineMessage(context.ToString(), OperationCategory)
.AsTimedMessage(stop);
MessageBroker.Publish(message);
throw;
}
}