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


C# HttpCookie.Select方法代码示例

本文整理汇总了C#中System.Web.HttpCookie.Select方法的典型用法代码示例。如果您正苦于以下问题:C# HttpCookie.Select方法的具体用法?C# HttpCookie.Select怎么用?C# HttpCookie.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpCookie的用法示例。


在下文中一共展示了HttpCookie.Select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderUrlImpl

            private RenderingResult RenderUrlImpl(HttpCookie[] cookies, string url, string outputImageFilePath, string mode)
            {
                Verify.ArgumentNotNull(cookies, nameof(cookies));

                string cookieDomain = new Uri(url).Host;
                string cookieInfo = string.Join(",",
                    cookies.Select(cookie => cookie.Name + "," + cookie.Value + "," + cookieDomain));

                string requestLine = cookieInfo + ";" + url + ";" + outputImageFilePath + ";" + mode;

                // Async way:
                //Task<string> readerTask = Task.Run(async () =>
                //{
                //    await _stdin.WriteLineAsync(requestLine);
                //    return await _stdout.ReadLineAsync();
                //});

                Task<string> readerTask = Task.Run(() =>
                {
                    _stdin.WriteLine(requestLine);
                    return _stdout.ReadLine();
                });

                double timeout = (DateTime.Now - _process.StartTime).TotalSeconds < 120 ? 65 : 30;

                readerTask.Wait(TimeSpan.FromSeconds(timeout));

                string output;

                switch (readerTask.Status)
                {
                    case TaskStatus.RanToCompletion:
                        output = readerTask.Result;
                        break;
                    default:
                        return new RenderingResult
                        {
                            Status = RenderingResultStatus.PhantomServerTimeout,
                            Output = "Request failed to complete within expected time: " +
#if DEBUG
                                requestLine
#else
                                url + " " + mode
#endif
                        };
                }

                if (C1File.Exists(outputImageFilePath))
                {
                    return new RenderingResult 
                    { 
                        Status = RenderingResultStatus.Success, 
                        Output = output,
                        FilePath = outputImageFilePath
                    };
                }

                const string redirectResponsePrefix = "REDIRECT: ";
                if (output.StartsWith(redirectResponsePrefix))
                {
                    return new RenderingResult
                    {
                        Status = RenderingResultStatus.Redirect,
                        Output = output,
                        RedirectUrl = output.Substring(redirectResponsePrefix.Length)
                    };
                }

                const string timeoutResponsePrefix = "TIMEOUT: ";
                if (output.StartsWith(timeoutResponsePrefix))
                {
                    return new RenderingResult
                    {
                        Status = RenderingResultStatus.Timeout,
                        Output = output,
                        RedirectUrl = output.Substring(timeoutResponsePrefix.Length)
                    };
                }

                const string errorResponsePrefix = "ERROR: ";
                if (output.StartsWith(errorResponsePrefix))
                {
                    return new RenderingResult
                    {
                        Status = RenderingResultStatus.Error,
                        Output = output,
                        RedirectUrl = output.Substring(errorResponsePrefix.Length)
                    };
                }

                return new RenderingResult
                {
                    Status = RenderingResultStatus.PhantomServerIncorrectResponse,
                    Output = output
                };
            }
开发者ID:REALTOBIZ,项目名称:C1-CMS,代码行数:96,代码来源:BrowserRender_PhantomServer.cs

示例2: RenderUrlImpl

        private RenderingResult RenderUrlImpl(HttpCookie[] cookies, string url, string outputImageFilePath, string mode)
        {
            Verify.ArgumentNotNull(cookies, nameof(cookies));

            string cookieDomain = new Uri(url).Host;

            var request = new RenderPreviewRequest
            {
                requestId = "1",
                mode = mode,
                url = url,
                outputFilePath = outputImageFilePath,
                cookies = cookies.Select(cookie => new CookieInformation
                {
                    name = cookie.Name,
                    value = cookie.Value,
                    domain = cookieDomain
                }).ToArray()
            };

            var ms = new MemoryStream();
            var ser = new DataContractJsonSerializer(typeof(RenderPreviewRequest));
            ser.WriteObject(ms, request);

            var json = Encoding.UTF8.GetString(ms.ToArray());

            var output = new List<string>();

            Task readerTask = Task.Run(() =>
            {
                _stdin.WriteLine(json);

                string line;

                do
                {
                    line = _stdout.ReadLine();
                    lock (output)
                    {
                        output.Add(line);
                    }

                } while (!IsEndOfReply(line));
            });

            var secondsSinceStartup = (DateTime.Now - _process.StartTime).TotalSeconds;
            double timeout = secondsSinceStartup < 120 || mode == "test" ? 65 : 30;

            readerTask.Wait(TimeSpan.FromSeconds(timeout));

            // TODO: check for theother task statuses
            switch (readerTask.Status)
            {
                case TaskStatus.RanToCompletion:
                    if (output.Count == 0)
                    {
                        return new RenderingResult
                        {
                            Status = RenderingResultStatus.PhantomServerNoOutput,
                            Output = new [] { "(null)" }
                        };
                    }
                    break;
                default:
                    string[] outputCopy;
                    lock (output)
                    {
                        outputCopy = output.ToArray();
                    }

                    string logMessage = "Request failed to complete within expected time: " +
#if DEBUG
                        json
#else
                                url + " " + mode
#endif
                        ;


                    return new RenderingResult
                    {
                        Status = RenderingResultStatus.PhantomServerTimeout,
                        Output = new [] { logMessage}.Concat(outputCopy).ToArray(),
                        FilePath = outputImageFilePath
                    };
            }

            if (C1File.Exists(outputImageFilePath))
            {
                return new RenderingResult
                {
                    Status = RenderingResultStatus.Success,
                    Output = output,
                    FilePath = outputImageFilePath
                };
            }

            var lastMessage = output.Last();

            if (!lastMessage.StartsWith(EndOfReplyMarker))
//.........这里部分代码省略.........
开发者ID:Orckestra,项目名称:C1-CMS,代码行数:101,代码来源:PhantomServer.cs


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