Book a Demo

Author Topic: Reports work in EA but don't produce same output in my code!  (Read 6214 times)

jbfurlong

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
I have a report template derived from one of the standard built-in templates.

When I run the template from EA at the level of a Use Case it produces the output I expect.

When I run it from my own .Net code it only produces what seems to be items at the Element level.

I cannot figure out a clear behaviour on this to be able to fix it so perhaps someone can tell me if there is something wrong with my code please?

The code is as follows:

        private string MakeAttachment(Element element)
        {
            var gen = _repo.CreateDocumentGenerator();
            gen.NewDocument("");
            var genSuccess = false;
            dynamic printItem = _repo.GetElementByID(element.ElementID);           
            Console.WriteLine($"Generating for {printItem.Name}");
            //var templateName = "Requirement Report - Details - Automation";
            var templateName = "Use Case - JBF2";
            genSuccess = gen.DocumentElement(printItem.ElementID, 0, templateName);
            if (!genSuccess) Console.WriteLine($"Failed generating {printItem.Name}" + gen.GetLastError());           
            string fileName = printItem.Name + ".pdf";
            var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),"Temp","EATFS",  $"{fileName}");
            gen.SaveDocument(path, DocumentType.dtPDF);
            return fileName;
        }

Many thanks
Brian


Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Reports work in EA but don't produce same output in my code!
« Reply #1 on: June 20, 2017, 06:21:14 pm »
Hi Brian,


Well the printItem variable is pointless -- your element parameter holds the same Element. Other than that, the code looks alright.

There are some options in the document generation dialog you can't set from the API, but apart from those, generating documents for the same element using the same template should yield the same result regardless of method.

When you say
Quote
When I run the template from EA at the level of a Use Case it produces the output I expect.
When I run it from my own .Net code it only produces what seems to be items at the Element level.
-- what do you actually mean by that? A use case is an element.


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

jbfurlong

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Reports work in EA but don't produce same output in my code!
« Reply #2 on: June 20, 2017, 09:03:21 pm »
Hi Uffe,

Thanks for your reply, and thank you for clarifying that I didn't need to use the printItem variable. It was a work-in-progress hack to attempt to fix the issue.

To explain the text you queried:

I see that there are different evels within the template. One of which is the "Element" item in the template editor selection tree. If I place some template markup into that area they seem to appear in the output from the .Net code generation. But the output I expect to appear does not (e.g. the formatted Requirements box and text from the "Requirement Report - Details" sample template.

But the reason this all started was because whenever I try to run a standard built-in template such as "Requirement Report - Details" my code returns with a Com Interop exception. In trying to deal with that I found that removing the embedded Template in that sample then Com Interop does not fail but of course the template produces nothing!

The ossue I get with Com INterop is:
System.Runtime.InteropServices.COMException was unhandled
  ErrorCode=-2147417851
  HResult=-2147417851
  Message=The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
  Source=mscorlib
  StackTrace:
       at System.Ru.......

I am running Visual Studio as Administrator.

If there is a means to deal with this problem then I would have a solution that works

Brian

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Reports work in EA but don't produce same output in my code!
« Reply #3 on: June 20, 2017, 09:35:40 pm »
I'm still not getting why there are so many people trying to create documents using the API.

I never felt the need to do that. I use Virtual Documents with lots of small simple templates. The only thing I automate is the creation of the virtual document, but not the document creation itself.

Geert

jbfurlong

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Reports work in EA but don't produce same output in my code!
« Reply #4 on: June 20, 2017, 09:58:26 pm »
Geert,

Once again thanks for your reply.

Are you saying I am doing this the wrong way?

I am writing an EA Add-in / Extension that allows the user to right-click an UseCase in EA and have it Synch to TFS. The sync process creates the necessary TFS items (Feature, Use Case or whatever), links the items and generates a PDF summary of the EA UseCase including scenarios etc.m which it then attaches to te TFS item.

Should I be using Virtual Document rether than GenerateDocument?

By the way I am using v 12.1 of EA.

Thanks

Brian
« Last Edit: June 20, 2017, 10:01:36 pm by jbfurlong »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Reports work in EA but don't produce same output in my code!
« Reply #5 on: June 20, 2017, 11:28:40 pm »
Yes,

I would use your add-in to create a virtual document, and then let the user generate the document himself.
That also allow for him to change the order of the elements, add an introduction or appendix, remove unneeded sections etc...

All in all it's much more flexible this way.

You can find more info on that approach in this article I wrote: https://bellekens.com/2015/11/12/tutorial-generate-complex-documents-from-enterprise-architect-with-a-two-step-semi-automated-approach/

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Reports work in EA but don't produce same output in my code!
« Reply #6 on: June 21, 2017, 01:41:03 am »
Well, virtual documents are not without their problems either. With virtual documents you end up with models which need to be maintained, whereas a scripted document generator pulls everything together on the fly and outputs the document.

As to virtual documents affording greater flexibility, that is a matter of opinion. A script is no less flexible than a model, it's just a question of which way of working you're more comfortable with: code or models. I should also point out that with the semi-automated approach you end up having to maintain both a script and the resultant set of models.

I would sum up the different approaches to document generation as follows.


With the most basic, just-hit-F8 way of generating a document, the document structure is tightly linked to the project browser structure. If this is something you can live with, then that's the simplest way to go.

With a virtual document, you put together the document structure manually in the form of a model. The document structure survives restructuring of the source model (up to a point), although of course if you delete parts of the source model your virtual document breaks. (Silently.)

With a scripted document generator, the structure goes in the script. This allows you to lay out your document according to other structures than the browser hierarchy -- you can easily follow connectors, instance/classifier relationships, attribute types, RefGUID tagged values, etc, and base the document structure on that. You can also InsertText(), which allows you to put in results of calculations or anything else that takes your fancy.

The combined script-and-virtual-document method creates a virtual document based on a source model and a structure hard-coded in a script. This gives you the option of modifying the virtual document structure after it's been set up, but it also brings the drawback that virtual documents have: the virtual document is based on the state of the source model at some point in time but has no in-EA relationship to it, and so needs to be maintained in lockstep with the source model.


When I refer to scripts above, the same applies to Add-Ins. But in terms of document generation, there's nothing an Add-In can do that a script can't (except automatically trigger a document generation based on some event fired by EA). Add-Ins are compiled, of course, so the development turnaround is longer.

In general, for complex documents I prefer a scripted approach in many-of-the-same scenarios, where many documents of the same type (eg software component requirements specifications) are to be produced from many distinct, but identically structured, models. In situations where the documents are fewer in number but perhaps broader in scope, such as a progress report on the requirements analysis work taking place in an EA project, I favour virtual documents. I have yet to find a use for the combined approach.

In this situation, where you want the process to generate a document and do a bunch of other stuff at that same time, I would advise against virtual documents in any guise. Virtual documents "freeze" a document structure at some moment in time, which is useful if you want to make changes to the document structure in between creating the virtual document and generating the output document but not otherwise. If you want the generated document to reflect what's in the source model at the moment of TFS synch, and if you don't want to generate the document at any other time, I see no reason to set up a virtual document.


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