<?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; vsx</title>
	<atom:link href="http://www.ticklishtechs.net/tag/vsx/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>Sun, 07 Feb 2010 14:41:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flow</title>
		<link>http://www.ticklishtechs.net/2009/01/05/flow/</link>
		<comments>http://www.ticklishtechs.net/2009/01/05/flow/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 06:49:00 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flow]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/01/05/flow/</guid>
		<description><![CDATA[It was very silent here in the past month. That was mainly because I was working on my diploma thesis until the end of September. After that I did my final exam and started working in Bonn. Now it is December and almost 2009. I’m sitting in a plane to Australia for holiday and have [...]]]></description>
			<content:encoded><![CDATA[<p>It was very silent here in the past month. That was mainly because I was working on my diploma thesis until the end of September. After that I did my final exam and started working in Bonn. Now it is December and almost 2009. I’m sitting in a plane to Australia for holiday and have much time to write articles. I will try to keep this blog alive and will write articles more frequently.</p>
<p>Today I will introduce <em><strong>Flow</strong></em>. With <em>Flow</em> you can model the behavior of nodes in a wireless sensor network (WSN) in a data driven and event driven manor. I developed <em>Flow</em> as part of my diploma thesis.</p>
<p><em>Flow</em> is build as a Visual Studio Addon (a VS Package) on top of the DSL-Tools containing three different domain specific languages to describe different parts of the software running on a sensor node. These different DSLs are working together and using most of the techniques I described earlier in this blog. E.g. my library JaDAL was initially build to support this diploma thesis.</p>
<p>You will find screenshots, more explanations and <em>Flow</em> itself on <a href="http://flow.irgendwie.net">http://flow.irgendwie.net</a>. While the webpage and the software are available in English the thesis itself is a pdf-document and can only be downloaded in a German version.</p>
<p>The software is fully working and if no wireless sensor network is available you can use a node simulator to evaluate <em>Flow</em>. The code is released under the new BSD license and also available for download.</p>
<h3>Screenshots:</h3>
<p>Dataflows modeled with <em>Flow</em> looks like that:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2009/01/dataflow.png"><img style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" title="dataflow" src="http://www.ticklishtechs.net/wp-content/uploads/2009/01/dataflow-thumb.png" border="0" alt="dataflow" width="456" height="191" /></a></p>
<p>The simulated sensor nodes are represented as Windows forms programmed by such dataflows:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2009/01/simulatednode.png"><img style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" title="simulatednode" src="http://www.ticklishtechs.net/wp-content/uploads/2009/01/simulatednode-thumb.png" border="0" alt="simulatednode" width="182" height="244" /></a></p>
<p>For more information just visit <a href="http://flow.irgendwie.net">http://flow.irgendwie.net</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/01/05/flow/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DirectiveProcessor for VSX</title>
		<link>http://www.ticklishtechs.net/2008/10/15/directiveprocessor-for-vsx/</link>
		<comments>http://www.ticklishtechs.net/2008/10/15/directiveprocessor-for-vsx/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 20:20:33 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[t4]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/10/15/directiveprocessor-for-vsx/</guid>
		<description><![CDATA[I created two DirectiveProcessor for Visual Studio to use in the T4 system. I added the classes to JaDAL hoping someone can use them in her project or use the code as an example when creating new DirectiveProcessors.
Let&#8217;s start with a short introduction to DirectiveProcessors. DirectiveProcessors are used in .tt-files to provide data to the [...]]]></description>
			<content:encoded><![CDATA[<p>I created two DirectiveProcessor for Visual Studio to use in the T4 system. I added the classes to JaDAL hoping someone can use them in her project or use the code as an example when creating new DirectiveProcessors.</p>
<p>Let&#8217;s start with a short introduction to DirectiveProcessors. DirectiveProcessors are used in .tt-files to provide data to the template. The DirectiveProcessor can take parameters from the declaration in the .tt-file and adds some code to the compiled template. This code (often properties) can be used from within the template. For example the DSL Tools are generating one DirectiveProcessor for each DSL model. In a template form the DSL Tools you will see a line like the following:</p>
<p><span style="background: gold">&lt;#@</span><span style="color: red;"> Language1 </span><span style="color: red;">processor=</span>&#8220;<span style="color: blue;">Language1DirectiveProcessor</span>&#8221;<br />
<span style="color: red;">requires=</span>&#8220;<span style="color: blue;">fileName=&#8217;Sample.mydsl1&#8242;</span>&#8221; <span style="background: gold">#&gt;</span></p>
<p>This line uses the <code>Language1DirectiveProcessor</code> and provides it with one parameter (<code>fileName</code>). The DirectiveProcessor adds code to the template to open the given file and creates (in this case) a <code>ExampleModel</code>-property to use in the template code.</p>
<p>I created two DirectiveProcessors to use the data of simple Xml-files and Visual Studio Project files in the templates. The code of the two DirectiveProcessors is very straight forward and maybe one could advance it (e.g. make it compatible with templates written in Visual Basic).</p>
<h3>Using the XmlFileDirectiveProcessor</h3>
<p>Add a line like the following to your .tt-file:</p>
<p><span style="background: gold">&lt;#@</span><span style="color: red;"> XmlFile processor=</span>&#8220;<span style="color: blue;">XmlFileDirectiveProcessor</span>&#8221; <span style="color: red;">FileName=</span>&#8220;<span style="color: blue;">example.xml</span>&#8221; <span style="background: gold">#&gt;</span></p>
<p>Inside this template you can access the (full qualified) filename via the <code>this.XmlFileName</code>-Property and the Content of this file (as a <code>XDocument</code>) via the <code>this.XmlFile</code>-Property.</p>
<h3>Using the VsProjectFileDirectiveProcessor</h3>
<p>Add this line to your template:</p>
<p><span style="background: gold">&lt;#@</span><span style="color: red;"> ProjectFile processor=</span>&#8220;<span style="color: blue;">VsProjectFileDirectiveProcessor</span>&#8221; <span style="color: red;">FileName=</span>&#8220;<span style="color: #0000ff;">x.csproj</span>&#8221; <span style="background: gold">#&gt;</span></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>A property named <code>this.ProjectFile</code> will be added to the template. This property provides you with an instance of the <code>VsProjectFile</code>-class containing the project file contents. This class contains only very little functionality (feel free to add some more and submit it back to me!). Just take a look at the source code of this class. The method <code>GetAllFiles()</code> returns a string array of all files found in the project (supporting C++ and C# project files &#8211; .vcproj and .csproj).</p>
<h3>Setup</h3>
<p>An entry in the registry is needed to allow the T4 system to find custom DirectiveProcessors. Just add the following entries to your registry and don&#8217;t forget to point to the right location of the <code>JaDAL.dll</code>.</p>
<p>[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0Exp\<br />
Configuration\TextTemplating\DirectiveProcessors\VsProjectFileDirectiveProcessor]<br />
&#8220;Class&#8221;=&#8221;BenjaminSchroeter.Dsl.DirectiveProcessors.VsProjectFileDirectiveProcessor&#8221;<br />
&#8220;CodeBase&#8221;=&#8221;D:\\JaDAL\\bin\\Debug\\JaDAL.dll&#8221;</p>
<p>[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0Exp\<br />
Configuration\TextTemplating\DirectiveProcessors\XmlFileDirectiveProcessor]<br />
&#8220;Class&#8221;=&#8221;BenjaminSchroeter.Dsl.DirectiveProcessors.XmlFileDirectiveProcessor&#8221;<br />
&#8220;CodeBase&#8221;=&#8221;D:\\JaDAL\\bin\\Debug\\JaDAL.dll&#8221;</p>
<p>These registry keys are for the Experimental Hive of Visual Studio. To register the DirectiveProcessors for the normal Visual Studio instance the registry key starts with HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0<br />
\TextTemplating\DirectiveProcessors\</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/10/15/directiveprocessor-for-vsx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting rid of the DSL model explorer</title>
		<link>http://www.ticklishtechs.net/2008/07/27/getting-rid-of-the-dsl-model-explorer/</link>
		<comments>http://www.ticklishtechs.net/2008/07/27/getting-rid-of-the-dsl-model-explorer/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 08:19:41 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/07/27/getting-rid-of-the-dsl-model-explorer/</guid>
		<description><![CDATA[Every DSL you create with DSL Tools has a model explorer. This model explorer is a tool window in Visual Studio displaying the elements of your model in a hierarchical way. This is often a nice feature but sometimes a hierarchical view of your data is not appropriate. So I came to the question: How [...]]]></description>
			<content:encoded><![CDATA[<p>Every DSL you create with DSL Tools has a model explorer. This model explorer is a tool window in Visual Studio displaying the elements of your model in a hierarchical way. This is often a nice feature but sometimes a hierarchical view of your data is not appropriate. So I came to the question: <em>How to remove the explorer from the generated code?</em></p>
<p>I could not find any option in the DSL design to remove the model explorer, but if you look at some of the .tt files you will find somewhere a query for <code>this.Dsl.Explorer != null</code>. For example in the <code>package.tt</code> file that generates the <code>package.cs</code> which is responsible for registering the tool window for the model explorer:</p>
<pre class="code"><span style="background: gold">&lt;#
</span><span style="background: #f0f8ff none repeat scroll 0% 0%; color: #191970;">    if(this.Dsl.Explorer != null)
    {
</span><span style="background: gold">#&gt;
</span><span style="color: red;">    </span><span style="color: gray;">[VSShell::ProvideToolWindow(         typeof(</span><span style="background: gold">&lt;#=</span><span style="background: #f0f8ff none repeat scroll 0% 0%; color: #191970;"> dslName </span><span style="background: gold">#&gt;</span><span style="color: gray;">ExplorerToolWindow),          MultiInstances = false,          Style = VSShell::VsDockStyle.Tabbed,          Orientation = VSShell::ToolWindowOrientation.Right,          Window = "{3AE79031-E1BC-11D0-8F78-00A0C9110057}")]
    [VSShell::ProvideToolWindowVisibility(         typeof(</span><span style="background: gold">&lt;#=</span><span style="background: #f0f8ff none repeat scroll 0% 0%; color: #191970;"> dslName </span><span style="background: gold">#&gt;</span><span style="color: gray;">ExplorerToolWindow),          Constants.</span><span style="background: gold">&lt;#=</span><span style="background: #f0f8ff none repeat scroll 0% 0%; color: #191970;"> dslName </span><span style="background: gold">#&gt;</span><span style="color: gray;">EditorFactoryId)]
</span><span style="background: gold">&lt;#
</span><span style="background: #f0f8ff none repeat scroll 0% 0%; color: #191970;">    }
</span><span style="background: gold">#&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>Even if I did not find any option to set the <code>Dsl.Explorer</code> property of the model to <code>null</code> (you did not see the Explorer property anywhere in the DSL diagram) it seems that the developers of the DSL Tools had this use case in mind.</p>
<p>To remove the <code>Dsl.Explorer</code> from your DSL model open the <code>.dsl</code> file with a text editor and go to the end. There you will find some XML tags like the following:</p>
<pre class="code"><span style="color: blue;">&lt;</span><span style="color: #a31515;">Explorer </span><span style="color: red;">ExplorerGuid</span><span style="color: blue;">=</span>"<span style="color: blue;">6c276297-6acd-4e9a-8740-b61ba834004b</span>"  <span style="color: red;">Title</span><span style="color: blue;">=</span>"<span style="color: blue;">HardwareDescription Explorer</span>"<span style="color: blue;">&gt;
    &lt;</span><span style="color: #a31515;">ExplorerBehaviorMoniker      </span><span style="color: red;">Name</span><span style="color: blue;">=</span>"<span style="color: blue;">HardwareDescription/HardwareDescriptionExplorer</span>" <span style="color: blue;">/&gt;
&lt;/</span><span style="color: #a31515;">Explorer</span><span style="color: blue;">&gt;
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Just delete these three lines and generate your code once again. Maybe you should reset your Experimental Hive, too.</p>
<p>I tested a DSL with a removed Model Explorer without any problems. It seems the developers of the DSL Tools did a very good job on the code generation templates . The generated <code>ModelExplorer.cs</code> file contains only a single line:</p>
<pre class="code"><span style="color: green;">// This source file is empty because    this DSL does not define a model explorer.
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>That should be a good proof that a DSL can run without the model explorer even if it might be not supported by the DSL Tools. <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/07/27/getting-rid-of-the-dsl-model-explorer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Workaround for Known Issue with TypeDescriptors in DSL Tools for Visual Studio</title>
		<link>http://www.ticklishtechs.net/2008/07/19/workaround-for-known-issue-with-typedescriptors-in-dsl-tools-for-visual-studio/</link>
		<comments>http://www.ticklishtechs.net/2008/07/19/workaround-for-known-issue-with-typedescriptors-in-dsl-tools-for-visual-studio/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 17:28:38 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/07/19/workaround-for-known-issue-with-typedescriptors-in-dsl-tools-for-visual-studio/</guid>
		<description><![CDATA[There is a known issue in the current version of the DSL Tools while dealing with custom TypeConverters or custom TypeDescriptors:
1.10 TypeConverters and TypeDescriptors are not picked up during the build process or during toolbox initialization.
When adding a custom TypeConverter or TypeDescriptor and then building the DSL, the TypeConvertor or TypeDescriptor is not picked up. [...]]]></description>
			<content:encoded><![CDATA[<p>There is a known issue in the current version of the DSL Tools while dealing with custom TypeConverters or custom TypeDescriptors:</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>
<p>[see <a href="http://blogs.msdn.com/vsxteam/archive/2008/01/30/Known-Issues-for-Microsoft-Visual-Studio-2008-SDK-1.0.aspx">Known Issues for Microsoft Visual Studio 2008 SDK 1.0</a>]</p></blockquote>
<p>Some time ago I <a href="http://www.ticklishtechs.net/2008/02/06/workaround-for-known-issue-with-typeconverters-in-dsl-tools-for-visual-studio/">posted a workaround</a> for this problem with the TypeConverter, but today a realized that this workaround does not work with the same issue for TypeDescriptors.</p>
<p>Imagine some class with the following attribute:</p>
<pre class="code">[TypeDescriptionProvider(<span style="color: blue;">typeof</span>(MyClassTypeDescriptionProvider))]
<span style="color: blue;">public partial class </span><span style="color: #2b91af;">MyClass </span>: ModelElement
{}</pre>
<p>The corresponding TypeDescriptor (provided by the <code>MyClassTypeDescriptionProvider</code> class) is loaded only the first time you build or rebuild your solution. Every time you start Visual Studio after that, this attribute seems to be ignored.</p>
<p>Fortunately there is another way to glue TypeDescriptors to your classes using a static method of the <code>TypeDescriptor</code> class at runtime:</p>
<pre class="code"><span style="color: #2b91af;">TypeDescriptor</span>.AddProvider(
   <span style="color: blue;">new </span><span style="color: #2b91af;">MyClassTypeDescriptionProvider</span>(), <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">MyClass</span>));</pre>
<p>I think a good place for this code is the static constructor of the <code>MyClass</code> type:</p>
<pre class="code"><span style="color: blue;">partial class </span><span style="color: #2b91af;">MyClass
</span>{
    <span style="color: blue;">static </span>MyClass()
    {
        <span style="color: #2b91af;">TypeDescriptor</span>.AddProvider(
            <span style="color: blue;">new </span>MyClassTypeDescriptionProvider(),
            <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">MyClass</span>));
    }
}</pre>
<p>Another interesting point is: Not only custom TypeDescriptors you write yourself are affected by this problem, also the TypeDescriptors that are generated by the DSL-Tools from your DslDefintion have to struggle with it:</p>
<p>In the <em>DSL Explorer</em> you can define custom TypeDescriptors for each <em>Domain Class</em> and each <em>Shape</em>. Even these TypeDescriptors will not be loaded after the first run. In other words: the definition of TypeDescriptors in the DSL Explorer is pretty useless as long as you do not add the three lines of code to each class. Of course this is something one can automate! <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I stole some code from <code>PropertiesGrid.tt</code> and added a few lines to create the <code>RegisterTypeDescriptor.tt</code>. Just add this file to your <code>Dsl</code> Project in the <code>GeneratedCode</code> folder and all TypeDescriptors defined in the <em>DSL Explore</em>r will be loaded every time you start your project.</p>
<div id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:1be880e0-1a85-4229-a307-aca8a23064bf" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<p>Download: <a href="http://www.ticklishtechs.net/wp-content/uploads/2008/07/registertypedescriptors.zip" target="_blank">RegisterTypeDescriptors.tt</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/07/19/workaround-for-known-issue-with-typedescriptors-in-dsl-tools-for-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where can I find the model filename in a text template (tt)?</title>
		<link>http://www.ticklishtechs.net/2008/07/03/where-can-i-find-the-model-filename-in-a-text-template-tt/</link>
		<comments>http://www.ticklishtechs.net/2008/07/03/where-can-i-find-the-model-filename-in-a-text-template-tt/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 00:46:18 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[t4]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/07/03/where-can-i-find-the-model-filename-in-a-text-template-tt/</guid>
		<description><![CDATA[As you know I was working with the DSL Tools in the past months. For some weeks I am writing the code generation for my project and I am struggling with new problems.
For some reason I want to know the filename of the model used in the tt-file. The default implementation provides you only with [...]]]></description>
			<content:encoded><![CDATA[<p>As you know I was working with the DSL Tools in the past months. For some weeks I am writing the code generation for my project and I am struggling with new problems.</p>
<p>For some reason I want to know the filename of the model used in the tt-file. The default implementation provides you only with a reference to the model but with no chance to get its filename.</p>
<p>In your tt-file you will find something similar to</p>
<pre class="code"><span style="background: gold">&lt;#@</span><span style="color: red;"> Language15 processor=</span>"<span style="color: blue;">Language15DirectiveProcessor</span>"
     <span style="color: red;">requires=</span>"<span style="color: blue;">fileName='Sample.mydsl1'</span>" <span style="background: gold">#&gt;</span></pre>
<p>This will use the <code>Language15DirectiveProcessor</code> to load the given file and provide your template with a global <code>ExampleModel</code> variable (of cause the name depends on your DSL and you can change it with the <code>provides</code> attribute in the tt-file).</p>
<p>To change the <code>Language15DirectiveProcessor</code> you can create a partial class in your DSL and add some code to it:</p>
<pre class="code"><span style="color: blue;">partial class </span><span style="color: #2b91af;">Language15DirectiveProcessor
</span>{
    <span style="color: blue;">protected override void </span>GenerateTransformCode
     (<span style="color: blue;">string </span>directiveName,
      <span style="color: #2b91af;">StringBuilder </span>codeBuffer,
      System.CodeDom.Compiler.<span style="color: #2b91af;">CodeDomProvider </span>languageProvider,
      <span style="color: #2b91af;">IDictionary</span>&lt;<span style="color: blue;">string</span>, <span style="color: blue;">string</span>&gt; requiresArguments,
      <span style="color: #2b91af;">IDictionary</span>&lt;<span style="color: blue;">string</span>, <span style="color: blue;">string</span>&gt; providesArguments)
      {
        <span style="color: blue;">base</span>.GenerateTransformCode(directiveName,
                    codeBuffer, languageProvider,
                    requiresArguments, providesArguments);           

        codeBuffer.AppendFormat(
           <span style="color: #a31515;">"public string {1} = @\"{0}\";"</span>,
             requiresArguments[<span style="color: #a31515;">"FileName"</span>],
             providesArguments[<span style="color: #a31515;">"FileName"</span>]);</pre>
<pre class="code">       codeBuffer.AppendLine();
    }

    <span style="color: blue;">protected override void </span>InitializeProvidesDictionary
    (<span style="color: blue;">string </span>directiveName,
      <span style="color: #2b91af;">IDictionary</span>&lt;<span style="color: blue;">string</span>, <span style="color: blue;">string</span>&gt; providesDictionary)
    {
        <span style="color: blue;">base</span>.InitializeProvidesDictionary(directiveName,
                            providesDictionary);

        providesDictionary.Add(<span style="color: #a31515;">"FileName"</span>,<span style="color: #a31515;">"FileName"</span>);
    }
}</pre>
<p>This adds a new global variable <code>FileName</code> to the tt and initializes it with the model file name.</p>
<p><strong>Attention:</strong> You see the variable in this example is generated by writing a line of C# code to the <code>codeBuffer</code>. This may be a bad idea if you want to use this DirectiveProcessor for templates where the template language is set to VB. The better way is to create the code using the Emit and CodeDom API, but I was to lazy to do it that way.</p>
<p>If anybody ports this code to work with VB templates by using the CodeDom or plain VB code, please post a comment here.</p>
<p><strong>Further reading</strong>: The process of creating your own DirectiveProcessor and everything you need to understand the code above can be found in the msdn: <a href="http://msdn.microsoft.com/en-us/library/bb126315.aspx">Creating Custom Text Template Directive Processors</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/07/03/where-can-i-find-the-model-filename-in-a-text-template-tt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual feedback for black connectors on mouse over</title>
		<link>http://www.ticklishtechs.net/2008/06/26/visual-feedback-for-black-connectors-on-mouse-over/</link>
		<comments>http://www.ticklishtechs.net/2008/06/26/visual-feedback-for-black-connectors-on-mouse-over/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 01:31:47 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/06/26/visual-feedback-for-black-connectors-on-mouse-over/</guid>
		<description><![CDATA[One of my DSLs uses many black connectors laying all over the screen. Every time I try to follow one connector I select it to change the border and to see a difference between all connectors. A colleague saw this design and asks me to implement a mouse over feedback for these connectors since all [...]]]></description>
			<content:encoded><![CDATA[<p>One of my DSLs uses many black connectors laying all over the screen. Every time I try to follow one connector I select it to change the border and to see a difference between all connectors. A colleague saw this design and asks me to implement a mouse over feedback for these connectors since all shapes have already such a visual feedback. The color of shapes changes a little bit if the mouse is over the shape. I had no idea how this should work for connectors&#8230;</p>
<p>First I take a look on the properties of the connector in the DSL designer and while searching I observed something: The DSL designer has this behavior on all connectors! I don&#8217;t have to write code for the MouseOver-event, but I have to figure out how to activate this behavior on my DSL editor.</p>
<p>For my surprise, the connectors on a newly created example language have a mouse over feedback, too. After playing around with some properties I was faced to a interesting fact: The mouse over feedback works pretty good for all connectors but black ones. I had no idea what&#8217;s going on.</p>
<p>Long story short: With Reflector I found one interesting method in the <a title="ShapeElement Class" href="http://msdn2.microsoft.com/bb161622.aspx">ShapeElement</a> class: <a title="ShapeElement..::.ModifyLuminosity Method " href="http://msdn2.microsoft.com/bb129238.aspx">ModifyLuminosity()</a>. The documentation is very clear: </p>
<blockquote><p>&quot;Calculates the luminosity of the highlight for the shape.&quot;     </p>
<p>&quot;The formula that creates luminosity. By default, the formula is: if luminosity is &gt;= 160, then luminosity = luminosity * 0.9; otherwise, luminosity = luminosity + 40.&quot;</p>
</blockquote>
<p>The luminosity of a black connector is 0 so the new luminosity will be 40. But for the color black you hardly see a difference between 0 and 40. But with this knowledge you can override the method in the connector class like this:</p>
<pre class="code"><span style="color: blue">protected override int </span>ModifyLuminosity
              (<span style="color: blue">int </span>currentLuminosity, <span style="color: #2b91af">DiagramClientView </span>view)
{
  <span style="color: blue">if(</span>!view.HighlightedShapes.Contains(<span style="color: blue">new </span><span style="color: #2b91af">DiagramItem</span>(<span style="color: blue">this</span>)))
     <span style="color: blue">return </span>currentLuminosity;

 <span style="color: blue">return </span>130;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The value 130 on a black connector works pretty good for me. Just try a few values und find a value you like.</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="280" alt="HighlightedConnector" src="http://www.ticklishtechs.net/wp-content/uploads/2008/06/highlightedconnector.png" width="470" border="0" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/06/26/visual-feedback-for-black-connectors-on-mouse-over/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom restrictions for Domain Properties</title>
		<link>http://www.ticklishtechs.net/2008/05/26/custom-restrictions-for-domain-properties/</link>
		<comments>http://www.ticklishtechs.net/2008/05/26/custom-restrictions-for-domain-properties/#comments</comments>
		<pubDate>Mon, 26 May 2008 09:43:47 +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[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/05/26/custom-restrictions-for-domain-properties/</guid>
		<description><![CDATA[In To restrict dynamically the usage of Domain Properties in DSL Models I described a way to restrict the usage of certain domain properties by the user. You can define different modes for your editor and thus allow or prevent the usage of domain properties via attributes on your domain classes. The technique is described [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/">To restrict dynamically the usage of Domain Properties in DSL Models</a> I described a way to restrict the usage of certain domain properties by the user. You can define different modes for your editor and thus allow or prevent the usage of domain properties via attributes on your domain classes. The technique is described in the linked article and the code is released as part of <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a>.</p>
<p>This is a pretty static way to control the domain properties. You have to define a few modes and decide at design time the visible and active properties for each mode. Sometimes you need a more dynamic way: So I introduced another attribute <code>CustomRestrictedPropertyAttribute</code> and an interface <code>ISupportsUserRestrictions</code>. If this attribute is present, the library will call the <code>GetRestriction()</code> method of this interface and your user code can decide whenever the domain property will be visible, hidden or read only.</p>
<p>I built a small example: a domain class contains a few properties: <em>CustomPropery</em>, <em>CustomPropertyVisible</em> and <em>CustomPropertyReadOnly</em>. The two flags cause the first property to be visible, hidden or read only in the properties window. </p>
<pre class="code">[<span style="color: #2b91af">CustomRestrictedProperty</span>(<span style="color: #a31515">&quot;CustomProperty&quot;</span>)]
<span style="color: blue">partial class </span><span style="color: #2b91af">ExampleElement </span>: <span style="color: #2b91af">ISupportsUserRestrictions
</span>{
    <span style="color: blue">public </span><span style="color: #2b91af">Restriction </span>GetRestriction(<span style="color: blue">string </span>property)
    {
        <span style="color: blue">if </span>(property == <span style="color: #a31515">&quot;CustomProperty&quot;</span>)
        {
            <span style="color: blue">if </span>(!<span style="color: blue">this</span>.CustomPropertyVisible)
                <span style="color: blue">return </span><span style="color: #2b91af">Restriction</span>.Hidden;

            <span style="color: blue">if </span>(<span style="color: blue">this</span>.CustumPropertyReadOnly)
                <span style="color: blue">return </span><span style="color: #2b91af">Restriction</span>.ReadOnly;

            <span style="color: blue">return </span><span style="color: #2b91af">Restriction</span>.Full;
        }

        <span style="color: blue">return </span><span style="color: #2b91af">Restriction</span>.Full;
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/properties.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="168" alt="properties" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/properties-thumb.png" width="490" border="0" /></a> </p>
<p>This example can be downloaded as part of the <a href="http://www.codeplex.com/JaDAL/SourceControl/ListDownloadableCommits.aspx">JaDAL source code</a>. Currently you have to catch the code directly from the Source Code tab at <a href="http://www.codeplex.com">CodePlex</a> since it isn&#8217;t part of the latest Release yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/05/26/custom-restrictions-for-domain-properties/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JaDAL &#8211; Just another DSL-Tools Addon Library</title>
		<link>http://www.ticklishtechs.net/2008/05/21/jadal-just-another-dsl-tools-addon-library/</link>
		<comments>http://www.ticklishtechs.net/2008/05/21/jadal-just-another-dsl-tools-addon-library/#comments</comments>
		<pubDate>Wed, 21 May 2008 10:43:31 +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[release]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/05/21/jadal-just-another-dsl-tools-addon-library/</guid>
		<description><![CDATA[Over the time I build some libraries that enhance the Microsoft DSL Tools framework and post them here. I wrote a number of articles and for many of them I provided a download with source code or examples. 
However we all know: zip files are a bad version management system!
I decided to put all these [...]]]></description>
			<content:encoded><![CDATA[<p>Over the time I build some libraries that enhance the <a href="http://msdn.com/vsx">Microsoft DSL Tools framework</a> and post them here. I wrote <a href="http://www.ticklishtechs.net/tag/dsl/">a number of articles</a> and for many of them I provided a download with source code or examples. </p>
<p><em>However we all know: zip files are a bad version management system!</em></p>
<p>I decided to put all these code together and compose a single library with addons for the DSL Tools, name it &#8220;<a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a>&#8221; and publish it at <a href="http://www.codeplex.com">CodePlex</a>. I will continue to write articles here, but now you can always find the latest code at CodePlex. </p>
<p>If you are interested in my work with the DSL Tools, just take a look at <a href="http://www.codeplex.com/JaDAL">JaDAL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/05/21/jadal-just-another-dsl-tools-addon-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connectors between compartment shape entries with DSL Tools &#8211; Version 2</title>
		<link>http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/</link>
		<comments>http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/#comments</comments>
		<pubDate>Wed, 21 May 2008 01:13:38 +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[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/</guid>
		<description><![CDATA[Few months ago I wrote a series of articles and released a library to create connectors between the entries of compartment shapes in Microsoft DSL Tools. In the meantime I found a setting that wasn&#8217;t working with my library and now it is time for version 2. I will release this new version as part [...]]]></description>
			<content:encoded><![CDATA[<p>Few months ago I wrote a <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">series of articles</a> and released a library to create connectors between the entries of compartment shapes in Microsoft DSL Tools. In the meantime I found a setting that wasn&#8217;t working with my library and now it is time for version 2. I will release this new version as part of <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> on <a href="http://www.codeplex.com">CodePlex</a>.</p>
<p>If you don&#8217;t have any idea what I&#8217;m talking about please take a look at (at least) the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">first part</a> of the series, but be careful and DO NOT read the second part! The second part contains obsolete information that will be corrected here. <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> describe the inside of the library and they are still valid for the new version.</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/sample.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="226" alt="sample" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/sample-thumb.png" width="440" border="0" /></a> </p>
<h3>Changes from version 1 to 2</h3>
<p>In the original version you have to decide (using the xml file) for the target and source of the connection to be mapped to a compartment or a regular shape. I thought this wouldn&#8217;t be an issue since you must know the mapping of your classes. I believed it until I created my DSL with the use of inheritance and some base class that can be mapped to regular or compartment shapes. For this base class I couldn&#8217;t create a mapping that goes from a regular or a compartment shape to a regular or compartment shape. </p>
<p>I removed this constraint and in version 2 you needn&#8217;t care about it. The library can handle all these cases (even the trivial mapping from regular to regular shape). And even the best: it turned out that removing this constraint made the code much clearer and simpler (both the code of the library itself and the code you have to write). Before this change there were many different cases (first regular to compartment, then compartment to regular, then compartment to compartment and at the end regular to regular which throws an exception) and now everything works the same way.</p>
<p><em>Lesson learned: If you can do something in an abstract and general way, don&#8217;t create different cases and handle only some of them!</em></p>
<h3>And again: the user guide</h3>
<p>In the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">2nd part</a> of this series I presented a user guide with a step by step walkthrough of creating a DSL using the compartment mapping. I will now create the same DSL with version 2. Most steps are still the same but I repeat them for completeness. The main difference is the xml file format at step 7 and the class you have to write yourself in steps 9 to 11.</p>
<p>You will find this example (and a more advanced one) in the release download over at CodePlex.</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 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 another. 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>JaDAL.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">CompartmentMappings </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.CompartmentMapping</span>&quot;<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: red">allowSelfReference</span><span style="color: blue">=</span>&quot;<span style="color: blue">true</span>&quot;
    <span style="color: red">suppressEntryDeletePropagation</span><span style="color: blue">=</span>&quot;<span style="color: blue">false</span>&quot;<span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">Source </span><span style="color: red">allowHead</span><span style="color: blue">=</span>&quot;<span style="color: blue">false</span>&quot;<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">Source</span><span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">Target </span><span style="color: red">allowHead</span><span style="color: blue">=</span>&quot;<span style="color: blue">true</span>&quot;<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">Target</span><span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">Connector </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">CompartmentShape </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">CompartmentShape </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">CompartmentMappings</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>CompartmentMappings.tt</code> file in the same directory, 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">CompartmentMappings.tt</span>&quot; <span style="background: gold">#&gt;</span></pre>
<p>(Be sure you use the right xml file name here.)</p>
</li>
<li>Now you have to write some code by yourself. In the generated cs file (<code>CompartmentMappings_xGen.cs</code>) there will be a class named <code>Parent1ReferencesParent2BuilderInstance </code>with three missing methods you have to override. Create a partial class in a new file and implement these methods (see 10 and 11).
<p></li>
<li>Implement 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;
    result = <span style="color: blue">new </span><span style="color: #2b91af">Parent1ReferencesParent2</span>(source, target);
    <span style="color: blue">if</span>(sourcePartType== <span style="color: #2b91af">SelectedCompartmentPartType</span>.Head)
        <span style="color: green">// use a empty guid for the Head
        </span>result.fromEntry = <span style="color: #2b91af">Guid</span>.Empty;
    <span style="color: blue">else
        </span>result.fromEntry = sourceEntry.Guid;

    <span style="color: blue">if</span>(targetPartType== <span style="color: #2b91af">SelectedCompartmentPartType</span>.Head)
        <span style="color: green">// use a empty guid for the Head
        </span>result.toEntry = <span style="color: #2b91af">Guid</span>.Empty;
    <span style="color: blue">else
        </span>result.toEntry = targetEntry.Guid;

    <span style="color: blue">return </span>result;
}</pre>
<p>    <a href="http://11011.net/software/vspaste"></a></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 additional 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)
{
    <span style="color: blue">if </span>(entry == <span style="color: blue">null</span>)
        <span style="color: blue">return </span>connection.fromEntry.Equals(<span style="color: #2b91af">Guid</span>.Empty);

    <span style="color: blue">return </span>connection.fromEntry.Equals(entry.Guid);
}

<span style="color: blue">public override bool </span>IsEntryConnectionTarget
    (<span style="color: #2b91af">Entry2 </span>entry,
     <span style="color: #2b91af">Parent1ReferencesParent2 </span>connection)
{
    <span style="color: blue">if </span>(entry == <span style="color: blue">null</span>)
        <span style="color: blue">return </span>connection.toEntry.Equals(<span style="color: #2b91af">Guid</span>.Empty);

    <span style="color: blue">return </span>connection.toEntry.Equals(entry.Guid);
}</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 to be 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. The mapping from compartment entry to compartment entry should be working after compiling the solution.</p>
<h3>Advanced Features</h3>
<p>As I mention above you can mix compartment and regular shapes. You only need to create a DSL with these shapes and configure the xml file another way. As you see, inside the <code>&lt;Connection&gt;</code> element there is no longer a reference to the diagram elements, only the domain classes are used here. Obviously if you use inheritance all your classes need to have the same base class for <code>&lt;DomainClass&gt;</code> itself and for <code>&lt;EntryDomainClass&gt;</code>. If the concrete class is mapped to a compartment shape, the compartment mappings, otherwise a mapping of regular shapes, will be used.</p>
<p>If one of source or target is always a regular shape, please use <code>ModelElement</code> for <code>&lt;EntryDomainClass&gt;</code>.</p>
<p>At the bottom of the xml file you have to list all shapes that play a role in your mapping. Use the xml elements <code>&lt;CompartmentShape&gt;</code> and <code>&lt;RegularShape&gt;</code> therefore.</p>
<p>Inside your <code>Parent1ReferencesParent2BuilderInstance</code> class you can override some more methods to allow or forbid the creation of connectors. I think the names and signatures speak for themselves:</p>
<ul>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptAsCompartmentSource (SOURCE_ELEMENT candidate,   <span style="color: #2b91af">SelectedCompartmentPartType </span>partType,   SOURCE_COMPARTMENT_ENTRY candidateEntry)</pre>
</li>
<p>  <a href="http://11011.net/software/vspaste"></a></p>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptAsCompartmentTarget (TARGET_ELEMENT candidate,   <span style="color: #2b91af">SelectedCompartmentPartType </span>partType,   TARGET_COMPARTMENT_ENTRY candidateEntry)</pre>
</li>
<p>  <a href="http://11011.net/software/vspaste"></a></p>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptAsCompartmentSourceAndTarget  (SOURCE_ELEMENT sourceElement, <span style="color: #2b91af">  SelectedCompartmentPartType </span>sourcePartType,   SOURCE_COMPARTMENT_ENTRY sourceEntry,   TARGET_ELEMENT targetElement, <span style="color: #2b91af">  SelectedCompartmentPartType </span>targetPartType,   TARGET_COMPARTMENT_ENTRY targetEntry)</pre>
</li>
</ul>
<h3>Advanced Sample</h3>
<p>In addition to the sample above I build a second one. There I want to create mappings form some <em>Inputs</em> to some <em>Outputs</em>, where one of these <em>Inputs</em> or <em>Outputs</em> can be an entry of a compartment shape or a whole regular shape. This regular shape contains a property <em>Kind</em> that makes the shape to an <em>Input </em>or an <em>Output</em> (to show you the use of the <code>CanAcceptAs...</code> methods).</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/advancedsample.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="207" alt="advancedsample" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/advancedsample-thumb.png" width="440" border="0" /></a> </p>
<p>The DSL model looks like this:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/advanceddslmodel.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="268" alt="advanceddslmodel" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/advanceddslmodel-thumb.png" width="444" border="0" /></a> </p>
<p>The project with all sources is part of the samples in the JaDAL download.</p>
<h3>Download</h3>
<p>The compartment mapping library and both samples are part of <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> which you can download from <a href="http://www.codeplex.com">CodePlex</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Changing the title of Compartments using code</title>
		<link>http://www.ticklishtechs.net/2008/05/20/changeing-the-title-of-compartments-using-code/</link>
		<comments>http://www.ticklishtechs.net/2008/05/20/changeing-the-title-of-compartments-using-code/#comments</comments>
		<pubDate>Tue, 20 May 2008 10:13:30 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/05/20/change-the-title-of-compartments-using-code/</guid>
		<description><![CDATA[When using CompartmentShapes in your DSL you can define the text displayed in the head of each compartment in the DSL designer (there is a property Title for every compartment):

Unfortunately I didn&#8217;t find any way to change this text from my source code or by binding it to some DomainProperty. I&#8217;m using an abstract base [...]]]></description>
			<content:encoded><![CDATA[<p>When using CompartmentShapes in your DSL you can define the text displayed in the head of each compartment in the DSL designer (there is a property <em>Title</em> for every compartment):</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="133" alt="compartmentheadertext" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/compartmentheadertext.png" width="162" border="0" /></p>
<p>Unfortunately I didn&#8217;t find any way to change this text from my source code or by binding it to some DomainProperty. I&#8217;m using an abstract base class with the embedded fields that are displayed in this compartment and I have some concrete classes inheriting from the base class. The shapes for all those concrete classes should look nearly the same; the only difference is the compartment header text. I think it is not a good idea to model a separate shape for every concrete class only for having different header texts.</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/model.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="268" alt="model" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/model-thumb.png" width="444" border="0" /></a></p>
<p>After a little bit of research I found an extension point to achieve my aim. The CompartmentShape class contains a <code>GetCompartmentDescriptions()</code> method. To override this method you have to create the CompartmentShape as <em>Double Derived</em> and create a <em>partial class</em>.</p>
<p>I think you should take a look at the implementation of this method in the generated class. Indeed this method is defined in the CompartmentShape class, but it caches the value in a static field. So all shapes (within the same type) share the same <code>CompartmentDescription</code>. Now you can change it before returning it in this method. Just alter the text or do some other funny things like coloring or setting font types.</p>
<pre class="code"><span style="color: blue">public override </span><span style="color: #2b91af">CompartmentDescription</span>[] GetCompartmentDescriptions()
{
    <span style="color: #2b91af">CompartmentDescription</span>[] descriptions;
    descriptions = <span style="color: blue">base</span>.GetCompartmentDescriptions();

    <span style="color: green">// I know there is only one CompartmentDescription
    // but maybe you should check it first
    </span><span style="color: #2b91af">CompartmentDescription </span>desc = descriptions[0];

    <span style="color: blue">if </span>(<span style="color: blue">this</span>.ModelElement <span style="color: blue">is </span><span style="color: #2b91af">ClassA</span>)
        desc.Title = <span style="color: #a31515">&quot;Fields of A&quot;</span>;

    <span style="color: blue">if </span>(<span style="color: blue">this</span>.ModelElement <span style="color: blue">is </span><span style="color: #2b91af">ClassB</span>)
    {
        desc.Title = <span style="color: #a31515">&quot;Fields of B&quot;</span>;
        desc.TitleFontSettings = <span style="color: blue">new </span><span style="color: #2b91af">FontSettings</span> {Bold=<span style="color: blue">true</span>};
        desc.CompartmentFillColor = <span style="color: #2b91af">Color</span>.LightBlue;
    }

    <span style="color: blue">return </span>descriptions;
}</pre>
<pre class="code"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="138" alt="shapes" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/shapes.png" width="337" border="0" /> </pre>
<p><font face="Trebuchet MS">However there is a little drawback: This method is called only once (at least it seems so) when a shape is created (or the diagram is loaded). After that you cannot change the compartment description. For my problem it doesn&#8217;t make any difference. Maybe you can call some method to invalidate the shape and force it to reevaluate the method, but I&#8217;m not sure. If somebody knows some working solution for this, please leave a comment.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/05/20/changeing-the-title-of-compartments-using-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
