在以编程方式创建时,Enterprise Architect不会在浏览器中显示包

时间:2014-04-03 07:56:19

标签: c# enterprise-architect

 How to create Packages in EA appropriately?

当我以编程方式创建包时,包不会出现在Project浏览器中 创建类和属性很好,但不是包。有什么建议? THX ...

这是我的创建包功能:

public void addNewPackage(String packageName, Package parentPackage, string elementType)
{
    // for every package under the  Root Model->Folder->...
    foreach (Package pack in r.Models)
    {
        foreach (Package package in pack.Packages)
        {

            foreach (Package innerPackage in package.Packages)
            {
                // ----addOrUpdateElement
                Package myPackage;
                // try to find existing class with the given name
                // this will only work correctly if there is only one element with the given name, and if it is a class
                myPackage = getPackageElementByName(parentPackage, packageName);

                if ((myPackage == null))
                {
                    // no existing class, create new
                    myPackage = parentPackage.Elements.AddNew(packageName, elementType);
                }
                // set properties
                // save class
                myPackage.Update();
                // refresh elements collection
                parentPackage.Elements.Refresh();



                innerPackage.Packages.Refresh();
            }
            package.Packages.Refresh();
            package.Update();
        }
        r.RefreshModelView(pack.PackageID);
    }

    models.Refresh();
    MessageBox.Show("Pack adding Ended: " + models.GetLastError());
}

1 个答案:

答案 0 :(得分:3)

您似乎正在将自己的软件包添加到Package.Elements集合中。它们应该在Package.Packages。一个UML包由EA ElementPackage表示,但Element是在您创建Package时自动创建的。

所以你需要做一些像

这样的事情
if (elementType.Equals("Package"))
{
    Package myPackage = parentPackage.Packages.AddNew(elementName, elementType);
    myPackage.Update();
    parentPackage.Packages.Refresh();
}
else
{
    Element myElement = parentPackage.Elements.AddNew(elementName, elementType);
    myElement.Update();
    parentPackage.Elements.Refresh();
}