Exemplo n.º 1
0
        public async Task F11_HtmlChangedGenerationAfterPostAddedTest()
        {
            var db = await Db.Context();

            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()}");

            await FileManagement.RemoveContentDirectoriesAndFilesNotFoundInCurrentDatabase(
                DebugTrackers.DebugProgressTracker());

            IronwoodHtmlHelpers.CheckIndexHtmlAndGenerationVersion(currentGeneration.GenerationVersion);

            var tagFiles = UserSettingsSingleton.CurrentSettings().LocalSiteTagsDirectory().GetFiles("*.html").ToList();

            var changedTags =
                Db.TagListParseToSlugs(await db.PostContents.SingleAsync(x => x.Title == "First Post"), false)
                .Select(x => $"TagList-{x}").ToList();

            var notChanged = tagFiles.Where(x => !changedTags.Contains(Path.GetFileNameWithoutExtension(x.Name)))
                             .ToList();

            notChanged.ForEach(x =>
                               IronwoodHtmlHelpers.CheckGenerationVersionLessThan(x, currentGeneration.GenerationVersion));

            tagFiles.Where(x => changedTags.Contains(Path.GetFileNameWithoutExtension(x.Name))).ToList().ForEach(x =>
                                                                                                                 IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion));

            var photoContent = UserSettingsSingleton.CurrentSettings().LocalSitePhotoDirectory()
                               .GetFiles("*.html", SearchOption.AllDirectories).ToList();

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

            var noteContent = UserSettingsSingleton.CurrentSettings().LocalSiteNoteDirectory()
                              .GetFiles("*.html", SearchOption.AllDirectories).Where(x => !x.Name.Contains("List")).ToList();

            noteContent.ForEach(x =>
                                IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion));
        }
        public async Task Z10_GenerateAllHtml()
        {
            var db = await Db.Context();

            var forIndex = await db.PointContents.OrderByDescending(x => x.ContentId).Take(4).ToListAsync();

            forIndex.ForEach(x => x.ShowInMainSiteFeed = true);
            await db.SaveChangesAsync(true);

            var currentGenerationCount = db.GenerationLogs.Count();

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

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

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

            await FileManagement.RemoveContentDirectoriesAndFilesNotFoundInCurrentDatabase(
                DebugTrackers.DebugProgressTracker());

            IronwoodHtmlHelpers.CheckIndexHtmlAndGenerationVersion(currentGeneration.GenerationVersion);
        }
Exemplo n.º 3
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
        }
Exemplo n.º 4
0
        public async Task D10_FirstGeneration()
        {
            var db = await Db.Context();

            Assert.True(!db.GenerationLogs.Any(), "Unexpected Content in Generation Logs");

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

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

            var currentGeneration = await db.GenerationLogs.FirstAsync();

            //Index File

            IronwoodHtmlHelpers.CheckIndexHtmlAndGenerationVersion(currentGeneration.GenerationVersion);

            //Tags

            var tags = await Db.TagSlugsAndContentList(true, false, DebugTrackers.DebugProgressTracker());

            var tagFiles = UserSettingsSingleton.CurrentSettings().LocalSiteTagsDirectory().GetFiles("*.html").ToList();

            Assert.AreEqual(tagFiles.Count - 1, tags.Select(x => x.tag).Count(),
                            "Did not find the expected number of Tag Files after generation.");

            foreach (var loopDbTags in tags.Select(x => x.tag).ToList())
            {
                Assert.True(tagFiles.Exists(x => x.Name == $"TagList-{loopDbTags}.html"),
                            $"Didn't find a file for Tag {loopDbTags}");
            }


            //DailyPhotos

            var photoRecords = await db.PhotoContents.ToListAsync();

            var photoDates = photoRecords.GroupBy(x => x.PhotoCreatedOn.Date).Select(x => x.Key).ToList();

            var dailyPhotoFiles = UserSettingsSingleton.CurrentSettings().LocalSiteDailyPhotoGalleryDirectory()
                                  .GetFiles("*.html").ToList();

            Assert.AreEqual(photoDates.Count, dailyPhotoFiles.Count,
                            "Didn't find the expected number of Daily Photo Files");

            foreach (var loopPhotoDates in photoDates)
            {
                Assert.True(dailyPhotoFiles.Exists(x => x.Name == $"DailyPhotos-{loopPhotoDates:yyyy-MM-dd}.html"),
                            $"Didn't find a file for Daily Photos {loopPhotoDates:yyyy-MM-dd}");
            }


            //Camera Roll
            var cameraRollFile = UserSettingsSingleton.CurrentSettings().LocalSiteCameraRollPhotoGalleryFileInfo();

            Assert.True(cameraRollFile.Exists, "Camera Roll File not found");

            var cameraRollDocument = IronwoodHtmlHelpers.DocumentFromFile(cameraRollFile);

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

            Assert.AreEqual(currentGeneration.GenerationVersion.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff"),
                            cameraRollGenerationVersionAttributeString,
                            "Generation Version of Camera Roll Does not match expected Log");

            //Note Check
            var noteContent = UserSettingsSingleton.CurrentSettings().LocalSiteNoteDirectory()
                              .GetFiles("*.html", SearchOption.AllDirectories).ToList();

            noteContent.ForEach(x =>
                                IronwoodHtmlHelpers.CheckGenerationVersionEquals(x, currentGeneration.GenerationVersion));
        }
        public MainWindow()
        {
            InitializeComponent();

            App.Tracker.Track(this);

            WindowInitialPositionHelpers.EnsureWindowIsVisible(this);

            InfoTitle =
                $"Pointless Waymarks CMS - Built On {GetBuildDate(Assembly.GetEntryAssembly())} - Commit {ThisAssembly.Git.Commit} {(ThisAssembly.Git.IsDirty ? "(Has Local Changes)" : string.Empty)}";

            ShowSettingsFileChooser = true;

            DataContext = this;

            StatusContext = new StatusControlContext();

            //Common
            GenerateChangedHtmlCommand = StatusContext.RunBlockingTaskCommand(GenerateChangedHtml);

            RemoveUnusedFilesFromMediaArchiveCommand =
                StatusContext.RunBlockingTaskCommand(RemoveUnusedFilesFromMediaArchive);

            RemoveUnusedFoldersAndFilesFromContentCommand =
                StatusContext.RunBlockingTaskCommand(RemoveUnusedFoldersAndFilesFromContent);

            GenerateIndexCommand = StatusContext.RunBlockingActionCommand(() =>
                                                                          HtmlGenerationGroups.GenerateIndex(null, StatusContext.ProgressTracker()));

            CheckAllContentForInvalidBracketCodeContentIdsCommand =
                StatusContext.RunBlockingTaskCommand(CheckAllContentForInvalidBracketCodeContentIds);

            //All/Forced Regeneration
            GenerateAllHtmlCommand = StatusContext.RunBlockingTaskCommand(GenerateAllHtml);

            ConfirmOrGenerateAllPhotosImagesFilesCommand =
                StatusContext.RunBlockingTaskCommand(ConfirmOrGenerateAllPhotosImagesFiles);

            DeleteAndResizePicturesCommand = StatusContext.RunBlockingTaskCommand(CleanAndResizePictures);

            //Diagnostics
            ToggleDiagnosticLoggingCommand = new Command(() =>
                                                         UserSettingsSingleton.LogDiagnosticEvents = !UserSettingsSingleton.LogDiagnosticEvents);

            ExceptionEventsHtmlReportCommand =
                StatusContext.RunNonBlockingTaskCommand(Reports.ExceptionEventsHtmlReport);
            DiagnosticEventsHtmlReportCommand =
                StatusContext.RunNonBlockingTaskCommand(Reports.DiagnosticEventsHtmlReport);
            ExceptionEventsExcelReportCommand =
                StatusContext.RunNonBlockingTaskCommand(Reports.ExceptionEventsExcelReport);
            DiagnosticEventsExcelReportCommand =
                StatusContext.RunNonBlockingTaskCommand(Reports.DiagnosticEventsExcelReport);
            AllEventsHtmlReportCommand  = StatusContext.RunNonBlockingTaskCommand(Reports.AllEventsHtmlReport);
            AllEventsExcelReportCommand = StatusContext.RunNonBlockingTaskCommand(Reports.AllEventsExcelReport);

            //Main Parts
            GenerateSiteResourcesCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                await FileManagement.WriteSiteResourcesToGeneratedSite(StatusContext.ProgressTracker()));

            WriteStyleCssFileCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                            await FileManagement.WriteStylesCssToGeneratedSite(StatusContext.ProgressTracker()));

            GenerateHtmlForAllFileContentCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                        await HtmlGenerationGroups.GenerateAllFileHtml(null, StatusContext.ProgressTracker()));

            GenerateHtmlForAllImageContentCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                         await HtmlGenerationGroups.GenerateAllImageHtml(null, StatusContext.ProgressTracker()));

            GenerateHtmlForAllNoteContentCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                        await HtmlGenerationGroups.GenerateAllNoteHtml(null, StatusContext.ProgressTracker()));

            GenerateHtmlForAllPhotoContentCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                         await HtmlGenerationGroups.GenerateAllPhotoHtml(null, StatusContext.ProgressTracker()));

            GenerateHtmlForAllPostContentCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                        await HtmlGenerationGroups.GenerateAllPostHtml(null, StatusContext.ProgressTracker()));

            GenerateHtmlForAllPointContentCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                         await HtmlGenerationGroups.GenerateAllPointHtml(null, StatusContext.ProgressTracker()));

            GenerateHtmlForAllLineContentCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                        await HtmlGenerationGroups.GenerateAllLineHtml(null, StatusContext.ProgressTracker()));

            GenerateHtmlForAllGeoJsonContentCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                           await HtmlGenerationGroups.GenerateAllGeoJsonHtml(null, StatusContext.ProgressTracker()));

            //Derived
            GenerateAllListHtmlCommand = StatusContext.RunBlockingActionCommand(() =>
                                                                                HtmlGenerationGroups.GenerateAllListHtml(null, StatusContext.ProgressTracker()));

            GenerateAllTagHtmlCommand = StatusContext.RunBlockingActionCommand(() =>
                                                                               HtmlGenerationGroups.GenerateAllTagHtml(null, StatusContext.ProgressTracker()));

            GenerateCameraRollCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                             await HtmlGenerationGroups.GenerateCameraRollHtml(null, StatusContext.ProgressTracker()));

            GenerateDailyGalleryHtmlCommand = StatusContext.RunBlockingTaskCommand(async() =>
                                                                                   await HtmlGenerationGroups.GenerateAllDailyPhotoGalleriesHtml(null, StatusContext.ProgressTracker()));

            //Rebuild
            ImportJsonFromDirectoryCommand = StatusContext.RunBlockingTaskCommand(ImportJsonFromDirectory);

            SettingsFileChooser = new SettingsFileChooserControlContext(StatusContext, RecentSettingsFilesNames);

            SettingsFileChooser.SettingsFileUpdated += SettingsFileChooserOnSettingsFileUpdatedEvent;

            StatusContext.RunFireAndForgetTaskWithUiToastErrorReturn(CleanupTemporaryFiles);
        }