Book a Demo

Author Topic: please help me with the ArrayLists  (Read 3978 times)

defi

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
please help me with the ArrayLists
« on: May 17, 2012, 02:58:36 am »
Hello, i have to make a research in the EA.model and find all the elements that are type= package, component,class and their connections or link. So I made "foreach" conditions for every case, but i have the problem with my ArrayLists. I can't Add anything to them, i don't understand why. I tried to make an example ArrayList where i Add a String but nothing gets it output.
The example is:

Code: [Select]
ArrayList example = new ArrayList();
example.Add("hello");
Console.WriteLine("my ArrayList is" + example);


I get in output:
my ArraList isSystem.Collections.ArrayList

Can you please tell me why i can't add any value to my ArrayLists?

Thank you a lot for your help, it means very much to me!


My code to find the elements and the connections that i need from the model is:
Code: [Select]
ArrayList elementsCol = new ArrayList();
            ArrayList packagesCol = new ArrayList();
            ArrayList connectorsCol = new ArrayList();
            ArrayList nodesList = new ArrayList();
            ArrayList nodeList = new ArrayList();
            ArrayList linkList = new ArrayList();
            
            
          
            Node thisNode = null;

            //inizializzazione nodi

            foreach (EA.Package pack in modelRepository.Models)
            {
                foreach (EA.Package inpack in pack.Packages)
                {
                    ArrayList nodespackage = new ArrayList();
                    nodespackage.Add(inpack.Element);

                    foreach (EA.Element elempack in nodespackage)
                    {
                        elementsCol.Add(elempack);
                    }
                }



                for (int i = 0; i < elementsCol.Count; i++)
                { nodesList.Add(elementsCol[i]); }

            while (nodesList.Count > 0)
            {
                thisNode = nodesList[0] as Node;
                nodesList.RemoveAt(0);

                nodeList.Add(thisNode);
             }



                foreach (EA.Element element in elementsCol)
                {
                    if ((element.Type == "Class") || (element.Type == "Component") || (element.Type == "Package"))
                    {
                        nodeList.Add(element);
                      
                    }
                }

                if (packagesCol != null)
                {
                    foreach (EA.Package package in packagesCol)
                    {
                        nodeList.Add(package);
                    }
                }


                            
            Console.WriteLine("The nodes of MDG are:" + nodeList); //stampato a schermo la lista dei nodi nel MDG finale



            foreach (EA.Element elementconect in elementsCol)
            {
                    foreach (EA.Connector connector in elementconect.Connectors)
                    {
                        if ((connector.Type == "Aggregation") || (connector.Type == "Association") || (connector.Type == "Generalization") || (connector.Type == "Realization") || (connector.Type == "Composite") ||
                        (connector.Type == "Depdendency"))
                        {
                            int client = connector.ClientID;
                            if (client != 0)
                            {
                                int supplier = connector.SupplierID;
                                if (supplier != 0)
                                {
                                    //Arrivato qua i due estremi del connettore fanno parte del mio grafo
                                    //Aggiungo la dipendenza solo se il nodo in cui mi trovo è l'elemento dipendente o se la connessione non è specificata o è bidirezionale
                                    if ((client.Equals(thisNode.nodeId)) && (connector.Direction != "Destination -> Source"))
                                        updateGraph();
                                    else if ((supplier.Equals(thisNode.nodeId)) && ((connector.Direction == "Unspecified") || (connector.Direction == "Bi-Directional") || (connector.Direction == "Destination -> Source")))
                                        updateGraph();
                                    linkList.Add(connector);
                                }
                            }
                        }
                    }
                }

                Console.WriteLine("The links of MDG are:" + linkList);//stampa a schermo la lista degli archi all'interno dell'MDG

« Last Edit: May 17, 2012, 03:00:53 am by defi »

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: please help me with the ArrayLists
« Reply #1 on: May 17, 2012, 03:37:41 am »
Oh my!! May be you really should take on Geerts advice from your last post, seriously! What would you expect as result, when adding the ArrayList type to a string?!?
Just one hint (it's too much to teach you C# programming just in this post):
You shouldn't instatiate an array you want to add elements inside the loop you use to iterate over these elements.
Also I don't think you need this nodespackage ArrayList thing at all, just iterate over inpack.Elements collection (inpack.Element refers to the Packages Element properties).

HTH (a little bit),
Günther

PS.: This is really not meant to sound arrogant to you or so.
PPS.: Please don't ask your common C# programming questions in this forum, since your problems don't really have to do anything with the specifics of the EA API. There are better places to search for answers or ask such questions (e.g. http://stackoverflow.com/).
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

defi

  • EA User
  • **
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: please help me with the ArrayLists
« Reply #2 on: May 17, 2012, 04:00:22 am »
Thank you for your help and sorry to bother you. It's that here i know that you are always helping me a lot and give me good advises. I know that i'm not good with the code but i have to learn, so i have to make stupid begginers questions. Sorry for bothering you a thank you a lot for your help.