本文整理汇总了C#中IResponse.WriteToResponse方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.WriteToResponse方法的具体用法?C# IResponse.WriteToResponse怎么用?C# IResponse.WriteToResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResponse
的用法示例。
在下文中一共展示了IResponse.WriteToResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RequestFilter
public static void RequestFilter(IRequest req, IResponse res, object requestDto)
{
var validator = ValidatorCache.GetValidator(req, requestDto.GetType());
if (validator == null) return;
var validatorWithHttpRequest = validator as IRequiresRequest;
if (validatorWithHttpRequest != null)
validatorWithHttpRequest.Request = req;
var ruleSet = req.Verb;
var validationResult = validator.Validate(
new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet)));
if (validationResult.IsValid) return;
var errorResponse = DtoUtils.CreateErrorResponse(
requestDto, validationResult.ToErrorResult());
var validationFeature = HostContext.GetPlugin<ValidationFeature>();
if (validationFeature != null && validationFeature.ErrorResponseFilter != null)
{
errorResponse = validationFeature.ErrorResponseFilter(validationResult, errorResponse);
}
res.WriteToResponse(req, errorResponse);
}
示例2: RequestFilter
public static void RequestFilter(IRequest req, IResponse res, object requestDto)
{
var validator = ValidatorCache.GetValidator(req, requestDto.GetType());
if (validator == null) return;
try
{
var ruleSet = req.Verb;
var validationResult = validator.Validate(
new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet)) {
Request = req
});
if (validationResult.IsValid) return;
var errorResponse = HostContext.RaiseServiceException(req, requestDto, validationResult.ToException())
?? DtoUtils.CreateErrorResponse(requestDto, validationResult.ToErrorResult());
var validationFeature = HostContext.GetPlugin<ValidationFeature>();
if (validationFeature?.ErrorResponseFilter != null)
{
errorResponse = validationFeature.ErrorResponseFilter(validationResult, errorResponse);
}
res.WriteToResponse(req, errorResponse);
}
finally
{
using (validator as IDisposable) {}
}
}
示例3: ProcessRequestAsync
public override Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName)
{
try
{
appHost.AssertFeatures(format);
if (appHost.ApplyPreRequestFilters(httpReq, httpRes))
return EmptyTask;
httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
var callback = httpReq.QueryString[Keywords.Callback];
var doJsonp = HostContext.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
var request = httpReq.Dto = CreateRequest(httpReq, operationName);
if (appHost.ApplyRequestFilters(httpReq, httpRes, request))
return EmptyTask;
var rawResponse = GetResponse(httpReq, request);
return HandleResponse(rawResponse, response =>
{
response = appHost.ApplyResponseConverters(httpReq, response);
if (appHost.ApplyResponseFilters(httpReq, httpRes, response))
return EmptyTask;
if (doJsonp && !(response is CompressedResult))
return httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
return httpRes.WriteToResponse(httpReq, response);
},
ex => !HostContext.Config.WriteErrorsToResponse
? ex.ApplyResponseConverters(httpReq).AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex.ApplyResponseConverters(httpReq)));
}
catch (Exception ex)
{
return !HostContext.Config.WriteErrorsToResponse
? ex.ApplyResponseConverters(httpReq).AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex.ApplyResponseConverters(httpReq));
}
}
示例4: ProcessRequest
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
if (Action == null)
throw new Exception("Action was not supplied to ActionHandler");
if (httpReq.OperationName == null)
httpReq.SetOperationName(RequestName);
var response = Action(httpReq, httpRes);
httpRes.WriteToResponse(httpReq, response);
}
示例5: ProcessRequestAsync
public override Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName)
{
try
{
var appHost = HostContext.AppHost;
if (appHost.ApplyPreRequestFilters(httpReq, httpRes))
return EmptyTask;
var restPath = GetRestPath(httpReq.Verb, httpReq.PathInfo);
if (restPath == null)
{
return new NotSupportedException("No RestPath found for: " + httpReq.Verb + " " + httpReq.PathInfo)
.AsTaskException();
}
httpReq.SetRoute(restPath as RestPath);
operationName = restPath.RequestType.GetOperationName();
var callback = httpReq.GetJsonpCallback();
var doJsonp = HostContext.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
if (ResponseContentType != null)
httpReq.ResponseContentType = ResponseContentType;
var responseContentType = httpReq.ResponseContentType;
appHost.AssertContentType(responseContentType);
var request = httpReq.Dto = CreateRequest(httpReq, restPath);
if (appHost.ApplyRequestFilters(httpReq, httpRes, request))
return EmptyTask;
var rawResponse = GetResponse(httpReq, request);
return HandleResponse(rawResponse, response =>
{
response = appHost.ApplyResponseConverters(httpReq, response);
if (appHost.ApplyResponseFilters(httpReq, httpRes, response))
return EmptyTask;
if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString[Keywords.Debug]))
return WriteDebugResponse(httpRes, response);
if (doJsonp && !(response is CompressedResult))
return httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
return httpRes.WriteToResponse(httpReq, response);
},
ex => !HostContext.Config.WriteErrorsToResponse
? ex.ApplyResponseConverters(httpReq).AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex.ApplyResponseConverters(httpReq)));
}
catch (Exception ex)
{
return !HostContext.Config.WriteErrorsToResponse
? ex.ApplyResponseConverters(httpReq).AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex.ApplyResponseConverters(httpReq));
}
}
示例6: WriteDebugResponse
public Task WriteDebugResponse(IResponse httpRes, object response)
{
return httpRes.WriteToResponse(response, WriteDebugRequest,
new BasicRequest { ContentType = MimeTypes.PlainText });
}
示例7: ProcessRequestAsync
public override Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName)
{
var metadata = DtoGenFeature.GetMetadataTypes(Config, httpReq);
return httpRes.WriteToResponse(httpReq, metadata);
}
示例8: ProcessRequestAsync
public override Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName)
{
var metadata = new MetadataTypes
{
Config = Config,
};
var existingTypes = new HashSet<Type> {
typeof(ResponseStatus),
typeof(ErrorResponse),
};
var meta = HostContext.Metadata;
foreach (var operation in meta.Operations)
{
if (!meta.IsVisible(httpReq, operation))
continue;
metadata.Operations.Add(new MetadataOperationType
{
Actions = operation.Actions,
Request = operation.RequestType.ToType(),
Response = operation.ResponseType.ToType(),
});
existingTypes.Add(operation.RequestType);
if (operation.ResponseType != null)
{
existingTypes.Add(operation.ResponseType);
}
}
foreach (var type in meta.GetAllTypes())
{
if (existingTypes.Contains(type))
continue;
metadata.Operations.Add(new MetadataOperationType
{
Request = type.ToType(),
});
existingTypes.Add(type);
}
var considered = new HashSet<Type>(existingTypes);
var queue = new Queue<Type>(existingTypes);
while (queue.Count > 0)
{
var type = queue.Dequeue();
foreach (var pi in type.GetSerializableProperties())
{
if (pi.PropertyType.IsUserType())
{
if (considered.Contains(pi.PropertyType))
continue;
considered.Add(pi.PropertyType);
queue.Enqueue(pi.PropertyType);
metadata.Types.Add(pi.PropertyType.ToType());
}
}
if (type.BaseType != null
&& type.BaseType.IsUserType()
&& !considered.Contains(type.BaseType))
{
considered.Add(type.BaseType);
queue.Enqueue(type.BaseType);
metadata.Types.Add(type.BaseType.ToType());
}
}
return httpRes.WriteToResponse(httpReq, metadata);
}