Ejemplo n.º 1
0
        public static async Task SelectedToExcel(List <dynamic> selected, StatusControlContext statusContext)
        {
            await ThreadSwitcher.ThreadSwitcher.ResumeBackgroundAsync();

            if (selected == null || !selected.Any())
            {
                statusContext?.ToastError("Nothing to send to Excel?");
                return;
            }

            ContentToExcelFileAsTable(selected.Select(x => x.DbEntry).Cast <object>().ToList(), "SelectedItems",
                                      progress: statusContext?.ProgressTracker());
        }
Ejemplo n.º 2
0
        public static async Task PdfPageToImageWithPdfToCairo(StatusControlContext statusContext,
                                                              List <FileContent> selected, int pageNumber)
        {
            await ThreadSwitcher.ThreadSwitcher.ResumeBackgroundAsync();


            var pdfToCairoDirectoryString = UserSettingsSingleton.CurrentSettings().PdfToCairoExeDirectory;

            if (string.IsNullOrWhiteSpace(pdfToCairoDirectoryString))
            {
                statusContext.ToastError(
                    "Sorry - this function requires that pdftocairo.exe be on the system - please set the directory... ");
                return;
            }

            var pdfToCairoDirectory = new DirectoryInfo(pdfToCairoDirectoryString);

            if (!pdfToCairoDirectory.Exists)
            {
                statusContext.ToastError(
                    $"{pdfToCairoDirectory.FullName} doesn't exist? Check your pdftocairo bin directory setting.");
                return;
            }

            var pdfToCairoExe = new FileInfo(Path.Combine(pdfToCairoDirectory.FullName, "pdftocairo.exe"));

            if (!pdfToCairoExe.Exists)
            {
                statusContext.ToastError(
                    $"{pdfToCairoExe.FullName} doesn't exist? Check your pdftocairo bin directory setting.");
                return;
            }

            var toProcess = new List <(FileInfo targetFile, FileInfo destinationFile, FileContent content)>();

            foreach (var loopSelected in selected)
            {
                var targetFile = new FileInfo(Path.Combine(
                                                  UserSettingsSingleton.CurrentSettings().LocalSiteFileContentDirectory(loopSelected).FullName,
                                                  loopSelected.OriginalFileName));

                if (!targetFile.Exists)
                {
                    continue;
                }

                if (!targetFile.Extension.ToLower().Contains("pdf"))
                {
                    continue;
                }

                FileInfo destinationFile;
                if (pageNumber == 1)
                {
                    destinationFile = new FileInfo(Path.Combine(UserSettingsUtilities.TempStorageDirectory().FullName,
                                                                $"{Path.GetFileNameWithoutExtension(targetFile.Name)}-CoverPage.jpg"));

                    if (destinationFile.Exists)
                    {
                        destinationFile.Delete();
                        destinationFile.Refresh();
                    }
                }
                else
                {
                    destinationFile = new FileInfo(Path.Combine(UserSettingsUtilities.TempStorageDirectory().FullName,
                                                                $"{Path.GetFileNameWithoutExtension(targetFile.Name)}-Page.jpg"));
                }

                toProcess.Add((targetFile, destinationFile, loopSelected));
            }

            if (!toProcess.Any())
            {
                statusContext.ToastError("No PDFs found? This process can only generate PDF previews...");
                return;
            }

            foreach (var loopSelected in toProcess)
            {
                if (loopSelected.destinationFile.Directory == null)
                {
                    statusContext.ToastError(
                        $"Problem with {loopSelected.destinationFile.FullName} - Directory is Null?");
                    continue;
                }

                var executionParameters = pageNumber == 1
                    ? $"-jpeg -singlefile \"{loopSelected.targetFile.FullName}\" \"{Path.Combine(loopSelected.destinationFile.Directory.FullName, Path.GetFileNameWithoutExtension(loopSelected.destinationFile.FullName))}\""
                    : $"-jpeg -f {pageNumber} -l {pageNumber} \"{loopSelected.targetFile.FullName}\" \"{Path.Combine(loopSelected.destinationFile.Directory.FullName, Path.GetFileNameWithoutExtension(loopSelected.destinationFile.FullName))}\"";

                var(success, _, errorOutput) = ProcessHelpers.ExecuteProcess(pdfToCairoExe.FullName,
                                                                             executionParameters, statusContext.ProgressTracker());

                if (!success)
                {
                    if (await statusContext.ShowMessage("PDF Generation Problem",
                                                        $"Execution Failed for {loopSelected.content.Title} - Continue??{Environment.NewLine}{errorOutput}",
                                                        new List <string> {
                        "Yes", "No"
                    }) == "No")
                    {
                        return;
                    }

                    continue;
                }

                FileInfo updatedDestination = null;

                if (pageNumber == 1)
                {
                    //With the singlefile option pdftocairo uses your filename directly
                    loopSelected.destinationFile.Refresh();
                    updatedDestination = loopSelected.destinationFile;
                }
                else
                {
                    var directoryToSearch = loopSelected.destinationFile.Directory;

                    var possibleFiles = directoryToSearch
                                        .EnumerateFiles($"{Path.GetFileNameWithoutExtension(loopSelected.destinationFile.Name)}-*.jpg")
                                        .ToList();

                    foreach (var loopFiles in possibleFiles)
                    {
                        var fileNamePageNumber = loopFiles.Name.Split("-Page-").ToList().Last().Replace(".jpg", "");

                        if (int.TryParse(fileNamePageNumber, out var possiblePageNumber) &&
                            possiblePageNumber == pageNumber)
                        {
                            updatedDestination = loopFiles;
                            break;
                        }
                    }
                }

                if (updatedDestination == null || !updatedDestination.Exists)
                {
                    if (await statusContext.ShowMessage("PDF Generation Problem",
                                                        $"Execution Failed for {loopSelected.content.Title} - Continue??{Environment.NewLine}{errorOutput}",
                                                        new List <string> {
                        "Yes", "No"
                    }) == "No")
                    {
                        return;
                    }

                    continue;
                }

                await ThreadSwitcher.ThreadSwitcher.ResumeForegroundAsync();

                var newImage = new ImageContent {
                    ContentId = Guid.NewGuid()
                };

                if (pageNumber == 1)
                {
                    newImage.Title   = $"{loopSelected.content.Title} Cover Page";
                    newImage.Summary = $"Cover Page from {loopSelected.content.Title}.";
                }
                else
                {
                    newImage.Title   = $"{loopSelected.content.Title} - Page {pageNumber}";
                    newImage.Summary = $"Page {pageNumber} from {loopSelected.content.Title}.";
                }

                newImage.ShowInSearch      = false;
                newImage.Folder            = loopSelected.content.Folder;
                newImage.Tags              = loopSelected.content.Tags;
                newImage.Slug              = SlugUtility.Create(true, newImage.Title);
                newImage.BodyContentFormat = ContentFormatDefaults.Content.ToString();
                newImage.BodyContent       = $"Generated by pdftocairo from {BracketCodeFiles.Create(loopSelected.content)}.";
                newImage.UpdateNotesFormat = ContentFormatDefaults.Content.ToString();

                var editor = new ImageContentEditorWindow(newImage, updatedDestination);
                editor.Show();

                await ThreadSwitcher.ThreadSwitcher.ResumeBackgroundAsync();
            }
        }
        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();

            GenerateIndexCommand = new Command(() => StatusContext.RunNonBlockingTask(GenerateIndex));
            OpenIndexUrlCommand  = new Command(() => StatusContext.RunNonBlockingTask(OpenIndexUrl));

            GenerateAllHtmlCommand = new Command(() => StatusContext.RunBlockingTask(GenerateAllHtml));
            ConfirmOrGenerateAllPhotosImagesFilesCommand = new Command(() =>
                                                                       StatusContext.RunBlockingTask(ConfirmOrGenerateAllPhotosImagesFiles));
            GenerateAllHtmlAndCleanAndResizePicturesCommand = new Command(() =>
                                                                          StatusContext.RunBlockingTask(GenerateAllHtmlAndCleanAndResizePictures));
            CleanAndResizePicturesCommand = new Command(() => StatusContext.RunBlockingTask(CleanAndResizePictures));

            NewPhotoContentCommand = new Command(() => StatusContext.RunNonBlockingTask(NewPhotoContent));
            GenerateHtmlForAllPhotoContentCommand =
                new Command(() => StatusContext.RunBlockingTask(GenerateAllPhotoHtml));

            NewPostContentCommand = new Command(() => StatusContext.RunNonBlockingTask(NewPostContent));
            GenerateHtmlForAllPostContentCommand =
                new Command(() => StatusContext.RunBlockingTask(GenerateAllPostHtml));

            NewImageContentCommand = new Command(() => StatusContext.RunNonBlockingTask(NewImageContent));
            GenerateHtmlForAllImageContentCommand =
                new Command(() => StatusContext.RunBlockingTask(GenerateAllImageHtml));

            NewFileContentCommand = new Command(() => StatusContext.RunNonBlockingTask(NewFileContent));
            GenerateHtmlForAllFileContentCommand =
                new Command(() => StatusContext.RunBlockingTask(GenerateAllFileHtml));

            NewLinkContentCommand = new Command(() => StatusContext.RunNonBlockingTask(NewLinkContent));

            GenerateAllTagHtmlCommand = new Command(() => StatusContext.RunBlockingTask(GenerateAllTagHtml));

            GenerateDailyGalleryHtmlCommand =
                new Command(() => StatusContext.RunBlockingTask(GenerateAllDailyPhotoGalleriesHtml));
            GenerateCamerRollCommand = new Command(() => StatusContext.RunBlockingTask(GenerateCameraRollHtml));

            PurgeInvalidPhotoDirectoriesCommand = new Command(async() =>
                                                              await StructureAndMediaContent.PurgePhotoDirectoriesNotFoundInCurrentDatabase(
                                                                  StatusContext.ProgressTracker()));

            ImportJsonFromDirectoryCommand = new Command(() => StatusContext.RunBlockingTask(ImportJsonFromDirectory));

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

            ExceptionEventsReportCommand  = new Command(() => StatusContext.RunNonBlockingTask(ExceptionEventsReport));
            DiagnosticEventsReportCommand = new Command(() => StatusContext.RunNonBlockingTask(DiagnosticEventsReport));
            AllEventsReportCommand        = new Command(() => StatusContext.RunNonBlockingTask(AllEventsReport));

            SettingsFileChooser = new SettingsFileChooserControlContext(StatusContext, RecentSettingsFilesNames);

            SettingsFileChooser.SettingsFileUpdated += SettingsFileChooserOnSettingsFileUpdatedEvent;

            StatusContext.RunFireAndForgetTaskWithUiToastErrorReturn(CleanUpTemporaryFiles);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public static async Task ImportFromExcel(StatusControlContext statusContext)
        {
            await ThreadSwitcher.ThreadSwitcher.ResumeBackgroundAsync();

            statusContext.Progress("Starting excel load.");

            var dialog = new VistaOpenFileDialog();

            if (!(dialog.ShowDialog() ?? false))
            {
                return;
            }

            var newFile = new FileInfo(dialog.FileName);

            if (!newFile.Exists)
            {
                statusContext.ToastError("File doesn't exist?");
                return;
            }

            ExcelContentImports.ExcelContentTableImportResults contentTableImportResult;

            try
            {
                contentTableImportResult =
                    await ExcelContentImports.ImportFromFile(newFile.FullName, statusContext.ProgressTracker());
            }
            catch (Exception e)
            {
                await statusContext.ShowMessageWithOkButton("Import File Errors",
                                                            $"Import Stopped because of an error processing the file:{Environment.NewLine}{e.Message}");

                return;
            }

            if (contentTableImportResult.HasError)
            {
                await statusContext.ShowMessageWithOkButton("Import Errors",
                                                            $"Import Stopped because errors were reported:{Environment.NewLine}{contentTableImportResult.ErrorNotes}");

                return;
            }

            var shouldContinue = await statusContext.ShowMessage("Confirm Import",
                                                                 $"Continue?{Environment.NewLine}{Environment.NewLine}{contentTableImportResult.ToUpdate.Count} updates from {newFile.FullName} {Environment.NewLine}" +
                                                                 $"{string.Join(Environment.NewLine, contentTableImportResult.ToUpdate.Select(x => $"{Environment.NewLine}{x.Title}{Environment.NewLine}{x.DifferenceNotes}"))}",
                                                                 new List <string> {
                "Yes", "No"
            });

            if (shouldContinue == "No")
            {
                return;
            }

            var saveResult =
                await ExcelContentImports.SaveAndGenerateHtmlFromExcelImport(contentTableImportResult,
                                                                             statusContext.ProgressTracker());

            if (saveResult.hasError)
            {
                await statusContext.ShowMessageWithOkButton("Excel Import Save Errors",
                                                            $"There were error saving changes from the Excel Content:{Environment.NewLine}{saveResult.errorMessage}");

                return;
            }

            statusContext.ToastSuccess(
                $"Imported {contentTableImportResult.ToUpdate.Count} items with changes from {newFile.FullName}");
        }