public async System.Threading.Tasks.Task HandleEventAsync(EntityDeletedEvent <ProductPicture> eventMessage) { // Is this an ABC product with an ABC Item Number? var pad = await _productAbcDescriptionService.GetProductAbcDescriptionByProductIdAsync(eventMessage.Entity.ProductId); if (pad == null) { return; } // Is there a picture in product_images? var abcProductImagePath = _nopFileProvider.GetFiles("wwwroot/product_images", $"{pad.AbcItemNumber}_large.*").FirstOrDefault(); if (abcProductImagePath == null) { return; } // Are they the same picture? If so delete. var nopPictureBinary = await _pictureService.GetPictureBinaryByPictureIdAsync(eventMessage.Entity.PictureId); var fileSystemBinary = await _nopFileProvider.ReadAllBytesAsync(abcProductImagePath); if (nopPictureBinary.BinaryData.SequenceEqual(fileSystemBinary)) { _nopFileProvider.DeleteFile(abcProductImagePath); await _logger.InformationAsync($"Deleted image `{abcProductImagePath}` (image deleted in NOP)"); } }
/// <summary> /// Loads a picture from file /// </summary> /// <param name="pictureId">Picture identifier</param> /// <param name="mimeType">MIME type</param> /// <returns>Picture binary</returns> protected virtual async Task <byte[]> LoadPictureFromFileAsync(int pictureId, string mimeType) { var lastPart = await GetFileExtensionFromMimeTypeAsync(mimeType); var fileName = $"{pictureId:0000000}_0.{lastPart}"; var filePath = await GetPictureLocalPathAsync(fileName); return(await _fileProvider.ReadAllBytesAsync(filePath)); }
/// <summary> /// Install plugin /// </summary> /// <returns>A task that represents the asynchronous operation</returns> public override async Task InstallAsync() { //pictures var sampleImagesPath = _fileProvider.MapPath("~/Plugins/Widgets.NivoSlider/Content/nivoslider/sample-images/"); //settings var settings = new NivoSliderSettings { Picture1Id = (await _pictureService.InsertPictureAsync(await _fileProvider.ReadAllBytesAsync(_fileProvider.Combine(sampleImagesPath, "banner1.jpg")), MimeTypes.ImagePJpeg, "banner_1")).Id, Text1 = "", Link1 = _webHelper.GetStoreLocation(), Picture2Id = (await _pictureService.InsertPictureAsync(await _fileProvider.ReadAllBytesAsync(_fileProvider.Combine(sampleImagesPath, "banner2.jpg")), MimeTypes.ImagePJpeg, "banner_2")).Id, Text2 = "", Link2 = _webHelper.GetStoreLocation() //Picture3Id = _pictureService.InsertPicture(File.ReadAllBytes(_fileProvider.Combine(sampleImagesPath,"banner3.jpg")), MimeTypes.ImagePJpeg, "banner_3").Id, //Text3 = "", //Link3 = _webHelper.GetStoreLocation(), }; await _settingService.SaveSettingAsync(settings); await _localizationService.AddLocaleResourceAsync(new Dictionary <string, string> { ["Plugins.Widgets.NivoSlider.Picture1"] = "Picture 1", ["Plugins.Widgets.NivoSlider.Picture2"] = "Picture 2", ["Plugins.Widgets.NivoSlider.Picture3"] = "Picture 3", ["Plugins.Widgets.NivoSlider.Picture4"] = "Picture 4", ["Plugins.Widgets.NivoSlider.Picture5"] = "Picture 5", ["Plugins.Widgets.NivoSlider.Picture"] = "Picture", ["Plugins.Widgets.NivoSlider.Picture.Hint"] = "Upload picture.", ["Plugins.Widgets.NivoSlider.Text"] = "Comment", ["Plugins.Widgets.NivoSlider.Text.Hint"] = "Enter comment for picture. Leave empty if you don't want to display any text.", ["Plugins.Widgets.NivoSlider.Link"] = "URL", ["Plugins.Widgets.NivoSlider.Link.Hint"] = "Enter URL. Leave empty if you don't want this picture to be clickable.", ["Plugins.Widgets.NivoSlider.AltText"] = "Image alternate text", ["Plugins.Widgets.NivoSlider.AltText.Hint"] = "Enter alternate text that will be added to image." }); await base.InstallAsync(); }
/// <summary> /// Create an file attachment for the specific file path /// </summary> /// <param name="filePath">Attachment file path</param> /// <param name="attachmentFileName">Attachment file name</param> /// <returns>A leaf-node MIME part that contains an attachment.</returns> protected async Task <MimePart> CreateMimeAttachmentAsync(string filePath, string attachmentFileName = null) { if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentNullException(nameof(filePath)); } if (string.IsNullOrWhiteSpace(attachmentFileName)) { attachmentFileName = Path.GetFileName(filePath); } return(CreateMimeAttachment( attachmentFileName, await _fileProvider.ReadAllBytesAsync(filePath), _fileProvider.GetCreationTime(filePath), _fileProvider.GetLastWriteTime(filePath), _fileProvider.GetLastAccessTime(filePath))); }
public override async Task InstallAsync() { //background var sampleBackgroundPath = _fileProvider.MapPath("~/Plugins/Misc.ComingSoonPage/Content/comingsoonpage/background.jpg"); //settings var settings = new ComingSoonPageSettings { BackgroundId = (await _pictureService.InsertPictureAsync(await _fileProvider.ReadAllBytesAsync(sampleBackgroundPath), MimeTypes.ImagePJpeg, "background")).Id, OpeningDate = DateTime.Now.AddDays(7), DisplayCountdown = true, DisplayNewsletterBox = true, DisplayLoginButton = true }; await _settingService.SaveSettingAsync(settings); //locales await _localizationService.AddLocaleResourceAsync(new Dictionary <string, string> { ["Plugins.Misc.ComingSoonPage.PageTitle"] = "Coming soon!", ["Plugins.Misc.ComingSoonPage.ComingSoon"] = "Our new webshop is coming soon!", ["Plugins.Misc.ComingSoonPage.ComingSoon.Hint"] = "Subscribe To Get Notified", ["Plugins.Misc.ComingSoonPage.Background"] = "Background", ["Plugins.Misc.ComingSoonPage.Background.Hint"] = "Fullscreen background image.", ["Plugins.Misc.ComingSoonPage.OpeningDate"] = "Opening date", ["Plugins.Misc.ComingSoonPage.OpeningDate.Hint"] = "Date and time when shop opens [countdown is displayed based on this setting).", ["Plugins.Misc.ComingSoonPage.DisplayCountdown"] = "Display countdown", ["Plugins.Misc.ComingSoonPage.DisplayCountdown.Hint"] = "Check to display countdown based on the opening date.", ["Plugins.Misc.ComingSoonPage.DisplayNewsletterBox"] = "Allow subscription", ["Plugins.Misc.ComingSoonPage.DisplayNewsletterBox.Hint"] = "Check to display input for visitors to subscribe.", ["Plugins.Misc.ComingSoonPage.DisplayLoginButton"] = "Display login button", ["Plugins.Misc.ComingSoonPage.DisplayLoginButton.Hint"] = "Check to display login button, so administrators can still log in.", ["Plugins.Misc.ComingSoonPage.Countdown.Day"] = "Day", ["Plugins.Misc.ComingSoonPage.Countdown.Days"] = "Days", ["Plugins.Misc.ComingSoonPage.Countdown.Week"] = "Week", ["Plugins.Misc.ComingSoonPage.Countdown.Weeks"] = "Weeks", }); await base.InstallAsync(); }