本文整理汇总了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
};
}
示例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))
//.........这里部分代码省略.........