本文整理汇总了C#中EventStore.Transport.Http.EntityManagement.HttpEntityManager类的典型用法代码示例。如果您正苦于以下问题:C# HttpEntityManager类的具体用法?C# HttpEntityManager怎么用?C# HttpEntityManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpEntityManager类属于EventStore.Transport.Http.EntityManagement命名空间,在下文中一共展示了HttpEntityManager类的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: SendOk
protected RequestParams SendOk(HttpEntityManager httpEntityManager)
{
httpEntityManager.ReplyStatus(HttpStatusCode.OK,
"OK",
e => Log.Debug("Error while closing http connection (ok): {0}.", e.Message));
return new RequestParams(done: true);
}
示例5: SendBadRequest
protected RequestParams SendBadRequest(HttpEntityManager httpEntityManager, string reason)
{
httpEntityManager.ReplyStatus(HttpStatusCode.BadRequest,
reason,
e => Log.Debug("Error while closing http connection (bad request): {0}.", e.Message));
return new RequestParams(done: true);
}
示例6: SendTooBig
protected RequestParams SendTooBig(HttpEntityManager httpEntityManager)
{
httpEntityManager.ReplyStatus(HttpStatusCode.RequestEntityTooLarge,
"Too large events received. Limit is 4mb",
e => Log.Debug("Too large events received over HTTP"));
return new RequestParams(done: true);
}
示例7: HttpEntity
public HttpEntity(DateTime timeStamp,
ICodec requestCodec,
ICodec responseCodec,
HttpListenerContext context,
string[] allowedMethods,
Action<HttpEntity> onRequestSatisfied)
{
Ensure.NotNull(requestCodec, "requestCodec");
Ensure.NotNull(responseCodec, "responseCodec");
Ensure.NotNull(context, "context");
Ensure.NotNull(allowedMethods, "allowedMethods");
Ensure.NotNull(onRequestSatisfied, "onRequestSatisfied");
TimeStamp = timeStamp;
UserHostName = context.Request.UserHostName;
RequestCodec = requestCodec;
ResponseCodec = responseCodec;
_context = context;
Request = context.Request;
Response = context.Response;
Manager = new HttpEntityManager(this, allowedMethods, onRequestSatisfied);
}
示例8: 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));
}
示例9: 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 => { });
}
示例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: HttpSend
public HttpSend(
HttpEntityManager httpEntityManager, ResponseConfiguration configuration, string data, Message message)
: base(Guid.Empty, null, httpEntityManager)
{
Data = data;
Configuration = configuration;
Message = message;
}
示例12: ReplyWithContent
private void ReplyWithContent(HttpEntityManager http, string contentLocalPath)
{
//NOTE: this is fix for Mono incompatibility in UriTemplate behavior for /a/b{*C}
if (("/" + contentLocalPath).StartsWith(_localWebRootPath))
contentLocalPath = contentLocalPath.Substring(_localWebRootPath.Length);
//_logger.Trace("{0} requested from MiniWeb", contentLocalPath);
try
{
var extensionToContentType = new Dictionary<string, string>
{
{ ".png", "image/png"} ,
{ ".svg", "image/svg+xml"} ,
{ ".woff", "application/x-font-woff"} ,
{ ".woff2", "application/x-font-woff"} ,
{ ".ttf", "application/font-sfnt"} ,
{ ".jpg", "image/jpeg"} ,
{ ".jpeg", "image/jpeg"} ,
{ ".css", "text/css"} ,
{ ".htm", "text/html"} ,
{ ".html", "text/html"} ,
{ ".js", "application/javascript"} ,
{ ".json", "application/json"} ,
{ ".ico", "image/vnd.microsoft.icon"}
};
var extension = Path.GetExtension(contentLocalPath);
var fullPath = Path.Combine(_fileSystemRoot, contentLocalPath);
string contentType;
if (string.IsNullOrEmpty(extension)
|| !extensionToContentType.TryGetValue(extension.ToLower(), out contentType)
|| !File.Exists(fullPath))
{
_logger.Info("Replying 404 for {0} ==> {1}", contentLocalPath, fullPath);
http.ReplyTextContent(
"Not Found", 404, "Not Found", "text/plain", null,
ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
}
else
{
var config = GetWebPageConfig(contentType);
var content = File.ReadAllBytes(fullPath);
http.Reply(content,
config.Code,
config.Description,
config.ContentType,
config.Encoding,
config.Headers,
ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
}
}
catch (Exception ex)
{
http.ReplyTextContent(ex.ToString(), 500, "Internal Server Error", "text/plain", null, Console.WriteLine);
}
}
示例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: OnGetPing
private void OnGetPing(HttpEntityManager entity, UriTemplateMatch match)
{
var response = new HttpMessage.TextMessage("Ping request successfully handled");
entity.ReplyTextContent(Format.TextMessage(entity, response),
HttpStatusCode.OK,
"OK",
entity.ResponseCodec.ContentType,
null,
e => Log.ErrorException(e, "Error while writing HTTP response (ping)"));
}
示例15: OnListNodeSubsystems
private void OnListNodeSubsystems(HttpEntityManager http, UriTemplateMatch match)
{
http.ReplyTextContent(
Codec.Json.To(_enabledNodeSubsystems),
200,
"OK",
"application/json",
null,
ex => Log.InfoException(ex, "Failed to prepare main menu")
);
}