public void PhotoCheckFileCountAndPictureAssetsAfterHtmlGeneration(PhotoContent newPhotoContent, int photoWidth) { var contentDirectory = UserSettingsSingleton.CurrentSettings() .LocalSitePhotoContentDirectory(newPhotoContent, false); Assert.True(contentDirectory.Exists, "Content Directory Not Found?"); var expectedNumberOfFiles = PictureResizing.SrcSetSizeAndQualityList().Count(x => x.size < photoWidth) // + 1 //Original image + 1 //Display image + 1 //HTML file + 1; //json file Assert.AreEqual(contentDirectory.GetFiles().Length, expectedNumberOfFiles, "Expected Number of Files Does Not Match"); var pictureAssetInformation = PictureAssetProcessing.ProcessPictureDirectory(newPhotoContent.ContentId); var pictureAssetPhotoDbEntry = (PhotoContent)pictureAssetInformation.DbEntry; Assert.IsTrue(pictureAssetPhotoDbEntry.ContentId == newPhotoContent.ContentId, $"Picture Asset appears to have gotten an incorrect DB entry of {pictureAssetPhotoDbEntry.ContentId} rather than {newPhotoContent.ContentId}"); var maxSize = PictureResizing.SrcSetSizeAndQualityList().Where(x => x.size < photoWidth).Max(); var minSize = PictureResizing.SrcSetSizeAndQualityList().Min(); Assert.AreEqual(pictureAssetInformation.LargePicture.Width, maxSize.size, $"Picture Asset Large Width is not the expected Value - Expected {maxSize}, Actual {pictureAssetInformation.LargePicture.Width}"); Assert.AreEqual(pictureAssetInformation.SmallPicture.Width, PictureResizing.SrcSetSizeAndQualityList().Min().size, $"Picture Asset Small Width is not the expected Value - Expected {minSize}, Actual {pictureAssetInformation.SmallPicture.Width}"); Assert.AreEqual(pictureAssetInformation.SrcsetImages.Count, PictureResizing.SrcSetSizeAndQualityList().Count(x => x.size < photoWidth), "Did not find the expected number of SrcSet Images"); }
/// <summary> /// This deletes Photo Directory jpeg files that match this programs generated sizing naming conventions. If deleteAll /// is true then all /// files will be deleted - otherwise only files where the width does not match one of the generated widths will be /// deleted. /// </summary> /// <param name="dbEntry"></param> /// <param name="deleteAll"></param> /// <param name="progress"></param> public static void CleanDisplayAndSrcSetFilesInPhotoDirectory(PhotoContent dbEntry, bool deleteAll, IProgress <string> progress) { var currentSizes = SrcSetSizeAndQualityList().Select(x => x.size).ToList(); progress?.Report($"Starting SrcSet Photo Cleaning... Current Size List {string.Join(", ", currentSizes)}"); var currentFiles = PictureAssetProcessing.ProcessPhotoDirectory(dbEntry); foreach (var loopFiles in currentFiles.SrcsetImages) { if (!currentSizes.Contains(loopFiles.Width) || deleteAll) { progress?.Report($" Deleting {loopFiles.FileName}"); loopFiles.File.Delete(); } } var sourceFileReference = UserSettingsSingleton.CurrentSettings().LocalMediaArchivePhotoContentFile(dbEntry); var expectedDisplayWidth = DisplayPictureWidth(sourceFileReference, progress); if (currentFiles.DisplayPicture != null && currentFiles.DisplayPicture.Width != expectedDisplayWidth || deleteAll) { currentFiles.DisplayPicture?.File?.Delete(); } }
public static async void WriteContentCommonListRss(List <IContentCommon> content, FileInfo fileInfo, string titleAdd, IProgress <string> progress) { var settings = UserSettingsSingleton.CurrentSettings(); var items = new List <string>(); progress?.Report($"Processing {content.Count} Content Entries to write to {titleAdd} RSS"); foreach (var loopContent in content) { var contentUrl = await settings.ContentUrl(loopContent.ContentId); string itemDescription = null; if (loopContent.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(loopContent.MainPicture.Value); if (imageInfo != null) { itemDescription = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(loopContent.Summary)}</p>" + $"<p>Read more at <a href=\"https:{contentUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(itemDescription)) { itemDescription = $"<p>{HttpUtility.HtmlEncode(loopContent.Summary)}</p>" + $"<p>Read more at <a href=\"https:{contentUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssItemString(loopContent.Title, $"https:{contentUrl}", itemDescription, loopContent.CreatedOn, loopContent.ContentId.ToString())); } progress?.Report($"Writing {titleAdd} RSS to {fileInfo.FullName}"); var localIndexFile = fileInfo; if (localIndexFile.Exists) { localIndexFile.Delete(); localIndexFile.Refresh(); } await FileManagement.WriteAllTextToFileAndLogAsync(localIndexFile.FullName, RssFileString($"{UserSettingsSingleton.CurrentSettings().SiteName} - {titleAdd}", string.Join(Environment.NewLine, items)), Encoding.UTF8); }
public void WriteRss() { var items = new List <string>(); foreach (var loopPosts in IndexContent) { if (loopPosts.GetType() == typeof(PostContent)) { var post = new SinglePostDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(NoteContent)) { var post = new SingleNoteDiv(loopPosts); var content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(PhotoContent)) { var post = new SinglePostDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } } if (loopPosts.GetType() == typeof(ImageContent)) { var post = new SingleImageDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(FileContent)) { var post = new SingleFileDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } } var localIndexFile = UserSettingsSingleton.CurrentSettings().LocalSiteRssIndexFeedListFile(); if (localIndexFile.Exists) { localIndexFile.Delete(); localIndexFile.Refresh(); } File.WriteAllText(localIndexFile.FullName, RssBuilder.RssFileString($"{UserSettingsSingleton.CurrentSettings().SiteName}", string.Join(Environment.NewLine, items)), Encoding.UTF8); }