public static void Configure()
        {
            var fileConfigPath = AppSettingsHelper.GetValue <string>("log4net.Config");
            var fileInfo       = new FileInfo(WebPathHelper.GetPhysicalPath(fileConfigPath));

            XmlConfigurator.Configure(fileInfo);
        }
Exemple #2
0
        public async Task Invoke(HttpContext context)
        {
            // TODO: Add support for caching.
            if (ShouldProcessImagePath(context.Request, out var imageResizeInfo))
            {
                var imagePath     = context.Request.Path;
                var imageFileInfo = _webHostEnvironment.WebRootFileProvider.GetFileInfo(imagePath);

                if (imageFileInfo.Exists)
                {
                    var imageStream = imageFileInfo.CreateReadStream();

                    imageStream = await _imageProcessor.ProcessAsync(imageStream, imageResizeInfo);

                    var imageContentType = WebPathHelper.GetMimeType(Path.GetExtension(imagePath));
                    context.Response.ContentType   = imageContentType;
                    context.Response.ContentLength = imageStream.Length;
                    await context.Response.Body.WriteAsync(await imageStream.ReadAllBytesAsync(), 0, (int)imageStream.Length);

                    return;
                }
            }

            await _next.Invoke(context);
        }
        public static string ProcessImage(this IUrlHelper urlHelper, string url, int?width = null, int?height = null, int?quality = null,
                                          ImageMode?mode = null, ImageFormat?format = null)
        {
            string queryString = "?";

            if (width != null)
            {
                queryString += $"width={width}&";
            }
            if (height != null)
            {
                queryString += $"height={height}&";
            }
            if (quality != null)
            {
                queryString += $"quality={quality}&";
            }
            if (mode != null)
            {
                queryString += $"format={format}&";
            }
            if (format != null)
            {
                queryString += $"mode={mode}&";
            }
            queryString = queryString.TrimEnd('?', '&');

            return(url != null?WebPathHelper.CombineUrlParts(url, queryString) : null);
        }
        /// <summary>
        /// Parses out all images in an email, as follows:
        ///
        /// 1) Looks for images with absolute paths like img src="/ui...
        ///
        /// 2) For each one breaks out its path
        ///
        /// 3) Replaces the paths with MIME cids like src="cid:0"
        ///
        /// 4) Emits in index-order the physical paths of these images into the returned List
        /// </summary>
        /// <param name="appRoot"></param>
        /// <param name="html"></param>
        /// <returns></returns>
        public ParseImageResults ParseImages(string appRoot, string html)
        {
            var regex = new Regex(@"(<img[^>]+src="")(/[^""]+)("")");

            var attachments = new Dictionary <string, int>();
            int cid         = 0;
            var updatedHtml = regex.Replace(html, new MatchEvaluator(match =>
            {
                var parts                  = RegexHelper.GetMatchCaptures(match);
                var attachmentWebPath      = parts[1];
                var attachmentPhysicalPath = WebPathHelper.WebPathToPhysical(attachmentWebPath, appRoot);

                // Only add this attachment if it's not a repeat
                int currentCid;
                if (!attachments.TryGetValue(attachmentPhysicalPath, out currentCid))
                {
                    currentCid = cid;
                    attachments.Add(attachmentPhysicalPath, currentCid);
                    cid++;
                }

                return(parts[0] + "cid:" + currentCid.ToString() + parts[2]);
            }));

            return(new ParseImageResults
            {
                Html = updatedHtml,
                Attachments = attachments.Keys.ToList()
            });
        }
Exemple #5
0
        public string GetSourceUrl(string directoryName, string fileName)
        {
            if (directoryName == null || fileName == null)
            {
                return(null);
            }

            var    factory   = _actionContextAccessor.ActionContext.HttpContext.RequestServices.GetRequiredService <IUrlHelperFactory>();
            var    urlHelper = factory.GetUrlHelper(_actionContextAccessor.ActionContext);
            string sourceUrl = urlHelper.ContentLink(WebPathHelper.CombineUrlParts(directoryUrl, directoryName, fileName));

            return(sourceUrl);
        }
        public async Task <IActionResult> SitemapIndexXml()
        {
            var sitemapList = new SitemapList();

            sitemapList.Sitemaps.Add(Sitemap.CreateSitemap(Url.ContentLink(Url.Action(nameof(SitemapXml)))));

            var users = await _userService.GetQuery(new UserFilter { StoreSetup = true, StoreAccess = StoreAccess.Approved })
                        .Select(x => new { x.StoreSlug })
                        .ToListAsync();

            sitemapList.Sitemaps.AddRange(from user in users select Sitemap.CreateSitemap(Url.ContentLink(Url.Action(nameof(SitemapXml), "Store", new { storeSlug = user.StoreSlug }))));

            return(File(Encoding.UTF8.GetBytes(sitemapList.ToXml()), WebPathHelper.GetMimeType(".xml")));
        }
        public IActionResult SitemapXml()
        {
            var sitemapUrlList = new SitemapUrlList
            {
                SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Index))), 1d),
                SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Pricing)))),
                SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Privacy)))),
                SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(About)))),
                SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Contact)))),
                SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Terms))))
            };

            return(File(Encoding.UTF8.GetBytes(sitemapUrlList.ToXml()), WebPathHelper.GetMimeType(".xml")));
        }
Exemple #8
0
        protected override Task PrepareAsync(Media media)
        {
            var fileExtension = Path.GetExtension(media.FileName).ToLowerInvariant();
            var contentType   = WebPathHelper.GetMimeType(fileExtension);
            var fileType      = fileExtension.TrimStart('.').ToUpperInvariant();

            var comparisonType = StringComparison.InvariantCultureIgnoreCase;

            media.ContentType   = contentType;
            media.FileType      = fileType;
            media.FileExtension = fileExtension;
            media.MediaType     =
                _appSettings.ImageFileExtensions.Any(x => string.Equals(x, fileExtension, comparisonType)) ? MediaType.Image :
                _appSettings.AudioFileExtensions.Any(x => string.Equals(x, fileExtension, comparisonType)) ? MediaType.Audio :
                _appSettings.VideoFileExtensions.Any(x => string.Equals(x, fileExtension, comparisonType)) ? MediaType.Video :
                _appSettings.DocumentFileExtensions.Any(x => string.Equals(x, fileExtension, comparisonType)) ? MediaType.Document :
                throw new InvalidOperationException();


            return(Task.CompletedTask);
        }
Exemple #9
0
        public async Task <IActionResult> SitemapXml()
        {
            var seller = await HttpContext.GetSellerAsync();

            var sitemapList = new SitemapUrlList();

            var products = await _productService.GetQuery().Where(x => x.SellerId == seller.Id && x.Published && !string.IsNullOrWhiteSpace(x.Slug)).Select(x => new { x.Slug }).ToListAsync();

            var categories = await _categoryService.GetQuery().Where(x => x.SellerId == seller.Id && x.Published && !string.IsNullOrWhiteSpace(x.Slug)).Select(x => new { x.Slug }).ToListAsync();

            sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Index)))));
            sitemapList.AddRange(from product in products select SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Products), "Store", new { slug = product.Slug }))));
            sitemapList.AddRange(from category in categories select SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Products), "Store", new { slug = category.Slug }))));
            sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Products)))));
            sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(About)))));
            sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Contact)))));
            sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(Terms)))));
            sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(PrivacyPolicy)))));
            sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(ReturnPolicy)))));
            sitemapList.Add(SitemapUrl.CreateUrl(Url.ContentLink(Url.Action(nameof(ReviewPolicy)))));

            return(File(Encoding.UTF8.GetBytes(sitemapList.ToXml()), WebPathHelper.GetMimeType(".xml")));
        }