public async Task <object> Post(PageInfoRequest request) { string address = request.Address; PageHtmlDownloader.Result result; string source; PageHtmlDownloader downloader = new PageHtmlDownloader(); try { result = await downloader.Download(address); if (result == null) { return(new { Error = "PageNotAvailable" }); } else { source = result.Source; } } catch (UriFormatException) { return(new { Error = "InvalidAddress" }); } string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value; FaviconLoader loader = new FaviconLoader(); FaviconLoader.Result favicon = await loader.Load(result.ResultUri, source); return(new { Error = "", Title = title, FaviconUrl = favicon?.FaviconUrl, FaviconData = favicon?.Data, FaviconMime = favicon?.MimeType, ResultUrl = result.ResultUri.ToString().TrimEnd('/') }); }
public void TestCorrectIcons() { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var loader = new FaviconLoader(); TestIcon(loader, "https://www.github.com"); TestIcon(loader, "http://www.seznam.cz"); TestIcon(loader, "https://sede.policia.gob.es/Tasa790_012/ImpresoRellenar"); // no favicon in HTML, no favicon.ico }
private static void TestIcon(FaviconLoader loader, string url) { Task <string> task = GetHtml(url); string html = GetHtml(url).Result; Assert.IsNotNull(html); FaviconLoader.Result result = loader.Load(new Uri(url), html).Result; if (result != null) { Assert.IsTrue(result.Data != null || result.FaviconUrl == null); Size size = new FaviconSizeDetector().DetectSize(result.Data); Console.WriteLine(result.FaviconUrl + " " + result.MimeType + " " + size); } else { Console.WriteLine(url + ": NO FAVICON"); } }
public void Configure(IApplicationBuilder app) { _loader = new PageLoader(); _favicon = new FaviconLoader(); _feebackSender = new FeedbackSmtpSender(new FeedbackSmtpSender.Config { from = "", to = "", subject = "Hello from DumBlog" }); //_feebackSender = new FeedbackDiscordSender(new FeedbackDiscordSender.Config //{ // clientId = "", // secret = "", // channelId = "", // code = "", // redirectUrl = "" //}); _feeback = new FeedbackLoader(new FeedbackLoader.Config { captcha = (DateTime.Now.Year + 1).ToString(), }, _feebackSender); app.Run(HttpRequestDelegate); }