本文整理汇总了C#中System.UriTemplateMatch类的典型用法代码示例。如果您正苦于以下问题:C# UriTemplateMatch类的具体用法?C# UriTemplateMatch怎么用?C# UriTemplateMatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UriTemplateMatch类属于System命名空间,在下文中一共展示了UriTemplateMatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test1Handler
private void Test1Handler(HttpEntityManager http, UriTemplateMatch match)
{
if (http.User != null)
http.Reply("OK", 200, "OK", "text/plain");
else
http.Reply("Please authenticate yourself", 401, "Unauthorized", "text/plain");
}
示例2: TestEncodingHandler
private void TestEncodingHandler(HttpEntityManager http, UriTemplateMatch match)
{
var a = match.BoundVariables["a"];
var b = match.BoundVariables["b"];
http.Reply(new { a = a, b = b, rawSegment = http.RequestedUrl.Segments[2] }.ToJson(), 200, "OK", "application/json");
}
示例3: TestAnonymousHandler
private void TestAnonymousHandler(HttpEntityManager http, UriTemplateMatch match)
{
if (http.User != null)
http.Reply("ERROR", 500, "ERROR", "text/plain");
else
http.Reply("OK", 200, "OK", "text/plain");
}
示例4: Find
public RouteHandler Find(HttpListenerRequest request, out UriTemplateMatch templateMatch)
{
var reqId = request.HttpMethod + ":" + request.Url.LocalPath;
KeyValuePair<RouteHandler, Uri> rh;
if (Cache.TryGetValue(reqId, out rh))
{
templateMatch = rh.Key.Template.Match(rh.Value, request.Url);
return rh.Key;
}
templateMatch = null;
List<RouteHandler> handlers;
if (!MethodRoutes.TryGetValue(request.HttpMethod, out handlers))
return null;
var reqUrl = request.Url;
var url = reqUrl.ToString();
var baseAddr = new Uri(url.Substring(0, url.Length - request.RawUrl.Length));
foreach (var h in handlers)
{
var match = h.Template.Match(baseAddr, reqUrl);
if (match != null)
{
templateMatch = match;
Cache.TryAdd(reqId, new KeyValuePair<RouteHandler, Uri>(h, baseAddr));
return h;
}
}
return null;
}
示例5: OnPostShutdown
private void OnPostShutdown(HttpEntity entity, UriTemplateMatch match)
{
Publish(new ClientMessage.RequestShutdown());
entity.Manager.Reply(HttpStatusCode.OK,
"OK",
e => Log.ErrorException(e, "Error while closing http connection (admin controller)"));
}
示例6: OnGetFreshStats
private void OnGetFreshStats(HttpEntityManager entity, UriTemplateMatch match)
{
var envelope = new SendToHttpEnvelope(_networkSendQueue,
entity,
Format.GetFreshStatsCompleted,
Configure.GetFreshStatsCompleted);
var statPath = match.BoundVariables["statPath"];
var statSelector = GetStatSelector(statPath);
bool useMetadata;
if (!bool.TryParse(match.QueryParameters["metadata"], out useMetadata))
useMetadata = false;
bool useGrouping;
if (!bool.TryParse(match.QueryParameters["group"], out useGrouping))
useGrouping = true;
if (!useGrouping && !string.IsNullOrEmpty(statPath))
{
SendBadRequest(entity, "Dynamic stats selection works only with grouping enabled");
return;
}
Publish(new MonitoringMessage.GetFreshStats(envelope, statSelector, useMetadata, useGrouping));
}
示例7: AckMessages
private void AckMessages(HttpEntityManager http, UriTemplateMatch match)
{
var envelope = new NoopEnvelope();
var groupname = match.BoundVariables["subscription"];
var stream = match.BoundVariables["stream"];
var messageIds = match.BoundVariables["messageIds"];
var ids = new List<Guid>();
foreach (var messageId in messageIds.Split(new[] { ',' }))
{
Guid id;
if (!Guid.TryParse(messageId, out id))
{
http.ReplyStatus(HttpStatusCode.BadRequest, "messageid should be a properly formed guid", exception => { });
return;
}
ids.Add(id);
}
var cmd = new ClientMessage.PersistentSubscriptionAckEvents(
Guid.NewGuid(),
Guid.NewGuid(),
envelope,
BuildSubscriptionGroupKey(stream, groupname),
ids.ToArray(),
http.User);
Publish(cmd);
http.ReplyStatus(HttpStatusCode.Accepted, "", exception => { });
}
示例8: TryUriTemplateMatch
private bool TryUriTemplateMatch(string uri, out UriTemplateMatch uriTemplateMatch)
{
var uriTemplate = new UriTemplate(uri);
var serverPath = Request.Url.GetServerBaseUri();
uriTemplateMatch = uriTemplate.Match(new Uri(serverPath), Request.Url);
return uriTemplateMatch != null;
}
示例9: OnPostShutdown
private void OnPostShutdown(HttpEntity entity, UriTemplateMatch match)
{
Log.Info("Request shut down of node because shutdown command has been received.");
Publish(new ClientMessage.RequestShutdown(exitProcessOnShutdown: true));
entity.Manager.ReplyStatus(HttpStatusCode.OK,
"OK",
e => Log.ErrorException(e, "Error while closing http connection (admin controller)"));
}
示例10: OnGetTcpConnectionStats
private void OnGetTcpConnectionStats(HttpEntityManager entity, UriTemplateMatch match)
{
var envelope = new SendToHttpEnvelope(_networkSendQueue,
entity,
Format.GetFreshTcpConnectionStatsCompleted,
Configure.GetFreshTcpConnectionStatsCompleted);
Publish(new MonitoringMessage.GetFreshTcpConnectionStats(envelope));
}
示例11: UriToActionMatch
public UriToActionMatch(UriTemplateMatch templateMatch,
ControllerAction controllerAction,
Func<HttpEntityManager, UriTemplateMatch, RequestParams> requestHandler)
{
TemplateMatch = templateMatch;
ControllerAction = controllerAction;
RequestHandler = requestHandler;
}
示例12: UriToActionMatch
public UriToActionMatch(UriTemplateMatch templateMatch,
ControllerAction controllerAction,
Action<HttpEntity, UriTemplateMatch> requestHandler)
{
TemplateMatch = templateMatch;
ControllerAction = controllerAction;
RequestHandler = requestHandler;
}
示例13: OnGetOptions
private void OnGetOptions(HttpEntityManager entity, UriTemplateMatch match)
{
entity.ReplyTextContent(Codec.Json.To(GetOptionsInfo(options)),
HttpStatusCode.OK,
"OK",
entity.ResponseCodec.ContentType,
null,
e => Log.ErrorException(e, "error while writing http response (options)"));
}
示例14: SerializedResultArrayBeta
public SerializedResultArrayBeta(List<Result> x, UriTemplateMatch templateMatch, Uri Prefix, UriTemplate ResultResourceTemplate, UriTemplate ResourceArrayTemplate)
{
List<SerializedResultArrayEntry> r = new List<SerializedResultArrayEntry>();
foreach (Result result in x)
{
r.Add(new SerializedResultArrayEntry(result, Prefix, ResultResourceTemplate));
}
Results = r;
}
示例15: GetPrincipal
/// <summary>
/// Virtual method to be able to extend principal.
/// Returns "Guest" identity with no roles.
/// </summary>
/// <param name="context"></param>
/// <param name="match"></param>
/// <returns></returns>
public virtual IPrincipal GetPrincipal(HttpContext context, UriTemplateMatch match)
{
// using System.Security.Permissions;
// using System.Security.Principal;
GenericIdentity gi = new GenericIdentity("Guest");
GenericPrincipal genPrincipal = new GenericPrincipal(gi, new string[]{});
return genPrincipal;
}