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 - MFruit

Pages: [1]
1
I encounter some difficulties between EA UML model and C# code generation and reversing.

Here are the elements which drive to questionings

Step 1: create a new EA UML project and use MDG Link with a Visual Studio 2008 project

Step 2: create a simple class diagram, 2 classes (no attribute, no operation) with a direct association (multiplicity 0..1). Class1 pointing to Class2

Step 3: in the EA Project Browser, right click on the package containing the class diagram and the two classes, Using “Add-In” / “Merge with Visual Studio” / select Type “Both”.  Associate classes with file name

Before reverse, just look to code generation:
Class1.cs
public class Class1 {
   public Class2 Asso;
}

Class2.cs
public class Class2 {
   //futur code
}

Then reverse each Class into model:
An attribute "Asso: Class2" is created under Class1 and the association is still visible.

Question 1: Why EA creates' an attribute called “Asso” under Class1 ? What is perturbing is that we have two objects with the same name (attribute called “Asso:Class2” and association with target role called “Asso”).

Step 4: updating Class1.cs (code) and rename the association name “Asso” to “Asso_Update”
 
Step 5: Using “Add-In” / “Merge with Visual Studio” / select Type “Both”, then click to reverse both Class1 and Class2
 
Have a look to the class diagram:
An attribute "Asso: Class2" still here under Class1 and the association "Asso" is still visible.
An attribute "Asso_Update: Class2" under Class1 and an association created with "Asso_Update" as target role name.

Question 2: Why does the reverse create a new attribute? can’t see that the previous attribute already exists?  Same for the association, a new one is created, why ?

Question 3: Do you believe that such synchronization will perfectly fit with a professional context? (Complex model implementation, with a lot of associations and classes).

Is there something that I didn’t see with option or whatever?

Question 4: Similarly problem with N-Array  association (0..*). Attribute is created, but not association. Why ?

If someone met one day such difficulties and found solution, or another way to work with, please answer.
Thanks very much.

2
 [smiley=thumbup.gif] I found what was missing:

I had already created a connector.
Code: [Select]
Connector con = (Connector)e.Connectors.AddNew("", "Association");
con.ClientID = Source.ElementID;
con.SupplierID = Target.ElemenID;
con.Direction = "Source -> Destination";
con.SupplierEnd.Role = "MyRoleName";
con.SupplierEnd.Cardinality = "0..*";


The key to add TaggedValue later is to update the connector, otherwise an error occured:
Quote
"The fiels 't_taggedvalue.ElementID' can't contain a Null value because the Required property for this field is set to True. Enter a value in this field"

So put the following code line before addin RoleTag:
Code: [Select]
con.Update();
After addin TagValue for Role Association works perfectly:
Code: [Select]
RoleTag rTag = (RoleTag)con.SupplierEnd.TaggedValues.AddNew("", "");
rTag.BaseClass = "ASSOCIATION_TARGET";
rTag.Tag = "Attribute";
rTag.Value = "[Persistent]";
rTag.Update();
con.SupplierEnd.TaggedValues.Refresh();

//Can now get TaggedValue
foreach (IDualRoleTag cTag in con.SupplierEnd.TaggedValues)
{
    // Get Name and Value
    MessageBox.Show(cTag.Tag);
    MessageBox.Show(cTag.Value);
}

Thanks Frank for spending time to this post !
Hope that will help someone else.

3
Yes, i saw this exemple, but it doesn't work or fit. You've right this is the good place because the documentation describe the RoleTag Attribute. And it is exactly what i want to do => specifie "BaseClass" as "ASSOCIATION_TARGET". Unfortunately, there is no exemple for this.

For information, i've done this exemple in C#, it works, but do nothing, i can't find added Tag later with the code describe in my post with the command:
Code: [Select]
foreach (IDualRoleTag cTag in con.SupplierEnd.TaggedValues)

4
Hello,

I searched across the forum and EA User Guid but can't find the answer.

Reading TaggedValues (that have been put under EA, click on Association into the diagramm, then add value to "Connector Target" under TaggedValue Window) with my AddIn is OK. I'm parsing the collection of my SupplierEnd.TaggedValues element
Code: [Select]
foreach (IDualRoleTag cTag in con.SupplierEnd.TaggedValues)
{
      // Get Name and Value
     MessageBox.Show(cTag.Tag);
     MessageBox.Show(cTag.Value);
}

But creating with AddIn TaggedValue for an association target is not so easy. In fact i don't find it yet.

If i wasn't clear i want to do exactly the same in an AddIn what EA does across his User Interface (as describe higher).

Thx a lot !


5
Automation Interface, Add-Ins and Tools / C# code generation for #region
« on: November 04, 2008, 08:06:50 pm »
Hello,
Is anybody know if is it possible to generate #region code for C# ?
What i saw is that reversing a class with defined #region works well. In fact, i've put in my code one region to define attributes and another one to define operation.

Code: [Select]
   public class Class1
    {
        #region Attribute
        int Attribute1;
        int Attribute2;
        private bool Attribute3;
        #endregion

        #region Operation
        public string Class1Operation2(int Id)
        {
            return "";
        }

        public void Class1Operation1(){ }

        public bool Class1Operation3(int Id2){
           return true;
        }
        #endregion
    }

Then reverse the class. Under Enterprise Architect i add one attribute and one operation. The generating works well because the new attribute is created into #region Attribute and the new operation into #region Operation.

My question is to know if we can define region under Entreprise Architect to generate the first time a class with pre-define region ?

Thx.

Pages: [1]