本文整理汇总了C#中IResponse类的典型用法代码示例。如果您正苦于以下问题:C# IResponse类的具体用法?C# IResponse怎么用?C# IResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IResponse类属于命名空间,在下文中一共展示了IResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public void SetUp()
{
request = MockRepository.GenerateStub<IRequest>();
response = MockRepository.GenerateStub<IResponse>();
engine = MockRepository.GenerateStub<ILessEngine>();
lessSource = MockRepository.GenerateStub<ILessSource>();
}
示例2: Evaluate
/// <summary>
/// Evaluates the response.
/// </summary>
/// <param name="response">The response to parse.</param>
/// <param name="options">The options to consider.</param>
public void Evaluate(IResponse response, ScriptOptions options)
{
var reader = new StreamReader(response.Content, options.Encoding ?? Encoding.UTF8, true);
var content = reader.ReadToEnd();
reader.Close();
Evaluate(content, options);
}
示例3: ProcessRequest
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes);
if (httpRes.IsClosed) return;
httpRes.ContentType = MimeTypes.Html;
if (RazorFormat == null)
RazorFormat = RazorFormat.Instance;
var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo);
if (contentPage == null)
{
httpRes.StatusCode = (int)HttpStatusCode.NotFound;
httpRes.EndHttpHandlerRequest();
return;
}
var model = Model;
if (model == null)
httpReq.Items.TryGetValue("Model", out model);
if (model == null)
{
var modelType = RazorPage != null ? RazorPage.ModelType : null;
model = modelType == null || modelType == typeof(DynamicRequestObject)
? null
: DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType);
}
RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes);
}
示例4: Execute
public override void Execute(IRequest req, IResponse res, object requestDto)
{
var authErrorMessage = "";
try
{
// Perform security check
if (CanExecute(req))
return;
}
catch (System.Exception ex)
{
authErrorMessage = ex.Message;
var message = string.Format("Blocked unauthorized request: {0} {1} by ip = {2} due to {3}",
req.Verb,
req.AbsoluteUri,
req.UserHostAddress ?? "unknown",
authErrorMessage);
Log.Error(message);
}
// Security failed!
var responseMessage = "You are not authorized. " + authErrorMessage;
res.StatusCode = (int)HttpStatusCode.Unauthorized;
res.StatusDescription = responseMessage;
res.AddHeader(HttpHeaders.WwwAuthenticate, string.Format("{0} realm=\"{1}\"", "", "custom api"));
res.ContentType = "text/plain";
res.Write(responseMessage);
res.Close();
}
示例5: ProcessRequest
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
if (!AssertAccess(httpReq, httpRes, httpReq.QueryString["op"])) return;
var operationTypes = HostContext.Metadata.GetAllTypes();
if (httpReq.QueryString["xsd"] != null)
{
var xsdNo = Convert.ToInt32(httpReq.QueryString["xsd"]);
var schemaSet = XsdUtils.GetXmlSchemaSet(operationTypes);
var schemas = schemaSet.Schemas();
var i = 0;
if (xsdNo >= schemas.Count)
{
throw new ArgumentOutOfRangeException("xsd");
}
httpRes.ContentType = "text/xml";
foreach (XmlSchema schema in schemaSet.Schemas())
{
if (xsdNo != i++) continue;
schema.Write(httpRes.OutputStream);
break;
}
return;
}
using (var sw = new StreamWriter(httpRes.OutputStream))
{
var writer = new HtmlTextWriter(sw);
httpRes.ContentType = "text/html";
ProcessOperations(writer, httpReq, httpRes);
}
}
示例6: Execute
public override async Task Execute(string[] parameters, IResponse response)
{
string sourceRepo;
string issueNumberString;
if (!RepoParser.ParseRepoAndIssueNumber(parameters[1], out sourceRepo, out issueNumberString))
{
await response.Send($"I could not parse the source repository and issue number from '{parameters[1]}'. Are you using the correct syntax?");
return;
}
string targetRepo;
if (!RepoParser.ParseRepo(parameters[2], out targetRepo))
{
await response.Send($"I could not parse the target repository from '{parameters[2]}'. Are you using the correct syntax?");
return;
}
int issueNumber;
if (!int.TryParse(issueNumberString, out issueNumber))
{
await response.Send("Issue number should be a valid number dude!");
return;
}
var owner = "Particular";
await response.Send($"Copying issue https://github.com/{owner}/{sourceRepo}/issues/{issueNumber}").IgnoreWaitContext();
var newIssue = await IssueUtility.Transfer(owner, sourceRepo, issueNumber, owner, targetRepo, false).IgnoreWaitContext();
await response.Send($"Issue copied to https://github.com/{owner}/{targetRepo}/issues/{newIssue.Number}").IgnoreWaitContext();
}
示例7: Assert
public void Assert(IResponse response)
{
// when there are no assertions it is a success
bool success = (this.assertions.Count == 0);
// when the response was timedout, there is no data to test/assert
if (!response.IsTimedOut())
{
foreach (AbstractAssertion assertion in this.assertions)
{
success = assertion.Assert(response);
LOG.DebugFormat("Assert: {0} result: {1}", assertion.GetType().Name, success);
if (!success)
{
break;
}
}
}
// record results
this.result.Executed = true;
this.result.ExecutionTime = response.GetExecutionTime();
this.result.Success = success;
this.result.TimedOut = response.IsTimedOut();
this.result.StatusCode = response.GetStatusCode();
this.result.StatusDescription = response.GetStatusDescription();
this.result.ResponseText = response.GetResponseText();
}
示例8: ProcessRequest
/// <summary>
/// This is called by the hosting environment via CatchAll usually for content pages.
/// </summary>
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
httpRes.ContentType = MimeTypes.Html;
ResolveAndExecuteRazorPage(httpReq, httpRes, null);
httpRes.EndRequest(skipHeaders: true);
}
示例9: Respond
public void Respond(IRequest request, IResponse response)
{
response.StatusCode = HttpStatusCode.NotFound;
response.StatusMessage = "Resource not found";
response.Output.WriteLine("<h1>404: The resource <i>{0}</i> could not be found.</h1>",
request.VirtualPath);
}
示例10: Results
/// <summary>
/// Handles rendering a previous MiniProfiler session, identified by its "?id=GUID" on the query.
/// </summary>
private static string Results(IRequest httpReq, IResponse httpRes)
{
// this guid is the MiniProfiler.Id property
var id = new Guid();
if (!Guid.TryParse(httpReq.QueryString["id"], out id))
{
return NotFound(httpRes, "text/plain", "No Guid id specified on the query string");
}
// load profiler
var profiler = Profiler.Settings.Storage.Load(id);
if (profiler == null)
{
return NotFound(httpRes, "text/plain", "No MiniProfiler results found with Id=" + id.ToString());
}
// ensure that callers have access to these results
var authorize = Profiler.Settings.Results_Authorize;
if (authorize != null && !authorize(httpReq, profiler))
{
httpRes.StatusCode = 401;
httpRes.ContentType = "text/plain";
return "Unauthorized";
}
// Only manage full page
return ResultsFullPage(httpRes, profiler);
}
示例11: RequestFilter
/// <summary>
/// The request filter is executed before the service.
/// </summary>
/// <param name="request">The http request wrapper</param>
/// <param name="response">The http response wrapper</param>
/// <param name="requestDto">The request DTO</param>
public void RequestFilter(IRequest request, IResponse response, object requestDto)
{
var serviceRequest = new ServiceStackServiceRequest(request);
//This code is executed before the service
var auth = AuthorizationContext.GetAuthorizationInfo(serviceRequest);
if (auth != null)
{
User user = null;
if (!string.IsNullOrWhiteSpace(auth.UserId))
{
var userId = auth.UserId;
user = UserManager.GetUserById(userId);
}
string deviceId = auth.DeviceId;
string device = auth.Device;
string client = auth.Client;
string version = auth.Version;
if (!string.IsNullOrEmpty(client) && !string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(device) && !string.IsNullOrEmpty(version))
{
var remoteEndPoint = request.RemoteIp;
SessionManager.LogSessionActivity(client, version, deviceId, device, remoteEndPoint, user);
}
}
}
示例12: HostContext
public HostContext(IRequest request, IResponse response)
{
Request = request;
Response = response;
Environment = new Dictionary<string, object>();
}
示例13: GetResponseText
public static string GetResponseText(IResponse response)
{
StringBuilder builder = new StringBuilder();
// Status
builder.AppendFormat("Status: {0}\n", response.Status);
// Headers
foreach (KeyValuePair<string,IEnumerable<string>> header in response.Headers)
foreach (string value in header.Value)
builder.AppendFormat("{0}: {1}\n", header.Key, value);
builder.Append("\n");
// Body ... just supports a string body for now ... next up: FileInfo support?
foreach (object bodyPart in response.GetBody())
if (bodyPart is string)
builder.Append(bodyPart as string);
else if (bodyPart is byte[])
throw new NotImplementedException("TODO test CGI byte[] body output"); //builder.Append(Encoding.UTF8.GetString(bodyPart)); // assume UTF8 encoding for now ...
else if (bodyPart is ArraySegment<byte>)
throw new NotImplementedException("TODO test CGI ArraySegment<byte> body output");
else if (bodyPart is FileInfo)
throw new NotImplementedException("TODO test CGI FileInfo body output");
else
throw new FormatException("Unknown object returned by IResponse.GetBody(): " + bodyPart.GetType().Name);
return builder.ToString();
}
示例14: ProcessRequest
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
if (HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes))
return;
Action(httpReq, httpRes);
}
示例15: ProcessResponseAsync
protected override async Task ProcessResponseAsync(IResponse response)
{
var context = new BrowsingContext(_parentDocument.Context, Sandboxes.None);
var options = new CreateDocumentOptions(response, _configuration, _parentDocument);
var factory = _configuration.GetFactory<IDocumentFactory>();
ChildDocument = await factory.CreateAsync(context, options, CancellationToken.None).ConfigureAwait(false);
}