本文整理汇总了C#中IRequest类的典型用法代码示例。如果您正苦于以下问题:C# IRequest类的具体用法?C# IRequest怎么用?C# IRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRequest类属于命名空间,在下文中一共展示了IRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:26,代码来源:ValidationFilters.cs
示例2: 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);
}
开发者ID:tystol,项目名称:ServiceStack,代码行数:30,代码来源:RazorHandler.cs
示例3: RequestEntityReaderHydrator
public RequestEntityReaderHydrator(IDependencyResolver resolver, IRequest request)
{
this.Log = NullLogger<CodecLogSource>.Instance;
this.ErrorCollector = NullErrorCollector.Instance;
this.resolver = resolver;
this.request = request;
}
开发者ID:endjin,项目名称:openrasta-stable,代码行数:7,代码来源:RequestEntityReaderHydrator.cs
示例4: OnConnected
protected override Task OnConnected(IRequest request, string connectionId)
{
// Should throw 404
using (HttpWebRequest.Create("http://httpstat.us/404").GetResponse()) { }
return base.OnConnected(request, connectionId);
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:7,代码来源:MyBadConnection.cs
示例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));
}
}
开发者ID:dittodhole,项目名称:dotnet-ServiceStack,代码行数:60,代码来源:RestHandler.cs
示例6: Uri
CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame,
IRequest request, IRequestCallback callback) {
if (CommonUrls.IsWithSixUrl(request.Url)) {
var headers = request.Headers;
headers[Common.ClientHeader] = DomainEvilGlobal.SecretData.UserInfo.ClientId.ToString();
headers[Common.ClientHeaderV] = Common.App.ProductVersion;
request.Headers = headers;
}
return CefReturnValue.Continue;
//Example of how to set Referer
// Same should work when setting any header
// For this example only set Referer when using our custom scheme
var url = new Uri(request.Url);
if (url.Scheme == "customscheme") // CefSharpSchemeHandlerFactory.SchemeName
{
var headers = request.Headers;
headers["Referer"] = "http://google.com";
request.Headers = headers;
}
//NOTE: If you do not wish to implement this method returning false is the default behaviour
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
//callback.Dispose();
//return false;
//NOTE: When executing the callback in an async fashion need to check to see if it's disposed
if (!callback.IsDisposed) {
using (callback) {
if (request.Method == "POST") {
using (var postData = request.PostData) {
if (postData != null) {
var elements = postData.Elements;
var charSet = request.GetCharSet();
foreach (var element in elements) {
if (element.Type == PostDataElementType.Bytes) {
var body = element.GetBody(charSet);
}
}
}
}
}
//Note to Redirect simply set the request Url
//if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase))
//{
// request.Url = "https://github.com/";
//}
//Callback in async fashion
//callback.Continue(true);
//return CefReturnValue.ContinueAsync;
}
}
return CefReturnValue.Continue;
}
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:60,代码来源:SixWebControlBehavior.cs
示例7: HttpResponseStreamWrapper
public HttpResponseStreamWrapper(Stream stream, IRequest request)
{
this.OutputStream = stream;
this.Request = request;
this.Headers = new Dictionary<string, string>();
this.Items = new Dictionary<string, object>();
}
开发者ID:jrmitch120,项目名称:ServiceStack,代码行数:7,代码来源:HttpResponseStreamWrapper.cs
示例8: OnConnectedAsync
OnConnectedAsync(IRequest request, string connectionId)
{
_userCount += 1;
Debug.WriteLine("OnConnectedAsync " + _userCount);
this.Connection.Broadcast(_userCount);
return base.OnConnectedAsync(request, connectionId);
}
开发者ID:rsahoo-git,项目名称:SignalR-Samples,代码行数:7,代码来源:UserCounterConnection.cs
示例9: using
CefReturnValue IRequestHandler.OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
using (callback)
{
if (request.Method == "POST")
{
using (var postData = request.PostData)
{
var elements = postData.Elements;
var charSet = request.GetCharSet();
foreach (var element in elements)
{
if (element.Type == PostDataElementType.Bytes)
{
var body = element.GetBody(charSet);
}
}
}
}
//Note to Redirect simply set the request Url
//if (request.Url.StartsWith("https://www.google.com", StringComparison.OrdinalIgnoreCase))
//{
// request.Url = "https://github.com/";
//}
//Callback in async fashion
//callback.Continue(true);
//return CefReturnValue.ContinueAsync;
}
return CefReturnValue.Continue;
}
开发者ID:bjarteskogoy,项目名称:CefSharp,代码行数:35,代码来源:RequestHandler.cs
示例10: Log
public override void Log(IRequest request, object requestDto, object response, TimeSpan requestDuration)
{
var requestType = requestDto != null ? requestDto.GetType() : null;
if (ExcludeRequestType(requestType))
return;
using (var redis = redisManager.GetClient())
{
var redisLogEntry = redis.As<RequestLogEntry>();
var entry = CreateEntry(request, requestDto, response, requestDuration, requestType);
entry.Id = redisLogEntry.GetNextSequence();
var key = UrnId.Create<RequestLogEntry>(entry.Id).ToLower();
var nowScore = DateTime.UtcNow.ToUnixTime();
using (var trans = redis.CreateTransaction())
{
trans.QueueCommand(r => r.AddItemToSortedSet(SortedSetKey, key, nowScore));
trans.QueueCommand(r => r.Store(entry));
if (loggerCapacity != null)
{
trans.QueueCommand(r => r.RemoveRangeFromSortedSet(SortedSetKey, 0, -loggerCapacity.Value - 1));
}
trans.Commit();
}
}
}
开发者ID:jin29neci,项目名称:ServiceStack,代码行数:31,代码来源:RedisRequestLogger.cs
示例11: OnReceived
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
ProcessInfo process;
data = data ?? String.Empty;
var shell = request.QueryString != null ? request.QueryString["shell"] : String.Empty;
if (!_processes.TryGetValue(connectionId, out process) || process.Process.HasExited)
{
process = _processes.AddOrUpdate(connectionId, cId => StartProcess(cId, shell), (s, p) => StartProcess(s, shell));
}
else
{
if (data == "\x3")
{
// If the user hit CTRL+C we sent the ^C character "\x3" from the client
// If the data is just ^C we then attach to the console and generate a CTRL_C signal (SIGINT)
CommandsNativeMethods.SetConsoleCtrlHandler(null, true);
CommandsNativeMethods.AttachConsole((uint)process.Process.Id);
CommandsNativeMethods.GenerateConsoleCtrlEvent(CommandsNativeMethods.ConsoleCtrlEvent.CTRL_C, 0);
Thread.Sleep(_cmdWaitTimeSpan);
CommandsNativeMethods.FreeConsole();
CommandsNativeMethods.SetConsoleCtrlHandler(null, false);
}
else
{
//Both cmd.exe and powershell.exe are okay with either \r\n or \n for end-of-line.
process.Process.StandardInput.Write(data);
process.Process.StandardInput.Flush();
}
process.LastInputTime = DateTime.UtcNow;
}
return base.OnReceived(request, connectionId, data);
}
开发者ID:albertjan,项目名称:kudu,代码行数:33,代码来源:PersistentCommandController.cs
示例12: WriteRequestBody
private void WriteRequestBody(IRequest request)
{
lock (thisLock)
{
File.WriteAllText(Environment.GetEnvironmentVariable("directory") + request.Resource, request.Body);
}
}
开发者ID:swalker-,项目名称:HttpServer,代码行数:7,代码来源:WriterResponse.cs
示例13: 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();
}
开发者ID:CodeRevver,项目名称:notekeeper-api,代码行数:30,代码来源:AuthSignatureRequired.cs
示例14: PrettyPrintEndpoint
internal static string PrettyPrintEndpoint(IRequest request, string endpoint)
{
var pretty = ReplaceParams.Replace(endpoint, (m) =>
{
var key = m.Groups[1].Value.ToLowerInvariant();
switch(key)
{
case "index" : return PrettyParam(key, request.RouteValues.Index);
case "name" : return PrettyParam(key, request.RouteValues.Name);
case "feature" : return PrettyParam(key, request.RouteValues.Feature);
case "field" : return PrettyParam(key, request.RouteValues.Field);
case "fields" : return PrettyParam(key, request.RouteValues.Fields);
case "id" : return PrettyParam(key, request.RouteValues.Id);
case "index_metric" : return PrettyParam(key, request.RouteValues.IndexMetric);
case "lang" : return PrettyParam(key, request.RouteValues.Lang);
case "metric" : return PrettyParam(key, request.RouteValues.Metric);
case "node_id" : return PrettyParam(key, request.RouteValues.NodeId);
case "repository" : return PrettyParam(key, request.RouteValues.Repository);
case "scroll_id" : return PrettyParam(key, request.RouteValues.ScrollId);
case "snapshot" : return PrettyParam(key, request.RouteValues.Snapshot);
case "type" : return PrettyParam(key, request.RouteValues.Type);
default: return PrettyParam(key, "<Unknown route variable>");
}
});
return pretty;
}
开发者ID:RossLieberman,项目名称:NEST,代码行数:26,代码来源:LowLevelDispatch.cs
示例15: RenderOperation
protected override void RenderOperation(System.Web.UI.HtmlTextWriter writer, IRequest httpReq, string operationName, string requestMessage, string responseMessage, string metadataHtml)
{
var operationControl = new Soap11OperationControl
{
HttpRequest = httpReq,
MetadataConfig = HostContext.Config.ServiceEndpointsMetadataConfig,
Title = HostContext.ServiceName,
Format = this.Format,
OperationName = operationName,
HostName = httpReq.GetUrlHostName(),
RequestMessage = requestMessage,
ResponseMessage = responseMessage,
MetadataHtml = metadataHtml,
};
if (!this.ContentType.IsNullOrEmpty())
{
operationControl.ContentType = this.ContentType;
}
if (!this.ContentFormat.IsNullOrEmpty())
{
operationControl.ContentFormat = this.ContentFormat;
}
operationControl.Render(writer);
}
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:25,代码来源:Soap11MetadataHandler.cs
示例16: Send
/// <summary>
/// Sends the specified request and returns a response.
/// </summary>
/// <param name="request">A <see cref="IRequest"/> that represents the HTTP request</param>
/// <param name="cancellationToken">Used to cancel the request</param>
/// <returns>A <see cref="Task" /> of <see cref="IResponse"/></returns>
public async Task<IResponse> Send(IRequest request, CancellationToken cancellationToken)
{
if (request == null)
throw new ArgumentNullException("request");
var httpOptions = CreateMessageHandler();
httpOptions.AllowAutoRedirect = request.AllowAutoRedirect;
if (httpOptions.SupportsAutomaticDecompression)
{
httpOptions.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
}
var http = new HttpClient(httpOptions)
{
BaseAddress = request.BaseAddress,
Timeout = request.Timeout
};
using (var requestMessage = _messageBuilder.BuildRequestMessage(request))
{
// Make the request
var responseMessage = await http.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, cancellationToken)
.ConfigureAwait(false);
return await _messageBuilder.BuildResponse(responseMessage).ConfigureAwait(false);
}
}
开发者ID:zdd910,项目名称:CodeHub,代码行数:32,代码来源:OctokitModernHttpClient.cs
示例17: OpenInSystemBrowser
bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
bool isRedirect) {
if (!frame.IsMain || CommonUrls.IsWithSixUrl(request.Url) || IsAuthUrl(new Uri(request.Url)))
return false;
OpenInSystemBrowser(request.Url);
return true;
}
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:7,代码来源:SixWebControlBehavior.cs
示例18: ProcessRequest
public override void ProcessRequest(IRequest request, IResponse response, string operationName)
{
response.ContentType = "text/plain";
response.StatusCode = 403;
response.EndHttpHandlerRequest(skipClose: true, afterBody: r => {
r.Write("Forbidden\n\n");
r.Write("\nRequest.HttpMethod: " + request.Verb);
r.Write("\nRequest.PathInfo: " + request.PathInfo);
r.Write("\nRequest.QueryString: " + request.QueryString);
if (HostContext.Config.DebugMode)
{
r.Write("\nRequest.RawUrl: " + request.RawUrl);
if (IsIntegratedPipeline.HasValue)
r.Write("\nApp.IsIntegratedPipeline: " + IsIntegratedPipeline);
if (!WebHostPhysicalPath.IsNullOrEmpty())
r.Write("\nApp.WebHostPhysicalPath: " + WebHostPhysicalPath);
if (!WebHostRootFileNames.IsEmpty())
r.Write("\nApp.WebHostRootFileNames: " + TypeSerializer.SerializeToString(WebHostRootFileNames));
if (!WebHostUrl.IsNullOrEmpty())
r.Write("\nApp.WebHostUrl: " + WebHostUrl);
if (!DefaultRootFileName.IsNullOrEmpty())
r.Write("\nApp.DefaultRootFileName: " + DefaultRootFileName);
if (!DefaultHandler.IsNullOrEmpty())
r.Write("\nApp.DefaultHandler: " + DefaultHandler);
if (!HttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
r.Write("\nApp.DebugLastHandlerArgs: " + HttpHandlerFactory.DebugLastHandlerArgs);
}
});
}
开发者ID:tystol,项目名称:ServiceStack,代码行数:33,代码来源:ForbiddenHttpHandler.cs
示例19: Execute
public IResponse Execute(IRequest cruiseRequest)
{
Hashtable velocityContext = new Hashtable();
IResponse decoratedActionResponse = decoratedAction.Execute(cruiseRequest);
if (decoratedActionResponse is HtmlFragmentResponse)
{
ICruiseRequestFactory CruiseRequestFactory = (ICruiseRequestFactory)objectGiver.GiveObjectByType(typeof(ICruiseRequestFactory));
IBuildNameFormatter BuildNameFormatter = (IBuildNameFormatter)objectGiver.GiveObjectByType(typeof(IBuildNameFormatter));
ICruiseRequest request = CruiseRequestFactory.CreateCruiseRequest(cruiseRequest);
if (!string.IsNullOrEmpty(request.ServerName))
{
velocityContext["serverName"] = request.ServerName;
if (!string.IsNullOrEmpty(request.ProjectName))
{
velocityContext["projectName"] = request.ProjectName;
if (!string.IsNullOrEmpty(request.BuildName))
velocityContext["prettybuildName"] = BuildNameFormatter.GetPrettyBuildName(request.BuildSpecifier);
}
}
velocityContext["breadcrumbs"] = (((TopControlsViewBuilder) objectGiver.GiveObjectByType(typeof(TopControlsViewBuilder))).Execute()).ResponseFragment;
velocityContext["sidebar"] = (((SideBarViewBuilder) objectGiver.GiveObjectByType(typeof(SideBarViewBuilder))).Execute()).ResponseFragment;
velocityContext["mainContent"] = ((HtmlFragmentResponse) decoratedActionResponse).ResponseFragment;
velocityContext["dashboardversion"] = GetVersion();
return velocityViewGenerator.GenerateView("SiteTemplate.vm", velocityContext);
}
else
{
return decoratedActionResponse;
}
}
开发者ID:vardars,项目名称:ci-factory,代码行数:33,代码来源:SiteTemplateActionDecorator.cs
示例20: 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);
}
}
开发者ID:vebin,项目名称:soa,代码行数:33,代码来源:BaseSoapMetadataHandler.cs
注:本文中的IRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论