Domain Specific Blog

.NET Chat, sort of, but not really, Domain Specific specific

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012

Why is my toolbox icon not showing? How do I make a transparent background to the bitmap?

Just loaded the VSX SDK 1.1 for my brand new laptop, and fired it up. Ignoring that baby #2 is (was) due 3 days ago, and might appear before I finish typing this, here we go.

I have decided to build the newly named project Morpork in my own time, as it has not so much fallen of the radar at work, radar has apparently been ignored too. So much for my bosses assurances 'I have already sold it, just build it for me!'. As it's been a while since my Sharp Develop efforts, I may even decide to Open Source the code (I'll have to check my current contract to see if that is allowed.)

 Anyway, starting small , I will post a few of those fairly obvious but annoying gotchas that may befall newbies until I get back up to speed and start to crack open the bonnet again.

 One thing I noticed in my past DSL coding was that sometimes my Toolbox Icon bitmaps showed and sometimes they didn't. Secondly, the fact that my toolbox icons were constrained to the bitmap type (don't even get me started on the cursor. cur type), I had no way to define a transperency.

 Neither of these questions are that tricky to crack. That horrid 'no one will ever use it, so it can be a transparency mask' #FF00FF colour appears to be translated as a transparency layer. Black in some experiments, when used as a surrounding colour to an image, also appears to have been translated on a few occasions as transparent, but I will need to test further to see ascertain if this is the case. Just rely on putrid pink, and your transparnecy should work fine.

 The only bitmaps accepted by the toolbox are 16 x 16. Quite why this is the case, I do not know, but I am assuming educated guessing it has to do with the C++ core of Visual Studio, and a defined data structure being required by the toolbox icon that a different size icon does not conform to, but it's at least 7 years since I coded C++ in anger, and I never touched graphics (over and above the MFC *spits*), so I am kind of making that assumption up.

I'm looking forward to getting into some deeper topics very soon (time lost to newborn birth notwithstanding).

Currently rated 3.0 by 15 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Basics | DSL | Gotchas
Posted by john on Monday, October 13, 2008 2:48 PM
Permalink | Comments (0) | Post RSSRSS comment feed

You mean I need to update this thing ?!?

I have actually been getting a fair bit of positive feedback for this blog, something I wasn't really expecting as

  1.  I am talking about a fairly domain specific area of technology (crap pun intentional, if not funny)
  2. The DSL technology is rather new
  3. I have not been updating recently

Thinking about this, points 1 and 2 actually make it more likely that anyone searching for information on VSX DSL are probably going to land here sooner or later, which only goes to make point 3 all the more embarrassing.

Excuses: Despite may religious tirade for DSL technology, over at Insert Company Name here my custom Meta Modeller (or Modeler for any Americans reading) application has been put on the back burner until such time as it gets put back on the front burner.

I am very close to writing the damn thing in my own time, however a 17 month old son and a pregnant wife so ready to pop that she'll probably go into labour before I hit Save Post ensures that the second I get home, my digital life (except where it pertains to watching the millionth showing of an In The Night Garden DVD) may as well be compared to a 19th century Quaker community.

I would like to say I have been putting most of my blogging efforts into www.obviouscode.com, but a quick visit there would reveal that to be a lie too, although I do have at least 3 posts I really need to get the time to type.

So, with a popular requests from the community that numbers almost 5, as well as a realisation that I am quickly losing my status as an Australian DSL Early Adopter, I shall begin to update as soon as I dust off my VSX Shell and polish the T4.

I promise ;)

Currently rated 3.0 by 15 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Rant
Posted by john on Monday, September 29, 2008 1:27 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Using ShapeCompartments - What to do and What Not to do

OK, slightly embarrasing this one, but I decided to add it here for a couple of reasons.
  • One, lets face it, only pretend people are reading this (comment to prove me wrong)
  • Two, it :( stumped me for a week, and if I can help just 1 (pretend) person avoid the horrid "No standard web pages containing all your search terms were found" Google page, then my karma will lighten a touch
What I wanted to do, I though would be relatively common for a DSL, but I was struggling to work out how to do it. I needed Model Element (lets call it an Entity for the moment) on my DSL Diagram to have 1 : * properties. I didn't want to have to model all of them as separate Model Elements related to the Entity on the DSL Diagram, but embedded in the Entity itself, with an Add New .. Context Menu option, such as adding class attributes on the Class Diagram in Visual Studio

Adding Properties to a DSL Model Element
I created a 'Property' Domain Class, and assigned it to the Entity Domain Class as an embedded relationship, Transformed Templates, fired up the Hive and hoped that it would 'Just Work'. I didn't hold much hope, and it turned out I had no right to as all I got for my (lazy) troubles was a nice rectangle representing my Entity when I dragged one onto my diagram.
No Properties

As it turned out, it was quite simple, perhaps sematically unintuitive. In fact it was simple enough to allow me to make a complete mess of a few days coding.

What I did was note that there was a Compartment Shape available to use in your model, and assumed it represented, not the whole shape for the Entity, but the indivdual Compartment for my attributes, so I added it to my Domain Class as well as its basic shape, and tried mapping my properties to it.

What not to do!

Now, things began to get a little more confusing, my transformation ran fine, however, when I fired up the Hive, I was met with the following in the generated code:

     // Multiple mappings have been defined for the class Entity.
     // Either implement a method as described below, or remove the multiple mappings from the DSL definition.
     //
     // Method:
     // private DslDiagrams::NodeShape CreateShapeForEntity(Entity newElement)
     //
     {
     //
     }
    // must be implemented in a partial class of Blog1Diagram. Given an instance of Entity,
    // the method should return a new shape or connector instance that should be associated with this element. If no shape or connector should be created, the method should return null.
    DslDiagrams::NodeShape newShape = CreateShapeForEntity((global::Pelion.Blog1.Entity)element);

At this point, in my defense, I was beginning to suspect that I was missing something fairly important (and most likely obvious), and did attempt to RTFM (in an MSDN sense, something fairly basic and confusing at this early stage of DSL Tools), and to WTFV (watch the training videos), none of which touched on this element of modelling. The sample code in the VS SDK did seem to point to the fact that I was on the correct track, but I didn't pay to much attention to them at first.

Instead I tried to code a new shape, something I am sure would have worked, by my results were laughable. I won't go through them here.

Anyhow, to cut a painful story short, I fired up the SDK samples again, and had that 'I've lost how many days?' sinking feeling when I realised the answer was, of course, obvious. The CompartmentShape defines the Domain Class's shape and all its compartments, and what the confusing message in the code was telling me was that I had defined 2 shapes, and which one did I want.

I deleted the non-Compartment shape, added a compartment and associated the Entity Property to it.
 
The correct set up

I hope this has helped at least one pretend reader on their way.

My properties

Currently rated 3.1 by 16 people

  • Currently 3.125/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: DSL
Posted by john on Thursday, May 22, 2008 4:48 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Flag Domain Enumerations

This is a nice one I discovered this morning, by setting the Flag Property of an enumeration, enumeration bitwise values and an editor box are supplied by default.

Consider we have an property, for the sake of this example I'll use Font, that uses an enumeration to define its state, with possible values of Bold, Underlined, Italic etc.

Where an owning object of such a property, like Pen, may have be in multiple states concurrerntly (eg, a Bold, Underlined state), we could define each property as a boolean, to say that property is in affect or not, or we could use bitwise shifting of an enumeration.  To do this we would define our enumeration as having set, bitshifted, values:

public enum FontProperty 
{
    Bold = 1 << 0, // 1 bit shifted 0 position to the left, therefore 0001 = 1
    Underlined = 1 << 1, // 1 bit shifted 1 position to the left, therefore 0010 = 2
    Italic = 1 << 2, // 1 bit shifted 2 positions to the left, therefore 0100 = 4
    Strikethrough = 1 << 3, // 1 bit shifted 3 positions to the left, therefore 0100 = 8  

 

We could then set our object state as follows:

Pen pen = new Pen();
pen.Font = FontProperty.Bold | Underlined

This would effectively set the Font property (confusingly, sorry, of type FontProperty) to be 3, or 0011, the amalgamation of 0001 and 0010, which is basic binary addition, a nice way of describing multiple states. This can be translated back as shown below:

//Test for Bold
if ((FontProperty &  FontProperty.Bold) != 0)
{
    //Font is bold


We can do a similar thing in a DSL definition: 


Define a Domain Enumeration (essentially just an enumeration like any other in .NET that is created in context of a DSL Definition) from the DSL explorer

 
Set the Enumeration Name property, and the flag property to True

 
Create the enumeration values 

 
Note, the bitwise integer value of the enumeration has been automatically set

Add a Domain Property to your owning Domain Class with your enumeration as its type

Now, when the property is used in the generated DSL, a checked box editor window has been automatically provided, and the correct bitwise value set 

Currently rated 3.0 by 15 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: DSL
Posted by john on Wednesday, May 14, 2008 7:16 AM
Permalink | Comments (0) | Post RSSRSS comment feed

DomainRoleInfo: Accessing relational domain properties from an Entity

This one had me scratching my head for days, and my eventual solution is far from elegant, and I would love to discover a nicer method.

The problem is I could not find any way to reference a Domain Property from a relationship within code (.tt generation or validation code) from the object sourcing (or targeting) the relationship.

In my case, I have nested relationships contained within BaseCollection *sigh, I know, legacy* inherited objects. There are other reasons we have kept this, despite wanting to refactor to List, but I can't be bothered going into that here [edit - thank God, we have finally got time to refactor this away!]. It's something I may address in my DSL project (based on the framework we are using here) when I publish it. 

In some cases an object can contain more than one type of contained object, and I want to maintain each list of type separately. In this case, I just use a List object property to store the other lists not being addressed by the BaseCollection.

To this ends, when we model this in our DSL, we have a 'IsMainEntity' boolean on the relationship, not either of the objects (as they have 0..* cardinality and may be referenced by other objects, so this boolean has to be a property of the relationship).

 

 
My next task was to ensure through validation, that there was only one "IsMainEntity" relationship for parent.

Whilst parent and child objects are easy to access through the generated object model as LinkElementCollections, relationships are not so easily accessed, either as a collection, or as a property on the source or target object.

Eventually, after hours of staring at the watch and immediate windows (and yelling at the non-public members for not being public) I discovered the DomainRoleInfo object, sitting in my target collection.SourceDomainRole.DomainRelationship, that the msdn rather concisely states "Represents a role of a domain relationship".

We can retrieve this object and query it for links (relationships) in the model based on an object (or modelElement) on the dsl model.

Using this, I crafted this rather clunky code for my validation block:

found = false;
//Build elements list to pass as an array to the violation, so the correct objects can be highlighted on the model
elements = new List();
elements.Add(this);

foreach (DomainRoleInfo info in Entity1s.SourceDomainRole.DomainRelationship.DomainRoles)
{
  if (info.Name.Equals("Entity2"))
  {
    foreach (Entity1ReferencesEntity2 e12e2 in info.GetElementLinks(this))
    {
      if (e12e2.IsMainEntity)
      {
        elements.Add(e12e2);

        if (found)
        {
          //Log the Error
        }
        else
          found = true;
      }
    }
    info.GetElementLinks(this);
  }
}


I have yet to craft the class generation .tt file, but I need a different code depending on whether IsMainEntity is set on a the relationship, so I will probably have to pass the source and target elements to a method, have it loop through the ElementLinks of the source object to find the appropriate DomainRoleInfo (accessable only by index, not name) and return a true if the MainEntity boolean is set. Not very pleasant, but doable.

 

Currently rated 3.0 by 15 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by john on Monday, April 28, 2008 4:30 PM
Permalink | Comments (0) | Post RSSRSS comment feed

What this is all about?

I am not a Microsoft Developer (in the sense that I do not work for MS) , I do not (as yet) have a particularly indepth knowledge of DSL, in fact I can honestly say I am somewhat of a noob.

I first learnt about the VSX DSL at a session given by Tom Hollander at TechEd 2007, however it wasn't until I listened to Ken Levy on
DotNetRocks that I really understood the possibilities.

So what I plan to do here is use this as a place to jot down my problems, successes and failures, at worst to allow me to revisit them later, but hopefully to start a conversation with like developers having like issues.

My role is architect and technical lead at a small consultancy in Sydney

Currently rated 3.0 by 15 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,
Posted by john on Wednesday, April 02, 2008 3:32 PM
Permalink | Comments (0) | Post RSSRSS comment feed