Book a Demo

Author Topic: Outputting Multiple Models  (Read 4543 times)

SwissSteve

  • EA User
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Outputting Multiple Models
« on: October 16, 2008, 03:41:42 pm »
Here is a strange issue which I cant solve.

I have a simple script that I run in a loop in a C# program.  The idea is that I have a number of models ( 2 currently ) that I want to publish as two html models.  So I read from a file the input and outptt info and feed it into the following code htat is looping.

Now here is the strange thing.   The first time it runs both models publish fine.    Second time I run, the first model publishes ok but the second not.  Third time it publishes both ok the 4th time it again only publishes the first.

I tried to change the order of the models in the config file but still the same behaviour and not the model at fault.

The strange thing is there are no errors.   I have added extensive debugging and all runs are identifcal.

What I did find is that on the failed run, the code enters project.RunHTMLReport() method for about 2 seconds and then exist without error but does not publish the model.

I then tried some silly fixes like executing project.RunHTMLReport() 3 times in a loop, clearing and resetting the project , repository variables again before running etc but it seems once the second model generation fails you must exit the app.

I would appreciate the input of anyone on this annoying issue.

TIA


Code: [Select]
                   repository = new EA.Repository();                    
                    bool result = repository.OpenFile(path.Repository);
                    project = repository.GetProjectInterface();
                    // Delete Output directory if it exists then recreate
                    if (Directory.Exists(path.WebSite))
                    {
                        Directory.Delete(path.WebSite, true);
                    }
                    
                    Directory.CreateDirectory(path.WebSite);
                    
                    // Create the New Model in the Directory
                    project.RunHTMLReport(path.RootGUID, path.WebSite, "PNG", "default", "htm");

                }
                catch (Exception ex)
                {
                    log.Debug(ex.Message);
                }
                finally
                {
                    // Tidy Up
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    repository.CloseFile();
                    project = null;
                    repository = null;

                }    
« Last Edit: October 16, 2008, 03:43:41 pm by SwissSteve »

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Outputting Multiple Models
« Reply #1 on: October 16, 2008, 05:58:31 pm »
Have you tried it manually? I mean opening EA and creating HTML reports for the model just like you loop does?

If if does not work, you may get an eror message which the API does not yield. If it works, I would suspect a COM interop problem. Maybe you could try to dereference your EA.Repository object between exports, force a garbage collection and create a new one.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Outputting Multiple Models
« Reply #2 on: October 17, 2008, 12:33:43 am »
I think you need to move the GC calls so they are after (i.e. later than) all references to EA.
No, you can't have it!

Oliver F.

  • EA User
  • **
  • Posts: 573
  • Karma: +2/-1
  • Aren´t we all in the model business ?
    • View Profile
    • Karl Storz homepage
Re: Outputting Multiple Models
« Reply #3 on: October 17, 2008, 12:54:09 am »
Similar issue here.
I have a JAVA deamon, which runs every 24 hours. Then it sets baselines for some packages and afterwards tries to export the model to HTML.

Sometimes it works, sometimes not. Baselining is ok, HTML export regularly stops without notice. I have a tray icon set up with a menu which lets me manually trigger the export and it perfectly works then.

However HTMLExport has proven to be very unreliable.

Oliver

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Outputting Multiple Models
« Reply #4 on: October 17, 2008, 05:26:30 am »
Quote
I think you need to move the GC calls so they are after (i.e. later than) all references to EA.

That's what I was trying to point out. Should have been more precise though, like "dereference anything to with EA, force garbage collection, and then init EA again".

I don't know if this helps though. Just a guess.

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Outputting Multiple Models
« Reply #5 on: October 17, 2008, 05:28:14 am »
Quote
Sometimes it works, sometimes not. Baselining is ok, HTML export regularly stops without notice. I have a tray icon set up with a menu which lets me manually trigger the export and it perfectly works then.

Looks like a serious bug then. API should either complete a call or return a meaningful error.

SwissSteve

  • EA User
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: Outputting Multiple Models
« Reply #6 on: October 17, 2008, 04:59:04 pm »
Thanks all for the advice.   I agree there should be some meaningful error message should be provided from the method.

Just to say that moving the Garbage Collection to the end of the finalize section fixed my problem.   I tested it this morning and it runs now without issue.

Thanks Midnight and Frank fo rhte code review.