Book a Demo

Author Topic: Problem: adding a taggedValue to a Connector  (Read 3720 times)

Hermes

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Problem: adding a taggedValue to a Connector
« on: November 04, 2009, 03:28:19 am »
Dear All,

I'm tring to write an addin in c# to manage a UML customized metamodel with EA.

But i got a strange exception when I try to analize connectors:
It seems that i'm not allowed to get/add tagged values to this items. :(

this are few lines from my code:

Code: [Select]

foreach( EA.Connector conn in child_req.Connectors )
                if (conn.Stereotype == AppConfig.EAP_MY_LINK_STEREOTYPE)
                {
                    EA.TaggedValue link_status_tag = BaseControl.GetTaggedValue(conn.TaggedValues, AppConfig.TAGVAL_MYLINK_STATUS);

                    if (link_status_tag == null)
                    {
                        //exception starts HERE
                        BaseControl.AddTaggedValue(conn.TaggedValues, AppConfig.TAGVAL_MYLINK_STATUS, AppConfig.EAP_TAGGEDVALUE_TYPE, AppConfig.MYLINK_STATUS_PROPOSED);
                        link_status_tag = BaseControl.GetTaggedValue(conn.TaggedValues, AppConfig.TAGVAL_MYLINK_STATUS);
                    }

...


and this are two helping functions that i call in the above snippet:

Code: [Select]
  public class BaseControl
    {
        public static bool AddTaggedValue(EA.Collection coll, String name, String type, String value)
        {

            EA.TaggedValue tag = GetTaggedValue(coll, name);
[highlight]
 //exception raised HERE[/highlight]
            if(tag==null)                
                tag = (EA.TaggedValue)coll.AddNew(name, type);

            tag.Value = value;

            if (!tag.Update())
            {
                AppConfig.last_error_msg = "Cant add TaggedValue [" + name + "],[" + type + "],[" + value + "]";
                return false;
            }

            return true;

        }

        public static EA.TaggedValue GetTaggedValue(EA.Collection coll, String name )
        {
            EA.TaggedValue tag = null;

            try
            {
                tag = (EA.TaggedValue) coll.GetByName(name);
            }
            catch (Exception)
            {
                return null;
            }

            return tag;
        }


when I try to run this, i got this:

Quote
Impossibile eseguire il cast di oggetti COM di tipo 'System.__ComObject' in tipi di interfaccia 'EA.TaggedValue'. L'operazione non è stata completata perché la chiamata QueryInterface sul componente COM per l'interfaccia con IID '{EF08950B-949E-435F-84A3-A59E3106C3BF}' non è riuscita a causa del seguente errore: Interfaccia non supportata. (Eccezione da HRESULT: 0x80004002 (E_NOINTERFACE)).

that Translated in English says that it is not possible to cast the returned value [from Collection.AddNew()] in the EA.TaggedValue inteface. Operation not completed from the QueryInterface because the interface is not supported  :(.

I use the string type: "TaggedValue" when calling the Collection.AddNew() method.
( ie: AppConfig.EAP_TAGGEDVALUE_TYPE = "TaggedValue" )

Note that: my code tries to insert a new tagged value because it not finds the specified taggedValue... but it should exists in the model. (I've created manully in a diagram using a drag&drop mode).

Why this happens? could someone helpme please?

Thankyou :)

/D

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Problem: adding a taggedValue to a Connector
« Reply #1 on: November 04, 2009, 08:21:50 am »
Look for EA.ConnectorTag (or something similar)  It is not an EA.TaggedValue.

Hermes

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Problem: adding a taggedValue to a Connector
« Reply #2 on: November 04, 2009, 10:00:09 pm »
Great! it worked  :)

Thankyou!