/// <summary>
        /// Find Activity from method name.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="methodName"></param>
        /// <param name="verbose"></param>
        /// <returns>Activity</returns>
        public static EA.Element GetActivityFromMethodName(EA.Repository rep, string methodName, bool verbose = true)
        {
            // object_id has to be included
            string query = $@"select object_id
                                from t_object o 
                                where o.name = '{methodName}' AND
                                      o.object_type = 'Activity'";

            EA.Collection colEl = rep.GetElementSet(query, 2);
            if (colEl.Count == 0)
            {
                return(null);
            }

            if (colEl.Count == 1)
            {
                return((EA.Element)colEl.GetAt(0));
            }

            if (verbose)
            {
                // more than one activity found
                var lActivities = from i in colEl.ToEnumerable <EA.Element>()
                                  orderby i.FQName
                                  select $"{i.FQName}";
                var sActivities = String.Join("\r\n", lActivities);

                // Message with Path to Activity
                MessageBox.Show($"{colEl.Count} Activities found for function '{methodName}'\r\nFirst one taken. See List in Clipboard.\r\n\r\n{sActivities}",
                                "More than one Activity found!");

                // Clipboard with GUID and Path to Activity
                lActivities = from i in colEl.ToEnumerable <EA.Element>()
                              orderby i.FQName
                              select $"{i.ElementGUID}  {i.FQName}";
                sActivities = String.Join("\r\n", lActivities);
                Clipboard.SetText(sActivities);
            }

            return((EA.Element)colEl.GetAt(0));
        }
        static void cacheDiagramElements(EA.Repository repository, EA.Collection collection, DiagramCache diagramCache)
        {
            //diagramCache.elementsList = new List<EA.Element>();
            Object o;

            EA.Element e;
            if (collection.Count == 0)
            {
                return;
            }

            int eId, pkgId;

            EA.Collection elements = null;

            List <int> els = new List <int>();

            for (short i = 0; i < collection.Count; i++)
            {
                o   = collection.GetAt(i);
                eId = ((EA.DiagramObject)o).ElementID;
                if (diagramCache.elementIDHash.ContainsKey(eId))//Skip elements already cached
                {
                    continue;
                }
                els.Add(eId);
            }


            StringBuilder sb;

            {
                sb = new StringBuilder();
                for (short i = 0; i < els.Count - 1; i++)
                {
                    eId = els[i];
                    sb.Append(eId);
                    sb.Append(",");
                }
                eId = els[(short)(els.Count - 1)];
                sb.Append(eId);
                String elementsString = sb.ToString();
                //logger.log("DiagramObjectIds"+sb.ToString());
                //logger.log("Getting elements:"+elementsString);

                elements = repository.GetElementSet(elementsString, 0);
            }
            sb = new StringBuilder();

            if (elements != null)
            {
                foreach (EA.Element el in elements)
                {
                    diagramCache.elementsList.Add(el);
                    if (!diagramCache.elementIDHash.ContainsKey(el.ElementID))
                    {
                        diagramCache.elementIDHash.Add(el.ElementID, el);
                    }
                    if (!diagramCache.elementGuidHash.ContainsKey(el.ElementGUID))
                    {
                        diagramCache.elementGuidHash.Add(el.ElementGUID, el);
                    }
                }
            }
        }
        static void cacheDiagramClassifiers(EA.Repository repository, DiagramCache diagramCache)
        {
            Object o;

            if (diagramCache.elementsList.Count == 0)
            {
                return;
            }

            int           classifierId;
            StringBuilder sb = new StringBuilder();

            for (short i = 0; i < diagramCache.elementsList.Count; i++)
            {
                o = diagramCache.elementsList[i];
                EA.Element el = (EA.Element)o;
                if (!diagramCache.elementIDHash.ContainsKey(el.ElementID))
                {
                    diagramCache.elementIDHash.Add(el.ElementID, el);
                }
                classifierId = el.ClassifierID;
                if (classifierId != 0)
                {
                    sb.Append(classifierId);
                    sb.Append(",");
                }
            }
            logger.log("Getting classifiers" + sb.ToString());

            String classifiersString = sb.ToString();

            if (classifiersString.Length == 0)
            {
                return;
            }
            classifiersString = classifiersString.Substring(0, classifiersString.Length - 1);
            EA.Collection classifierCollection = repository.GetElementSet(classifiersString, 0);

            logger.log("Classifiers Length" + classifierCollection.Count);

            int elementId;

            for (short i = 0; i < classifierCollection.Count; i++)
            {
                logger.log("Get classifier" + i);
                logger.log(classifierCollection.GetType().Name);

                o = classifierCollection.GetAt(i);

                EA.Element element = (EA.Element)o;
                elementId = element.ElementID;
                logger.log("A");
                if (!diagramCache.elementIDHash.ContainsKey(elementId))
                {
                    diagramCache.elementIDHash.Add(elementId, element);
                }
                logger.log("B");
                if (!diagramCache.elementGuidHash.ContainsKey(element.ElementGUID))
                {
                    diagramCache.elementGuidHash.Add(element.ElementGUID, element);
                }
            }
        }
Example #4
0
 public EA.Collection GetElementSet(string IDList, int Unused)
 {
     return(eaRepository.GetElementSet(IDList, Unused));
 }