public void ProcessPage(Uri outputFolder, Func<Uri, bool> isLocalUrl, Dictionary<Uri, string> pages, Dictionary<Uri, string> resources, Uri pageUrl, HtmlDocument pageDocument, Logger logger) { var resourcesUrls = pageDocument.GetResourcesUrls(outputFolder, isLocalUrl, resources, pageUrl); using (var webClient = new WebClient()) { foreach (var resourceUrls in resourcesUrls) { var localResourcePath = resourceUrls.FilePath.LocalPath; if (!Path.GetExtension(localResourcePath).Equals(".js", StringComparison.OrdinalIgnoreCase)) { continue; } string errorMessage; if (!VerifyDirectoryExists(Path.GetDirectoryName(localResourcePath), logger, out errorMessage)) { continue; } var externsFileName = GetExternsFilePath(localResourcePath); try { webClient.DownloadFile(GetExternsFileUrl(resourceUrls.ResourceUrl), externsFileName); } catch (WebException) { using (File.Create(externsFileName)) { } } } } }
private void GetResources(Uri outputFolder, Func<Uri, bool> isLocalUrl, Dictionary<Uri, string> pages, Dictionary<Uri, string> resources, Uri pageUrl, HtmlDocument pageDocument, Logger logger) { var resourcesUrls = pageDocument.GetResourcesUrls(outputFolder, isLocalUrl, resources, pageUrl); using (var webClient = new WebClient()) { foreach (var resourceUrls in resourcesUrls) { var localResourcePath = resourceUrls.FilePath.LocalPath; logger.LogDebugMessage("Saving resource {0} to {1}", pageUrl, localResourcePath); string errorMessage; if (!VerifyDirectoryExists(Path.GetDirectoryName(localResourcePath), logger, out errorMessage)) { pages[pageUrl] = errorMessage; continue; } webClient.DownloadFile(resourceUrls.ResourceUrl, localResourcePath); resources.Add(resourceUrls.FilePath, null); } } }