private bool _LoadToFile(HttpRequest httpRequest, string file, bool exportRequest = false, HttpRequestParameters requestParameters = null) { TraceLevel.WriteLine(1, "LoadToFile(\"{0}\", \"{1}\");", httpRequest.Url, file); Http http = CreateHttp(httpRequest, requestParameters); return(http.LoadToFile(file, exportRequest)); }
public Http Load(HttpRequest httpRequest, HttpRequestParameters requestParameters = null, string exportFile = null, bool setExportFileExtension = false) { try { for (int i = 0; i < _loadRepeatIfError - 1; i++) { try { return(_Load(httpRequest, requestParameters, exportFile, setExportFileExtension)); } catch (Exception ex) { if (ex is WebException) { WebException wex = (WebException)ex; // WebExceptionStatus : ConnectFailure, PipelineFailure, ProtocolError, ReceiveFailure, SendFailure, ServerProtocolViolation, Timeout, UnknownError // $$pb modif le 27/01/2015 WebExceptionStatus.NameResolutionFailure ex : "The remote name could not be resolved: 'pixhost.me'" if (wex.Status == WebExceptionStatus.ProtocolError || wex.Status == WebExceptionStatus.NameResolutionFailure) { throw; } } if (ex is ProtocolViolationException) { throw; } TraceLevel.WriteLine(1, "Error : \"{0}\" ({1})", ex.Message, ex.GetType().ToString()); } } return(_Load(httpRequest, requestParameters, exportFile, setExportFileExtension)); } catch (Exception ex) { //Load("http://www.frboard.com/magazines-et-journaux/441873-multi-les-journaux-mardi-13-aout-2013-pdf-lien-direct.html"); //15/08/2013 12:00:32 Error : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 5.199.168.178:80 (System.Net.Sockets.SocketException) //Unable to connect to the remote server (System.Net.WebException) //---------------------- // at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) // at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) //---------------------- // at System.Net.HttpWebRequest.GetResponse() // at pb.old.Http.OpenWebRequest() in c:\pib\dropbox\pbeuz\Dropbox\dev\project\Source\Source_01\Source\PB_Tools\\Http_Html.cs:line 911 // at pb.old.Http.Open() in c:\pib\dropbox\pbeuz\Dropbox\dev\project\Source\Source_01\Source\PB_Tools\\Http_Html.cs:line 780 // at pb.old.Http.Load() in c:\pib\dropbox\pbeuz\Dropbox\dev\project\Source\Source_01\Source\PB_Tools\\Http_Html.cs:line 503 // at pb.old.HtmlXmlReader.Load(String sUrl) in c:\pib\dropbox\pbeuz\Dropbox\dev\project\Source\Source_01\Source\PB_Tools\\HtmlXmlReader.cs:line 426 // at Print.download.w.Test_frboard_02() // at Print.download.w.Run() if (_traceException) { Trace.WriteError(ex); } else { throw; } return(null); } }
private Http _Load(HttpRequest httpRequest, HttpRequestParameters requestParameters = null, string exportFile = null, bool setExportFileExtension = false) { TraceLevel.WriteLine(1, "Load \"{0}\" ({1}){2}", httpRequest.Url, httpRequest.Method, exportFile != null ? "(\"" + exportFile + "\")" : null); Http http = CreateHttp(httpRequest, requestParameters, exportFile, setExportFileExtension); http.LoadAsText(); return(http); }
//private async Task<bool> Load() private async Task Load() { _urlCachePath = _httpCacheManager._urlCache.GetUrlPathResult(_request, _request.CacheSubDirectory); string cacheFile = _urlCachePath.Path; if (_request.ReloadFromWeb || !zFile.Exists(cacheFile)) { // cache file dont exists, create 2 cache files : file with content response, file with request response //TraceLevel.WriteLine(1, $"Load from web \"{_httpRequest.Url}\" ({_httpRequest.Method})"); //Http_v3 http2 = CreateHttp(httpRequest); //http2.LoadToFile(urlPath); //http2.SaveRequest(zpath.PathSetExtension(urlPath, ".request.json")); using (Http_v5 http = new Http_v5(_request, _httpCacheManager._httpManager)) { zfile.CreateFileDirectory(cacheFile); HttpResult_v5 result = await http.LoadToFile(cacheFile); //if (result.Success) //{ _httpMessageResult = http.GetHttpMessageResult(); _httpMessageResult.CacheFile = _urlCachePath.SubPath; _httpMessageResult.zSave(zpath.PathSetExtension(cacheFile, ".request.json"), jsonIndent: true); _success = result.Success; _loadFromWeb = true; //return true; //} //else // return false; } //trace = true; } else { // cache file exists, load request from cache file _loadFromCache = true; TraceLevel.WriteLine(1, "Load from cache \"{0}\"", _urlCachePath.Path); string requestFile = zpath.PathSetExtension(cacheFile, ".request.json"); if (!zFile.Exists(requestFile)) { throw new PBException($"request file not found \"{requestFile}\""); } _httpMessageResult = zMongo.ReadFileAs <HttpMessageResult>(requestFile); _success = _httpMessageResult.Response.StatusCode == 200; //return true; } }
private Image _LoadImage(HttpRequest httpRequest, HttpRequestParameters requestParameters = null) { TraceLevel.WriteLine(1, "LoadImage(\"{0}\");", httpRequest.Url); if (httpRequest.Url.StartsWith("http://")) { return(CreateHttp(httpRequest, requestParameters).LoadImage()); } else { try { return(zimg.LoadBitmapFromFile(httpRequest.Url)); } catch (Exception ex) { Trace.WriteLine("Error : \"{0}\" ({1})", ex.Message, ex.GetType().ToString()); return(null); } } }
public bool LoadToFile(HttpRequest httpRequest, string file, bool exportRequest = false, HttpRequestParameters requestParameters = null) { try { for (int i = 0; i < _loadRepeatIfError - 1; i++) { try { return(_LoadToFile(httpRequest, file, exportRequest, requestParameters)); } catch (Exception ex) { if (ex is WebException) { WebException wex = (WebException)ex; // WebExceptionStatus : ConnectFailure, PipelineFailure, ProtocolError, ReceiveFailure, SendFailure, ServerProtocolViolation, Timeout, UnknownError // $$pb modif le 27/01/2015 WebExceptionStatus.NameResolutionFailure ex : "The remote name could not be resolved: 'pixhost.me'" if (wex.Status == WebExceptionStatus.ProtocolError || wex.Status == WebExceptionStatus.NameResolutionFailure) { throw; } } TraceLevel.WriteLine(1, "Error : \"{0}\" ({1})", ex.Message, ex.GetType().ToString()); } } return(_LoadToFile(httpRequest, file, exportRequest, requestParameters)); } catch (Exception ex) { if (_traceException) { Trace.WriteLine("Error : \"{0}\" ({1})", ex.Message, ex.GetType().ToString()); } else { throw; } return(false); } }
public void Progress(int value, int total, string message, params object[] prm) { if (ProgressChange == null) { return; } if (giProgressMinimumMillisecondsBetweenMessage > 0) { DateTime t = DateTime.Now; if (t.Subtract(gLastProgressTime).TotalMilliseconds < giProgressMinimumMillisecondsBetweenMessage) { return; } gLastProgressTime = t; } if (total < value) { total = value; } string s = ""; if (message != null) { s = string.Format(message, prm); } gsProgressTxt = s; giProgressValue = value; giProgressTotal = total; if (gbProgress_AddProgressValueToMessage) { s += string.Format(" ({0} / {1})", value, total); } //if (Trace.CurrentTrace.TraceLevel >= 2) // Trace.WriteLine("{0:yyyy-MM-dd HH:mm:ss} {1}", DateTime.Now, s); TraceLevel.WriteLine(2, "{0:yyyy-MM-dd HH:mm:ss} {1}", DateTime.Now, s); ProgressChange(value, total, s); }
private async Task SendRequest() { TraceLevel.WriteLine(1, "Load from web \"{0}\" ({1})", _request.Url, _request.Method); _httpManager.InitLoadFromWeb(); CreateHttpRequestMessage(); DateTime start = DateTime.Now; while (true) { try { //Trace.WriteLine($"Http_v3.SendRequest() : send request"); _sendRequestTime = DateTime.Now; _httpResponse = await _httpManager.HttpClient.SendAsync(_httpRequest); break; } catch (Exception ex) { //Trace.WriteLine($"Http_v3.SendRequest() : error \"{ex.Message}\""); if (!Retry(ex)) { throw; } else if (_httpManager.LoadRetryTimeout != -1) { start = DateTime.Now; TimeSpan ts = DateTime.Now.Subtract(start); if (ts.Seconds > _httpManager.LoadRetryTimeout) { throw; } } Trace.WriteLine($"error : loading \"{_httpRequest.RequestUri}\" ({_httpRequest.Method}) {ex.Message}"); } } }
private HttpResult <TData> Load <TData>(HttpRequest httpRequest, Func <Http_v2, TData> loadData, string subDirectory = null) { bool success = false; bool loadFromWeb = false; bool loadFromCache = false; bool trace = false; Http_v2 http = null; TData data = default(TData); try { if (_urlCache != null) { //HttpResult<UrlCachePathResult> cachePathResult = LoadHttpToCache(httpRequest); //httpRequest.UrlCachePath = cachePathResult.Data; UrlCachePathResult urlCachePath = _urlCache.GetUrlPathResult(httpRequest, subDirectory); string urlPath = urlCachePath.Path; if (httpRequest.ReloadFromWeb || !zFile.Exists(urlPath)) { TraceLevel.WriteLine(1, "Load \"{0}\" ({1})", httpRequest.Url, httpRequest.Method); Http_v2 http2 = CreateHttp(httpRequest); http2.LoadToFile(urlPath, true); loadFromWeb = true; trace = true; } else { loadFromCache = true; } httpRequest.UrlCachePath = urlCachePath; } else { loadFromWeb = true; } if (!trace) { TraceLevel.WriteLine(1, "Load \"{0}\" ({1})", httpRequest.UrlCachePath != null ? httpRequest.UrlCachePath.Path : httpRequest.Url, httpRequest.Method); } http = CreateHttp(httpRequest); //text = http.LoadText(); data = loadData(http); success = true; } catch (Exception ex) { if (_traceException) { Trace.WriteLine("{0:dd/MM/yyyy HH:mm:ss} Error : loading \"{1}\" ({2}) {3}", DateTime.Now, httpRequest.UrlCachePath != null ? httpRequest.UrlCachePath.Path : httpRequest.Url, httpRequest.Method, ex.Message); } else { throw; } } return(new HttpResult <TData> { Success = success, LoadFromWeb = loadFromWeb, LoadFromCache = loadFromCache, Http = http, Data = data }); }