Exemplo n.º 1
0
 /// <summary>
 /// Try to create a new <see cref="PowerPoint"/> object, handle exceptions
 /// </summary>
 private static PowerPoint CreatePowerpoint(string templatePath, string outputPath)
 {
     try
     {
         PowerPoint powerpoint = new PowerPoint(templatePath, outputPath);
         return(powerpoint);
     }
     catch (FileNotFoundException ex)
     {
         Dialogs.GenericWarning($"Het bestand '{ex.FileName}' is niet gevonden. Controleer het bestandspad en probeer opnieuw.");
     }
     catch (DirectoryNotFoundException)
     {
         Dialogs.GenericWarning($"Het bestandspad '{templatePath}' of '{outputPath}' bestaat niet. Controleer het bestandspad " +
                                $"en probeer opnieuw");
     }
     catch (IOException ex) when((ex.HResult & 0x0000FFFF) == 32)
     {
         Dialogs.GenericWarning($"Het bestand '{outputPath}' kon niet worden bewerkt omdat het geopend is in een ander " +
                                "programma. Sluit het bestand en probeer opnieuw.");
     }
     catch (Exception ex) when(ex is IOException ||
                               ex is UnauthorizedAccessException ||
                               ex is NotSupportedException ||
                               ex is System.Security.SecurityException)
     {
         Dialogs.GenericWarning($"'{templatePath}' of '{outputPath}' kon niet worden geopend.\n\n" +
                                $"De volgende foutmelding werd gegeven: {ex.Message}");
     }
     return(null);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create the three presentations with information from the user interface
        /// </summary>
        public void CreatePresentations(object sender, EventArgs e)
        {
            // Check if fields are filled in and if the output folder is right
            if (!CheckValidInputs())
            {
                return;
            }
            if (!Directory.Exists(Settings.Instance.PathOutputFolder))
            {
                Dialogs.GenericWarning("De outputfolder bestaat niet, " +
                                       "selecteer een bestaande folder in de instellingen");
                return;
            }

            // Get the filled in information from the window
            KeywordSettings             tags     = Settings.Instance.Keywords;
            Dictionary <string, string> keywords = GetFormKeywords();
            List <ServiceElement>       elements = GetServiceElements();
            string filenamepart = GetFilenamePart(dateTimePickerCurrent);

            // Create the presentation before the service
            PowerPoint beforeService = CreatePowerpoint(Settings.Instance.PathTemplateBefore,
                                                        Settings.Instance.PathOutputFolder + $"/voor {filenamepart}.pptx");

            if (beforeService == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(keywords[tags.Theme]))
            {
                beforeService.RemoveThemeRuns();
            }

            beforeService.ReplaceKeywords(keywords);
            beforeService.ReplaceImage(textBoxQRPath.Text);
            beforeService.ReplaceMultilineKeywords(
                from ServiceElement element in elements where element.IsSong select element,
                from ServiceElement element in elements where element.IsReading select element
                );

            beforeService.SaveClose();

            // Create the presentation during the service
            PowerPoint duringService = CreatePowerpoint(Settings.Instance.PathTemplateDuring,
                                                        Settings.Instance.PathOutputFolder + $"/tijdens {filenamepart}.pptx");

            if (duringService == null)
            {
                return;
            }

            duringService.ReplaceKeywords(keywords);
            duringService.ReplaceImage(textBoxQRPath.Text);

            foreach (ServiceElement element in elements)
            {
                duringService.DuplicateAndReplace(new Dictionary <string, string> {
                    { tags.ServiceElementTitle, element.Title },
                    { tags.ServiceElementSubtitle, element.Subtitle }
                }, element.ShowQR);
            }

            duringService.SaveClose();

            // Create the presentation after the service
            PowerPoint afterService = CreatePowerpoint(Settings.Instance.PathTemplateAfter,
                                                       Settings.Instance.PathOutputFolder + $"/na {filenamepart}.pptx");

            if (afterService == null)
            {
                return;
            }

            afterService.ReplaceKeywords(keywords);
            afterService.ReplaceImage(textBoxQRPath.Text);

            afterService.SaveClose();

            // Done, message the user
            Dialogs.GenericInformation("Voltooid", $"De presentaties zijn gemaakt " +
                                       $"en staan in de folder '{Settings.Instance.PathOutputFolder}'.");
            Settings.Instance.NextService = dateTimePickerNext.Value;
        }