예제 #1
0
        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);
            }
        }
예제 #2
0
파일: HttpRun_v1.cs 프로젝트: 24/source_04
 public static Http Load(HttpRequest httpRequest, HttpRequestParameters requestParameters = null, string exportFile = null, bool setExportFileExtension = false)
 {
     RazSource();
     __xmlDocumentSourceType = XmlDocumentSourceType.Http;
     //__http = __httpManager.Load(httpRequest, requestParameters);
     __http = HttpManager.CurrentHttpManager.Load(httpRequest, requestParameters, exportFile, setExportFileExtension);
     return(__http);
 }
예제 #3
0
        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);
        }
예제 #4
0
파일: Http.cs 프로젝트: 24/source_04
        //public string GetNewHttpFileName(string dir, string ext)
        //{
        //    return GetNewUrlFileName(dir, _httpRequest.Url, ext);
        //}

        //private static string GetNewUrlFileName(string dir, string url, string ext)
        //{
        //    //string file = UrlToFileName(url, ext);
        //    //return zfile.GetNewIndexedFileName(zPath.Combine(dir, "{0:0000}")) + "_" + file;
        //    //return zfile.GetNewIndexedFileName(dir) + "_" + UrlToFileName(url, ext);
        //    return zfile.GetNewIndexedFileName(dir) + "_" + zurl.UrlToFileName(url, UrlFileNameType.Host | UrlFileNameType.Path | UrlFileNameType.Ext | UrlFileNameType.Query, ext);
        //}

        //public static string UrlToFileName(string url, string ext, UrlFileNameType type = UrlFileNameType.FileName)
        //{
        //    string file;
        //    Uri uri = new Uri(url);
        //    if (type == UrlFileNameType.FileName)
        //    {
        //        file = uri.LocalPath;
        //        while (file.StartsWith("/")) file = file.Remove(0, 1);
        //        file = file.Replace("/", "_");
        //        if (file != "")
        //            file = uri.Host + "_" + file;
        //        else
        //            file = uri.Host;
        //        if (ext != null) file = file + ext;
        //    }
        //    else
        //    {
        //        if (type == UrlFileNameType.Path)
        //            file = uri.AbsolutePath;
        //        else if (type == UrlFileNameType.Query)
        //            file = uri.Query;
        //        else
        //            return null;
        //        int i = file.IndexOf("://");
        //        if (i != -1) file = zstr.right(file, file.Length - i - 3);
        //        i = file.IndexOf('?');
        //        if (i != -1) file = zstr.left(file, i);
        //        file = file.Replace('/', '_');
        //        file = file.Replace('%', '_');
        //        if (ext != null) file = file + ext;
        //    }
        //    file = zPath.GetFileName(file);
        //    return file;
        //}

        public static Http LoadAsText(HttpRequest httpRequest, HttpRequestParameters requestParameters = null, string exportFile = null, bool setExportFileExtension = false)
        {
            Http http = new Http(httpRequest, requestParameters);

            http.ExportFile             = exportFile;
            http.SetExportFileExtension = setExportFileExtension;
            http.LoadAsText();
            return(http);
        }
예제 #5
0
파일: Http.cs 프로젝트: 24/source_04
 public Http(HttpRequest httpRequest, HttpRequestParameters requestParameters = null)
 {
     _httpRequest = httpRequest;
     if (requestParameters != null)
     {
         _requestParameters = requestParameters;
     }
     else
     {
         _requestParameters = new HttpRequestParameters();
     }
     _progress = new Progress();
 }
예제 #6
0
파일: HttpBase.cs 프로젝트: 24/source_04
 // bool cacheFile = false
 public HttpBase(HttpRequest httpRequest, HttpRequestParameters requestParameters = null)
 {
     _httpRequest = httpRequest;
     if (requestParameters != null)
     {
         _requestParameters = requestParameters;
     }
     else
     {
         _requestParameters = new HttpRequestParameters();
     }
     //_cacheFile = cacheFile;
     //_progress = new Progress();
 }
예제 #7
0
        public Http CreateHttp(HttpRequest httpRequest, HttpRequestParameters requestParameters = null, string exportFile = null, bool setExportFileExtension = false)
        {
            Http http = new Http(httpRequest, requestParameters);

            //http.HttpRetry += new Http.fnHttpRetry(LoadRetryEvent);
            http.LoadRetryTimeout = _loadRetryTimeout;
            if (exportFile != null)
            {
                http.ExportFile             = exportFile;
                http.SetExportFileExtension = setExportFileExtension;
            }
            else if (_exportResult && _exportDirectory != null)
            {
                http.ExportFile             = GetNewHttpFileName(httpRequest);
                http.SetExportFileExtension = true;
            }
            return(http);
        }
예제 #8
0
 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);
         }
     }
 }
예제 #9
0
 public Image LoadImage(HttpRequest httpRequest, HttpRequestParameters requestParameters = null)
 {
     try
     {
         for (int i = 0; i < _loadRepeatIfError - 1; i++)
         {
             try
             {
                 return(_LoadImage(httpRequest, requestParameters));
             }
             catch (Exception ex)
             {
                 if (!ex.GetType().FullName.StartsWith("System.Net."))
                 {
                     throw;
                 }
                 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(_LoadImage(httpRequest, requestParameters));
     }
     catch (Exception ex)
     {
         Trace.WriteLine("Error : \"{0}\" ({1})", ex.Message, ex.GetType().ToString());
         return(null);
     }
 }
예제 #10
0
        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));
        }
예제 #11
0
파일: HttpRun_v1.cs 프로젝트: 24/source_04
 public static Image LoadImage(HttpRequest httpRequest, HttpRequestParameters requestParameters = null)
 {
     return(HttpManager.CurrentHttpManager.LoadImage(httpRequest, requestParameters));
 }
예제 #12
0
파일: HttpRun_v1.cs 프로젝트: 24/source_04
 public static Image LoadImage(string url, HttpRequestParameters requestParameters = null)
 {
     return(HttpManager.CurrentHttpManager.LoadImage(new HttpRequest {
         Url = url
     }, requestParameters));
 }
예제 #13
0
파일: HttpRun_v1.cs 프로젝트: 24/source_04
 public static bool LoadToFile(HttpRequest httpRequest, string file, bool exportRequest = false, HttpRequestParameters requestParameters = null)
 {
     return(HttpManager.CurrentHttpManager.LoadToFile(httpRequest, file, exportRequest, requestParameters));
 }
예제 #14
0
파일: HttpRun_v1.cs 프로젝트: 24/source_04
 public static Http Load(string url, HttpRequestParameters requestParameters = null, string exportFile = null, bool setExportFileExtension = false)
 {
     return(Load(new HttpRequest {
         Url = url
     }, requestParameters, exportFile, setExportFileExtension));
 }
예제 #15
0
 public static void SetRequestParameters(HttpRequestParameters requestParameters)
 {
     _httpManager.RequestParameters = requestParameters;
 }