c# - 企业架构师 - 查找原型(prototype)的所有元素的最快方法

标签 c# enterprise-architect

我们使用 C# 中的方法来确定构造型的所有元素,但这非常慢:

    public List<EA.Element> findElementsByStereotype(string stereotype){
        List<EA.Element> result = new List<EA.Element>();
        String xmlQueryResult = repository.SQLQuery(
                                        "select obj1.object_id " +
                                        "from t_object obj1 " +
                                        "where obj1.stereotype = '" + stereotype + "';");
        XmlDocument xml = Tools.XMLUtil.convertStringToXMLDocument(xmlQueryResult);
        XmlNodeList xnList = xml.SelectNodes("/EADATA/Dataset_0/Data/Row");
        foreach (XmlNode xn in xnList){
            result.Add(repository.GetElementByID(Convert.ToInt32(xn.InnerText)));
        }
        return result;
    }

您知道性能更高的解决方案吗?

最佳答案

如果您想加快速度,XML 永远不是您的 friend 。幸运的是,EA API 提供了一种不同的方式来检索一组元素:Repository.GetElementSet() ,它返回 EA.CollectionEA.Element来自以逗号分隔的元素 ID 列表或来自 SQL 查询。

public List<EA.Element> findElementsByStereotype(string stereotype) {
    List<EA.Element> result = new List<EA.Element>();
    foreach (EA.Element element in repository.GetElementSet("select Object_ID " +
             "from t_object where Stereotype='" + stereotype + "'", 2)) {
        result.Add(element);
    }
    return result;
}

请注意,我尚未验证其运行速度是否更快。我假设会,但有可能 GetElementSet()本质上与您在幕后执行的 XML 解析相同。但如果不出意外的话,它会更短。

关于c# - 企业架构师 - 查找原型(prototype)的所有元素的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25421189/

相关文章:

enterprise-architect - Enterprise Architect (Sparx Systems) - 在参数列表中添加参数名称和类型

c# - 是否有跨解决方案文件的重构工具?

c# - 在 WPF 中进行 DataBound 时将 TextBlock 设置为完全粗体

C# 在字典中使用类作为对象

c# - 允许多个 IP 地址连接到 Windows Azure SQL Server

c - Q : How to handle more than one condition in a UML state machine transition

c# - 无法将 ObservableCollection 从 MVVM 绑定(bind)到 WPF 中的 ListView

java - Enterprise Architect使用Java API,如何从序列图中读取交互操作符信息?

uml - 如何使用 Enterprise Architect 连接 Lollipop - 组件图(装配关系)

namespaces - Enterprise Architect 代码生成模板 : import hierarchical package structure as a string