Beispiel #1
0
        public static async Task <string> ToHtmlEmail(PhotoContent content, IProgress <string> progress)
        {
            if (content == null)
            {
                return(string.Empty);
            }

            var mdBuilder = new StringBuilder();

            mdBuilder.AppendLine(BracketCodePhotos.Create(content));

            var detailsList = new List <string>
            {
                content.Aperture,
                content.ShutterSpeed,
                content.Iso?.ToString("F0"),
                content.Lens,
                content.FocalLength,
                content.CameraMake,
                content.CameraModel,
                content.License
            }.Where(x => !string.IsNullOrWhiteSpace(x)).ToList();

            mdBuilder.AppendLine($"<p style=\"text-align: center;\">Details: {string.Join(", ", detailsList)}</p>");

            var tags = Tags.TagListTextLinkList(content);

            tags.Style("text-align", "center");
            mdBuilder.AppendLine(tags.ToString());

            mdBuilder.AppendLine();

            if (!string.IsNullOrWhiteSpace(content.BodyContent))
            {
                mdBuilder.AppendLine(content.BodyContent);
            }

            mdBuilder.AppendLine();

            mdBuilder.AppendLine($"<p style=\"text-align: center;\">{Tags.CreatedByAndUpdatedOnString(content)}</p>");

            var preprocessResults = BracketCodeCommon.ProcessCodesForEmail(mdBuilder.ToString(), progress);
            var bodyHtmlString    = ContentProcessing.ProcessContent(preprocessResults, content.BodyContentFormat);

            var innerContent = HtmlEmail.ChildrenIntoTableCells(
                $"{await HtmlEmail.EmailSimpleTitle(content)}{bodyHtmlString}{HtmlEmail.EmailSimpleFooter()}");

            var emailHtml = HtmlEmail.WrapInNestedCenteringTable(innerContent);

            return(emailHtml);
        }
Beispiel #2
0
        public async Task G10_PostUpdateChangedDetectionTest()
        {
            var db = await Db.Context();

            var wikiQuotePost = db.PostContents.Single(x => x.Slug == IronwoodPostInfo.WikiQuotePostContent01.Slug);

            var allPhotos = db.PhotoContents.ToList();

            foreach (var loopPhotos in allPhotos)
            {
                wikiQuotePost.BodyContent += BracketCodePhotos.Create(loopPhotos);
            }

            wikiQuotePost.LastUpdatedBy = "Changed Html Test";
            wikiQuotePost.LastUpdatedOn = DateTime.Now;

            var saveResult =
                await PostGenerator.SaveAndGenerateHtml(wikiQuotePost, null, DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(saveResult.generationReturn.HasError);

            var currentGenerationCount = db.GenerationLogs.Count();

            var currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync();

            await HtmlGenerationGroups.GenerateChangedToHtml(DebugTrackers.DebugProgressTracker());

            currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync();

            Assert.AreEqual(currentGenerationCount + 1, db.GenerationLogs.Count(),
                            $"Expected {currentGenerationCount + 1} generation logs - found {db.GenerationLogs.Count()}");

            var relatedContentEntries = await db.GenerationRelatedContents
                                        .Where(x => x.GenerationVersion == currentGeneration.GenerationVersion).ToListAsync();

            Assert.AreEqual(relatedContentEntries.Count, allPhotos.Count() + 1);
            Assert.AreEqual(relatedContentEntries.Select(x => x.ContentOne).Distinct().Count(), 2);
            Assert.AreEqual(relatedContentEntries.Select(x => x.ContentTwo).Count(), allPhotos.Count() + 1);
            Assert.AreEqual(
                relatedContentEntries.Select(x => x.ContentTwo).Except(allPhotos.Select(x => x.ContentId)).Count(), 1);
            Assert.AreEqual(
                allPhotos.Select(x => x.ContentId).Except(relatedContentEntries.Select(x => x.ContentTwo)).Count(), 0);

            var photoContent = UserSettingsSingleton.CurrentSettings().LocalSitePhotoDirectory()
                               .GetFiles("*.html", SearchOption.AllDirectories).ToList().Where(x =>
                                                                                               !x.Name.Contains("Daily") && !x.Name.Contains("Roll") && !x.Name.Contains("List")).ToList();

            photoContent.ForEach(x =>
                                 IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion));


            wikiQuotePost = db.PostContents.Single(x => x.Slug == IronwoodPostInfo.WikiQuotePostContent01.Slug);

            wikiQuotePost.BodyContent =
                wikiQuotePost.BodyContent.Replace(BracketCodePhotos.Create(allPhotos.First()), "");

            wikiQuotePost.LastUpdatedBy = "Changed Html Test 02";
            wikiQuotePost.LastUpdatedOn = DateTime.Now;

            saveResult =
                await PostGenerator.SaveAndGenerateHtml(wikiQuotePost, null, DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(saveResult.generationReturn.HasError);

            currentGenerationCount = db.GenerationLogs.Count();

            currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync();

            await HtmlGenerationGroups.GenerateChangedToHtml(DebugTrackers.DebugProgressTracker());

            currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync();

            Assert.AreEqual(currentGenerationCount + 1, db.GenerationLogs.Count(),
                            $"Expected {currentGenerationCount + 1} generation logs - found {db.GenerationLogs.Count()}");

            relatedContentEntries = await db.GenerationRelatedContents
                                    .Where(x => x.GenerationVersion == currentGeneration.GenerationVersion).ToListAsync();

            Assert.AreEqual(relatedContentEntries.Count, allPhotos.Count() - 1 + 1);
            Assert.AreEqual(relatedContentEntries.Select(x => x.ContentOne).Distinct().Count(), 2);
            Assert.AreEqual(relatedContentEntries.Select(x => x.ContentTwo).Count(), allPhotos.Count() - 1 + 1);
            Assert.AreEqual(
                relatedContentEntries.Select(x => x.ContentTwo).Except(allPhotos.Select(x => x.ContentId)).Count(), 1);
            Assert.AreEqual(
                allPhotos.Select(x => x.ContentId).Except(relatedContentEntries.Select(x => x.ContentTwo)).Count(), 1);

            photoContent = UserSettingsSingleton.CurrentSettings().LocalSitePhotoDirectory()
                           .GetFiles("*.html", SearchOption.AllDirectories).ToList().Where(x =>
                                                                                           !x.Name.Contains("Daily") && !x.Name.Contains("Roll") && !x.Name.Contains("List")).ToList();

            photoContent.ForEach(x =>
                                 IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion));


            wikiQuotePost = db.PostContents.Single(x => x.Slug == IronwoodPostInfo.WikiQuotePostContent01.Slug);

            wikiQuotePost.BodyContent += $"{Environment.NewLine}Visit Ironwood Today!";

            wikiQuotePost.LastUpdatedBy = "Changed Html Test 02";
            wikiQuotePost.LastUpdatedOn = DateTime.Now;

            saveResult =
                await PostGenerator.SaveAndGenerateHtml(wikiQuotePost, null, DebugTrackers.DebugProgressTracker());

            Assert.IsFalse(saveResult.generationReturn.HasError);

            currentGenerationCount = db.GenerationLogs.Count();

            currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync();

            await HtmlGenerationGroups.GenerateChangedToHtml(DebugTrackers.DebugProgressTracker());

            currentGeneration = await db.GenerationLogs.OrderByDescending(x => x.GenerationVersion).FirstAsync();

            Assert.AreEqual(currentGenerationCount + 1, db.GenerationLogs.Count(),
                            $"Expected {currentGenerationCount + 1} generation logs - found {db.GenerationLogs.Count()}");

            relatedContentEntries = await db.GenerationRelatedContents
                                    .Where(x => x.GenerationVersion == currentGeneration.GenerationVersion).ToListAsync();

            Assert.AreEqual(relatedContentEntries.Count, allPhotos.Count() - 1 + 1);
            Assert.AreEqual(relatedContentEntries.Select(x => x.ContentOne).Distinct().Count(), 2);
            Assert.AreEqual(relatedContentEntries.Select(x => x.ContentTwo).Count(), allPhotos.Count() - 1 + 1);
            Assert.AreEqual(
                relatedContentEntries.Select(x => x.ContentTwo).Except(allPhotos.Select(x => x.ContentId)).Count(), 1);
            Assert.AreEqual(
                allPhotos.Select(x => x.ContentId).Except(relatedContentEntries.Select(x => x.ContentTwo)).Count(), 1);

            //Todo: Check that the excluded photo is not regened
        }