<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ticklish Techs &#187; orcas</title>
	<atom:link href="http://www.ticklishtechs.net/tag/orcas/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ticklishtechs.net</link>
	<description>a mostly .NET but also some other cool techs blog</description>
	<lastBuildDate>Fri, 23 Jul 2010 06:07:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>To restrict dynamically the usage of Domain Properties in DSL Models</title>
		<link>http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/</link>
		<comments>http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 21:10:33 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/</guid>
		<description><![CDATA[What&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<h3>What&#8217;s the matter?</h3>
<p>If you define <em>Domain Properties</em> on your <em>Domain Classes</em> and <em>Shapes</em>, you can configure the way a user of your DSL can interact with this <em>Domain Properties</em>. With the properties <em>Is Browsable </em>and <em>Is UI Read Only</em> you can hide a property from the Properties Window, make it read only or give the user full access to it.</p>
<p>But I want to change this behavior of certain Domain Properties dynamically at runtime!    <br />Why the heck would someone need this? I don&#8217;t know, but I can tell why I need it: I&#8217;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.</p>
<p>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.</p>
<h3>How do you use it?</h3>
<p>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.</p>
<p>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 <em>Is Browsable </em>set to <code>true</code> and <em>Is UI Read Only </em>set to <code>false</code>.</p>
<pre class="code"><span style="color: blue">public enum </span><span style="color: #2b91af">RestrictionModes
</span>{
    Original = 0,
    Simple,
    Advanced
}</pre>
<p>Than you can provide your <em>Domain Classes </em>and the <em>Domain Model </em>with the <code>RestrictedProperty</code>-Attribute to configure the different properties:</p>
<pre class="code">[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Simple,
                    <span style="color: #a31515">&quot;P1&quot;</span>, <span style="color: #2b91af">Restriction</span>.Hidden)]
[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Simple,
                    <span style="color: #a31515">&quot;P2&quot;</span>, <span style="color: #2b91af">Restriction</span>.ReadOnly)]
[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Simple,
                    <span style="color: #a31515">&quot;P3&quot;</span>, <span style="color: #2b91af">Restriction</span>.ReadOnly)]

[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Advanced,
                    <span style="color: #a31515">&quot;P1&quot;</span>, <span style="color: #2b91af">Restriction</span>.Full)]
[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Advanced,
                    <span style="color: #a31515">&quot;P2&quot;</span>, <span style="color: #2b91af">Restriction</span>.Full)]
[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Advanced,
                    <span style="color: #a31515">&quot;P3&quot;</span>, <span style="color: #2b91af">Restriction</span>.ReadOnly)]
<span style="color: blue">partial class </span><span style="color: #2b91af">ExampleModel
</span>{
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The <code>ExampleModel</code> has three properties (<code>P1</code>, <code>P2</code>, <code>P3</code>) and in the original DSL Editor these properties are all writable. Properties that are not mentioned by the attributes will work as defined. </p>
<p>If the Restriction Mode is set to <code>RestrictionModes.Advanced</code> two of them are fully assessable (in fact you do not need to create Attributes to set the properties to <code>Restriction.Full</code> since this is the default value) and one is read only. In the <code>RestrictionModes.Simple</code>-case one property will be hidden and two are read only.</p>
<p>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.</p>
<p>After that you have to create a <code>partial</code> class for your <code>Package</code> and &quot;activate&quot; my library for each Class that uses these attributes:</p>
<pre class="code"><span style="color: blue">partial class </span><span style="color: #2b91af">RestrictPropertiesTestPackage
</span>{
 <span style="color: blue">protected override void </span>Initialize()
 {
<span style="color: #2b91af">  UserRestrictionProvider</span>.RegisterRestrictedElement&lt;<span style="color: #2b91af">ExampleElement</span>&gt;();
  <span style="color: #2b91af">UserRestrictionProvider</span>.RegisterRestrictedElement&lt;<span style="color: #2b91af">ExampleModel</span>&gt;();

  <span style="color: blue">base</span>.Initialize();
 }}</pre>
<p>Or use the shorter way to add all classes with one line of code. This will use reflection to find the classes.</p>
<pre class="code"><span style="color: #2b91af">UserRestrictionProvider
 </span>.RegisterAllRestrictedElements    &lt;<span style="color: #2b91af">RestrictPropertiesExampleDiagram</span>&gt;();</pre>
<p>Now there is only one step left: how to change the mode. Each <code>Store</code> (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 <code>Store</code> and so one mode for each <code>Model</code> or <code>Diagram</code>. The <code>Store</code> can be accessed from each <code>ModelElement</code>, so as a key for this purpose it is a great value. There is a <code>UserRestrictionProvider</code> class with two <code>static</code> methods:</p>
<ul>
<li>
<pre class="code"><span style="color: blue">public static void </span>SetRestrictionMode(<span style="color: #2b91af">Store </span>store, <span style="color: blue">int </span>mode)</pre>
</li>
<li>
<pre class="code"><span style="color: blue">public static int </span>GetRestrictionMode(<span style="color: #2b91af">Store </span>store)</pre>
</li>
</ul>
<p>You can use these methods whenever you want to change the Restriction Mode. For the demo project I used a <em>Domain Property</em> of the Diagram with <em>Custom Storage.</em></p>
<h3>How does it work?</h3>
<p>With the <code>UserRestrictionProvider.RegisterRestrictedElement()</code>method I register a special <a title="TypeDescriptionProvider Class" href="http://msdn2.microsoft.com/57y792w8.aspx">TypeDescriptionProvider</a> to the global Component Model (via the <a title="TypeDescriptor..::.AddProvider Method " href="http://msdn2.microsoft.com/8dtk2wwz.aspx">TypeDescriptor.AddProvider()</a> 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 <code>ReadOnlyPropertyDescriptor</code> class in my code).</p>
<p>For more in depth information feel free to take a look at the source code.</p>
<h3>&#8230;but beware</h3>
<p>All these property restrictions <strong>effect only the properties windows</strong>. The properties can be changed and accessed by code and via other elements of the DSL Designer (for example TextDecorators and the DSL Explorer).</p>
<h3><strike>Download</strike></h3>
<p><strike>In the zip file you will find all described classes in one project and an example DSL project.</strike></p>
</p>
<div class="wlWriterSmartContent" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:97ecb1ea-90a4-4953-9c57-8995ca4f1190" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<p><strike>Download: </strike><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/04/restrictpropertiesexample.zip"><strike>Source code and example</strike></a></p>
</div>
<h3>Update</h3>
<p>This code is now part of the <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> project. Please download the current version from that page. The download over at <a href="http://www.codeplex.com">CodePlex</a> 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.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Some great resources on VSX</title>
		<link>http://www.ticklishtechs.net/2008/04/02/good-resources-on-vsx/</link>
		<comments>http://www.ticklishtechs.net/2008/04/02/good-resources-on-vsx/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 20:36:48 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/04/02/good-resources-on-vsx/</guid>
		<description><![CDATA[As you all know I&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>As you all know I&#8217;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.</p>
<p>As a starting point I will recommend <a href="http://www.architekturaforum.hu/blogs/divedeeper/">DiveDeepers blog</a> to you. He posted a great series of articles on VSX. Take a look at the articles starting with &quot;LearnVSXNow!&quot; and &quot;LVN Sidebar&quot;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/04/02/good-resources-on-vsx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finding and removing a default command in DSL Tools (part 4 of Compartment Mappings)</title>
		<link>http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/</link>
		<comments>http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 20:25:57 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/</guid>
		<description><![CDATA[[Update (2008-05-21): This code is now hosted at CodePlex as part of JaDAL. And a follow-up article was published.]
Previously on&#8230;
This article is part of a series. A table of contents can be found at the end of the first article. Part 2 contains a user guide and in part 3 I showed most of the [...]]]></description>
			<content:encoded><![CDATA[<p>[<strong>Update (2008-05-21): </strong>This code is now hosted at CodePlex as part of <a href="http://www.codeplex.com/JaDAL">JaDAL</a>. And a <a href="http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/">follow-up article</a> was published.]</p>
<h3>Previously on&#8230;</h3>
<p>This article is part of a series. A table of contents can be found at the end of the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">first article</a>. <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">Part 2</a> contains a user guide and in <a href="http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/">part 3</a> I showed most of the internals of the library.</p>
<h3>The &quot;Reroute&quot; command</h3>
<p>For each connector there is a command named &quot;Reroute&quot; in the context menu of the DSL editor. Now I have to remove this command for the compartment entry mappings. If the user would use it, the layout of my connectors will be destroyed. Unfortunately I did not find an option, an extension point or anything else where I could change or handle this particular command or the context menu of the connectors.</p>
<h3>The generated code</h3>
<p>First I looked at the generated code of my <code>Dsl</code> and <code>DslPackage</code> project. There is a <code>GeneratedVSCT.vsct</code> file. In <code>vsct</code> files the commands are defined, but in this one I could not find anything with &quot;Reroute&quot;. Then I searched for the string &quot;Reroute&quot; in all files and found nothing.</p>
<h3>The DSL binaries</h3>
<p>I found no documentation for this command and&#160; was a little desperate. I needed to find the place where it comes from. I searched the whole VS SDK folder (text and binary files) for the string &quot;reroute&quot;. A promising hint was found in the Microsoft.VisualStudio.Modeling.Sdk.Shell.dll file. Now let&#8217;s go to the <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a> and take a deeper look inside.</p>
<p>After a while I found the <a title="CommandSet Class" href="http://msdn2.microsoft.com/bb163614.aspx">Microsoft.VisualStudio.Modeling.Shell.CommandSet</a> class. And hey, in the msdn documentation article for this class there is also the <em>Reroute Line </em>command mentioned. With this knowledge one can easily find the generated <code>CommandSet.cs</code> file as part of the <code>DslPackage</code>. In this file there are two classes <code>AbcCommandSetBase</code> and <code>AbcCommandSet</code> where <code>Abc</code> is the name of you DSL project. </p>
<p>The design pattern of this classes is called <em>double derived</em> and can be found quiet often within the generated DSL code. The <code>...Base</code> class stays abstract and derives from a class defined in the Microsoft Visual Studio SDK libraries, in this case from the <a title="CommandSet Class" href="http://msdn2.microsoft.com/bb163614.aspx">CommandSet</a> class I found above. All code created by the code generator is added to this <code>...Base </code>class. The other class derives from the <code>...Base</code> class and is empty &#8211; all parts of the project uses this one. Since it is declared with the <code>partial</code> keyword, the user can override ALL methods and change the behavior of all aspects of this class.</p>
<p>And that is what we are going to do: override the <code>GetMenuCommands()</code> method and remove the reroute command:</p>
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">MenuCommand</span>&gt; GetMenuCommands()
{
  <span style="color: green">// get the base list
  </span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">MenuCommand</span>&gt; cmds = <span style="color: blue">base</span>.GetMenuCommands();
  <span style="color: green">// find the reroute command
  </span><span style="color: #2b91af">MenuCommand </span>rerouteCommand = cmds.First(
    c =&gt; c.CommandID == <span style="color: #2b91af">CommonModelingCommands</span>.RerouteLine);
  <span style="color: green">// if found, remove it
  </span><span style="color: blue">if </span>(rerouteCommand != <span style="color: blue">null</span>)
      cmds.Remove(rerouteCommand); 

  <span style="color: green">// and return the changed list
  </span><span style="color: blue">return </span>cmds;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>That&#8217;s it. Pretty easy, but you have to discover where to add this logic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Connectors between compartment shape entries with DSL Tools &#8211; part 3</title>
		<link>http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/</link>
		<comments>http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 17:42:14 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/</guid>
		<description><![CDATA[[Update (2008-05-21): This code is now hosted at CodePlex as part of JaDAL. And a follow-up article was published.]
Previously on&#8230;
This article is part of a series. The table of contents can be found at the end of the first article. In that article you can also find a brief overview. In the second part there [...]]]></description>
			<content:encoded><![CDATA[<p>[<strong>Update (2008-05-21): </strong>This code is now hosted at CodePlex as part of <a href="http://www.codeplex.com/JaDAL">JaDAL</a>. And a <a href="http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/">follow-up article</a> was published.]</p>
<h3>Previously on&#8230;</h3>
<p>This article is part of a series. The table of contents can be found at the end of the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">first article</a>. In that article you can also find a brief overview. In the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">second part</a> there is a short user guide and a download link of the source code and binaries.</p>
<h3>How does it all work?</h3>
<p>I don&#8217;t want to explain every single detail of my code. If you want to go that deep, you have to read the source code yourself and maybe you will find some comments. I will only show you the fundamental parts of the CompartmentMapping library.</p>
<p>There are a few things you have to consider to achieve the aim of the library:</p>
<ol>
<li>When creating a connector from <em>Shape A</em> to <em>Shape B</em> how should I get and store the <em>Compartment Entry</em> information for the <em>Reference Relationship</em>? </li>
<li>After that, the connector representing this relationship must be drawn in such a way that it seems to be a connector from one entry to another. </li>
<li>What can a user do to destroy the layout of my connectors? And even more important: how can I prevent him from doing so? </li>
<li>If the user deletes a <em>compartment entry</em> that is part of a relationship, the relationship needs to be deleted, too. </li>
</ol>
<h3>The Connection Builder</h3>
<p>There is the concept of <em>Connection Builders</em> used by the DSL Tools. While your day to day use of DSL, you don&#8217;t have to worry about <em>Connection Builders</em> since they will be generated by the DSL Tools code generator. But you can turn this generation off and provide your implementation of a <em>Connection Builder </em>for a certain relationship. (see number 5 in the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">user guide</a>). </p>
<p>A <em>Connection Builder</em> is a static class and will be assigned to a connection toolbar item of your editor. This class contains four interesting methods:</p>
<ol>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptSource(<span style="color: #2b91af">ModelElement</span>)</pre>
</li>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptTarget(<span style="color: #2b91af">ModelElement</span>)</pre>
</li>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptSourceAndTarget(<span style="color: #2b91af">ModelElement</span>, <span style="color: #2b91af">ModelElement</span>)</pre>
</li>
<li>
<pre class="code"><span style="color: #2b91af">ElementLink </span>Connect(<span style="color: #2b91af">ModelElement</span>, <span style="color: #2b91af">ModelElement</span>)</pre>
</li>
</ol>
<p>The first two methods are used to determine if a particular <code>ModelElement</code> can act as source or target of you connection. For example you can check the <code>ModelElement</code> for a certain property to be set and only allow elements with this property as source and with another property as target, or whatever. </p>
<p>With&#160; <code>CanAcceptSourceAndTarget()</code> you can check whenever a concrete combination of source and target <code>ModelElements</code> is allowed to be connected by your relationship. </p>
<p>Last but not least with the <code>Connect()</code> method you have to create this new relationship for the two selected <code>ModelElements</code>.</p>
<p>In such a <em>Connection Builder</em> I will add the logic to check not only the model elements but also the selected entry inside the <em>Compartment Shape</em>. At this point I will mix the model representation (containing of <em>Domain Classes</em> and <em>Relationships</em>) and the graphical appearance (containing of <em>Shapes </em>and <em>Connectors</em>) but there is no better way at this time since the DSL Tools can only create connectors from shape to shape.</p>
<p>The first problem I ran into: How to get the shape of the model element in the <em>Connection Builder</em> if the only parameter is the <code>ModelElement?</code> I used the <a title="PresentationViewsSubject..::.GetPresentation Method " href="http://msdn2.microsoft.com/bb128952.aspx">PresentationViewsSubject.GetPresentation()</a> method and I&#8217;m hoping it will always work. The architecture is build in such a way, that one <code>ModelElement</code> can have multiple shapes, but I didn&#8217;t saw such a configuration until now, so I assume there will be only one shape.</p>
<p>After holding the shape in my hand I need to know something about the selected <em>Compartment Entry</em>. This becomes a little bit complicated, too: Sometimes I need the entry right below the mouse cursor (for <code>CanAcceptSource()</code>) and sometimes the entry that was below the mouse when the user pressed the mouse button. Of course a <em>Compartment Shape</em> doesn&#8217;t provide any of that information. Take a look at <code>CompartmentMouseTrack</code> and <code>ICompartmentMouseActionTrackable</code> in the CompartmentMapping library and you will see in which way I handle mouse events of the shape to track all these mouse actions for the <em>Compartment Shapes</em> that are under the control of my library.</p>
<p>With all these new information my <code>CompartmentMappingBuilderBase</code> can decide to allow or permit the creation of a connection. With some <code>virtual</code> methods, it can delegate&#160; more details of this decision to your code (see the advanced options <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">here</a>).</p>
<ol><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></ol>
<h3>How to trick the routing algorithm of DSL Tools</h3>
<p>With the <em>Connection Builder</em> one can create relationships in the domain model but the connector inside the visual representation of your model will still be routed from shape to shape and won&#8217;t give you a proper understanding of the entry to entry relationship. So we have to change the routing in a way that the start and endpoints of the connector will be glued near to the entry on one side of the shape.</p>
<p>This will be done with an <a title="AddRule Class" href="http://msdn2.microsoft.com/bb141674.aspx">AddRule</a> (<code>CompartmentMappingAddRuleBase</code>) every time a new connector will be added to the diagram (and when opening a saved diagram). </p>
<p>After determination the favored points on the shape outline you can set them to the connector with the <a title="BinaryLinkShapeBase..::.FromEndPoint Property " href="http://msdn2.microsoft.com/bb135134.aspx">FromEndPoint</a> and <a title="BinaryLinkShapeBase..::.ToEndPoint Property " href="http://msdn2.microsoft.com/bb135144.aspx">ToEndPoint</a> properties. Don&#8217;t forget to change the <a title="BinaryLinkShapeBase..::.FixedFrom Property " href="http://msdn2.microsoft.com/bb135132.aspx">FixedFrom</a> and <a title="BinaryLinkShapeBase..::.FixedTo Property " href="http://msdn2.microsoft.com/bb135133.aspx">FixedTo</a> to <code>VGFixedCode.Caller</code> as well.</p>
<h3>Don&#8217;t get tricked by the routing algorithm</h3>
<p>If you change the start and endpoints of a connector in the <em><u>AddRule</u></em> these values aren&#8217;t set forever.&#160; The user could collapse and expand the compartment shape or use the &quot;Reroute&quot; command that is visible in the context menu of every connector. He could also move the connector or only the start and endpoints on the shape outline. If he deletes one entry that was shown above an entry with a connection this entry moves closer to the top and the connection should do the same.</p>
<p>With a few lines of code, we can forbid the user to change the routing of a connectors. In the connector class the <code>CanManuallyRoute</code> property simply have to return <code>false</code>.</p>
<p>Every time the size of the shape changes (see <a title="NodeShape..::.OnAbsoluteBoundsChanged Method " href="http://msdn2.microsoft.com/bb128708.aspx">OnAbsoluteBoundsChanged event</a>) I will recalculate the connection points of all connectors assigned to this shape. This event will handle a bunch of cases for me: insertion and deletion of other entries, expanding and collapsing of the whole shape and singe compartment lists and renaming of entries which can cause reordering of the compartment list.</p>
<h3>Delete propagation</h3>
<p>The delete propagation is an easy requirement. I just added a <a title="DeletingRule Class" href="http://msdn2.microsoft.com/bb142028.aspx">DeletingRule</a> that keep track of the deletion of certain <em>Compartment Entries</em> and if one is deleted it looks for <em>Compartment Mapping Relationships</em> and deletes them. </p>
<p>It is a little bit challenging to find the relationships coming from the entry. If you want to know more details take a look at the <code>CompartmentEntryDeletingRuleBase</code> source code.</p>
<h3>Upcoming article</h3>
<p>In the <a href="http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/">last article</a> of this series I will explain the way of removing the &quot;Reroute&quot; command from the connector context menu. The actual code consist only of a few lines, but the way I found the point to do it can be interesting for someone because the &quot;Reroute&quot; command is not proper documented anywhere.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Connectors between compartment shape entries with DSL Tools &#8211; part 2</title>
		<link>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/</link>
		<comments>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 22:05:02 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/</guid>
		<description><![CDATA[[Update (2008-05-21): This code is now hosted at CodePlex as part of JaDAL. And a follow-up article was published.]
Previously on&#8230;
This article is part of a series. A table of contents can be found at the end of the first article. In that article you can also find a brief overview.

User guide
If you read this article [...]]]></description>
			<content:encoded><![CDATA[<p>[<strong>Update (2008-05-21): </strong>This code is now hosted at CodePlex as part of <a href="http://www.codeplex.com/JaDAL">JaDAL</a>. And a <a href="http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/">follow-up article</a> was published.]</p>
<h3>Previously on&#8230;</h3>
<p>This article is part of a series. A table of contents can be found at the end of the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">first article</a>. In that article you can also find a brief overview.</p>
<ul></ul>
<h3>User guide</h3>
<p>If you read this article to this point you will properly use or at least evaluate the CompartmentMapping library. I will provide you with a step-by-step tutorial. There are pretty some steps, but its the shortest way I could imagine to create my solution. Please give it a try. <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<ol>
<li>You need <a href="http://code.msdn.microsoft.com/TTxGen">TTxGen</a> to generate some code from my templates. See <a href="http://www.ticklishtechs.net/2008/02/28/codegeneration-with-codesmith-and-orcas-t4/">my last article</a> for more information and a workaround for an installation problem.       </li>
<li>I assume you have a DSL solution and at least two <em>Domain Classes</em> mapped to two compartment shapes and two more <em>Domain Classes</em> used as entries of the compartment shapes created. In my example these classes are called <code>Parent1</code>, <code>Entry1</code>, <code>Parent2</code> and <code>Entry2</code>.       <br />The entries need a unique identifier. You could use a name property for this, but there will be some difficulties if the user creates two entries in one shape with the same name, so I will use a guid. (Don&#8217;t forget to create a new guid in the constructor or another proper place.)       </li>
<li>Create a <em>Reference Relationship</em> from <code>Parent1</code> to <code>Parent2</code>. This will be automatically named <code>Parent1ReferencesParent2</code>. We will use this reference to present the relationship from one entry to the other. I would like to create <em>Reference Relationships</em> from this relationship to the entries, but relationships of relationships are not supported. We have to store the guids of the entries in the relationship and add two <em>Domain Properties</em> for this purpose to it. I named them <code>fromEntry</code> and <code>toEntry</code>.       <br /><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/02/dsldefinition.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="298" alt="DslDefinition" src="http://www.ticklishtechs.net/wp-content/uploads/2008/02/dsldefinition-thumb.png" width="440" border="0" /></a>&#160; </li>
<li>Set the <code>Allows Duplicates</code> property of the <code>Parent1ReferencesParent2</code> relationship to <code>true</code>.       </li>
<li>Set the <code>Is Custom</code> property of the <em>Connection Builder</em> (<code>Parent1ReferencesParent2Builder</code>) in the <em>DSL Explorer</em> to <code>true</code>.       </li>
<li>Add a reference to <code>CompartmentMapping.dll</code> to both the <code>Dsl</code> and <code>DslPackage</code> project.       </li>
<li>Add a new xml file (in my example <code>CompartmentMappings.xml</code>) to your solution and write the following code in it:
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot; <span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">CompartmentConnections
    </span><span style="color: red">xmlns:xsi</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://www.w3.org/2001/XMLSchema-instance</span>&quot;
    <span style="color: red">xsi:noNamespaceSchemaLocation</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentMappings.xsd</span>&quot;
    <span style="color: red">namespace</span><span style="color: blue">=</span>&quot;<span style="color: blue">BenjaminSchroeter.CompartmentMappingExample</span>&quot; <span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">CompartmentConnection</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">CompartmentSource</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">DomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent1</span>&quot;<span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">EntryDomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Entry1</span>&quot;<span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">Shape </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentShape1</span>&quot; <span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">CompartmentSource</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">CompartmentTarget</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">DomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent2</span>&quot; <span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">EntryDomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Entry2</span>&quot; <span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">Shape </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentShape2</span>&quot; <span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">CompartmentTarget</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Connection </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent1ReferencesParent2</span>&quot;<span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">Shape </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Connector</span>&quot; <span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">Connection</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">CompartmentConnection</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">CompartmentConnections</span><span style="color: blue">&gt;</span></pre>
<p>(If you place the xsd file in the same directory you get IntelliSense and error checking for free.)</p>
</li>
<li>Place the <code>CompartmentConnections.tt</code> file in the same directory and right-click on the xml file and choose <em>Generate xGen Template</em>. A <code>CompartmentMappings_xGen.tt</code> file will be created below the xml file and there you have to add the following lines:
<pre class="code"><span style="background: gold">&lt;#@</span><span style="color: red"> ParentFileInjector processor=</span>&quot;<span style="color: blue">TTxGenDirectiveProcessor</span>&quot;
    <span style="color: red">requires=</span>&quot;<span style="color: blue">fileName='CompartmentMappings.xml'</span>&quot; <span style="background: gold">#&gt;
&lt;#@</span><span style="color: red"> </span><span style="color: brown">include </span><span style="color: red">file=</span>&quot;<span style="color: blue">CompartmentConnections.tt</span>&quot; <span style="background: gold">#&gt;</span></pre>
<p>(Be sure you use the right xml file name here.)</p>
<p>Now press the <em>Transform All Templates</em> Button in the <em>Solution Explorer </em>to generate the the code from this template.</p>
</li>
<li>Now you have to write code by yourself (nearly by yourself, the frames are generated, too). Take a look at the generated cs file <code>CompartmentConnections_xGen.cs</code>.
<p>At the top you will find commented code. Copy this code to a new cs file and remove the comments. All code you will write for the compartment mappings you will write in this file.</p>
</li>
<li>Complete the <code>CreateElementLink()</code> method in this file. Here you have to add code to store the selected compartment entries for source and target in the properties of the relationship (see 3).
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">ElementLink </span>CreateElementLink(<span style="color: #2b91af">Parent1 </span>source,
  <span style="color: #2b91af">SelectedCompartmentPartType </span>sourcePartType,
  <span style="color: #2b91af">Entry1 </span>sourceEntry,
  <span style="color: #2b91af">Parent2 </span>target,
  <span style="color: #2b91af">SelectedCompartmentPartType </span>targetPartType,
  <span style="color: #2b91af">Entry2 </span>targetEntry)
{
    <span style="color: #2b91af">Parent1ReferencesParent2 </span>result =
        <span style="color: blue">new </span><span style="color: #2b91af">Parent1ReferencesParent2</span>(source, target);
<strong>    result.fromEntry = sourceEntry.Guid;
    result.toEntry = targetEntry.Guid;</strong>
    <span style="color: blue">return </span>result;
}</pre>
</li>
<li>In the <code>CreateElementLink()</code> method you have stored the source and target entry information somewhere; my library does not know about this location. So we need two more methods to compare an entry with a relationship and answer the question &quot;Is this entry the source of a given relationship?&quot; and the same for the target. These code resists in the same file:
<pre class="code"><span style="color: blue">public override bool </span>IsEntryConnectionSource
    (<span style="color: #2b91af">Entry1 </span>entry, <span style="color: #2b91af">Parent1ReferencesParent2 </span>connection)
{
<strong>    <span style="color: blue">if </span>(entry == <span style="color: blue">null</span>)
        <span style="color: blue">return false</span>;
    <span style="color: blue">return </span>connection.fromEntry.Equals(entry.Guid);</strong>
}
<span style="color: blue">public override bool </span>IsEntryConnectionTarget
    (<span style="color: #2b91af">Entry2 </span>entry, <span style="color: #2b91af">Parent1ReferencesParent2 </span>connection)
{
<strong>    <span style="color: blue">if </span>(entry == <span style="color: blue">null</span>)
        <span style="color: blue">return false</span>;
    <span style="color: blue">return </span>connection.toEntry.Equals(entry.Guid);</strong>
}</pre>
<p>Always care for <code>entry == null</code> this will be used to check whether the head of the shape is meant. Even if you do not allow the head as source or target this method will be called with a <code>null</code> parameter from time to time.</p>
</li>
<li>Create a <code>partial class</code> for your <em>Domain Model </em>(<code>CompartmentMappingExampleDomainModel</code>) and add the following methods.
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">Type</span>[] GetCustomDomainModelTypes()
{
  <span style="color: blue">return </span><span style="color: #2b91af">CompartmentMappingUtil</span>.AllCompartmentMappingRules(<span style="color: blue">this</span>);
}</pre>
<p>(If you have already some custom rules, you can use an overloaded version of the <code>AllCompartmentMappingRules()</code> method.)</p>
</li>
<li>
<p>In the <code>DslPackage</code> project create a <code>partial class</code> for the generated <em>Command Set</em> and add the following code:</p>
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">MenuCommand</span>&gt; GetMenuCommands()
{
    <span style="color: blue">return </span><span style="color: #2b91af">CompartmentMappingUtil</span>.RemoveRerouteCommand
                                (<span style="color: blue">base</span>.GetMenuCommands());
}</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
</li>
</ol>
<p>That&#8217;s all. Only 13 steps, a few settings and conventions and 10 lines of C# code to write. I know it is not very easy but I think it is ok. And the best: as you will see it is working.</p>
<p>Now compile and start you solution. You can now create connectors from one entry of the <code>Parent1</code> shape to an entry of the <code>Parent2</code> shape. Great &#8211; isn&#8217;t it?</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="319" alt="mapping" src="http://www.ticklishtechs.net/wp-content/uploads/2008/02/mapping.png" width="462" border="0" />&#160;</p>
<p>Take a look at the properties in the <em>Properties window</em> when selecting a connector. You see the guids of the corresponding entries and can use them in your code when working with this connections for code generation or whatever you need to do.</p>
<h3>Advanced options</h3>
<p>There are some more options besides the basics described above to configure and extend the compartment mappings.</p>
<p>Some of them can easily turned on in the xml file:</p>
<ul>
<li>For <code>CompartmentSource</code> and <code>CompartmentTarget</code> you can specify an attribute called <code>allowHeadAsSource</code> (and <code>allowHeadAsTarget</code> respectively) and set it to <code>true</code>, to allow the head of the compartment shape as source or target. Remember, if you do this the <code>CreateElementLink()</code> method will be called with <code>null</code> values for the entries and you have to handle this. </li>
<li>On the <code>Connection</code> element there are two more optional attributes, too.
<p>If you set <code>allowSelfReference</code> to <code>true</code> the user can create connections from one entry of one shape to another (or the same) entry of the same shape (source = target). This makes only sense if you specify <code>CompartmentSource</code> and <code>CompartmentTarget</code> to be the same <em>Domain Class </em>and the same shape.</p>
<p>With the <code>suppressEntryDeletePropagation</code> attribute set to <code>true</code> you suppress the deletion of the connection when a corresponding compartment entry is deleted. Be careful with this setting: Wrong connections will remain in your model and produce ugly diagrams.</p>
</li>
<li>One of source and target can be a regular shape (that is a geometry or image shape and not a compartment shape). Replace either <code>CompartmentSource</code> with <code>Source</code> or <code>CompartmentTarget</code> with <code>Target</code>. For these elements you don&#8217;t need to define a <code>EntryDomainClass</code> element since regular shapes do not have entries. </li>
</ul>
<p>You can add even more code to the C# file from step 9 to 11. There are two more methods you can override: <code>CanAcceptAsCompartmentSource()</code> and <code>CanAcceptAsCompartmentSourceAndTarget()</code>. If you do so, the DSL editor will ask your code while the user moves the mouse over shapes when creating the connection to identify the current shape and entry as a valid source or target in you scenario. It is pretty much the same pattern as used in the DSL Tools itself. But remember, this method will be called very often und should have a very short running time.</p>
<h3><stroke>Download</stroke></h3>
<p><stroke>The archive contains the library both as a compiled dll and as source code and the Example DSL created in this article.</stroke></p>
<h3>Update</h3>
<p>This code is now part of the <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> project. Please download the current version from that page. The download over at <a href="http://www.codeplex.com">CodePlex</a> 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.</p>
<div class="wlWriterSmartContent" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:1f1d4156-e123-40e6-bec0-9bfe126fbf7e" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/03/compartmentmapping.zip" target="_blank">CompartmentMapping.zip</a></p>
</div>
<h3>Upcoming articles</h3>
<p><a href="http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/">Part 3</a> and <a href="http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/">part 4</a> of this series will give an in depth view into the internals of the library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Connectors between compartment shape entries with DSL Tools &#8211; part 1</title>
		<link>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/</link>
		<comments>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 22:04:34 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/</guid>
		<description><![CDATA[[Update (2008-05-21): This code is now hosted at CodePlex as part of JaDAL. And a follow-up article was published.]
This is the first part of an article series to this topic on a library I wrote. At the end of this article you find links to the upcoming articles. The download can be found at part [...]]]></description>
			<content:encoded><![CDATA[<p>[<strong>Update (2008-05-21): </strong>This code is now hosted at CodePlex as part of <a href="http://www.codeplex.com/JaDAL">JaDAL</a>. And a <a href="http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/">follow-up article</a> was published.]</p>
<p>This is the first part of an article series to this topic on a library I wrote. At the end of this article you find links to the upcoming articles. The download can be found at <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">part 2</a> along with a brief &quot;user guide&quot;.</p>
<h3>Let&#8217;s begin&#8230;</h3>
<p>With DSL Tools you get compartment shapes for your diagrams that look very much like the class-shapes in the graphical class designer of Visual Studio. These compartment shapes are very useful in many model designs and can visualize much information in a compact way. The user can collapse the whole shape (<em>Shape 4</em>) or single compartment lists (<em>Shape 1</em>, <em>Shape 6</em>) to save even more space on his diagram.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="380" alt="compartmentExample" src="http://www.ticklishtechs.net/wp-content/uploads/2008/02/compartmentexample.png" width="340" border="0" /></p>
<p>Like in the class designer you can only create connections from one shape to another not from one <strong>compartment entry</strong> to a shape or another compartment entry. The ability to create such connectors can simplify many DSL designs and on the <a href="http://forums.microsoft.com/msdn/showforum.aspx?forumid=57&amp;siteid=1">VSX forum</a> a couple of people asked for this feature. But there is a simple answer to this topic:</p>
<blockquote><p>&quot;This would be a useful feature, but unfortunately it doesn&#8217;t fit into our plans for DSL tools V1.&#160; It&#8217;s something we&#8217;ll consider for the next version, though.&quot;      <br />[<a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=160231&amp;SiteID=1">Grayson Myers MSFT</a>]</p>
</blockquote>
<p>What should I do? Change my DSL and make it complicated and less useful because of a limitation of the framework? Wait for an upcoming Version without a release date and without knowing that it will work for me? This all sounds like a very bad idea to me. So let&#8217;s change or extend the framework!</p>
<p>I wrote a library to bring this feature to the DSL Tools. With this library you can</p>
<ul>
<li>Create connections between compartment entries of two different compartment shapes (or even within the same shape, if you like). You can specify the allowed type of the source or target shape or select the same type for source and target. You can also constraint the allowed compartment entries by type if your source (or target) compartment shapes define more then one compartment group. </li>
<li>The user experience isn&#8217;t changed: The user creates this connections with drag and drop as usual in the generated DSL model designer. </li>
<li>You can add code to write custom accept rules for this connection. </li>
<li>You can decide how the information of the source and target entry is stored in the generated D<em>omain Relationship</em>. </li>
<li>If you want, the whole compartment shape can be the source or target of a connection as well. This will be visualized through a connector from or to the head of the shape. </li>
<li>When the user deletes the compartment entry, the connection will be automatically deleted, too. (optional) </li>
<li><strike>One of source or target can be a regular shape. E.g. you can create a connector where the source is a compartment entry of a certain compartment shape and the target is a regular geometry or image shape.</strike> Since the <a href="http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/">update</a> (see top of article) both source and target can be a regular shape, too or a base class mapped to a regular and compartment shape.</li>
<li>All other properties, extension points, configuration, visualizations and so on will be used from DSL Tools. </li>
</ul>
<p>Since I can not change the code of the DSL Tools framework and libraries and I want not change the generated code in your DSL project (this will be overwritten each time you generate it) I started to write a library. To use this library in your DSL project you have to design some elements in your DSL as described by me later on. It is <strong>curial</strong> to set certain properties or it will not work as expected. Then you have to add come code to your DSL project to extend the partial classes generated by the DSL Tools code generator. To minimize the amount of&#160; hand written code I created a code generator as well. With this generator you need only to specify the connection you want to use as a compartment entry connection. Then only one class with three methods is left to be filled with code.</p>
<p>Because of the limitations of the DSL Tools framework and the given extension points not everything is working as someone will expect. But at this moment I can only think of one feature you may miss with my solution:</p>
<ul>
<li>Obviously the connector have to start on the left or right side of the shape just besides the corresponding compartment entry. Every time you change (add or remove entries; collapse or expand the shape) or move the compartment shape this connection points will be recalculated.      <br />The routing of the connector may change when this happens, but it will always use the routing algorithm you already know within the DSL editors. To ensure a correct visual presentation of the connector the user MUST NOT change the routing! For every connector under the control of my library the user CANNOT change the routing. &#8211; In my opinion this is a small price for the features you can add to the DSL framework. </li>
</ul>
<h3>Upcoming articles</h3>
<ul>
<li>This article showed the basics of what my library can do. </li>
<li>In the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">next article</a> I will give you a brief user guide on how to provide this functionality to your DSL developments. The download of the library, the source code and examples will be there as well. </li>
<li>The <a href="http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/">third part</a> gives you a deeper look inside of the library and shows you the way it is working </li>
<li>In the <a href="http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/">last part</a> I will explain a way of finding and removing some default commands from the DSL editor. </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Codegeneration with CodeSmith and Orcas T4</title>
		<link>http://www.ticklishtechs.net/2008/02/28/codegeneration-with-codesmith-and-orcas-t4/</link>
		<comments>http://www.ticklishtechs.net/2008/02/28/codegeneration-with-codesmith-and-orcas-t4/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 23:10:30 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[t4]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/02/28/godegeneration-with-codesmith-and-orcas-t4/</guid>
		<description><![CDATA[As a professional software developer you will come one day to the point where you want to generate some source code or text files instead of writing it yourself. I don&#8217;t speak about dynamic web pages or big frameworks with code generation. But I bet in some of your last projects you could generate some [...]]]></description>
			<content:encoded><![CDATA[<p>As a professional software developer you will come one day to the point where you want to generate some source code or text files instead of writing it yourself. I don&#8217;t speak about dynamic web pages or big frameworks with code generation. But I bet in some of your last projects you could generate some code, too.</p>
<p>Maybe you do this already with a codegenerator of some kind or by using a scripting language like PHP or Python. Maybe you have reasons not to generate it and write it by yourself. Very often these reasons are bad reasons: you don&#8217;t know any adequate tool, you don&#8217;t want to buy one or you don&#8217;t have the time to learn it.</p>
<h3>CodeSmith</h3>
<p>The first time I had to generate source code we wanted to generate a library to access the data of an external software in a type safe way with real properties and not throwing around with strings. The input was a xml configuration file of this software.</p>
<p>For this aim we used a freeware code generator named <a title="CodeSmtih 2.6 Freeware" href="http://www.codesmithtools.com/freeware.aspx">CodeSmith</a>. CodeSmith is a templating engine using C# or Visual Basic as embedded language and a syntax that is very similar to ASP. You can use all .Net framework classes and function within your template, load your own or 3rd party libraries into it and use all these classes as parameter of the template.</p>
<p>A few years later we had to generate code again and discovered that CodeSmith became a <a href="http://www.codesmithtools.com/">company</a> that sells an enhanced standard and professional version of the well known tool. They added a very powerful IDE to create and edit your templates and for the professional version Visual Studio integration and an API to use the engine with your templates in your applications.<br />
After buying the professional version we discovered that we cannot use CodeSmith for our needs. We wanted to build a product that generates code for the end-user on his machine but you are not allowed to distribute the CodeSmith libraries that are needed when you use the API. It took a long time for me to imagine a good usecases for an API like this if I cannot give my software away (or every user of my software has to buy a $399 licence of CodeSmith).<br />
Fortunately the old freeware version was capable of this. It can compile your template to C# code that runs without any external reference or library. You can add this code to your application and that&#8217;s it. You do not have the fancy IDE (or you can buy a CodeSmith licence and use the IDE but process your template with the freeware version &#8211; the syntax is nearly the same) and maybe not all of the features of the new version but it is free and works. The freeware version is still downloadable on their <a href="http://www.codesmithtools.com/freeware.aspx">webpage</a>.</p>
<h3>T4 &#8211; Text Templating Transformation Toolkit</h3>
<p>Visual Studio 2008 (aka. Orcas) comes with its own templating engine that is a free part of every Visual Studio Professional or Team System installation (free as in: you paid for it with your Visual Studio licence). This engine is powerful with C# (<a href="http://www.clariusconsulting.net/blogs/pga/archive/2008/01/22/53585.aspx">or even C# 3.0</a>) and Visual Basic as language and access the whole .Net framework and external assemblies as well.</p>
<p>Unfortunately there is no editor integrated in Visual Studio for the TT files. And even worse, you cannot use the engine out of the box. The DSL Tools use it but if you want to do so, you have to write code and access the public interfaces. But for both drawbacks there are solutions.</p>
<p>You can download a beta version of the <a href="http://www.t4editor.net/">T4 Editor</a>. It integrates in Visual Studio (the download for the Beta 2 works fine with the final version of Visual Studio for me, too) and has syntax highlighting for template files. It comes also with some Intellisense, but only for the template syntax and not for code you write inside your templates.</p>
<p>Then there is <a href="http://code.msdn.microsoft.com/TTxGen">TTxGen</a> that allows you to use every file you want as input for a template in a Visual Studio solution. It adds a template to the input file and generates the output from the input using the template. It&#8217;s really that easy. TTxGen is a very lightweight thing (only 45 kByte for the installer) because it delegates most of the work to the T4 stuff from Microsoft and adds only a few menus to Visual Studio.<br />
I had some trouble with the installation of the <a href="http://code.msdn.microsoft.com/TTxGen/Release/ProjectReleases.aspx?ReleaseId=136">February 2008 CTP release</a>. You can find my <a href="http://code.msdn.microsoft.com/TTxGen/Thread/View.aspx?ThreadId=90">workaround</a> at the discussions over at MSDN Code Gallery.</p>
<p>For one of my DSL Tools add-on libraries I use TTxGen to generate code from a xml file. Later I will post an article with the source code of the template that can be used as an example.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/02/28/codegeneration-with-codesmith-and-orcas-t4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Workaround for Known Issue with TypeConverters in DSL Tools for Visual Studio</title>
		<link>http://www.ticklishtechs.net/2008/02/06/workaround-for-known-issue-with-typeconverters-in-dsl-tools-for-visual-studio/</link>
		<comments>http://www.ticklishtechs.net/2008/02/06/workaround-for-known-issue-with-typeconverters-in-dsl-tools-for-visual-studio/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 00:01:05 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/02/06/workaround-for-known-issue-with-typeconverters-in-dsl-tools-for-visual-studio/</guid>
		<description><![CDATA[When I tried to add a Domain Property with a custom TypeConverter to my Domain Class I ran into serious problems. Sometimes it worked and this property was shown correctly in the properties window using the custom TypeConverter, but sometimes not. I was desperately searching for a bug in my code for hours but then [...]]]></description>
			<content:encoded><![CDATA[<p>When I tried to add a Domain Property with a custom TypeConverter to my Domain Class I ran into serious problems. Sometimes it worked and this property was shown correctly in the properties window using the custom TypeConverter, but sometimes not. I was desperately searching for a bug in my code for hours but then I figured out: Each first build after a solution cleanup was working and all other builds not. Even when I start the working build a second time without rebuilding it, the custom TypeConverter was not used.</p>
<p>This looks very much like the number 1.10 (the second 1.10 <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ) in the <a href="http://blogs.msdn.com/vsxteam/archive/2008/01/30/Known-Issues-for-Microsoft-Visual-Studio-2008-SDK-1.0.aspx">known issues list</a> posted on the <a href="http://blogs.msdn.com/vsxteam/">VSX Team blog</a>:</p>
<blockquote><p><strong>1.10 TypeConverters and TypeDescriptors are not picked up during the build process or during toolbox initialization.</strong><br />
When adding a custom TypeConverter or TypeDescriptor and then building the DSL, the TypeConvertor or TypeDescriptor is not picked up.  The workaround is to rebuild the solution with a clean build.</p></blockquote>
<p>And as you see: I discovered this workaround for myself, too. But I also found another workaround. I’m not sure if it is working for all situations with the described known issue but if you have the same problem you might want to try it. If it works or not, please comment some feedback here.</p>
<p>I simply used another constructor of the <code>TypeConverterAttribute</code>. Instead of providing the type information I used the constructor with a string:<br />
<!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20     \cf3 // this one does not work:\par ??\cf0     [\cf4 TypeConverter\cf0 (\cf5 typeof\cf0 (\cf4 DynamicPropertiesTypeConverter\cf0 ))]\par ??\par ??    \cf3 // this one is not nice, but works:\par ??\cf0     [\cf4 TypeConverter\cf0 (\cf6 "BenjaminSchroeter.DynamicPropertiesTypeConverter"\cf0 )] \par ??    \cf5 public\cf0  \cf5 class\cf0  \cf4 DynamicProperties\cf0  : \cf4 ICustomTypeDescriptor\par ??}<br />
--></p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px; padding:0px;"><span style="color: green;">// this one does not work:</span></p>
<p style="margin: 0px; padding:0px;">[<span style="color: #2b91af;">TypeConverter</span>(<span style="color: blue;">typeof</span>(<span style="color: #2b91af;">DynamicPropertiesTypeConverter</span>))]</p>
<p style="margin: 0px; padding:0px;">&nbsp;</p>
<p style="margin: 0px; padding:0px;"><span style="color: green;">// this one is not nice, but works:</span></p>
<p style="margin: 0px; padding:0px;">[<span style="color: #2b91af;">TypeConverter</span>(<span style="color: #a31515;">"BenjaminSchroeter.DynamicPropertiesTypeConverter"</span>)] </p>
<p style="margin: 0px; padding:0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">DynamicProperties</span> : <span style="color: #2b91af;">ICustomTypeDescriptor</span></p>
</div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/02/06/workaround-for-known-issue-with-typeconverters-in-dsl-tools-for-visual-studio/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CopySourceAsHtml Add-In with Visual Studio 2008</title>
		<link>http://www.ticklishtechs.net/2008/02/03/copysourceashtml-add-in-with-visual-studio-2008/</link>
		<comments>http://www.ticklishtechs.net/2008/02/03/copysourceashtml-add-in-with-visual-studio-2008/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 00:01:14 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/02/03/copysourceashtml-add-in-with-visual-studio-2008/</guid>
		<description><![CDATA[CopySourceAsHtml (CSAH) is a small and nice add-in for Visual Studio 2005 to copy the selected source code html-formatted to the clipboard. This is very useful if you want to paste this code into your blog (as I do here sometimes).
Unfortunately the current version 2.0.0 does not work with Visual Studio 2008 out of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/">CopySourceAsHtml (CSAH)</a> is a small and nice add-in for Visual Studio 2005 to copy the selected source code html-formatted to the clipboard. This is very useful if you want to paste this code into your blog (as I do here sometimes).</p>
<p>Unfortunately the current version 2.0.0 does not work with Visual Studio 2008 out of the box, but it is very simple to get it running. </p>
<p>The add-ins are located in below documents-folder in a path like this: <code>C:\Users \Benjamin \Documents \Visual Studio 2005 \Addins</code>. Just copy all files beginning with <code>CopySourceAsHtml*.*</code> to the corresponding folder for Visual Studio 2008: <code>C:\Users \Benjamin \Documents\ Visual Studio 2008 \Addins</code>.</p>
<p>Now you have to edit the <code>CopySourceAsHtml.AddIn</code> file with a text editor: only change at two positions in this short xml-file the <code>Version</code> value from <code>8.0</code> to <code>9.0</code>.</p>
<p>After a restart of Visual Studio 2008 you should find the CopySourceAsHtml add-in in the Tools / Add-in menu and of cause in the context menu of the code editor.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/02/03/copysourceashtml-add-in-with-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
