//---------------------------------------------------------------------------------------------
        // updateActionParameter(EA.Repository rep, EA.Element actionPin)
        //---------------------------------------------------------------------------------------------
        public static bool UpdateActionPinParameter(Repository rep, EA.Element action)
        {
            foreach (EA.Element actionPin in action.EmbeddedElements)
            {
                // pin target for the return type of the action
                if (actionPin.Name == "target")
                {
                    //// return type
                    //Int32 parTypeID = Util.getTypeID(rep, m.ReturnType);
                    //if (parTypeID != 0)
                    //{
                    //    //pin.Name = par.
                    //    pin.ClassfierID = parTypeID;
                    //    EA.Element el = rep.GetElementByID(parTypeID);
                    //    pin.Update(); // do it before update table
                    //    Util.setElementPDATA1(rep, pin, el.ElementGUID);// set PDATA1

                    //}
                }
                else
                {
                    // get type of synchronized parameter
                    // if parameter isn't synchronized it will not work
                    string type = HoUtil.GetParameterType(rep, actionPin.ElementGUID);
                    if (type == "")
                    {
                        string txt = "No type is available for action:'" + action.Name + "'";
                        rep.WriteOutput("hoReverse", txt, 0);
                    }
                    else
                    {
                        Int32 parTypeId = HoUtil.GetTypeId(rep, type);
                        if (parTypeId != 0)
                        {
                            //pin.Name = par.
                            EA.Element el = rep.GetElementByID(parTypeId);
                            HoUtil.SetElementPdata1(rep, actionPin, el.ElementGUID);// set PDATA1
                        }
                    }
                }
            }

            return(true);
        }
Example #2
0
        //-------------------------------------------------------------------------------------------------
        // get Parameter from operation
        // visualize them on diagram / activity
        //-------------------------------------------------------------------------------------------------
        public static bool UpdateParameterFromOperation(Repository rep, EA.Element act, Method m)
        {
            if (m == null)
            {
                return(false);
            }
            if (act.Locked)
            {
                return(false);
            }
            if (!act.Type.Equals("Activity"))
            {
                return(false);
            }

            EA.Element parTrgt = null;


            ///////////////////////////////////////////////////////////////////////////////////
            // return code
            string parName = "Return";
            int    methodReturnTypId;

            // is type defined?
            if ((m.ClassifierID != "0") & (m.ClassifierID != ""))
            {
                methodReturnTypId = Convert.ToInt32(m.ClassifierID);
            }

            // type is only defined as text
            else
            {
                methodReturnTypId = Convert.ToInt32(HoUtil.GetTypeId(rep, m.ReturnType));
            }

            bool withActivityReturnParameter = false;

            if (withActivityReturnParameter)
            {
                parTrgt.ClassifierID = methodReturnTypId;
                // create an return Parameter for Activity (in fact an element with properties)
                parTrgt = HoUtil.GetParameterFromActivity(rep, null, act, true);
                if (parTrgt == null)
                {
                    parTrgt = (EA.Element)act.EmbeddedElements.AddNew(parName, "Parameter");
                }
                else
                {
                    parTrgt.Name = parName;
                }


                parTrgt.Alias        = "return:" + m.ReturnType;
                parTrgt.ClassifierID = parTrgt.ClassifierID;

                parTrgt.Update();
                // update properties for return value
                Param par = new Param(rep, parTrgt);
                par.setParameterProperties("direction", "out");
                par.save();
                par = null;
            }
            // returnType for activity
            act.ClassfierID = methodReturnTypId;
            act.Name        = m.Name;

            // use stereotype of operation as stereotype for activity
            act.StereotypeEx = m.StereotypeEx;
            act.Update();
            act.EmbeddedElements.Refresh();

            // over all parameters
            string guids = "";
            // It looks as if parSrc.Position isn't reliable
            int pos = 0;

            foreach (EA.Parameter parSrc in m.Parameters)
            {
                // create an Parameter for Activity (in fact an element with properties)
                // - New if the parameter don't exists
                // - Update if the parameter exists
                // -- Update according to the parameter position

                //string direction = " [" + parSrc.Kind + "]";
                string direction = "";
                string prefixTyp = "";
                if (parSrc.IsConst)
                {
                    prefixTyp = " const";
                }
                var postfixName = "";
                if (parSrc.Kind.Contains("out"))
                {
                    postfixName = "*";
                }
                //parName = parSrc.Position + ":" + parSrc.Name + postfixName + prefixTyp + direction;
                parName = $"{pos}:{parSrc.Name}{postfixName}{prefixTyp}{direction}";

                // check if parameter already exists (last parameter = false)
                parTrgt = HoUtil.GetParameterFromActivity(rep, parSrc, act);



                // parameter doesn't exists
                if (parTrgt == null)
                {
                    parTrgt = (EA.Element)act.EmbeddedElements.AddNew(parName, "Parameter");
                }
                else
                {
                    parTrgt.Name = parName;
                }
                guids = guids + parTrgt.ElementGUID;

                // is type defined?
                if ((parSrc.ClassifierID != "0") & (parSrc.ClassifierID != ""))
                {
                    parTrgt.ClassifierID = Convert.ToInt32(parSrc.ClassifierID);
                }
                // type is only defined as text
                else
                {   // try to find classifier
                    parTrgt.ClassifierID = Convert.ToInt32(HoUtil.GetTypeId(rep, parSrc.Type));
                    // use type in name (no classifier found)
                    if (parTrgt.ClassifierID == 0)
                    {
                        parTrgt.Name = parTrgt.Name + ":" + parSrc.Type;
                    }
                }

                parTrgt.Notes = parSrc.Notes;
                parTrgt.Alias = $"par_{pos}:{parSrc.Type}";
                //parTrgt.Alias = $"par_{parSrc.Position}:{parSrc.Type}";

                // update properties for parameter
                Param par = new Param(rep, parTrgt);
                par.setParameterProperties("direction", parSrc.Kind);
                if (parSrc.IsConst)
                {
                    par.setParameterProperties("constant", "true");
                }
                par.save();
                parTrgt.Update();
                pos += 1;
            }
            act.EmbeddedElements.Refresh();
            // delete all unused parameter
            for (short i = (short)(act.EmbeddedElements.Count - 1); i >= 0; --i)
            {
                EA.Element embeddedEl = (EA.Element)act.EmbeddedElements.GetAt(i);
                if (embeddedEl.Type.Equals("ActivityParameter"))
                {
                    if (!(guids.Contains(embeddedEl.ElementGUID)))
                    {
                        act.EmbeddedElements.Delete(i);
                    }
                }
            }
            act.EmbeddedElements.Refresh();

            return(true);
        }