Author Topic: Help with C# and Automation API  (Read 11413 times)

jep9816

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Help with C# and Automation API
« on: April 21, 2009, 06:44:10 am »
Hello,

New user here.
Boss has given me task of using automation api to generate reports from EA.

He wants to generate the reports via Nant and integrate with CruiseControl.

My intent is have a simple .exe app that would take a couple of command line parameters that would point to a EAP file and generate an HTML report.

I have looked at the API docs online and I can't quite figure out how to get started.

Anybody have a quick and dirty example on how to build a simple "faceless" .exe in C# to access the API to do this?

thanks,

Jerry

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Help with C# and Automation API
« Reply #1 on: April 21, 2009, 08:11:30 am »
In your install directory is a C# code sample.

jep9816

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #2 on: April 21, 2009, 09:01:47 am »
Hello,

Thanks for the reply.

I looked at that example and I did not quite get it.

BTW I am using V 7.0 perhaps there it a better example in the newer version?

Also where are the API docs?

thanks,

Jerry

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Help with C# and Automation API
« Reply #3 on: April 21, 2009, 03:55:43 pm »
API docs are in the help (user manual)
Your application should be quite simple.
- Connect to the correct project (this should get you a Repository object)
- get the project interface from the repository
- call Project.RunHTMLReport (string PackageGUID, string ExportPath, string ImageFormat, string Style, string Extension)

I think there are some examples on the website too that show you how to open an EA model using the API.

xhanness

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #4 on: April 21, 2009, 09:19:36 pm »
look at this code. It goes through the whole project and print out all element and package names. When u find the desired package u can run your HTML report as Geert Bellekens has written.

I hope, it will get you start



Code: [Select]
       public void zzz1(EA.Package aP)
        {
            foreach (EA.Element e in aP.Elements)
            {
                Console.WriteLine(e.Name);
            }
            foreach (EA.Package p in aP.Packages)
            {
                Console.WriteLine(p.Name);
                zzz1(p);
            }

        }

        public void zzz0()
        {
            EA.Repository r = new EA.RepositoryClass();
            r.OpenFile("c:\\hannes\\skola\\PEF\\studium\\dp\\giuModelling.eap");
            foreach (EA.Package p in r.Models)
            {                
                Console.WriteLine(p.Name);
                zzz1(p);
            }
        }

jep9816

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #5 on: April 21, 2009, 09:57:01 pm »
Hello again,

Thanks for the quick reply!

I will take a look and see what I can do.

jep9816

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #6 on: April 22, 2009, 12:15:10 am »
Hello,

Ok this is what I did:
using System;
using System.Collections.Generic;
using System.Text;
using EA;

namespace EAReportGenerator {
    class Program {
        static void Main(string[] args) {
            Program program = new Program();
            program.runReport(args[0], args[1], args[2]);
        }

        // arg0 "C:\\Source\\BaseLibraries\\Documentation\\BaseLoggingLibrary.EAP"
        // arg1 "Model" {0F14A2A8-0BD4-46f9-A6EA-00C433C05F61}
        // arg2 "C:\\temp\BaseLibraries"
        public void runReport(String arg0, String arg1, String arg2) {
            EA.Repository r = new EA.RepositoryClass();
            EA.Project project;
            r.OpenFile(arg0);
            project = r.GetProjectInterface();
            try {
                project.RunHTMLReport(arg1, arg2, "GIF", "<default>", ".html");
            } catch (Exception e) {
                Console.Out.Write(e.Message);
            }
            r.CloseFile();
            r.Exit();
        }
    }
}

It appears that I am opening my repository file.
In the debugger I see it initialized and no exceptions.
However, when I try the project.RunHTMLReport() method it does not generate the report.
I don't really know what I should use for the PackageGUID.

Sorry for the obtuse questions but the docs are not very clear on how to obtain this information.

Or maybe I can't read :)

Jerry

xhanness

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #7 on: April 22, 2009, 12:24:54 am »
You have to provide the PackageGUID as the first parameter ot method RunHTMLReport.

I guess, u know a package (name, path, ...) in your UML model for which u want to generate a documentation.

You have to find the package (you can go iteratively through all the packages until you find it. u can use the code I had put here). When u find it, get its PackageGUID - it is a property of each package and provide to the method.

jep9816

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #8 on: April 22, 2009, 02:08:03 am »
Ok I did this:
        public void runReport(String aFilepath, String anExportPath) {
            EA.Repository repository = new EA.RepositoryClass();
            bool success = repository.OpenFile(aFilepath);
            if (success) {
                try {
                    EA.Project project = repository.GetProjectInterface();
                    EA.Package aModel = (EA.Package)repository.Models.GetAt(0);
                    project.RunHTMLReport(aModel.PackageGUID, anExportPath, "GIF", "<default>", ".html");
                } catch (Exception e) {
                    Console.Out.Write(e.Message);
                }
                repository.CloseFile();
            }
            repository.Exit();
        }

but no report.
Again in the debugger it looks like the model is found, I can get is GUID, but I call the report method, and no output, no exceptions.

jep9816

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #9 on: April 22, 2009, 03:04:44 am »
Additional Info.

I was able to get an output from the RunReport() method.

But the RunHTMLReport() method does not work.

jep9816

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #10 on: April 23, 2009, 02:12:43 am »
As a Followup,

I installed EA 7.5 and rebuilt my report generation tool.

The project.RunReport() method works but the project.RunHTMLReport() still does not completely work.

I can see that an Images sub-directory is being created in my target directory as well as intermediate temp files.

However, at the end of the report generation no html file is created.

Jerry

ja1234

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Help with C# and Automation API
« Reply #11 on: January 05, 2017, 02:01:51 am »
Additional Info.

I was able to get an output from the RunReport() method.

But the RunHTMLReport() method does not work.

Mind to share how you did the RunReport() ?