Book a Demo

Author Topic: Import XMI ... Replace existing Root-Model  (Read 3145 times)

blue5teel

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Import XMI ... Replace existing Root-Model
« on: January 23, 2009, 08:48:06 pm »
Its me again.
I use following function to import an XMI to EA:

Code: [Select]
App.Repository.GetProjectInterface().ImportPackageXMI(ModelGUID, WorkingDirectory + @"ProjectXML.xmi", 1, 0);
Why doesnt it replace the existing root-model (The one corresponding to "ModelGUID")?
He just adds the imported branch as a child to the model. but i expected that the model-object will be replaced by the imported stuff.

Thx in advance

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8098
  • Karma: +118/-20
    • View Profile
Re: Import XMI ... Replace existing Root-Model
« Reply #1 on: January 27, 2009, 08:30:51 am »
Does the top level package GUID in the XMI match the GUID of the root node?

It will only replace the package if that is the case, otherwise it will behave as you have described.

blue5teel

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Import XMI ... Replace existing Root-Model
« Reply #2 on: January 29, 2009, 07:22:00 pm »
Quote
Does the top level package GUID in the XMI match the GUID of the root node?

It will only replace the package if that is the case, otherwise it will behave as you have described.

No the top level package GUID in the xmi (OriginalModel) doesnt match the GUID of the root node (DestinationModel). I tried to manipulate it with:

Code: [Select]
DestinationModel.PackageGUID = System.Guid.NewGuid().ToString();
I hoped that the imported stuff always besomes a child-element of the existing model. So that i can rely on deterministic behaviour.

But now it doesnt import anything.The DestinationModel stays emtpy.

Yes i also tried to give both models the same guid. No desired effect.
Here is the whole XML-Import-Code:

Code: [Select]
public static void StartNewEAInstance(EA.Repository Repository)
        {
            Logging.Initialize(WorkingDirectory + @"Log.txt");

            Repository.GetProjectInterface().ExportPackageXMI(Model.PackageGUID, EA.EnumXMIType.xmiEADefault, 1, 1, 1, 1, WorkingDirectory + @"ProjectXML.xmi");


            EA.App App = new EA.App();

            App.Repository.OpenFile(AddInDirectory + @"dummy.eap");
            App.Visible = true;

            //TODO: Import von XMI.
            EA.Package OriginalModel = (EA.Package)Repository.Models.GetAt(0);
            EA.Package DestinationModel = (EA.Package)App.Repository.Models.GetAt(0);

            DestinationModel.PackageGUID = System.Guid.NewGuid().ToString();
            DestinationModel.Update();
            App.Repository.RefreshModelView(0);

            string ModelGUID = DestinationModel.PackageGUID;
            string OriginalGUID = OriginalModel.PackageGUID;

            App.Repository.Models.Refresh();

            App.Repository.GetProjectInterface().ImportPackageXMI(ModelGUID, WorkingDirectory + @"ProjectXML.xmi", 1, 0);

            App.Repository.Models.Refresh();
            App.Repository.RefreshModelView(0);

            TransformDiagramsToPackagesWithTree(App.Repository);

            
            ReportingKernel.Notify();
            //App.Repository.Exit();

            Logging.Close();
        }

Any solutions out there ?
Maybe i have to manipulate the GUID of the corresponding "Element" of the Package ?

EA Api is such a pain in the ass ... sorry for that.
« Last Edit: January 29, 2009, 07:31:15 pm by blue5teel »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8098
  • Karma: +118/-20
    • View Profile
Re: Import XMI ... Replace existing Root-Model
« Reply #3 on: January 30, 2009, 06:40:02 am »
Okay, I would recommend not changing the package guid in the destination model.  A guid is supposed to be a unique identifier over all projects, but also across the entire lifetime of an element.

Try setting the stripguids flag in the ImportPackageXMI function.  Then your behavior is deterministic.  It will always import as a new package under the package you passed in.