Exemple #1
0
        public static HtmlTag FromContentCommon(IContentCommon content)
        {
            if (content == null)
            {
                return(HtmlTag.Empty());
            }

            var compactContentContainerDiv = new DivTag().AddClass("content-compact-container");

            var linkTo = UserSettingsSingleton.CurrentSettings().ContentUrl(content.ContentId).Result;

            if (content.MainPicture != null)
            {
                var compactContentMainPictureContentDiv =
                    new DivTag().AddClass("content-compact-image-content-container");

                var image = new PictureSiteInformation(content.MainPicture.Value);

                compactContentMainPictureContentDiv.Children.Add(Tags.PictureImgThumbWithLink(image.Pictures, linkTo));

                compactContentContainerDiv.Children.Add(compactContentMainPictureContentDiv);
            }

            var compactContentMainTextContentDiv = new DivTag().AddClass("content-compact-text-content-container");

            var compactContentMainTextTitleTextDiv =
                new DivTag().AddClass("content-compact-text-content-title-container");
            var compactContentMainTextTitleLink =
                new LinkTag(content.Title, linkTo).AddClass("content-compact-text-content-title-link");

            compactContentMainTextTitleTextDiv.Children.Add(compactContentMainTextTitleLink);

            HtmlTag compactContentSummaryTextDiv;

            if (content.MainPicture == null)
            {
                compactContentSummaryTextDiv = new DivTag().AddClass("content-compact-text-content-summary")
                                               .Text(content.Summary);
            }
            else
            {
                compactContentSummaryTextDiv = new DivTag().AddClass("content-compact-text-content-optional-summary")
                                               .Text(content.Summary);
            }

            var compactContentMainTextCreatedOrUpdatedTextDiv = new DivTag()
                                                                .AddClass("content-compact-text-content-date")
                                                                .Text(Tags.LatestCreatedOnOrUpdatedOn(content)?.ToString("M/d/yyyy") ?? string.Empty);

            compactContentMainTextContentDiv.Children.Add(compactContentMainTextTitleTextDiv);
            compactContentMainTextContentDiv.Children.Add(compactContentSummaryTextDiv);
            compactContentMainTextContentDiv.Children.Add(compactContentMainTextCreatedOrUpdatedTextDiv);

            compactContentContainerDiv.Children.Add(compactContentMainTextContentDiv);

            return(compactContentContainerDiv);
        }
        public static HtmlTag RelatedContentDiv(IContentCommon post)
        {
            if (post == null)
            {
                return(HtmlTag.Empty());
            }

            var relatedPostContainerDiv = new DivTag().AddClass("related-post-container");

            if (post.MainPicture != null)
            {
                var relatedPostMainPictureContentDiv = new DivTag().AddClass("related-post-image-content-container");

                var image = new PictureSiteInformation(post.MainPicture.Value);

                relatedPostMainPictureContentDiv.Children.Add(Tags.PictureImgThumbWithLink(image.Pictures,
                                                                                           UserSettingsSingleton.CurrentSettings().ContentUrl(post.ContentId).Result));

                relatedPostContainerDiv.Children.Add(relatedPostMainPictureContentDiv);
            }

            var relatedPostMainTextContentDiv = new DivTag().AddClass("related-post-text-content-container");

            var relatedPostMainTextTitleTextDiv = new DivTag().AddClass("related-post-text-content-title-container");

            HtmlTag relatedPostMainTextTitleLink;

            if (post.MainPicture == null)
            {
                relatedPostMainTextTitleLink =
                    new LinkTag($"{post.Title} - {post.Summary}",
                                UserSettingsSingleton.CurrentSettings().ContentUrl(post.ContentId).Result)
                    .AddClass("related-post-text-content-title-link");
            }
            else
            {
                relatedPostMainTextTitleLink =
                    new LinkTag(post.Title, UserSettingsSingleton.CurrentSettings().ContentUrl(post.ContentId).Result)
                    .AddClass("related-post-text-content-title-link");
            }

            relatedPostMainTextTitleTextDiv.Children.Add(relatedPostMainTextTitleLink);

            var relatedPostMainTextCreatedOrUpdatedTextDiv = new DivTag().AddClass("related-post-text-content-date")
                                                             .Text(Tags.LatestCreatedOnOrUpdatedOn(post)?.ToString("M/d/yyyy") ?? string.Empty);

            relatedPostMainTextContentDiv.Children.Add(relatedPostMainTextTitleTextDiv);
            relatedPostMainTextContentDiv.Children.Add(relatedPostMainTextCreatedOrUpdatedTextDiv);

            relatedPostContainerDiv.Children.Add(relatedPostMainTextContentDiv);

            return(relatedPostContainerDiv);
        }
        public static async Task <HtmlTag> RelatedContentTag(IContentCommon content, DateTime?generationVersion,
                                                             IProgress <string> progress = null)
        {
            var toSearch = string.Empty;

            toSearch += content.BodyContent + content.Summary;

            if (content is IUpdateNotes updateContent)
            {
                toSearch += updateContent.UpdateNotes;
            }

            return(await RelatedContentTag(content.ContentId, toSearch, generationVersion, progress));
        }
Exemple #4
0
        public static async Task CommonContentChecks(IHtmlDocument document, IContentCommon toCheck)
        {
            Assert.AreEqual(toCheck.Title, document.Title);

            var contentVersionAttributeString =
                document.Head.Attributes.Single(x => x.Name == "data-contentversion").Value;

            Assert.AreEqual(toCheck.ContentVersion.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff"),
                            contentVersionAttributeString, "Content Version of HTML Does not match Data");

            //Todo - check description

            Assert.AreEqual(toCheck.Tags,
                            document.QuerySelector("meta[name='keywords']")?.Attributes
                            .FirstOrDefault(x => x.LocalName == "content")?.Value);

            Assert.AreEqual(UserSettingsSingleton.CurrentSettings().SiteName,
                            document.QuerySelector("meta[property='og:site_name']")?.Attributes
                            .FirstOrDefault(x => x.LocalName == "content")?.Value);

            Assert.AreEqual($"https:{await UserSettingsSingleton.CurrentSettings().PageUrl(toCheck.ContentId)}",
                            document.QuerySelector("meta[property='og:url']")?.Attributes
                            .FirstOrDefault(x => x.LocalName == "content")?.Value);

            Assert.AreEqual("article",
                            document.QuerySelector("meta[property='og:type']")?.Attributes
                            .FirstOrDefault(x => x.LocalName == "content")?.Value);

            var tagContainers = document.QuerySelectorAll(".tags-detail-link-container");
            var contentTags   = Db.TagListParseToSlugsAndIsExcluded(toCheck);

            Assert.AreEqual(tagContainers.Length, contentTags.Count);

            var tagLinks = document.QuerySelectorAll(".tag-detail-link");

            Assert.AreEqual(tagLinks.Length, contentTags.Count(x => !x.IsExcluded));

            var tagNoLinks = document.QuerySelectorAll(".tag-detail-text");

            Assert.AreEqual(tagNoLinks.Length, contentTags.Count(x => x.IsExcluded));
        }
Exemple #5
0
        public static async Task ExtractAndWriteRelatedContentDbReferences(DateTime generationVersion,
                                                                           IContentCommon content, PointlessWaymarksContext db, IProgress <string> progress)
        {
            var toAdd = new List <Guid>();

            if (content.MainPicture != null && content.MainPicture != content.ContentId)
            {
                toAdd.Add(content.MainPicture.Value);
            }

            var toSearch = string.Empty;

            toSearch += content.BodyContent + content.Summary;

            if (content is IUpdateNotes updateContent)
            {
                toSearch += updateContent.UpdateNotes;
            }

            if (string.IsNullOrWhiteSpace(toSearch) && !toAdd.Any())
            {
                return;
            }

            toAdd.AddRange(BracketCodeCommon.BracketCodeContentIds(toSearch));

            if (!toAdd.Any())
            {
                return;
            }

            var dbEntries = toAdd.Distinct().Select(x => new GenerationRelatedContent
            {
                ContentOne = content.ContentId, ContentTwo = x, GenerationVersion = generationVersion
            });

            await db.GenerationRelatedContents.AddRangeAsync(dbEntries);

            await db.SaveChangesAsync();
        }
Exemple #6
0
        public static bool ContainsSpatialBracketCodes(IContentCommon content)
        {
            if (content == null)
            {
                return(false);
            }

            var toSearch = string.Empty;

            toSearch += content.BodyContent + content.Summary;

            if (content is IUpdateNotes updateContent)
            {
                toSearch += updateContent.UpdateNotes;
            }

            if (string.IsNullOrWhiteSpace(toSearch))
            {
                return(false);
            }

            return(ContainsSpatialBracketCodes(toSearch));
        }
Exemple #7
0
 int replaceOccurencesOfText(IContentCommon c, string find, string replace, bool caseSensitive, bool searchHtmlSource)
 {
     int count = 0;
     string s;
     if (c is ContentBase) {
         s = ((ContentBase)c).Name;
         count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
         ((ContentBase)c).Name = s;
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.LongTextProperty)) {
         LongStringPropertyValue pv = (LongStringPropertyValue)p;
         s = pv.Value;
         count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
         pv.Value = s;
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.HTMLProperty)) {
         HTMLPropertyValue pv = (HTMLPropertyValue)p;
         if (!searchHtmlSource) {
             s = pv.Value;
             count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
             pv.Value = s;
             //HtmlNode htmlMain = new HtmlNode(pv.Value, HtmlFilter.TextFilter);
             //// count += replaceOccurencesOfText(textOnly, find, replace, caseSensitive);
             //throw new NotImplementedException("Non HTML source replace in HTML field is not supported yet. ");
         } else {
             s = pv.Value;
             count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
             pv.Value = s;
         }
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.ShortTextProperty)) {
         if (p is ShortStringPropertyValue) {
             ShortStringPropertyValue pv = (ShortStringPropertyValue)p;
             s = pv.Value;
             count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
             pv.Value = s;
         }
     }
     foreach (IInnerContentsPropertyValue icp in c.GetAllPropertyValues(PropertyBaseClass.InnerContents)) {
         foreach (IInnerContent ic in icp.GetAllContents()) {
             count += replaceOccurencesOfText(ic, find, replace, caseSensitive, searchHtmlSource);
         }
     }
     return count;
 }
Exemple #8
0
 int countOccurencesOfText(IContentCommon c, string find, bool caseSensitive, bool searchHtmlSource)
 {
     int count = 0;
     if (c is ContentBase) {
         count += countOccurencesOfText(((ContentBase)c).Name, find, caseSensitive);
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.LongTextProperty)) {
         try {
             LongStringPropertyValue pv = (LongStringPropertyValue)p;
             count += countOccurencesOfText(pv.Value, find, caseSensitive);
         } catch {
         }
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.HTMLProperty)) {
         HTMLPropertyValue pv = (HTMLPropertyValue)p;
         if (!searchHtmlSource) {
             string textOnly = new HtmlNode(pv.Value, HtmlFilter.TextFilter).ToString();
             count += countOccurencesOfText(textOnly, find, caseSensitive);
         } else {
             count += countOccurencesOfText(pv.Value, find, caseSensitive);
         }
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.ShortTextProperty)) {
         if (p is ShortStringPropertyValue) {
             ShortStringPropertyValue pv = (ShortStringPropertyValue)p;
             count += countOccurencesOfText(pv.Value, find, caseSensitive);
         }
     }
     foreach (IInnerContentsPropertyValue icp in c.GetAllPropertyValues(PropertyBaseClass.InnerContents)) {
         foreach (IInnerContent ic in icp.GetAllContents()) {
             count += countOccurencesOfText(ic, find, caseSensitive, searchHtmlSource);
         }
     }
     return count;
 }
Exemple #9
0
 void resizeImages(IContentCommon ic, int max)
 {
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.FileProperty)) {
         if (WFContext.BreakExecution) return;
         var fp = (FilePropertyValue)f;
         if (fp.IsImage()) {
             WFContext.Caption = "Rescaling images...";
             WFContext.Description = _countContents + " contents examined. " + _countResized + " images rescaled. Before: " + Utils.GetByteSizeString(bytesBefore) + ". After: " + Utils.GetByteSizeString(bytesAfter);
             _totalCount++;
             int pixels = fp.ImageHeight * fp.ImageWidth;
             if (pixels > max) {
                 double ration = Math.Sqrt((double)pixels / (double)max);
                 int newHeight = (int)Math.Round((double)fp.ImageHeight / ration);
                 int newWidth = (int)Math.Round((double)fp.ImageWidth / ration);
                 string tempFilePath = Engine.FileTempPath + Guid.NewGuid();
                 ImageAdjustments ia = new ImageAdjustments();
                 ia.CanvasX = newWidth;
                 ia.CanvasY = newHeight;
                 bytesBefore += WAFRuntime.FileSystem.GetFileInfo(fp.GetFilePath()).Length;
                 WAFRuntime.FileSystem.FileCopy(fp.GetFilePath(ia), tempFilePath);
                 bytesAfter += WAFRuntime.FileSystem.GetFileInfo(tempFilePath).Length;
                 string newFileName = fp.FileName.Replace("%20", "_").Replace(" ", "_") + "_" + fp.FileExtension;
                 fp.SetFile(tempFilePath, newFileName, true);
                 _countResized++;
             }
         }
     }
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.FileFolderProperty)) {
         var fp = (IInnerContentsPropertyValue)f;
         foreach (var ff in fp.GetAllContents()) resizeImages(ff, max);
     }
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.InnerContents)) {
         var fp = (IInnerContentsPropertyValue)f;
         foreach (var ff in fp.GetAllContents()) resizeImages(ff, max);
     }
 }
 public static string IncludeIfNeeded(IContentCommon content)
 {
     return(BracketCodeCommon.ContainsSpatialBracketCodes(content) ? ScriptsAndLinks() : string.Empty);
 }
Exemple #11
0
        public static async Task <GenerationReturn> CheckForBadContentReferences(IContentCommon content,
                                                                                 PointlessWaymarksContext db, IProgress <string> progress)
        {
            progress?.Report($"Checking ContentIds for {content.Title}");

            var extracted = new List <Guid>();

            if (content.MainPicture != null && content.MainPicture != content.ContentId)
            {
                extracted.Add(content.MainPicture.Value);
            }

            var toSearch = string.Empty;

            toSearch += content.BodyContent + content.Summary;

            if (content is IUpdateNotes updateContent)
            {
                toSearch += updateContent.UpdateNotes;
            }

            if (content is PointContentDto pointDto)
            {
                pointDto.PointDetails.ForEach(x => toSearch += x.StructuredDataAsJson);
            }

            if (content is PointContent point)
            {
                (await Db.PointDetailsForPoint(point.ContentId, db)).ForEach(x => toSearch += x.StructuredDataAsJson);
            }

            if (string.IsNullOrWhiteSpace(toSearch) && !extracted.Any())
            {
                return(await GenerationReturn.Success(
                           $"{Db.ContentTypeString(content)} {content.Title} - No Content Ids Found", content.ContentId));
            }

            extracted.AddRange(BracketCodeCommon.BracketCodeContentIds(toSearch));

            if (!extracted.Any())
            {
                return(await GenerationReturn.Success(
                           $"{Db.ContentTypeString(content)} {content.Title} - No Content Ids Found", content.ContentId));
            }

            progress?.Report($"Found {extracted.Count} ContentIds to check for {content.Title}");

            var notFoundList = new List <Guid>();

            foreach (var loopExtracted in extracted)
            {
                var contentLookup = await db.ContentFromContentId(loopExtracted);

                if (contentLookup != null)
                {
                    continue;
                }
                if (await db.MapComponents.AnyAsync(x => x.ContentId == loopExtracted))
                {
                    continue;
                }

                progress?.Report($"ContentId {loopExtracted} Not Found in Db...");
                notFoundList.Add(loopExtracted);
            }

            if (notFoundList.Any())
            {
                return(await GenerationReturn.Error(
                           $"{Db.ContentTypeString(content)} {content.Title} has " +
                           $"Invalid ContentIds in Bracket Codes - {string.Join(", ", notFoundList)}", content.ContentId));
            }

            return(await GenerationReturn.Success(
                       $"{Db.ContentTypeString(content)} {content.Title} - No Invalid Content Ids Found"));
        }
Exemple #12
0
        public static async Task <(bool valid, string explanation)> ValidateContentCommon(IContentCommon toValidate)
        {
            if (toValidate == null)
            {
                return(false, "Null Content to Validate");
            }

            var isNewEntry = toValidate.Id < 1;

            var isValid      = true;
            var errorMessage = new List <string>();

            if (toValidate.ContentId == Guid.Empty)
            {
                isValid = false;
                errorMessage.Add("Content ID is Empty");
            }

            var titleValidation = ValidateTitle(toValidate.Title);

            if (!titleValidation.isValid)
            {
                isValid = false;
                errorMessage.Add(titleValidation.explanation);
            }

            var summaryValidation = ValidateSummary(toValidate.Summary);

            if (!summaryValidation.isValid)
            {
                isValid = false;
                errorMessage.Add(summaryValidation.explanation);
            }

            var(createdUpdatedIsValid, createdUpdatedExplanation) =
                ValidateCreatedAndUpdatedBy(toValidate, isNewEntry);

            if (!createdUpdatedIsValid)
            {
                isValid = false;
                errorMessage.Add(createdUpdatedExplanation);
            }

            var slugValidation = await ValidateSlugLocalAndDb(toValidate.Slug, toValidate.ContentId);

            if (!slugValidation.isValid)
            {
                isValid = false;
                errorMessage.Add(slugValidation.explanation);
            }

            var folderValidation = ValidateFolder(toValidate.Folder);

            if (!folderValidation.isValid)
            {
                isValid = false;
                errorMessage.Add(folderValidation.explanation);
            }

            var tagValidation = ValidateTags(toValidate.Tags);

            if (!tagValidation.isValid)
            {
                isValid = false;
                errorMessage.Add(tagValidation.explanation);
            }

            var bodyContentFormatValidation = ValidateBodyContentFormat(toValidate.BodyContentFormat);

            if (!bodyContentFormatValidation.isValid)
            {
                isValid = false;
                errorMessage.Add(bodyContentFormatValidation.explanation);
            }

            var contentIdCheck = await CheckForBadContentReferences(toValidate, await Db.Context(), null);

            if (contentIdCheck.HasError)
            {
                isValid = false;
                errorMessage.Add(contentIdCheck.GenerationNote);
            }

            return(isValid, string.Join(Environment.NewLine, errorMessage));
        }
 public static async Task WriteRelatedContentInformationToDb(IContentCommon content)
 {
 }
Exemple #14
0
 void resetVideoEncoding(IContentCommon ic)
 {
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.FileProperty)) {
         if (WFContext.BreakExecution) return;
         var fp = (FilePropertyValue)f;
         if (fp.IsVideo()) {
             WFContext.Caption = "Resetting encoding video files...";
             WFContext.Description = _countContents + " contents examined. " + _countReset + " video files reset. ";
             _totalCount++;
             string tempFilePath = Engine.FileTempPath + Guid.NewGuid();
             string newFileName = fp.FileName.Replace("%20", "_").Replace(" ", "_") + "_" + fp.FileExtension;
             WAFRuntime.FileSystem.FileMove(fp.GetFilePath(), tempFilePath);
             fp.SetFile(tempFilePath, newFileName, true);
             _countReset++;
         }
     }
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.FileFolderProperty)) {
         var fp = (IInnerContentsPropertyValue)f;
         foreach (var ff in fp.GetAllContents()) resetVideoEncoding(ff);
     }
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.InnerContents)) {
         var fp = (IInnerContentsPropertyValue)f;
         foreach (var ff in fp.GetAllContents()) resetVideoEncoding(ff);
     }
 }