Sunday, December 6, 2009

Catching more information in your model

Once you have started to travel the path of Model driven development you might find that the declarative approach is useful for even more things than what you thought of at first.

You may find yourself searching for a way to mark up certain classes as UserFriendly or an association as being HeavyToLoad, so that your code can see this and perform differently. Of course you can create code that checks if it used on a particular class or on a particular association, but that will eventually cost you in more maintenance.

We cannot and should not try to understand your future needs, after all you probably do not even know yourself yet. So what to do… Tag extensions…

Tag extensions definition

image

Brings up this dialog

image

You can create new extensions. In the example above there are 3 extensions, Kasper.Seeker, EcoExtensions and Kasper.

Each extension has a number of TagTypes – on the example above the Kasper extension has 4 tag types; Kasper.AutoSeekAndPick, Kasper.AllowUserNew, Kasper.UserFriendlyClass, Kasper.BusinessDeleteValue.

Each TagType is applicable to only one type of “TagExtendableItem” in the item. In the example above the Kasper.BusinessDeleteValue is active on Association end points.

A TagType can be made to act as a enumerable valueset, the example above allows for 4 values; PSCheckMustBeEmpty, MustBeEmpty, OkEvenIfNotEmpty and NoOneHasMadeADescisionForThisYet.

Tag extension usage

Once you have defined the tag extensions the property inspector is updated.

image

The Extensions shows up as any other properties of your modeled elements.

The values of the tag extensions are stored as tagged values and translated into .net code attributes in the generated code:

   1: [UmlElement("AssociationEnd", Id="31cfadd7-2b04-493c-a5e5-399913764949", Index=Eco_LoopbackIndices.Reserverad)]
   2: [UmlMetaAttribute("association", typeof(KasperPackage.LagerrorelsePrioriteringLagerrorelsePrioriteringarAnvandareReserverad), Index=1)]
   3: [UmlMetaAttribute("multiplicity", "0..1")]
   4: [UmlTaggedValue("Kasper.BusinessDeleteValue", "OkEvenIfNotEmpty")]
   5: public Anvandare Reserverad {
   6:   get {
   7:     return ((Anvandare)(this.eco_Content.get_MemberByIndex(Eco_LoopbackIndices.Reserverad)));
   8:   }
   9:   set {
  10:     this.eco_Content.set_MemberByIndex(Eco_LoopbackIndices.Reserverad, ((object)(value)));
  11:   }
  12: }

And you can access it in your code, either by using standard .net approaches to get to code attributes, or by using the extended meta  information that ECO brings.

   1: foreach (IStructuralFeature sf in TheObject.AsIObject().UmlClass.AllStructuralFeatures)
   2: {
   3:   if (sf is IAssociationEnd)
   4:   {
   5:     IAssociationEnd ae = (sf as IAssociationEnd);
   6:     string tv = ae.TaggedValues.ValueForTag("Kasper.BusinessDeleteValue", "NoOneHasMadeADecisionForThis");
   7:     if (tv == "PSCheckMustBeEmpty" || tv == "NoOneHasMadeADecisionForThis" && !(ae.DeleteAction == DeleteAction.Prohibit))
   8:  

Tag extension visualization

Even if the Tag extensions has been in ECO and Gaffr.net for some time, a new way in how they can be displayed has been added recently. A new tab on the TagExtension dialog called Symbols has been added:

image

In this dialog you can define symbols that are built up by a piece of xaml:

   1: <Rectangle xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Fill='Blue' Width='16' Height='16'>
   2:   <Rectangle.RenderTransform>
   3:    <RotateTransform Angle='45'/>
   4:    </Rectangle.RenderTransform>
   5: </Rectangle>

Any stand alone xaml is valid to use here so you can define any kind of symbol you want.

You can then associate the TagTypeValues to a symbol:

image

And then your diagram displays the symbols when the values are set:

image

When hovering over a symbol, you get a tooltip that explains what tag extension it is and what the value is.

So start decorating your business models. Move stuff from your memory to Modlr for more people to see and for you to relax. Remember that development is still the hardest thing in world to truly master so accept any help you can get.

2 Comments:

Blogger Алексей said...

cool that is what ai need :)

December 16, 2009 at 10:41 AM  
Blogger Peter Morris said...

Brilliant!

August 25, 2010 at 11:32 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

 
Contact Us | Terms of Use | Privacy Statement © 2009 CapableObjects