Bed time story "the weird hard disc"

No Comments »

Here is a true story that happened to me six month ago:

My girl friend Grace wanted to go shopping and put me in the trunk, so I had to join her. We went to some discount supermarket (“Plus”) and she bought veggies, I bought meat, she bought tooth paste, I bought sweets. Then I stumbled about a nice offer: “400GB external USB-HDD for 99€” with a sticker saying “Samsung-HDD inside”. 99 was pretty cheap at that time and my experience with Samsung-HDDs is very good, so I put one in our shopping cart.

Back home I stored the meat and attached the new hdd to my laptop. Plopp – new drive found, drivers installed, everything cool. I did a format which went through quickly. “Here you are – congratulation to you new hard disc! – 3 GB ready to go.”

Uhm.. wait a moment. I didn’t expect 400, but something like 370GB found be fine. 3 GB is a little lesser than I expected. Hmm..

unattached it, attached it again – 3GB.

did another format – 3GB.

looked for a software or even a bios update for my laptop – up to date.

did some silly Google searched – nothing found.

tried another computer – 3GB.

Hmm… I started thinking… okay, let’s face it – 1 kb is officially reduced to 10byte, they just didn’t inform you.  Or maybe there is something wrong with the wires inside, a pin broken for the higher bytes or something. I fetched my mini screw driver and opened the case. Looked okay, the cable was clean and in place, the pins seemed  fine. There was a little table in a blue font giving numbers of sectors, cylinders and heads, but I couldn’t find any information on the size. Then I saw the brand: Maxtor. Maxtor? It was supposed to be a Samsung, wasn’t it? … What the heck?!? Suddenly the light of realization hit me very, very hard. I sat in silence for minutes – in deep disbelieve. It was sooo simple.

Some criminal had bought the original 400GB-HDD and replaced it with his (or her) old 3GB. Then he (or she) had taken it back to the shop, saying it wouldn’t work. He would get another one or his money back. Buy one – get one free. Bastard!

When I discovered this I felt like Monk and I was very excited. I went back to the shop, asked for the store manager (which was a friendly woman who looked like YarYar Binggs) and told her everything. Her reaction was very… well.. minimalistic and a little disappointing – all she did was to hand me a new hdd. (That one was 400GB)

Later I found I should have tried to recover some data from the 3GB-HDD, perhaps I could have helped to arrest a thief of 397GB but the good ideas are always late…

Have a good night and don’t let the bed bug bite you.

To restrict dynamically the usage of Domain Properties in DSL Models

Tags: , , , , ,
1 Comment »

What’s the matter?

If you define Domain Properties on your Domain Classes and Shapes, you can configure the way a user of your DSL can interact with this Domain Properties. With the properties Is Browsable and Is UI Read Only you can hide a property from the Properties Window, make it read only or give the user full access to it.

But I want to change this behavior of certain Domain Properties dynamically at runtime!
Why the heck would someone need this? I don’t know, but I can tell why I need it: I’m designing a DSL with two types of users in mind. The DSL should look the same to both users, but one user can edit the whole DSL and change every property while the other user is not allowed to do so. Some properties will be disabled (read only) and some other properties will be invisible to the second user.

Another scenario could be a simple and advanced mode for some DSL Editor and the user can switch between these modes in some options dialog.

How do you use it?

First I want to describe the using of my library. If you are not interested in understanding how it works, you can use the library after reading this section.

First you have to define an enumeration with the modes your editor should support. The enumeration can contain more then two elements if you need more modes. The special Value 0 is used for the editor in the way you defined it within the DSL Tools. You should define your properties with Is Browsable set to true and Is UI Read Only set to false.

public enum RestrictionModes
    Original = 0,

Than you can provide your Domain Classes and the Domain Model with the RestrictedProperty-Attribute to configure the different properties:

                    "P1", Restriction.Hidden)]
                    "P2", Restriction.ReadOnly)]
                    "P3", Restriction.ReadOnly)]

                    "P1", Restriction.Full)]
                    "P2", Restriction.Full)]
                    "P3", Restriction.ReadOnly)]
partial class ExampleModel

The ExampleModel has three properties (P1, P2, P3) and in the original DSL Editor these properties are all writable. Properties that are not mentioned by the attributes will work as defined.

If the Restriction Mode is set to RestrictionModes.Advanced two of them are fully assessable (in fact you do not need to create Attributes to set the properties to Restriction.Full since this is the default value) and one is read only. In the RestrictionModes.Simple-case one property will be hidden and two are read only.

You can assign these attribute to each class that shows properties in the Properties Window. That are Model Elements, Shapes, Connectors and the Model itself.

After that you have to create a partial class for your Package and "activate" my library for each Class that uses these attributes:

partial class RestrictPropertiesTestPackage
 protected override void Initialize()


Or use the shorter way to add all classes with one line of code. This will use reflection to find the classes.


Now there is only one step left: how to change the mode. Each Store (that is the class where the Elements of a Model are stored in memory) is mapped to one Restriction Mode. So you can define one mode for each Store and so one mode for each Model or Diagram. The Store can be accessed from each ModelElement, so as a key for this purpose it is a great value. There is a UserRestrictionProvider class with two static methods:

  • public static void SetRestrictionMode(Store store, int mode)
  • public static int GetRestrictionMode(Store store)

You can use these methods whenever you want to change the Restriction Mode. For the demo project I used a Domain Property of the Diagram with Custom Storage.

How does it work?

With the UserRestrictionProvider.RegisterRestrictedElement()method I register a special TypeDescriptionProvider to the global Component Model (via the TypeDescriptor.AddProvider() method). This new Provider is be asked from the IDE whenever a list of all properties of a particular object is needed. At this point it is easy to remove some properties form the original list (this properties are not be shown in the Properties Windows) or make them read only (see the ReadOnlyPropertyDescriptor class in my code).

For more in depth information feel free to take a look at the source code.

…but beware

All these property restrictions effect only the properties windows. The properties can be changed and accessed by code and via other elements of the DSL Designer (for example TextDecorators and the DSL Explorer).


In the zip file you will find all described classes in one project and an example DSL project.


This code is now part of the JaDAL – Just another DSL-Tools Addon Library project. Please download the current version from that page. The download over at CodePlex contains the source code described here, an example DSL language and the library as a binary. Future enhancements of the code will be published there, too.

Some great resources on VSX

Tags: , , ,
1 Comment »

As you all know I’m working with Visual Studio Extensibility (VSX) at the moment. VSX is a interesting field to work with but it is badly documented. There are some samples, some books, communities and so on and if you search the web for a while you can find answers to most of the basic questions. But to begin programming Visual Studio extensions it is hard to find some place to start.

As a starting point I will recommend DiveDeepers blog to you. He posted a great series of articles on VSX. Take a look at the articles starting with "LearnVSXNow!" and "LVN Sidebar".

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in