Book a Demo

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - defi

Pages: [1] 2
1
i resolved the thing, with the following code:

Code: [Select]
EA.Element node;
Client thisNode = new Client(node.ElementID);


Thank you for your help.

2
Hi!
I created an object Client with all the properties I want this Object to have. Now i want and object of type EA.Element of a Diagram to cast in an object Client. How can i do that?

I tried with
Code: [Select]
EA.Element node;
Client thisNode = (Client)node;

but it doesn't work, it gives me an exception.

Can please someone help me.
Thank you a lot. And please don't tell me that I'm a noob and that I have to start over to study programming. I want some help to solve this easy (for an expert) problem. Thank you  :)

3
Hi! Sorry, it wasn't the diagram but the model. So the idea is to calculate the CCD of the elements in the whole Model.
And for the other things you mentioned, I haven't thought about that, but i think that the connectors type that i want to condider are: ass, agg,generalization,realization,compose and dependency like in another part of the project where i have to build another diagram that contains only element.type class and the connectors.type that i said before.

4
Automation Interface, Add-Ins and Tools / CCD metrics from EA in C#
« on: July 03, 2012, 10:51:40 pm »
Hi! I have a logistic problem, I have a diagram in EA and i have to calculate the CCD (cumulative component dependency) metrics for every element in the diagram. My idea is to have the list of the clients and for each client i have a list of supplier. If the supplier doesn't appear in the client list it means that is a leaf, so CCD is 1, and the i go up on the client and add the CCD to the client and so on.

But i have to admit that my idea has has some bugs, because when i think how to put it into code i don't know how.

So my inputs are two lists (client and supplier) , and a diagram with elements and connectors to refer to.

Has anyone some idea? Please someone help me, because except the theoretical part i can't find anything useful on the web.

Thank you.

5
I noticed that the connection were analyzed twice, so i find a solution: I made a dictionary of the connectors so every time i search in this dictionary if the connector with the specific ID has been evaluated yet, if is not, then i proceed, and if it is then i pass to another connector. And so i get the result that i wanted:
the client is:14
the suppliers are:
Interface1
B

the client is:15
the suppliers are:
C

the client is:16
the suppliers are:
PB
Co1

the client is:21
the suppliers are:
Co2

the client is:22
the suppliers are:
Co2


What do you think about this solution, is it ok? The code is:
Code: [Select]
List<String> supplierList = new List<String>(); // nomi dei nodi supplier di ogni connessione di un dato client
                List<int> clientList = new List<int>();  // lista dei clientID di ogni client presente nel diagramma
                var clientLookup = new Dictionary<int,Client>();
               [highlight] var connectionLookup = new Dictionary<int,String>();
[/highlight]

                foreach (EA.Package package in modelRepository.Models)
                {
                    foreach (EA.Package inpack in package.Packages)
                    {
                        foreach (EA.Element element in inpack.Elements)
                        {
                            foreach (EA.Connector link in element.Connectors)
                            {

                                int connection = link.ConnectorID;
                                int supplier = link.SupplierID; // target
                                int client = link.ClientID; // source

                                EA.Element classNome = modelRepository.GetElementByID(supplier);
                                String connectionName = link.Name;
                                
                              [highlight]  if (!connectionLookup.ContainsKey(connection))
                                    {
                                    connectionLookup.Add(connection,link.Name);[/highlight]
                                

                                if (!clientLookup.ContainsKey(client))
                                {
                                    clientLookup.Add(client, new Client(client));
                                    
                                    Client node = clientLookup[client];
                                    node.addSupplier(classNome.Name);
                                }
                                else
                                {
                                    Client node = clientLookup[client];
                                    node.addSupplier(classNome.Name);
                                }

6
I modified the question and inserted the code of the procedure .getSupplierList. But it is a simple return of the list where I add every time the supplier.

Can you suggest me how can i fix it?

7
Hi! My goal is to create an object Client for each client of every connection in the diagram and insert the supplier in a list inside the Client object. To have as a result: client -ID- : [list of suppliers of this client].

The following code do what i want:
Code: [Select]
public Metrics(EA.Repository repository)
        {
                      
            this.modelRepository = repository;
            

            using (StreamWriter writer = new StreamWriter("C:\\Users\\Martina\\Desktop\\metrics.txt"))
            {
                Console.SetOut(writer);

                List<String> supplierList = new List<String>();
                List<int> clientList = new List<int>();
                var clientLookup = new Dictionary<int,Client>();


                foreach (EA.Package package in modelRepository.Models)
                {
                    foreach (EA.Package inpack in package.Packages)
                    {
                        foreach (EA.Element element in inpack.Elements)
                        {
                            foreach (EA.Connector link in element.Connectors)
                            {
                                int supplier = link.SupplierID; // target
                                int client = link.ClientID; // source

                                EA.Element classNome = modelRepository.GetElementByID(supplier);

                              

                                if (!clientLookup.ContainsKey(client))
                                {
                                    clientLookup.Add(client, new Client(client));
                                    
                                    Client node = clientLookup[client];
                                    node.addSupplier(classNome.Name);
                                }
                                else
                                {
                                    Client node = clientLookup[client];
                                    node.addSupplier(classNome.Name);
                                }

                                /*
                                ArrayList connectionList = new ArrayList();
                                connectionList.Add(link.Type);

                              
                                foreach (String type in connectionList)
                                { Console.WriteLine(type); }
                                Console.WriteLine("");*/
                            }                    
                        }
                    }
                }
                foreach (KeyValuePair<int, Client> item in clientLookup)
                {
                    int clientID = item.Key;
                    Client clientNode = item.Value;

                    supplierList = clientNode.getSupplierList();

                    Console.WriteLine("the client is:" + clientID);
                    Console.WriteLine("the suppliers are: ");
                    foreach (String number in supplierList)
                    { Console.WriteLine(number); }
                    Console.WriteLine("");
                }


the code of .getSupplierList is:
Code: [Select]
public List<String> getSupplierList()
        {
            return supplierListObj;
        }

I made a List of String just to see what nodes it will print out in the txt., so i can understand by the name.

but as a result i get double supplier. In fact i noticed that every connection is considered in both ways source-destination and destination-source. How can i fix it?

The .txt that i get as a result is the following:

the client is:14
the suppliers are:
Interface1
B
B
Interface1

the client is:15
the suppliers are:
C
C

the client is:16
the suppliers are:
PB
Co1
Co1

the client is:21
the suppliers are:
Co2
Co2

8
I have fix it thank you. I restored the system to the checkpoint of two days ago e now it works. Very weird thing.

9
I looked and i get "error-missing" but i have never deleted it or move it so i don't get it why for enterprise architect it result missing. So it's normal this hide and seek add-in? I'm freaking out  ;D

10
Hi!
I have a problem with the activation of the Add-In that I created in Visual Studio C#. I've done it before and it worked untill today. I have the following file:
Code: [Select]
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Sparx Systems\EAAddins\NeatDiagram]@="NeatDiagram.Main"

and it worked before to insert the registry and activate the add-in. But today i compiled the project in visual studio, activated enterprise architect and the add-in was gone. I can't activated anymore. I haven't changed anything significant in my project so i don't understand why it happened so suddenly.

Can someone help me?

11
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.

12
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


13
sorry, but i don't understand what do you mean with that post.

14
Thank you for your help.
Is this any better?
Code: [Select]
public void buildMDG(MDG graph)
        {
            ArrayList diagramList = new ArrayList();
            ArrayList dObject = new ArrayList();
            ArrayList dLink = new ArrayList();

            foreach (EA.Diagram diagram in modelRepository.Models)
            {
                diagramList.Add(diagram);
                foreach (EA.DiagramObject dobj in diagramList)
                {
                    dObject.Add(dobj);
                    foreach (EA.Element elem in dObject)
                    {
                        if ((elem.Type == "Class") || (elem.Type == "Component") || (elem.Type == "Package"))
                        elementList.Add(elem);
                    }
                }

                foreach (EA.DiagramLink dlink in diagramList)
                {
                    dLink.Add(dlink);
                    foreach (EA.Connector conn in dLink)
                    {
                        if ((conn.Type == "Aggregation") || (conn.Type == "Association") || (conn.Type == "Generalization") || (conn.Type == "Realization") || (conn.Type == "Composite") ||
                             (conn.Type == "Depdendency"))
                        {
                            int client = conn.ClientID;
                            if (client != 0)
                             {
                                int supplier = conn.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 ((elementList.Contains(client)) && (conn.Direction != "Destination -> Source"))
                                        updateGraph();
                                    else if ((elementList.Contains(supplier) && ((conn.Direction == "Unspecified") || (conn.Direction == "Bi-Directional") || (conn.Direction == "Destination -> Source")))
                                        updateGraph();
                                     connectorList.Add(conn);
                                    }
                               }
                         }
                    }
                }

I have to access the elements and connectors because i have to verify the type of this objects. Because i need only some of them.

Why i get the "InvalidCastException" in each foreach. I look in the diagram of the dependencies and diagram was connected with diagramLink and diagramObject so why i can look into the diagram and took only the diagramLink/diagramObject that i want?

15
Hi!
I have to retrieve from a diagram that i have in input only elements of the type class, component and package. I made it with the following code:

 public void buildMDG(MDG graph)
        {
            List<Node> elementsCol = null;
            List<Node> packagesCol = null;
            List<Link> connectorsCol = null;
            ArrayList nodeList = 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)
                    {
                        nodesList.Add(elempack);
                    }
                }
            }
          
  
            for (int i = 0; i < graph.getNodesList().Count; i++)
                nodesList.Add(graph.getNodesList());

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

                if (thisNode.GetType().Equals("Package"))
                {
                    packagesCol.Add(thisNode);
                    elementsCol.Add(thisNode);
                }
                else if (thisNode.GetType().Equals("Element"))
                {
                    packagesCol.Add(null);
                    elementsCol.Add(thisNode);
                }

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

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


but i get all the time the error "object reference not set to an instance of an object" for every value in every "foreach". Can someone help me? i don't get it why i get this error for every value.
Thank you a lot for your time and sorry for the long question.

Pages: [1] 2