Book a Demo

Author Topic: Generate html report from models in sql repository (C#)  (Read 10824 times)

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Generate html report from models in sql repository (C#)
« on: June 14, 2016, 08:07:40 pm »
I'm trying to generate an html report from our models in the MS SQL Server repository.

Code: [Select]
EA.Repository repo = new EA.Repository();

            EA.Package package = null;

 

            String conn = "EATEST-- - DBType = 1; Connect = Provider = SQLOLEDB.1; Password=sparxEA2014; Persist Security Info = False; User ID = eatest; Initial Catalog = EATEST; Data Source = SQLFOREA; LazyLoad = 1";

            String username = "eatest";

            String password = "sparxEA2014";



 

            //Transfer DBMS to EAP

            String eapfile = "C:\\Temp\\html\\model.eap";

            String eaplog = "C:\\Temp\\html\\transfer_log.log";

           repo.GetProjectInterface().ProjectTransfer(conn, eapfile, eaplog);

 

            // Browse through structure

            repo.OpenFile2(eapfile, username, password);

            package = repo.GetPackageByGuid("{FE3C4071 - 1D16 - 49cf - 874C - 588B42CEACE7}");

 

            // Generate HTML Documentation

            String guid = "" + package.PackageGUID + "";

            //String guid = "{FE3C4071-1D16-49cf-874C-588B42CEACE7}";

            String exportPath = "C:\\Temp\\html";

            String imageFormat = "PNG";

            //String template = "Feedback";

            String style = "<default>";

            String ext = ".htm";

 

            repo.GetProjectInterface().RunHTMLReport(guid, exportPath, imageFormat, style, ext);

 

            // Close connection to database

            repo.CloseFile();

Is it necessary to transfer the project to a local eap file, or can I create a report directly from the SQL repository?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Generate html report from models in sql repository (C#)
« Reply #1 on: June 14, 2016, 08:45:37 pm »
Just create a shortcut .eap file that points to the SQL Server repository.

This is the script I'm using

Code: [Select]
'[path=\Framework\Publish]
'[group=Publish]

option explicit

'
' Script Name: ExportHTML
' Author: Geert Bellekens
' Purpose: Export the model HTML format. This script is suitable to be executed as a scheduled task in order to export the model
' to HTML and publish it on a webserver or sharepoint site.
' Date: 09/06/2016
'
sub main
dim repository
dim projectInterface
set repository = CreateObject("EA.Repository")

'the path to put the inital export to
dim exportPath
exportPath = "C:\temp\EAExport"

' the path where the exported model should be copied to (sharepoint location, or webserver)
' in case of a sharepoint location make sure to use the UNC path (\\sharepoint-site\location\)
' and make sure that section of sharepoint not version controlled (no check-in/checkout)
dim publishPath
publishPath = "C:\temp\copiedFolder"

'the path to the eap file
dim eapPath
eapPath = "C:\temp\TMF SQL Server shortcut.EAP"

'open the model
repository.OpenFile eapPath

'get project interface
set projectInterface = repository.GetProjectInterface()

dim packageGUID
dim rootPackage
for each rootPackage in repository.Models
packageGUID = projectInterface.GUIDtoXML(rootPackage.PackageGUID)
projectInterface.RunHTMLReport packageGUID, exportPath, ".png", "<default>" , ".html"
exit for
next
'close the model
repository.CloseFile
repository.Exit

'copy the export to sharepoint or webserver location
dim fileSystemObject
set fileSystemObject = CreateObject( "Scripting.FileSystemObject" )
fileSystemObject.CopyFolder exportPath, publishPath
end sub

main

Geert

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Generate html report from models in sql repository (C#)
« Reply #2 on: June 14, 2016, 09:11:38 pm »
Thanks Geert, but can't you directly connect to the sql server and generate the html report from there?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Generate html report from models in sql repository (C#)
« Reply #3 on: June 14, 2016, 10:14:01 pm »
Sure you can, you can also pass a connectionstring to OpenFile().
But that would make it less flexible. It's much easier to change the .eap file then it is to change the "hardcoded" connection string.

Geert

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Generate html report from models in sql repository (C#)
« Reply #4 on: June 15, 2016, 12:28:26 am »
It works!

Code: [Select]
foreach (EA.Package package in repo.Models)
             {
             
              modelName = package.Name;
              GUID = package.PackageGUID;
              Console.WriteLine(modelName + " - " + GUID);
              modelPath = exportPath + modelName;
              System.IO.Directory.CreateDirectory(modelPath);
            repo.GetProjectInterface().RunHTMLReport(GUID, modelPath, imageFormat, style, ext);
             }

I have to create another subfolder for each report because otherwise he overwrites it. Is it possible to combine all the models in one report so that I have the same as my project browser in the sql repository?

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Generate html report from models in sql repository (C#)
« Reply #5 on: June 20, 2016, 07:19:30 pm »
Just a bump, is it possible to combine all the models in one report so that I have the same as my project browser in the sql repository? Now the code creates and overwrites the html report for each model.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Generate html report from models in sql repository (C#)
« Reply #6 on: June 20, 2016, 07:46:49 pm »
No, you can't combine root nodes in a single HTML export, so the best option is to make sure you only have one root in the model.

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Generate html report from models in sql repository (C#)
« Reply #7 on: June 21, 2016, 02:01:42 pm »
I thought that it generated everything if you passed in an empty guid.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Generate html report from models in sql repository (C#)
« Reply #8 on: June 21, 2016, 03:58:16 pm »
I thought that it generated everything if you passed in an empty guid.

Ah, nice little trick if that works, but of course only if using the API.
I'll keep advising my clients to use only one root node in any repository in case they want to do a manual HTML publish from the whole model.

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Generate html report from models in sql repository (C#)
« Reply #9 on: June 21, 2016, 06:18:59 pm »
If you use a model document, you can select not project roots but all the views in all the roots in a project. As long as they don't change on a minute-by-minute basis that works just fine.

That's not the way the OP was initiating his HTML dump, but it does work. Only thing is that in the resulting HTML dump, all the views get placed under a single root node, which can be confusing if you're reusing the same view name in different root nodes.

The trick for that situation is that after you've dragged the package onto the model document (creating an attribute) you can rename the attribute. It then retains the reference to the package, but it's the attribute name that's shown in the HTML version of the project browser.


/Uffe
My theories are always correct, just apply them to the right reality.

MatthiasVDE

  • EA User
  • **
  • Posts: 196
  • Karma: +1/-0
    • View Profile
Re: Generate html report from models in sql repository (C#)
« Reply #10 on: June 30, 2016, 12:19:21 am »
I thought that it generated everything if you passed in an empty guid.

It doesn't work...

Code: [Select]
repo.GetProjectInterface().RunHTMLReport("", modelPath, imageFormat, style, ext);

Julian O

  • EA Novice
  • *
  • Posts: 10
  • Karma: +1/-0
    • View Profile
Re: Generate html report from models in sql repository (C#)
« Reply #11 on: June 30, 2016, 02:04:28 am »
Yes it does also not work for me. Funny thing is the RTF-Report works with an empty GUID.

Code: [Select]
EA.Project project = Repository.GetProjectInterface();
project.RunHTMLReport("", "C:\\Temp\\EA_Export\\", "PNG", "<default>", ".html"); //does not work with "" nor Guid.Empty.ToString()
project.RunReport(Guid.Empty.ToString(), "<default>", "C:\\Temp\\EA_Export\\export.rtf"); //works with "" as well as Guid.Empty.ToString()