Author Topic: Creating C# Project from Exported XMI  (Read 6832 times)

jmad

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Creating C# Project from Exported XMI
« on: July 10, 2008, 12:00:38 am »
Hi,

I need to transform the XMI created from EA7.1 to a different format for storage in a EbXML registry/repository.

I noticed that there was an API that could allow me to transform the exported XMI to a EA.Project item in C#. Upon attempting to do this however, I get a message that states
RPC_E_SERVERFAULT

My code is like this:
Code: [Select]
if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                EA.Project newProj = new EA.Project();
                newProj.ImportPackageXMI(newProj.GUIDtoXML(System.Guid.NewGuid().ToString()),openFileDialog1.FileName,0,1);
            }
I have the Interop loaded and this seems to be a general COM error, so am a bit lost on how to proceed.

The XMI was created using UML2.1(XMI2.1), Enable Roundtrip, Format XMI output.

Does the ImportPackageFromXMI work with XMI2.1? Does anyone have any advice on what to do with the error message?

Is there another way to use C# to serialize the XML output of the XMI Export?

Failing the above, does anyone have any advice on a different tactic?

Thanks,
jmad

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #1 on: July 10, 2008, 12:38:41 am »
Ensure that your project can find UML_EA.DTD in its file path somehow. Normally this would require placing that file in the same folder as your XMI file.

Alternatively, you could read the XMI file into a string object and pass (the contents of) the string instead of the file name.
No, you can't have it!

jmad

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #2 on: July 10, 2008, 12:50:10 am »
Starting with the "Alternatively" bit.

The following:
Code: [Select]
           if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                XmlDocument newDoc = new XmlDocument();
                newDoc.Load(openFileDialog1.FileName);
                EA.Project newProj = new EA.Project();
                newProj.ImportPackageXMI(newProj.GUIDtoXML(System.Guid.NewGuid().ToString()),newDoc.OuterXml,0,1);
            }

Produces the same error.

Looking for the UML_EA.DTD now.

Edit: It appears that UML_EA.DTD is on the desktop along with my XMI file.

-jmad
« Last Edit: July 10, 2008, 12:51:56 am by jmad »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #3 on: July 10, 2008, 01:58:40 am »
If nobody comes up with a plausible solution by close of business, I suggest you send an email to Sparx support. You'll find their address by clicking the Support link at the top or bottom of any forum page and looking near the top of the resulting page.
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #4 on: July 10, 2008, 04:17:52 am »
Maybe your

Code: [Select]
EA.Project newProj = new EA.Project()is just an empty thing in memory which needs to get a file (or database connection) before it can do anything at all. There's a LoadProject(string filename) method for that, but I don't know how to create a new file on the EA.Project class.

Or you start with a

Code: [Select]
new EA.Repository()and its OpenFile() method and then GetProjectInterface().

jmad

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #5 on: July 10, 2008, 04:40:00 am »
I did see that. So, I attepted to create an empty repository that I could load my XMI into using the following:

Code: [Select]
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                XmlDocument newDoc = new XmlDocument();
                newDoc.Load(openFileDialog1.FileName);
                EA.Repository rep = new EA.Repository();
                EA.Project newProj = rep.GetProjectInterface();
                newProj.ImportPackageXMI(newProj.GUIDtoXML(System.Guid.NewGuid().ToString()),newDoc.OuterXml,0,1);
            }

But that did not seem to help.

The thing is, I am trying to give it a file, in XMI format from which I am hoping, it can populate the necessary connection, element and diagram fields.

I'm not sure what else it requires. I think may have to initialize the repository in a different manner, but I am stumped on how to do so.

Maybe I should create a blank EA document and load it from a C# resource file. So that the repository has something to connect to.

Edit: Hm. That won't work if the function requires a filename in order to load. I'll try with just a blank file.

Edit2: Ok. If I populate the repository with a blank .eap file, it seems that the code functions. Now, I probably need to figure out if there is a method to create a repository without using a file, so that I can store initialization code in a resource file. Also, I need to determine if the loaded XMI file populated by stub file correctly.

-jmad
« Last Edit: July 10, 2008, 05:16:11 am by jmad »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #6 on: July 10, 2008, 08:27:15 am »
All of the methods in the Project interface require a currently loaded model.  Your last sample should work if you load a model after creating the Repository object.

jmad

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #7 on: July 10, 2008, 11:38:30 am »
So, a model can not be created programatically?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8083
  • Karma: +118/-20
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #8 on: July 10, 2008, 11:49:57 am »
The easiest way to create a new model is to copy the EABase.eap from the EA install directory.

jmad

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #9 on: July 15, 2008, 04:23:12 am »
Ok. Question 2.

I have a package which I would like to add to a repository, the package contains sub-packages of the same XML layout.

To add a package to a repository it seems as though I would create an element, copy over a few parameters from the XML. Then for sub-packages, I would create sub-elements and link them.

So, I pass the XML package to an element constructor, create a EA.Element copy a few parameters (name, guid etc.) and then attempt to add an element to it's Elements collection, it seems as if I should be able to set this up recursively so that all the subpackages would be included in the EA.Element.Elements

This does not seem to work. EA.Element.Elements seems to have only one method for adding a new EA.Element to it's collection, but the parameters for the EA.Element.AddNew(string, string) are incorrect.

How are Elements meant to be added in such a case?

Here's some code
Code: [Select]
namespace XMIMain
{
    class Element
    {
//element property
        private EA.Element _element;
        public EA.Element Element
        {
            get { return _element; }
        }

//constructor
        public Element(RegistryPackageType package)
        {
            _element = new EA.Element();
            _element.Name = package.Name;
            _element.ElementGUID = package.id;
            foreach (IdentifiableType id in package.RegistryObjectList)
            {
                if (id is RegistryPackageType)
                {
                     XMIMain.Element subElement = new XMIMain.Element((RegistryPackageType)id);
                    //in here we need to add this new element to the elements collection?
                    //_element.Elements.Add(subElement.Element)?
                }
            }

        }
    }
}

So, is there something that I can replace the comment with that will add this element to the elements collection?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Creating C# Project from Exported XMI
« Reply #10 on: July 15, 2008, 05:35:28 am »
Create the package instead of the element for the package. EA will take care of the details.

Remember to call Update on each package (and anything else) before you add any 'owned' objects to it. Some properties can be set beforehand (such as name) but for most it is best to Update() first (and after making more changes of course).

Also remember to Refresh() any collection (such as the Packages collection of a parent package) before you attempt to retrieve a new member. Even a Get<x>ByName call will fail (sometimes returning nothing without throwing an exception) if you have not called Refresh() since you added the named item.

David
No, you can't have it!