Add trigger for transition

How do I add a trigger to the Properties-Constraints-Triggers area of ​​a state machine transition in Enterprise Architect? The quotes are how you get there manually in EA.

What i tried

Below, this actually results in a trigger being added to the state machine, but I need to associate it with a specific transition. The stateMachine variable is of type EA.Element.

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

      

The state is of type EA.Element. the connector is of type EA.Connector (a specific StateFlow transition to which I am trying to add a trigger). They all seem to be doing nothing. In fact, Constraints appear to be an empty assembly, even after adding new elements.

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

      

I also dug EA advisor. The search function is not that good, although I may have missed something.

Interesting information (maybe for something)

The MiscData type for the Connector type seems to contain information about the start of the State Flow. According to a very reliable book (thanks to Mr. Kilian), PDATA1 of MiscData appears to be the name of the State Flow trigger. But how do you add a new trigger? MiscData is read-only.

+3


source to share


1 answer


This particular relationship (from transition to trigger) is probably not supported by the API as such. In this case, you will have to use a workaround.

First, you need to find out exactly where EA stores this information. The easiest way to figure this out is to start with an empty model, create only the elements you need (state machine, two states, transition and trigger), and create a link using the EA GUI.

Then check the database. Since you only have these few items, it should be fairly easy to find where EA has kept the link.



If I had to guess, I would say that it will probably be stored in the t_xref table, or somewhere in the style or styleEx column (or the Pdata column as you pointed out yourself). Then you will need to add this information directly to the database using an SQL or insert query and an undocumented Repository.Execute operation. You can find an example of such a thing on 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);

        }

      

+3


source







All Articles