var useragent = project.Variables["UserAgent"].Value;
//var pageCount = project.Variables["PageCount"].Value;
var sb = new StringBuilder();
System.Threading.Tasks.Parallel.For(0, 50000, (p) =>
{
if (Global.Variables.IsProjectMaker && !Global.Variables.IsDebugMode) throw new Exception();
if (((ZennoLab.InterfacesLibrary.ProjectModel.Collections.IContextExt)project.Context).IsInterrupted) throw new Exception();
using (var request = new HttpRequest())
{
try
{
var url = "https://yandex.ru/";
request.ReconnectLimit = 3;
request.ReconnectDelay = 50;
request.KeepAlive = true;
request.UserAgent = useragent;
request.AllowAutoRedirect = false;
// request.IgnoreProtocolErrors = true;
request.EnableEncodingContent = false;
request.MaximumAutomaticRedirections = 5;
request["Upgrade-Insecure-Requests"] = "1";
request["Accept-Language"] = "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7";
request["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
bool status = request.Raw(HttpMethod.HEAD, url, null).IsOK;
if (status)
{
// project.SendInfoToLog("", "Status -> " + status + " -> Count -> " + p.Count.ToString(), true);
sb.Append(p.ToString() + "|");
}
else
{
project.SendWarningToLog("", "error", true);
}
}
catch (HttpException e)
{
string answer = string.Empty;
switch (e.Status)
{
case HttpExceptionStatus.Other:
answer = "Неизвестная ошибка";
break;
case HttpExceptionStatus.ProtocolError:
answer = "Код состояния: " + (int)e.HttpStatusCode;
break;
case HttpExceptionStatus.ConnectFailure:
answer = "Не удалось соединиться с HTTP-сервером";
break;
case HttpExceptionStatus.SendFailure:
answer = "Не удалось отправить запрос HTTP-серверу";
break;
case HttpExceptionStatus.ReceiveFailure:
answer = "Не удалось загрузить ответ от HTTP-сервера";
break;
}
project.SendErrorToLog("", answer, true);
}
}
});
var list = sb.ToString().Split(new string[]{ "|" }, StringSplitOptions.RemoveEmptyEntries);
FileSystem.FileAppendString(project.Directory + "\\Result.txt", string.Join("\r\n", list), true);