本文整理汇总了C#中IResponse.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.Flush方法的具体用法?C# IResponse.Flush怎么用?C# IResponse.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResponse
的用法示例。
在下文中一共展示了IResponse.Flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
if (HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes))
return;
if (textContents == null && bytes == null)
return;
httpRes.ContentType = contentType;
if (textContents != null)
httpRes.Write(textContents);
else if (bytes != null)
httpRes.OutputStream.Write(bytes, 0, bytes.Length);
httpRes.Flush();
httpRes.EndHttpHandlerRequest(skipHeaders: true);
}
示例2: ProcessRequestAsync
public override Task ProcessRequestAsync(IRequest req, IResponse res, string operationName)
{
res.ContentType = MimeTypes.ServerSentEvents;
res.AddHeader(HttpHeaders.CacheControl, "no-cache");
res.KeepAlive = true;
res.Flush();
IAuthSession session = req.GetSession();
var userAuthId = session != null ? session.UserAuthId : null;
var feature = HostContext.GetPlugin<SimpleServerEventsFeature>();
//var now = DateTime.UtcNow;
var subscriptionId = SessionExtensions.CreateRandomSessionId();
var eventClient = new EventClient(res)
{
SubscriptionId = subscriptionId, // A session can have multiple subscriptions / clients
};
if (feature.OnCreated != null)
feature.OnCreated(eventClient, req);
//var heartbeatUrl = req.ResolveAbsoluteUrl("~/".CombineWith(feature.HeartbeatPath))
// .AddQueryParam("id", subscriptionId);
var privateArgs = new Dictionary<string, string>(eventClient.Meta) {
{"id", subscriptionId },
//{"heartbeatUrl", heartbeatUrl},
//{"heartbeatIntervalMs", ((long)feature.HeartbeatInterval.TotalMilliseconds).ToString(CultureInfo.InvariantCulture) }
};
// Register the client
req.TryResolve<IServerEventsBroker>().Connect(eventClient);
if (feature.OnConnected != null)
feature.OnConnected(eventClient, privateArgs);
// Welcome our new client
res.OutputStream.Write(": " + subscriptionId + " connected\n\n"); // Write initial stream so the client knows we're alive
res.Flush();
var tcs = new TaskCompletionSource<bool>();
eventClient.OnDispose = client =>
{
try
{
res.EndHttpHandlerRequest(skipHeaders: true);
}
catch { }
tcs.SetResult(true);
};
return tcs.Task;
}