public static void AddorUpdateHistoryItem(string title, string url) { var realm = Realm.GetInstance(); var item = realm.All <History>().FirstOrDefault(x => x.Title == title && x.Url == url); using (var trans = realm.BeginWrite()) { if (item == null) { var auth = FaviconHelper.GetAuthority(url); var fav = FaviconHelper.GetFavicon(auth); item = new History { Id = GetHistoryData().Count() + 1, Title = title, Favicon = fav, Visted = "Visited: " + DateTime.Now.ToString("D") }; realm.Add(item); } else { realm.Add(item, true); } trans.Commit(); } }
public static void AddItem(string title, string url) { urlHistory.Add(new History() { Id = urlHistory.Count + 1, Title = title, Url = url, Favicon = FaviconHelper.GetFavicon(FaviconHelper.GetAuthority(url)), VisitDateTime = DateTime.Now }); }
public IActionResult Get([SwaggerParameter("Url of the website", Required = true)] string url, [SwaggerParameter("Should the favicon be returned as image or base64")] bool base64 = false) { try { var faviconModel = _cache.GetOrCreate(url, entry => { entry.SlidingExpiration = TimeSpan.FromDays(1); var model = new FaviconModel { WebsiteUrl = url, FaviconUrl = UrlHelper.EnsureAbsoluteUrl(url, FaviconHelper.RetrieveFavicon(url)) }; if (string.IsNullOrEmpty(model.FaviconUrl) || !UrlHelper.UrlExists(model.FaviconUrl)) { model.Data = null; return(model); } using (var webClient = new WebClient()) { model.Data = webClient.DownloadData(model.FaviconUrl); model.Mimetype = webClient.ResponseHeaders["Content-Type"]; } return(model); }); if (faviconModel.Data == null) { return(NoContent()); } if (base64) { return(Ok($"data:{faviconModel.Mimetype};base64,{Convert.ToBase64String(faviconModel.Data)}")); } return(File(faviconModel.Data, faviconModel.Mimetype)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, $"{url} | {e.Message} | {e.StackTrace}")); } }
public static void AddBookmark(string title, string url) { var authority = FaviconHelper.GetAuthority(url); var realm = Realm.GetInstance(); using (var trans = realm.BeginWrite()) { var bookmark = new Bookmark { Id = GetBookmarksData().Count(), Title = title, Url = url, Favicon = FaviconHelper.GetFavicon(authority) }; realm.Add(bookmark); trans.Commit(); } }
private byte[] GetWebThumbnail(string originalPath) { if (string.IsNullOrEmpty(originalPath)) { return(null); } if (Path.GetExtension(originalPath).Equals(".pdf", StringComparison.OrdinalIgnoreCase)) { return(GetPdfThumbnail(originalPath)); } var helper = new WebShortcutHelper(originalPath); var bytes = FaviconHelper.GetIconImage(helper.Uri); if (bytes != null) { bytes = CreateFramedSmallIcon(bytes); return(bytes); } return(_standardWebThumbnail.Value); }
private static IEnumerable <Bookmark> DefaultBookmarks() { return(new List <Bookmark> { new Bookmark { Id = 1, Title = "Google", Url = "http://www.google.com", Favicon = FaviconHelper.GetFavicon("google.com") }, new Bookmark { Id = 2, Title = "LinkedIn", Url = "http://www.linkedin.com", Favicon = FaviconHelper.GetFavicon("linkedin.com") }, new Bookmark { Id = 3, Title = "YouTube", Url = "http://www.youtube.com", Favicon = FaviconHelper.GetFavicon("youtube.com") }, new Bookmark { Id = 4, Title = "FaceBook", Url = "http://www.facebook.com", Favicon = FaviconHelper.GetFavicon("facebook.com") }, new Bookmark { Id = 5, Title = "Twitter", Url = "http://www.twitter.com", Favicon = FaviconHelper.GetFavicon("twitter.com") }, new Bookmark { Id = 6, Title = "Microsoft", Url = "http://www.microsoft.com", Favicon = FaviconHelper.GetFavicon("microsoft.com") }, new Bookmark { Id = 7, Title = "Github", Url = "http://www.github.com", Favicon = FaviconHelper.GetFavicon("github.com") }, new Bookmark { Id = 999, Title = "Add", Url = "Add", Favicon = "https://www.pngrepo.com/png/154811/170/thin-add-button.png" } }); }