Example #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public ReportHtmlPage(IRecognizableComposite Source, ReportHtmlGenerator Generator)
        {
            this.Source = Source;

            Generator.CreateUniqueRelativeLocation(Source); // This already was created for root (Composition).

            this.PhysicalLocation = Generator.GetPhysicalLocationOf(Source);
            this.PageContentDir   = Path.Combine(Path.GetDirectoryName(this.PhysicalLocation),
                                                 Path.GetFileNameWithoutExtension(this.PhysicalLocation)
                                                 + ReportHtmlGenerator.CONTENT_FOLDER_SUFFIX + "\\");
        }
        public static void GenerateHtmlReport(CompositionEngine Engine)
        {
            if (Engine == null)
            {
                return;
            }

            if (!ProductDirector.ValidateEditionPermission(AppExec.LIC_EDITION_STANDARD, "Generate HTML Report", false, new DateTime(2013, 1, 1)))
            {
                return;
            }

            if (Engine.TargetComposition.CompositeContentDomain.ReportingConfiguration == null)
            {
                Engine.TargetComposition.CompositeContentDomain.ReportingConfiguration = new ReportConfiguration();
            }

            if (!ReportingManager.EditReportConfiguration("HTML", Engine.TargetComposition.CompositeContentDomain.ReportingConfiguration))
            {
                return;
            }

            var FilePath       = Path.Combine(AppExec.UserDataDirectory, (Engine.TargetComposition.TechName + ".html").TextToUrlIdentifier());
            var DialogResponse = Display.DialogGetSaveFile("Select HTML file to create", ".html", "HTML document (*.html)|*.html", FilePath);

            if (DialogResponse == null)
            {
                return;
            }

            // Enforce url-identifier to avoid file-names with space in between.
            var Location = Path.Combine(Path.GetDirectoryName(DialogResponse.LocalPath),
                                        Path.GetFileName(DialogResponse.LocalPath).TextToUrlIdentifier());

            var WarnResponse = Display.DialogPersistableMultiOption("Note", "Your HTML Document is generated along with a '" + ReportHtmlGenerator.CONTENT_FOLDER_SUFFIX + "' directory.\n" +
                                                                    "Please don't forget to manage (copy/move/erase) them together to keep consistency." +
                                                                    (Location == DialogResponse.LocalPath ? ""
                                                                             : "\n\nThe file will be saved as '" + Path.GetFileName(Location) + "'."),
                                                                    null, "Reporting", "InformHTMLContentDir", null,
                                                                    new SimplePresentationElement("OK", "Ok", "", Display.GetAppImage("accept.png")));

            if (WarnResponse == null)
            {
                return;
            }

            var Title = "HTML Report of " + Engine.TargetComposition.Name;

            var Generator = new ReportHtmlGenerator(Engine.TargetComposition, Location,
                                                    Engine.TargetComposition.CompositeContentDomain.ReportingConfiguration);

            ProgressiveThreadedExecutor <int> .Execute("Generating " + Title, Generator.Generate,
                                                       (opresult) =>
            {
                if (opresult.WasSuccessful && !File.Exists(Generator.GeneratedTempWorkingDocumentFile))
                {
                    opresult = OperationResult.Failure <int>("Cannot write temporal report file at: " + Generator.GeneratedTempWorkingDocumentFile);
                }

                if (!opresult.WasSuccessful)
                {
                    Display.DialogMessage("Report not completed!", opresult.Message, EMessageType.Warning);
                    return;
                }

                try
                {
                    var TargetFolder = Path.GetDirectoryName(Location);
                    General.CopyDirectory(Generator.GeneratedTempWorkingDocumentDir, TargetFolder);

                    AppExec.CallExternalProcess(Location);

                    if (File.Exists(Generator.GeneratedTempWorkingDocumentFile))
                    {
                        File.Delete(Generator.GeneratedTempWorkingDocumentFile);
                    }

                    if (Directory.Exists(Generator.GeneratedTempWorkingDocumentDir))
                    {
                        Directory.Delete(Generator.GeneratedTempWorkingDocumentDir, true);
                    }
                }
                catch (Exception Problem)
                {
                    Display.DialogMessage("Attention!", "Cannot show generated Report.\n"
                                          + (!Generator.GeneratedTempWorkingDocumentFile.IsAbsent() && File.Exists(Generator.GeneratedTempWorkingDocumentFile)
                                                 ? "It can be still found at: " + Generator.GeneratedTempWorkingDocumentFile : "")
                                          + "\nProblem: " + Problem.Message);
                }
            });
        }