// HttpRequestParameters requestParameters = null //private HttpResult<UrlCachePathResult> LoadHttpToCache(HttpRequest httpRequest, string subDirectory = null) //{ // HttpResult<UrlCachePathResult> cachePathResult = new HttpResult<UrlCachePathResult>(); // //UrlCachePathResult urlCachePath = _urlCache.GetUrlPathResult(httpRequest, subDirectory); // cachePathResult.Data = _urlCache.GetUrlPathResult(httpRequest, subDirectory); // string urlPath = cachePathResult.Data.Path; // if (httpRequest.ReloadFromWeb || !zFile.Exists(urlPath)) // { // //_InitLoadFromWeb(httpRequest); // //if (!HttpManager.CurrentHttpManager.LoadToFile(httpRequest, urlPath, _urlCache.SaveRequest, _GetHttpRequestParameters())) // // return webResult; // Trace.WriteLine(1, "Load \"{0}\" ({1})", httpRequest.Url, httpRequest.Method); // Http_v2 http = CreateHttp(httpRequest); // http.LoadToFile(urlPath, true); // cachePathResult.Http = http; // } // return cachePathResult; //} // HttpRequestParameters requestParameters = null, string exportFile = null, bool setExportFileExtension = false // bool cacheFile = false public Http_v2 CreateHttp(HttpRequest httpRequest) { //if (!cacheFile) if (httpRequest.UrlCachePath == null) { _InitLoadFromWeb(); } Http_v2 http = new Http_v2(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); }
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 }); }