Book a Demo

Author Topic: Exception on create PackageImport connector in AI  (Read 3260 times)

XC

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Exception on create PackageImport connector in AI
« on: July 19, 2008, 04:48:12 am »
Hello,
I have to create PackageImport connector from one Package to another. Here is code:

Code: [Select]
EA.IDualPackage clientPkg = this.GetNative();
EA.IDualPackage splPkg = this.NativeProject.GetPackageByID(((EAPackage)supplier).NID);

EA.IDualConnector nlnk= (EA.IDualConnector)clientPkg.Connectors.AddNew("import", "Package");
nlnk.SupplierID = splPkg.Element.ElementID;
nlnk.Stereotype = "import";
nlnk.Direction = "Source -> Destination";
nlnk.ClientEnd.Containment = nlnk.SupplierEnd.Containment = "Unspecified";
nlnk.ClientEnd.IsNavigable = false;
nlnk.ClientEnd.Navigable = "Non-Navigable";
nlnk.SupplierEnd.IsNavigable = true;
nlnk.SupplierEnd.Navigable = "Navigable";

try {
      nlnk.Update(); // Exception
}
catch (Exception x) {
      Context.LogError(CError.CreateTechError(string.Format("Package link update failed {1}->{0} [{2}]: {3}.\r\n", nlnk.ClientID, nlnk.SupplierID, nlnk.Type, nlnk.GetLastError()), x));
}

Exception is thrown on nlnk.Update() only when EA Tools>Options>Diagram>Strict UML Syntax is checked.

Creation of Dependency between the same packages works fine.

What is wrong?
Thanks!

XC

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Exception on create PackageImport connector in
« Reply #1 on: July 28, 2008, 11:17:45 pm »
OK, tech support confirmed that this is a known issue. Hopefully they will fix it in next release.
Meanwhile if somebody interested here is a dirty and dangerous work around:
Code: [Select]
EA.IDualPackage clientPkg = this.GetNative();
EA.IDualPackage splPkg = this.NativeProject.GetPackageByID(((EAPackage)supplier).NID);

EA.IDualConnector nlnk= (EA.IDualConnector)clientPkg.Connectors.AddNew("", "Dependency");
nlnk.SupplierID = splPkg.Element.ElementID;
nlnk.Stereotype = "import";
nlnk.Direction = "Source -> Destination";
nlnk.ClientEnd.Containment = nlnk.SupplierEnd.Containment = "Unspecified";
nlnk.ClientEnd.IsNavigable = false;
nlnk.ClientEnd.Navigable = "Non-Navigable";
nlnk.SupplierEnd.IsNavigable = true;
nlnk.SupplierEnd.Navigable = "Navigable";

nlnk.Update(); // this time it works because it's Dependency. Everything is correct except the connector type.

//This trick was tested on EAP file and MS SqlServer. I'm pretty sure it will work an many others RDBMS:
EA.IDualRepository nativeRepository= this.NativeProject;
nativeRepository.Execute(string.Format("update t_Connector set Connector_Type='Package' where Connector_Id={0}", nlnk.ConnectorID));

Don't use this approach if you can do it other way; it is not nice and creates dependency on the actual field name in the EA repository.
Still - it works and I assume it will work for some time in future - just because change of this name would create problems for Sparx as well.