コード例 #1
0
        public void WriteLocalHtml()
        {
            WriteRss();

            foreach (var loopPosts in IndexContent.Take(_numberOfContentItemsToDisplay))
            {
                if (BracketCodeCommon.ContainsSpatialBracketCodes(loopPosts) ||
                    loopPosts.GetType() == typeof(PointContentDto))
                {
                    IncludeSpatialScripts = true;
                }
            }

            var parser  = new HtmlParser();
            var htmlDoc = parser.ParseDocument(TransformText());

            var stringWriter = new StringWriter();

            htmlDoc.ToHtml(stringWriter, new PrettyMarkupFormatter());

            var htmlString = stringWriter.ToString();

            var htmlFileInfo =
                new FileInfo($@"{UserSettingsSingleton.CurrentSettings().LocalSiteRootDirectory}\index.html");

            if (htmlFileInfo.Exists)
            {
                htmlFileInfo.Delete();
                htmlFileInfo.Refresh();
            }

            FileManagement.WriteAllTextToFileAndLog(htmlFileInfo.FullName, htmlString);
        }
コード例 #2
0
        public static async Task WriteImageFromMediaArchiveToLocalSite(ImageContent imageContent,
                                                                       bool forcedResizeOverwriteExistingFiles, IProgress <string> progress)
        {
            var userSettings = UserSettingsSingleton.CurrentSettings();

            var sourceFile = new FileInfo(Path.Combine(userSettings.LocalMediaArchiveImageDirectory().FullName,
                                                       imageContent.OriginalFileName));

            var targetFile = new FileInfo(Path.Combine(
                                              userSettings.LocalSiteImageContentDirectory(imageContent).FullName, imageContent.OriginalFileName));

            if (targetFile.Exists && forcedResizeOverwriteExistingFiles)
            {
                targetFile.Delete();
                targetFile.Refresh();
            }

            if (!targetFile.Exists)
            {
                await sourceFile.CopyToAndLogAsync(targetFile.FullName);
            }

            PictureResizing.DeleteSupportedPictureFilesInDirectoryOtherThanOriginalFile(imageContent, progress);

            PictureResizing.CleanDisplayAndSrcSetFilesInImageDirectory(imageContent, forcedResizeOverwriteExistingFiles,
                                                                       progress);

            await PictureResizing.ResizeForDisplayAndSrcset(imageContent, forcedResizeOverwriteExistingFiles, progress);
        }
コード例 #3
0
        public PictureSiteInformation(Guid toLoad)
        {
            var settings = UserSettingsSingleton.CurrentSettings();

            Pictures = PictureAssetProcessing.ProcessPictureDirectory(toLoad);
            PageUrl  = settings.PicturePageUrl(toLoad);
        }
コード例 #4
0
ファイル: Tags.cs プロジェクト: lulzzz/PointlessWaymarksCms
        public static HtmlTag TagListTextLinkList(List <string> tags)
        {
            tags ??= new List <string>();

            tags = tags.Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToList();

            if (!tags.Any())
            {
                return(HtmlTag.Empty());
            }

            var tagsContainer = new HtmlTag("p");

            var innerContent = new List <string>();

            foreach (var loopTag in tags)
            {
                var tagLink =
                    new LinkTag(loopTag.Replace("-", " "), UserSettingsSingleton.CurrentSettings().TagPageUrl(loopTag))
                    .AddClass("tag-detail-link");
                innerContent.Add(tagLink.ToString());
            }

            tagsContainer.Text($"Tags: {string.Join(", ", innerContent)}").Encoded(false);

            return(tagsContainer);
        }
コード例 #5
0
        public void WriteLocalHtmlRssAndJson()
        {
            var settings = UserSettingsSingleton.CurrentSettings();

            var parser  = new HtmlParser();
            var htmlDoc = parser.ParseDocument((string)TransformText());

            var stringWriter = new StringWriter();

            htmlDoc.ToHtml(stringWriter, new PrettyMarkupFormatter());

            var htmlString = stringWriter.ToString();

            var htmlFileInfo = settings.LocalSiteLinkListFile();

            if (htmlFileInfo.Exists)
            {
                htmlFileInfo.Delete();
                htmlFileInfo.Refresh();
            }

            File.WriteAllText(htmlFileInfo.FullName, htmlString);

            WriteContentListRss();
        }
コード例 #6
0
        public static void WriteTagListAndTagPages(IProgress <string> progress)
        {
            progress?.Report("Tag Pages - Getting Tag Data");
            var tags = Db.TagAndContentList(false, progress).Result;

            var allTags = new TagListPage {
                ContentFunction = () => tags
            };

            progress?.Report("Tag Pages - Writing All Tag Data");
            allTags.WriteLocalHtml();

            //Tags is reset - above for tag search we don't include tags from pages that are hidden from search - but to
            //ensure all tags have a page we generate pages from all tags (if an image excluded from search had a unique
            //tag we need a page for the links on that page, excluded from search does not mean 'unreachable'...)
            var pageTags = Db.TagAndContentList(true, progress).Result;

            var loopCount = 0;

            foreach (var loopTags in pageTags)
            {
                loopCount++;

                if (loopCount % 30 == 0)
                {
                    progress?.Report($"Generating Tag Page {loopTags.tag} - {loopCount} of {tags.Count}");
                }

                WriteSearchListHtml(() => loopTags.contentObjects,
                                    UserSettingsSingleton.CurrentSettings().LocalSiteTagListFileInfo(loopTags.tag),
                                    $"Tag - {loopTags.tag}", string.Empty);
            }
        }
コード例 #7
0
        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");
        }
コード例 #8
0
        public static void CheckIndexHtmlAndGenerationVersion(DateTime generationVersion)
        {
            var indexFile = UserSettingsSingleton.CurrentSettings().LocalSiteIndexFile();

            Assert.True(indexFile.Exists, "Index file doesn't exist after generation");

            var indexDocument = DocumentFromFile(indexFile);

            var generationVersionAttributeString =
                indexDocument.Head.Attributes.Single(x => x.Name == "data-generationversion").Value;

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

            Assert.AreEqual(UserSettingsSingleton.CurrentSettings().SiteName, indexDocument.Title);

            Assert.AreEqual(UserSettingsSingleton.CurrentSettings().SiteSummary,
                            indexDocument.QuerySelector("meta[name='description']")?.Attributes
                            .FirstOrDefault(x => x.LocalName == "content")?.Value);

            Assert.AreEqual(UserSettingsSingleton.CurrentSettings().SiteAuthors,
                            indexDocument.QuerySelector("meta[name='author']")?.Attributes
                            .FirstOrDefault(x => x.LocalName == "content")?.Value);

            Assert.AreEqual(UserSettingsSingleton.CurrentSettings().SiteKeywords,
                            indexDocument.QuerySelector("meta[name='keywords']")?.Attributes
                            .FirstOrDefault(x => x.LocalName == "content")?.Value);

            Assert.AreEqual(UserSettingsSingleton.CurrentSettings().SiteSummary,
                            indexDocument.QuerySelector("meta[name='description']")?.Attributes
                            .FirstOrDefault(x => x.LocalName == "content")?.Value);
        }
コード例 #9
0
        public static string RssFileString(string channelTitle, string items)
        {
            var rssBuilder = new StringBuilder();
            var settings   = UserSettingsSingleton.CurrentSettings();

            rssBuilder.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            rssBuilder.AppendLine("<!--");
            rssBuilder.AppendLine($"    RSS generated by Pointless Waymarks CMS on {DateTime.Now:R}");
            rssBuilder.AppendLine("-->");
            rssBuilder.AppendLine("<rss version=\"2.0\">");
            rssBuilder.AppendLine("<channel>");
            rssBuilder.AppendLine($"<title>{channelTitle}</title>");
            rssBuilder.AppendLine($"<link>https://{settings.SiteUrl}</link>");
            rssBuilder.AppendLine($"<description>{settings.SiteSummary}</description>");
            rssBuilder.AppendLine("<language>en-us</language>");
            rssBuilder.AppendLine($"<copyright>{DateTime.Now.Year} {settings.SiteAuthors}</copyright>");
            rssBuilder.AppendLine($"<lastBuildDate>{DateTime.Now:R}</lastBuildDate>");
            rssBuilder.AppendLine("<generator>Pointless Waymarks CMS</generator>");
            rssBuilder.AppendLine($"<managingEditor>{settings.SiteEmailTo}</managingEditor>");
            rssBuilder.AppendLine($"<webMaster>{settings.SiteEmailTo}</webMaster>");
            rssBuilder.AppendLine(items);
            rssBuilder.AppendLine("</channel>");
            rssBuilder.AppendLine("</rss>");

            return(rssBuilder.ToString());
        }
コード例 #10
0
        public static async Task <GenerationReturn> CopyCleanResizeImage(ImageContent dbEntry,
                                                                         IProgress <string> progress)
        {
            if (dbEntry == null)
            {
                return(await GenerationReturn.Error("Null Image Content submitted to Copy Clean and Resize"));
            }

            progress?.Report($"Starting Copy, Clean and Resize for {dbEntry.Title}");

            if (string.IsNullOrWhiteSpace(dbEntry.OriginalFileName))
            {
                return(await GenerationReturn.Error($"Image {dbEntry.Title} has no Original File", dbEntry.ContentId));
            }

            var imageDirectory = UserSettingsSingleton.CurrentSettings().LocalSiteImageContentDirectory(dbEntry);

            var syncCopyResults = await FileManagement.CheckImageFileIsInMediaAndContentDirectories(dbEntry, progress);

            if (!syncCopyResults.HasError)
            {
                return(syncCopyResults);
            }

            CleanDisplayAndSrcSetFilesInImageDirectory(dbEntry, true, progress);

            ResizeForDisplayAndSrcset(new FileInfo(Path.Combine(imageDirectory.FullName, dbEntry.OriginalFileName)),
                                      false, progress);

            return(await GenerationReturn.Success($"{dbEntry.Title} Copied, Cleaned, Resized", dbEntry.ContentId));
        }
コード例 #11
0
        public async Task WriteLocalHtml()
        {
            var settings = UserSettingsSingleton.CurrentSettings();

            await LineData.WriteLocalJsonData(DbEntry);

            var parser  = new HtmlParser();
            var htmlDoc = parser.ParseDocument(TransformText());

            var stringWriter = new StringWriter();

            htmlDoc.ToHtml(stringWriter, new PrettyMarkupFormatter());

            var htmlString = stringWriter.ToString();

            var htmlFileInfo =
                new FileInfo(
                    $"{Path.Combine(settings.LocalSiteLineContentDirectory(DbEntry).FullName, DbEntry.Slug)}.html");

            if (htmlFileInfo.Exists)
            {
                htmlFileInfo.Delete();
                htmlFileInfo.Refresh();
            }

            await FileManagement.WriteAllTextToFileAndLogAsync(htmlFileInfo.FullName, htmlString);
        }
コード例 #12
0
        public IndexPage()
        {
            var settings = UserSettingsSingleton.CurrentSettings();

            SiteUrl      = settings.SiteUrl;
            SiteName     = settings.SiteName;
            SiteKeywords = settings.SiteKeywords;
            SiteSummary  = settings.SiteSummary;
            SiteAuthors  = settings.SiteAuthors;
            PageUrl      = settings.IndexPageUrl();

            IndexContent = Db.MainFeedRecentDynamicContent(20).Result.OrderByDescending(x => x.CreatedOn).ToList();

            var mainImageGuid = IndexContent
                                .FirstOrDefault(x => x.GetType() == typeof(PostContent) && x.MainPicture != null)?.MainPicture;

            if (mainImageGuid != null)
            {
                MainImage = new PictureSiteInformation(mainImageGuid);
            }

            if (!IndexContent.Any())
            {
                PreviousPosts = new List <IContentCommon>();
            }
            else
            {
                DateTime previousDate = IndexContent.Skip(_numberOfContentItemsToDisplay - 1).Max(x => x.CreatedOn);

                var previousLater = Tags.MainFeedPreviousAndLaterContent(6, previousDate);

                PreviousPosts = previousLater.previousContent;
            }
        }
コード例 #13
0
        public static async Task WriteLocalJsonData()
        {
            var db = await Db.Context();

            var allPointIds = await db.PointContents.Select(x => x.ContentId).ToListAsync();

            var extendedPointInformation = await Db.PointAndPointDetails(allPointIds, db);

            var settings = UserSettingsSingleton.CurrentSettings();

            var pointJson = JsonSerializer.Serialize(extendedPointInformation.Select(x =>
                                                                                     new
            {
                x.ContentId,
                x.Title,
                x.Longitude,
                x.Latitude,
                x.Slug,
                PointPageUrl     = settings.PointPageUrl(x),
                DetailTypeString = string.Join(", ", PointDetailUtilities.PointDtoTypeList(x))
            }).ToList());

            var dataFileInfo = new FileInfo($"{settings.LocalSitePointDataFile()}");

            if (dataFileInfo.Exists)
            {
                dataFileInfo.Delete();
                dataFileInfo.Refresh();
            }

            await FileManagement.WriteAllTextToFileAndLogAsync(dataFileInfo.FullName, pointJson);
        }
コード例 #14
0
        public static HtmlTag TagList(List <string> tags)
        {
            tags ??= new List <string>();

            tags = tags.Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToList();

            if (!tags.Any())
            {
                return(HtmlTag.Empty());
            }

            var tagsContainer = new DivTag().AddClass("tags-container");

            tagsContainer.Children.Add(new DivTag().Text("Tags:").AddClass("tag-detail-label-tag"));

            foreach (var loopTag in tags)
            {
                var tagLinkContainer = new DivTag().AddClass("tags-detail-link-container");
                var tagLink          =
                    new LinkTag(loopTag.Replace("-", " "), UserSettingsSingleton.CurrentSettings().TagPageUrl(loopTag))
                    .AddClass("tag-detail-link");
                tagLinkContainer.Children.Add(tagLink);
                tagsContainer.Children.Add(tagLinkContainer);
            }

            return(tagsContainer);
        }
コード例 #15
0
        public async Task B21_FileMapAddingImageMapBracketCodeToBody()
        {
            var db = await Db.Context();

            var mapImage = db.ImageContents.Single(x => x.Title == IronwoodImageInfo.MapContent01.Title);

            var mapFile = db.FileContents.Single(x => x.Title == TestFileInfo.MapContent01.Title);

            mapFile.BodyContent =
                $"{BracketCodeImages.Create(mapImage)} {Environment.NewLine}{Environment.NewLine}{mapFile.BodyContent}";

            mapFile.LastUpdatedBy = "Test B21";
            mapFile.LastUpdatedOn = DateTime.Now;

            var bodyUpdateReturn = await FileGenerator.SaveAndGenerateHtml(mapFile,
                                                                           UserSettingsSingleton.CurrentSettings().LocalMediaArchiveFileContentFile(mapFile), false, null,
                                                                           DebugTrackers.DebugProgressTracker());

            Assert.False(bodyUpdateReturn.generationReturn.HasError, bodyUpdateReturn.generationReturn.GenerationNote);

            var mapFileRefresh = db.FileContents.Single(x => x.Title == TestFileInfo.MapContent01.Title);

            Assert.AreEqual(mapImage.ContentId, mapFileRefresh.MainPicture,
                            "Adding an image code to the Map File Content Body didn't result in Main Image being set.");
        }
コード例 #16
0
        public static async Task WriteLocalJsonData(MapComponentDto dto)
        {
            var dtoElementGuids = dto.Elements.Select(x => x.ElementContentId).ToList();

            var db = await Db.Context();

            var pointGuids = await db.PointContents.Where(x => dtoElementGuids.Contains(x.ContentId))
                             .Select(x => x.ContentId).ToListAsync();

            var lineGuids = await db.LineContents.Where(x => dtoElementGuids.Contains(x.ContentId))
                            .Select(x => x.ContentId).ToListAsync();

            var geoJsonGuids = await db.GeoJsonContents.Where(x => dtoElementGuids.Contains(x.ContentId))
                               .Select(x => x.ContentId).ToListAsync();

            var showDetailsGuid = dto.Elements.Where(x => x.ShowDetailsDefault).Select(x => x.MapComponentContentId)
                                  .Distinct().ToList();

            var mapDtoJson = new MapSiteJsonData(dto.Map, geoJsonGuids, lineGuids, pointGuids, showDetailsGuid);

            var dataFileInfo = new FileInfo(Path.Combine(
                                                UserSettingsSingleton.CurrentSettings().LocalSiteMapComponentDataDirectory().FullName,
                                                $"Map-{dto.Map.ContentId}.json"));

            if (dataFileInfo.Exists)
            {
                dataFileInfo.Delete();
                dataFileInfo.Refresh();
            }

            await FileManagement.WriteAllTextToFileAndLogAsync(dataFileInfo.FullName,
                                                               JsonSerializer.Serialize(mapDtoJson));
        }
コード例 #17
0
        public void WriteLocalHtml()
        {
            var settings = UserSettingsSingleton.CurrentSettings();

            var parser  = new HtmlParser();
            var htmlDoc = parser.ParseDocument((string)TransformText());

            var stringWriter = new StringWriter();

            htmlDoc.ToHtml(stringWriter, new PrettyMarkupFormatter());

            var htmlString = stringWriter.ToString();

            var htmlFileInfo =
                new FileInfo(
                    $"{Path.Combine(settings.LocalSiteNoteContentDirectory(DbEntry).FullName, DbEntry.Slug)}.html");

            if (htmlFileInfo.Exists)
            {
                htmlFileInfo.Delete();
                htmlFileInfo.Refresh();
            }

            File.WriteAllText(htmlFileInfo.FullName, htmlString);
        }
コード例 #18
0
        /// <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();
            }
        }
コード例 #19
0
        public static string Process(string toProcess, IProgress <string> progress)
        {
            if (string.IsNullOrWhiteSpace(toProcess))
            {
                return(string.Empty);
            }

            var resultList = BracketCodeCommon.ContentBracketCodeMatches(toProcess, BracketCodeToken);

            var context = Db.Context().Result;

            foreach (var loopMatch in resultList)
            {
                var dbContent = context.FileContents.FirstOrDefault(x => x.ContentId == loopMatch.contentGuid);
                if (dbContent == null)
                {
                    continue;
                }

                progress?.Report($"Adding file download link {dbContent.Title} from Code");

                var settings = UserSettingsSingleton.CurrentSettings();

                var linkTag = new LinkTag(
                    string.IsNullOrWhiteSpace(loopMatch.displayText) ? dbContent.Title : loopMatch.displayText.Trim(),
                    dbContent.PublicDownloadLink
                        ? settings.FileDownloadUrl(dbContent)
                        : settings.FilePageUrl(dbContent), "file-download-link");

                toProcess = toProcess.Replace(loopMatch.bracketCodeText, linkTag.ToString());
            }

            return(toProcess);
        }
コード例 #20
0
        public void PhotoHtmlChecks(PhotoContent newPhotoContent)
        {
            var htmlFile = UserSettingsSingleton.CurrentSettings().LocalSitePhotoHtmlFile(newPhotoContent);

            Assert.True(htmlFile.Exists, "Html File not Found for Html Checks?");

            var config = Configuration.Default;

            var context  = BrowsingContext.New(config);
            var parser   = context.GetService <IHtmlParser>();
            var source   = File.ReadAllText(htmlFile.FullName);
            var document = parser.ParseDocument(source);

            Assert.AreEqual(newPhotoContent.Title, document.Title);

            //Todo - check description

            Assert.AreEqual(newPhotoContent.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:{UserSettingsSingleton.CurrentSettings().PhotoPageUrl(newPhotoContent)}",
                            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);

            //Todo: Continue checking...
        }
コード例 #21
0
        public static PictureAsset ProcessImageDirectory(ImageContent dbEntry)
        {
            var settings         = UserSettingsSingleton.CurrentSettings();
            var contentDirectory = settings.LocalSiteImageContentDirectory(dbEntry);

            return(ProcessImageDirectory(dbEntry, contentDirectory, settings.SiteUrl));
        }
コード例 #22
0
#pragma warning disable 1998
        public static async Task <PointlessWaymarksContext> Context()
#pragma warning restore 1998
        {
            var optionsBuilder = new DbContextOptionsBuilder <PointlessWaymarksContext>();
            var dbPath         = UserSettingsSingleton.CurrentSettings().DatabaseFile;

            return(new PointlessWaymarksContext(optionsBuilder.UseSqlite($"Data Source={dbPath}").Options));
        }
コード例 #23
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);
        }
コード例 #24
0
 public static string ScriptsAndLinks()
 {
     return
         ($"<link rel=\"stylesheet\" href=\"{UserSettingsSingleton.CurrentSettings().SiteResourcesUrl()}leaflet.css\" />\r\n" +
          $"<script src=\"{UserSettingsSingleton.CurrentSettings().SiteResourcesUrl()}leaflet.js\"></script>\r\n" +
          $"<link rel=\"stylesheet\" href=\"{UserSettingsSingleton.CurrentSettings().SiteResourcesUrl()}leaflet-gesture-handling.min.css\" type=\"text/css\">\r\n" +
          $"<script src=\"{UserSettingsSingleton.CurrentSettings().SiteResourcesUrl()}leaflet-gesture-handling.min.js\"></script>\r\n" +
          $"<script src=\"{UserSettingsSingleton.CurrentSettings().SiteResourcesUrl()}pointless-waymarks-spatial-common.js\"></script>");
 }
コード例 #25
0
#pragma warning disable 1998
        public static async Task <EventLogContext> Log()
#pragma warning restore 1998
        {
            var optionsBuilder = new DbContextOptionsBuilder <EventLogContext>();
            var dbPath         = Path.Combine(UserSettingsSingleton.CurrentSettings().LocalMediaArchive,
                                              "PointlessWaymarksCms-EventLog.db");

            return(new EventLogContext(optionsBuilder.UseSqlite($"Data Source={dbPath}").Options));
        }
コード例 #26
0
        private static void WriteContentListRss()
        {
            var settings = UserSettingsSingleton.CurrentSettings();

            var db = Db.Context().Result;

            var content = db.LinkStreams.Where(x => x.ShowInLinkRss).OrderByDescending(x => x.CreatedOn).ToList();

            var feed = new SyndicationFeed(settings.SiteName, $"{settings.SiteSummary} - Links",
                                           new Uri($"https://{settings.SiteUrl}"), $"https:{settings.LinkRssUrl()}", DateTime.Now)
            {
                Copyright = new TextSyndicationContent($"{DateTime.Now.Year} {settings.SiteAuthors}")
            };

            var items = new List <string>();

            foreach (var loopContent in content)
            {
                var linkParts = new List <string>();
                if (!string.IsNullOrWhiteSpace(loopContent.Site))
                {
                    linkParts.Add(loopContent.Site);
                }
                if (!string.IsNullOrWhiteSpace(loopContent.Author))
                {
                    linkParts.Add(loopContent.Author);
                }
                if (loopContent.LinkDate != null)
                {
                    linkParts.Add(loopContent.LinkDate.Value.ToString("M/d/yyyy"));
                }
                if (!string.IsNullOrWhiteSpace(loopContent.Description))
                {
                    linkParts.Add(loopContent.Description);
                }
                if (!string.IsNullOrWhiteSpace(loopContent.Comments))
                {
                    linkParts.Add(loopContent.Comments);
                }

                items.Add(RssBuilder.RssItemString(loopContent.Title, loopContent.Url, string.Join(" - ", linkParts),
                                                   loopContent.CreatedOn, loopContent.ContentId.ToString()));
            }

            var localIndexFile = settings.LocalSiteLinkRssFile();

            if (localIndexFile.Exists)
            {
                localIndexFile.Delete();
                localIndexFile.Refresh();
            }

            File.WriteAllText(localIndexFile.FullName,
                              RssBuilder.RssFileString($"{UserSettingsSingleton.CurrentSettings().SiteName} - Link List",
                                                       string.Join(Environment.NewLine, items)), Encoding.UTF8);
        }
コード例 #27
0
        public SinglePostDiv(PostContent dbEntry)
        {
            DbEntry = dbEntry;

            var settings = UserSettingsSingleton.CurrentSettings();

            SiteUrl  = settings.SiteUrl;
            SiteName = settings.SiteName;
            PageUrl  = settings.PostPageUrl(DbEntry);
        }
コード例 #28
0
        public static void ConfirmOrGeneratePhotoDirectoryAndPictures(PhotoContent dbEntry, IProgress <string> progress)
        {
            StructureAndMediaContent.CheckPhotoFileIsInMediaAndContentDirectories(dbEntry, progress).Wait();

            var targetDirectory = UserSettingsSingleton.CurrentSettings().LocalSitePhotoContentDirectory(dbEntry);

            var sourceImage = new FileInfo(Path.Combine(targetDirectory.FullName, dbEntry.OriginalFileName));

            PictureResizing.ResizeForDisplayAndSrcset(sourceImage, false, null);
        }
コード例 #29
0
        public SingleGeoJsonDiv(GeoJsonContent dbEntry)
        {
            DbEntry = dbEntry;

            var settings = UserSettingsSingleton.CurrentSettings();

            SiteUrl  = settings.SiteUrl;
            SiteName = settings.SiteName;
            PageUrl  = settings.GeoJsonPageUrl(DbEntry);
        }
コード例 #30
0
        public SingleLineDiv(LineContent dbEntry)
        {
            DbEntry = dbEntry;

            var settings = UserSettingsSingleton.CurrentSettings();

            SiteUrl  = settings.SiteUrl;
            SiteName = settings.SiteName;
            PageUrl  = settings.LinePageUrl(DbEntry);
        }