Exemplo n.º 1
0
        public ActionResult Favicon()
        {
            var icons = new string[]
            {
                "favicon-{0}.ico".FormatInvariant(_services.StoreContext.CurrentStore.Id),
                "favicon.ico"
            };

            string virtualPath = null;

            foreach (var icon in icons)
            {
                virtualPath = Url.ThemeAwareContent(icon);
                if (virtualPath.HasValue())
                {
                    break;
                }
            }

            if (virtualPath.IsEmpty())
            {
                return(Content(""));
            }

            var model = new FaviconModel()
            {
                Uploaded   = true,
                FaviconUrl = virtualPath
            };

            return(PartialView(model));
        }
Exemplo n.º 2
0
        public virtual FaviconModel PrepareFavicon()
        {
            var model           = new FaviconModel();
            var faviconFileName = string.Format("favicon-{0}.ico", _storeContext.CurrentStore.Id);

            //tbh, this whas original
            //var localFaviconPath = System.IO.Path.Combine(_httpContextAccessor.Request.PhysicalApplicationPath, faviconFileName);

            //test1
            var localFaviconPath = System.IO.Path.Combine(_httpContextAccessor.HttpContext.Request.PathBase, faviconFileName);

            //test2
            //var localFaviconPath = System.IO.Path.Combine(_httpContextAccessor.HttpContext.Request.Path, faviconFileName);


            if (!System.IO.File.Exists(localFaviconPath))
            {
                //try loading a generic favicon
                faviconFileName = "favicon.ico";

                //tbh, the same as above
                localFaviconPath = System.IO.Path.Combine(_httpContextAccessor.HttpContext.Request.PathBase, faviconFileName);
                if (!System.IO.File.Exists(localFaviconPath))
                {
                    return(model);
                }
            }
            model.FaviconUrl = _webHelper.GetStoreLocation() + faviconFileName;
            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prepare the favicon model
        /// </summary>
        /// <returns>Favicon model</returns>
        public virtual FaviconModel PrepareFaviconModel()
        {
            var model           = new FaviconModel();
            var faviconFileName = "/favicon.ico";

            model.FaviconUrl = faviconFileName;
            return(model);
        }
Exemplo n.º 4
0
        public PartialViewResult Favicon()
        {
            var faviconModel = new FaviconModel {
                Uploaded   = System.IO.File.Exists(Request.PhysicalApplicationPath + "favicon.ico"),
                FaviconUrl = _webHelper.GetLocation + "favicon.ico"
            };

            return(PartialView(faviconModel));
        }
Exemplo n.º 5
0
        public ActionResult Favicon()
        {
            var model = new FaviconModel()
            {
                Uploaded = System.IO.File.Exists(System.IO.Path.Combine(Request.PhysicalApplicationPath, "favicon.ico")),
                FaviconUrl = _webHelper.GetWebLocation() + "favicon.ico"
            };

            return PartialView(model);
        }
Exemplo n.º 6
0
        public ActionResult Favicon()
        {
            var model = new FaviconModel()
            {
                Uploaded   = System.IO.File.Exists(System.IO.Path.Combine(Request.PhysicalApplicationPath, "favicon.ico")),
                FaviconUrl = _webHelper.GetStoreLocation() + "favicon.ico"
            };

            return(PartialView(model));
        }
Exemplo n.º 7
0
        public FaviconModel PrepareFaviconModel()
        {
            var model = new FaviconModel();

            var faviconFileName = "favicon.ico";

            var localFaviconPath = System.IO.Path.Combine(_httpContext.Request.PhysicalApplicationPath, faviconFileName);

            if (!File.Exists(localFaviconPath))
            {
                return(model);
            }

            model.FaviconUrl = _webHelper.GetLocation() + faviconFileName;
            return(model);
        }
Exemplo n.º 8
0
        public ActionResult Favicon()
        {
            var store        = Services.StoreContext.CurrentStore;
            var mediaService = _mediaService.Value;

            var model = new FaviconModel
            {
                FavIcon        = mediaService.GetFileById(Convert.ToInt32(store.FavIconMediaFileId), MediaLoadFlags.AsNoTracking),
                PngIcon        = mediaService.GetFileById(Convert.ToInt32(store.PngIconMediaFileId), MediaLoadFlags.AsNoTracking),
                AppleTouchIcon = mediaService.GetFileById(Convert.ToInt32(store.AppleTouchIconMediaFileId), MediaLoadFlags.AsNoTracking),
                MsTileIcon     = mediaService.GetFileById(Convert.ToInt32(store.MsTileImageMediaFileId), MediaLoadFlags.AsNoTracking),
                MsTileColor    = store.MsTileColor
            };

            return(PartialView(model));
        }
Exemplo n.º 9
0
        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}"));
            }
        }
Exemplo n.º 10
0
        public virtual FaviconModel PrepareFavicon()
        {
            var model            = new FaviconModel();
            var faviconFileName  = string.Format("favicon-{0}.ico", _storeContext.CurrentStore.Id);
            var localFaviconPath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, faviconFileName);

            if (!System.IO.File.Exists(localFaviconPath))
            {
                //try loading a generic favicon
                faviconFileName  = "favicon.ico";
                localFaviconPath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, faviconFileName);
                if (!System.IO.File.Exists(localFaviconPath))
                {
                    return(model);
                }
            }
            model.FaviconUrl = _webHelper.GetStoreLocation() + faviconFileName;
            return(model);
        }
Exemplo n.º 11
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var store = Services.StoreContext.CurrentStore;

            var model = await Services.Cache.GetAsync(ModelCacheInvalidator.STORE_FAVICON_MODEL_KEY.FormatInvariant(store.Id), async (o) =>
            {
                o.ExpiresIn(TimeSpan.FromDays(1));

                var model = new FaviconModel
                {
                    // Favicon
                    FavIconUrl = await _mediaService.GetUrlAsync(store.FavIconMediaFileId, 0, null, false)
                };

                // PngIcon 16x16(browser tabs), 32x32(Taskbar), 96x96(Desktop), 196x196(Android Chrome)
                var pngIcon = await _mediaService.GetFileByIdAsync(store.PngIconMediaFileId ?? 0, MediaLoadFlags.AsNoTracking);
                if (pngIcon != null)
                {
                    var pngSizes = new[] { 16, 32, 96, 196 };
                    AddThumbnails(pngIcon, pngSizes, model.PngIcons);
                }

                // AppleTouchIcon
                var appleTouchIcon = await _mediaService.GetFileByIdAsync(store.AppleTouchIconMediaFileId ?? 0, MediaLoadFlags.AsNoTracking);
                if (appleTouchIcon != null)
                {
                    var appleTouchSizes = new[] { 57, 60, 72, 76, 114, 120, 144, 152, 180 };
                    AddThumbnails(appleTouchIcon, appleTouchSizes, model.AppleTouchIcons);
                }

                // MS Tiles
                model.MsTileIconUrl = await _mediaService.GetUrlAsync(store.MsTileImageMediaFileId, 144, null, false);
                model.MsTileColor   = store.MsTileColor;

                return(model);
            });

            return(View(model));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Prepare the favicon model
        /// </summary>
        /// <returns>Favicon model</returns>
        public virtual FaviconModel PrepareFaviconModel()
        {
            var model = new FaviconModel();

            //try loading a store specific favicon

            var faviconFileName  = $"favicon-{_storeContext.CurrentStore.Id}.ico";
            var localFaviconPath = _fileProvider.Combine(_hostingEnvironment.WebRootPath, faviconFileName);

            if (!_fileProvider.FileExists(localFaviconPath))
            {
                //try loading a generic favicon
                faviconFileName  = "favicon.ico";
                localFaviconPath = _fileProvider.Combine(_hostingEnvironment.WebRootPath, faviconFileName);
                if (!_fileProvider.FileExists(localFaviconPath))
                {
                    return(model);
                }
            }

            model.FaviconUrl = _webHelper.GetStoreLocation() + faviconFileName;
            return(model);
        }
        public ActionResult Favicon()
        {
            //try loading a store specific favicon
            var faviconFileName  = string.Format("favicon-{0}.ico", _storeContext.CurrentStore.Id);
            var localFaviconPath = System.IO.Path.Combine(Request.PhysicalApplicationPath, faviconFileName);

            if (!System.IO.File.Exists(localFaviconPath))
            {
                //try loading a generic favicon
                faviconFileName  = "favicon.ico";
                localFaviconPath = System.IO.Path.Combine(Request.PhysicalApplicationPath, faviconFileName);
                if (!System.IO.File.Exists(localFaviconPath))
                {
                    return(Content(""));
                }
            }
            var model = new FaviconModel
            {
                FaviconUrl = _webHelper.GetStoreLocation() + faviconFileName
            };

            return(PartialView(model));
        }
Exemplo n.º 14
0
        public ActionResult Favicon()
        {
            //try loading a store specific favicon
            var faviconFileName = string.Format("favicon-{0}.ico", _storeContext.CurrentStore.Id);
            var localFaviconPath = System.IO.Path.Combine(Request.PhysicalApplicationPath, faviconFileName);
            if (!System.IO.File.Exists(localFaviconPath))
            {
                //try loading a generic favicon
                faviconFileName = "favicon.ico";
                localFaviconPath = System.IO.Path.Combine(Request.PhysicalApplicationPath, faviconFileName);
                if (!System.IO.File.Exists(localFaviconPath))
                {
                    return Content("");
                }
            }

            var model = new FaviconModel
            {
                FaviconUrl = _webHelper.GetStoreLocation() + faviconFileName
            };
            return PartialView(model);
        }
Exemplo n.º 15
0
        public ActionResult Favicon()
        {
            var model = new FaviconModel();

            return(PartialView(model));
        }