将触发器添加到转换

本文关键字:转换 添加 触发器 | 更新日期: 2023-09-27 18:29:50

如何将触发器添加到Enterprise Architect中状态机转换的"Properties Constraints Triggers"区域?报价是你在EA中手动到达那里的方式。

我尝试了什么

下面,这实际上导致触发器被添加到状态机中,但我需要将其链接到特定的转换。变量stateMachine属于EA.Element.类型

EA.Element trigger = (EA.Element)stateMachine.Elements.AddNew("trigger", "Trigger");

State属于EA.Element类型。连接器是EA.connector类型(我试图将触发器添加到的特定StateFlow转换)。所有这些似乎都毫无作用。事实上,Constraints似乎是一个空集合,即使在我添加了新项之后也是如此。

state.Constraints.AddNew("trigger", "Trigger");
connector.Constraints.AddNew("trigger", "Trigger");
state.StateTransitions.AddNew("trigger", "Trigger");

我在EA的帮助下也没有运气。搜索功能不是很好,所以我可能错过了什么。

有趣的信息(可能涉及某些内容)

连接器类型的杂项数据似乎具有状态流触发器信息。根据一本非常可靠的书(谢谢Kilian先生),MiscDataPDATA1似乎是状态流触发器的名称。但我该如何添加新的触发器MiscData为只读。

将触发器添加到转换

API可能不支持这种特殊关系(从转换到触发器)。在这种情况下,您必须使用变通方法。

首先,您需要弄清楚EA将这些信息准确存储在哪里。最简单的方法是从一个空模型开始,只创建所需的元素(状态机、两个状态、一个转换和一个触发器),然后使用EAGUI创建链接。

然后检查数据库。由于只有这几个元素,所以应该很容易找到EA存储关系的位置。

如果非要我猜测的话,我会说它可能会存储在t_xref表中,或者存储在style或styleEx列(或者您自己指出的Pdata列)中的某个位置。然后,您需要使用SQL更新或插入查询以及未记录的Repository.Execute操作将这些信息直接添加到数据库中。你可以在github上找到这样一个例子:

        /// <summary>
        /// copy the workingset tot the given user
        /// </summary>
        /// <param name="user">the user to copy the working set to</param>
        /// <param name="overwrite">if true then the first workingset found with the same name
        /// for the given user will be overwritten</param>
        public void copyToUser(User user, bool overwrite)
        {
            if (overwrite)
            {
                //check if a workingset with the same name already exists
                WorkingSet workingSetToOverwrite = this.model.workingSets.Find(w => 
                                                                    w.user != null
                                                                    && w.user.login == user.login 
                                                                    && w.name == this.name);
                if (workingSetToOverwrite != null)
                {
                    workingSetToOverwrite.delete();
                }
            }
            string insertQuery = @"insert into t_document (DocID,DocName, Notes, Style,ElementID, ElementType,StrContent,BinContent,DocType,Author,DocDate )
                                select '"+Guid.NewGuid().ToString("B")+@"',d.DocName, d.Notes, d.Style,
                                d.ElementID, d.ElementType,d.StrContent,d.BinContent,d.DocType,'" + user.fullName + @"',d.DocDate from t_document d
                                where d.DocID like '"+this.ID+"'";
            this.model.executeSQL(insertQuery);
        }