当前位置: 首页>>代码示例>>C#>>正文


C# IResponse.Flush方法代码示例

本文整理汇总了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);
        }
开发者ID:CLupica,项目名称:ServiceStack,代码行数:17,代码来源:StaticContentHandler.cs

示例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;
            }
开发者ID:jklemmack,项目名称:ServerSentEvents4ServiceStack,代码行数:53,代码来源:SimpleServerEventsFeature.cs


注:本文中的IResponse.Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。