<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" version="2.0">
  <channel>
    <title>Rockford Lhotka - MOslo</title>
    <link>http://www.lhotka.net/weblog/</link>
    <description>Creator of the CSLA .NET framework</description>
    <language>en-us</language>
    <copyright>Marimer LLC</copyright>
    <lastBuildDate>Thu, 04 Mar 2010 17:06:23 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>rocky@lhotka.net</managingEditor>
    <webMaster>rocky@lhotka.net</webMaster>
    <item>
      <trackback:ping>http://www.lhotka.net/weblog/Trackback.aspx?guid=fad6f528-04ec-4856-86ff-c32ad4bfe037</trackback:ping>
      <pingback:server>http://www.lhotka.net/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.lhotka.net/weblog/PermaLink,guid,fad6f528-04ec-4856-86ff-c32ad4bfe037.aspx</pingback:target>
      <dc:creator>Rockford Lhotka</dc:creator>
      <wfw:comment>http://www.lhotka.net/weblog/CommentView,guid,fad6f528-04ec-4856-86ff-c32ad4bfe037.aspx</wfw:comment>
      <wfw:commentRss>http://www.lhotka.net/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=fad6f528-04ec-4856-86ff-c32ad4bfe037</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
MCsla is a prototype that takes SQL Server Modeling (aka “Oslo” and “M”) and CSLA
.NET, using them to create an end-to-end story. This story goes like this:
</p>
        <ol>
          <li>
Developer creates a business database for business data 
</li>
          <li>
Developer writes concise DSL code 
</li>
          <li>
Developer “compiles” DSL code into the SQL Server Modeling repository 
</li>
          <li>
End user executes a runtime application, which dynamically creates a UI, business
layer and data layer that uses the business database – all this based on the compiled
DSL metadata stored in the repository 
</li>
        </ol>
        <p>
This saves the developer from a lot of work. In fact the developer writes perhaps
5% of the code they would have written to create the UI, business layer and data layer
by hand.
</p>
        <p>
See my discussion of the concepts and prototype in a three part video series:
</p>
        <p>
          <a href="http://msdn.microsoft.com/en-us/data/ff381673.aspx">Exploring SQL Server
Modeling through MCsla</a>
        </p>
        <p>
You can see the MCsla code in the CSLA .NET repository (<a href="http://www.lhotka.net/cslacvs/viewvc.cgi/mcsla/">web
view</a>) or grab it using any svn client from svn://svn.lhotka.net/csla/mcsla/tags/Video1001.
</p>
        <img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=fad6f528-04ec-4856-86ff-c32ad4bfe037" />
      </body>
      <title>Exploring SQL Server Modeling through MCsla</title>
      <guid isPermaLink="false">http://www.lhotka.net/weblog/PermaLink,guid,fad6f528-04ec-4856-86ff-c32ad4bfe037.aspx</guid>
      <link>http://www.lhotka.net/weblog/ExploringSQLServerModelingThroughMCsla.aspx</link>
      <pubDate>Thu, 04 Mar 2010 17:06:23 GMT</pubDate>
      <description>&lt;p&gt;
MCsla is a prototype that takes SQL Server Modeling (aka “Oslo” and “M”) and CSLA
.NET, using them to create an end-to-end story. This story goes like this:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Developer creates a business database for business data 
&lt;li&gt;
Developer writes concise DSL code 
&lt;li&gt;
Developer “compiles” DSL code into the SQL Server Modeling repository 
&lt;li&gt;
End user executes a runtime application, which dynamically creates a UI, business
layer and data layer that uses the business database – all this based on the compiled
DSL metadata stored in the repository 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
This saves the developer from a lot of work. In fact the developer writes perhaps
5% of the code they would have written to create the UI, business layer and data layer
by hand.
&lt;/p&gt;
&lt;p&gt;
See my discussion of the concepts and prototype in a three part video series:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/data/ff381673.aspx"&gt;Exploring SQL Server
Modeling through MCsla&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
You can see the MCsla code in the CSLA .NET repository (&lt;a href="http://www.lhotka.net/cslacvs/viewvc.cgi/mcsla/"&gt;web
view&lt;/a&gt;) or grab it using any svn client from svn://svn.lhotka.net/csla/mcsla/tags/Video1001.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=fad6f528-04ec-4856-86ff-c32ad4bfe037" /&gt;</description>
      <comments>http://www.lhotka.net/weblog/CommentView,guid,fad6f528-04ec-4856-86ff-c32ad4bfe037.aspx</comments>
      <category>CSLA .NET</category>
      <category>MOslo</category>
    </item>
    <item>
      <trackback:ping>http://www.lhotka.net/weblog/Trackback.aspx?guid=91458ba8-fe7b-4320-b49a-f5aca0222578</trackback:ping>
      <pingback:server>http://www.lhotka.net/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.lhotka.net/weblog/PermaLink,guid,91458ba8-fe7b-4320-b49a-f5aca0222578.aspx</pingback:target>
      <dc:creator>Rockford Lhotka</dc:creator>
      <wfw:comment>http://www.lhotka.net/weblog/CommentView,guid,91458ba8-fe7b-4320-b49a-f5aca0222578.aspx</wfw:comment>
      <wfw:commentRss>http://www.lhotka.net/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=91458ba8-fe7b-4320-b49a-f5aca0222578</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’m heading to Atlanta to talk about “Microsoft Oslo” – oh wait – to talk about the
SQL Server Modeling at <a href="http://alemug.net/">ALEMUG on Wednesday, December
2</a>.
</p>
        <p>
Actually I’ll be talking about MCsla, which is the prototype domain specific language
and runtime I created for CSLA .NET using the SQL Server Modeling tools. It is a good
topic, because I get to talk about designing and defining a DSL with a custom grammar,
using the m.exe and mx.exe tools to compile DSL code into instance data, and then
defining a schema so that data can be loaded into SQL Server tables. Tables that you
can view (and edit) using “Quadrant”, or any other SQL Server tools of your choice.
</p>
        <p>
In short, nearly every part of SQL Server Modeling gets used, and the DSL code actually
executes as a WPF application – so it is an end-to-end prototype solution.
</p>
        <p>
So if you are in the Atlanta area, maybe I’ll see you there!
</p>
        <img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=91458ba8-fe7b-4320-b49a-f5aca0222578" />
      </body>
      <title>Heading to Atlanta to talk about Oslo</title>
      <guid isPermaLink="false">http://www.lhotka.net/weblog/PermaLink,guid,91458ba8-fe7b-4320-b49a-f5aca0222578.aspx</guid>
      <link>http://www.lhotka.net/weblog/HeadingToAtlantaToTalkAboutOslo.aspx</link>
      <pubDate>Mon, 30 Nov 2009 04:39:08 GMT</pubDate>
      <description>&lt;p&gt;
I’m heading to Atlanta to talk about “Microsoft Oslo” – oh wait – to talk about the
SQL Server Modeling at &lt;a href="http://alemug.net/"&gt;ALEMUG on Wednesday, December
2&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Actually I’ll be talking about MCsla, which is the prototype domain specific language
and runtime I created for CSLA .NET using the SQL Server Modeling tools. It is a good
topic, because I get to talk about designing and defining a DSL with a custom grammar,
using the m.exe and mx.exe tools to compile DSL code into instance data, and then
defining a schema so that data can be loaded into SQL Server tables. Tables that you
can view (and edit) using “Quadrant”, or any other SQL Server tools of your choice.
&lt;/p&gt;
&lt;p&gt;
In short, nearly every part of SQL Server Modeling gets used, and the DSL code actually
executes as a WPF application – so it is an end-to-end prototype solution.
&lt;/p&gt;
&lt;p&gt;
So if you are in the Atlanta area, maybe I’ll see you there!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=91458ba8-fe7b-4320-b49a-f5aca0222578" /&gt;</description>
      <comments>http://www.lhotka.net/weblog/CommentView,guid,91458ba8-fe7b-4320-b49a-f5aca0222578.aspx</comments>
      <category>CSLA .NET</category>
      <category>MOslo</category>
    </item>
    <item>
      <trackback:ping>http://www.lhotka.net/weblog/Trackback.aspx?guid=7f590822-fc92-48b4-8a83-93b937a119b3</trackback:ping>
      <pingback:server>http://www.lhotka.net/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.lhotka.net/weblog/PermaLink,guid,7f590822-fc92-48b4-8a83-93b937a119b3.aspx</pingback:target>
      <dc:creator>Rockford Lhotka</dc:creator>
      <wfw:comment>http://www.lhotka.net/weblog/CommentView,guid,7f590822-fc92-48b4-8a83-93b937a119b3.aspx</wfw:comment>
      <wfw:commentRss>http://www.lhotka.net/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7f590822-fc92-48b4-8a83-93b937a119b3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ve updated my prototype MCsla project to work on the “Olso” May CTP. The update
took some effort, because there are several subtle changes in the syntax of “Oslo”
grammars and instance data. What complicated this a little, is that I am using a custom
DSL compiler because the standard mgx.exe utility can’t handle my grammar.
</p>
        <p>
Still, I spent less than 8 hours getting my grammar, schemas, compiler and runtime
fixed up and working with the CTP (thanks to some help from the “Oslo” team).
</p>
        <p>
I chose at this point, to put the MCsla project into my public code repository. You
can use the <a href="http://www.lhotka.net/cslacvs/viewvc.cgi/mcsla/">web view</a> to
see the various code elements if you are interested.
</p>
        <p>
The prototype has limited scope – it supports only the CSLA .NET editable root stereotype,
which means it can be used to create simple CRUD screens over single records of data.
But even that is pretty cool I think, because it illustrates the end-to-end flow of
the whole “Oslo” platform concept.
</p>
        <p>
A business developer writes DSL code like this:
</p>
        <blockquote>
          <p>
Object Product in Test 
<br />
{ 
<br />
  Public ReadOnly int Id; 
<br />
  Public string Name; 
<br />
  Public double ListPrice; 
<br />
} Identity Id;
</p>
        </blockquote>
        <p>
(this is the simplest form – the DSL grammar also allows per-type and per-property
authorization rules, along with per-property business and validation rules)
</p>
        <p>
Then they run a batch file to compile this code and insert the resulting metadata
into the “Oslo” repository.
</p>
        <p>
The user runs the MCslaRuntime WPF application, which reads the metadata from the
repository and dynamically creates a XAML UI, CSLA .NET business object and related
data access object that talks to a SQL Server database.
</p>
        <p>
          <a href="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/MCslaontheOlsoMayCTP_10093/f01_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="f01" border="0" alt="f01" src="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/MCslaontheOlsoMayCTP_10093/f01_thumb.png" width="477" height="240" />
          </a>
        </p>
        <p>
The basic functionality you get automatically from CSLA .NET is all used by the runtime.
This includes application of authorization, business and validation rules, automatic
enable/disable for the Save/Cancel buttons based on the business object’s rules and
so forth.
</p>
        <p>
If the business developer “recompiles” their DSL code, the new metadata goes into
the repository. The user can click a <em>Refresh App</em> button to reload the metadata,
immediately enjoying the new or changed functionality provided by the business developer.
</p>
        <p>
The point is that the business developer writes that tiny bit of DSL code instead
of pages of XAML and C#. If you calculate the difference in terms of lines of code,
the business developer writes perhaps 5% of the code they’d have written by hand.
That 95% savings in effort is what makes me so interested in the overall “Oslo” platform
story!
</p>
        <img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=7f590822-fc92-48b4-8a83-93b937a119b3" />
      </body>
      <title>MCsla on the Olso May CTP</title>
      <guid isPermaLink="false">http://www.lhotka.net/weblog/PermaLink,guid,7f590822-fc92-48b4-8a83-93b937a119b3.aspx</guid>
      <link>http://www.lhotka.net/weblog/MCslaOnTheOlsoMayCTP.aspx</link>
      <pubDate>Wed, 01 Jul 2009 23:15:07 GMT</pubDate>
      <description>&lt;p&gt;
I’ve updated my prototype MCsla project to work on the “Olso” May CTP. The update
took some effort, because there are several subtle changes in the syntax of “Oslo”
grammars and instance data. What complicated this a little, is that I am using a custom
DSL compiler because the standard mgx.exe utility can’t handle my grammar.
&lt;/p&gt;
&lt;p&gt;
Still, I spent less than 8 hours getting my grammar, schemas, compiler and runtime
fixed up and working with the CTP (thanks to some help from the “Oslo” team).
&lt;/p&gt;
&lt;p&gt;
I chose at this point, to put the MCsla project into my public code repository. You
can use the &lt;a href="http://www.lhotka.net/cslacvs/viewvc.cgi/mcsla/"&gt;web view&lt;/a&gt; to
see the various code elements if you are interested.
&lt;/p&gt;
&lt;p&gt;
The prototype has limited scope – it supports only the CSLA .NET editable root stereotype,
which means it can be used to create simple CRUD screens over single records of data.
But even that is pretty cool I think, because it illustrates the end-to-end flow of
the whole “Oslo” platform concept.
&lt;/p&gt;
&lt;p&gt;
A business developer writes DSL code like this:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Object Product in Test 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160; Public ReadOnly int Id; 
&lt;br /&gt;
&amp;#160; Public string Name; 
&lt;br /&gt;
&amp;#160; Public double ListPrice; 
&lt;br /&gt;
} Identity Id;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
(this is the simplest form – the DSL grammar also allows per-type and per-property
authorization rules, along with per-property business and validation rules)
&lt;/p&gt;
&lt;p&gt;
Then they run a batch file to compile this code and insert the resulting metadata
into the “Oslo” repository.
&lt;/p&gt;
&lt;p&gt;
The user runs the MCslaRuntime WPF application, which reads the metadata from the
repository and dynamically creates a XAML UI, CSLA .NET business object and related
data access object that talks to a SQL Server database.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/MCslaontheOlsoMayCTP_10093/f01_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="f01" border="0" alt="f01" src="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/MCslaontheOlsoMayCTP_10093/f01_thumb.png" width="477" height="240" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The basic functionality you get automatically from CSLA .NET is all used by the runtime.
This includes application of authorization, business and validation rules, automatic
enable/disable for the Save/Cancel buttons based on the business object’s rules and
so forth.
&lt;/p&gt;
&lt;p&gt;
If the business developer “recompiles” their DSL code, the new metadata goes into
the repository. The user can click a &lt;em&gt;Refresh App&lt;/em&gt; button to reload the metadata,
immediately enjoying the new or changed functionality provided by the business developer.
&lt;/p&gt;
&lt;p&gt;
The point is that the business developer writes that tiny bit of DSL code instead
of pages of XAML and C#. If you calculate the difference in terms of lines of code,
the business developer writes perhaps 5% of the code they’d have written by hand.
That 95% savings in effort is what makes me so interested in the overall “Oslo” platform
story!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=7f590822-fc92-48b4-8a83-93b937a119b3" /&gt;</description>
      <comments>http://www.lhotka.net/weblog/CommentView,guid,7f590822-fc92-48b4-8a83-93b937a119b3.aspx</comments>
      <category>CSLA .NET</category>
      <category>MOslo</category>
    </item>
    <item>
      <trackback:ping>http://www.lhotka.net/weblog/Trackback.aspx?guid=8f888072-94d6-476f-a14d-cc93fb55e818</trackback:ping>
      <pingback:server>http://www.lhotka.net/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.lhotka.net/weblog/PermaLink,guid,8f888072-94d6-476f-a14d-cc93fb55e818.aspx</pingback:target>
      <dc:creator>Rockford Lhotka</dc:creator>
      <wfw:comment>http://www.lhotka.net/weblog/CommentView,guid,8f888072-94d6-476f-a14d-cc93fb55e818.aspx</wfw:comment>
      <wfw:commentRss>http://www.lhotka.net/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=8f888072-94d6-476f-a14d-cc93fb55e818</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In working on MCsla I have learned quite a few things. Obviously I had to learn the
ins and outs of MGrammar, MSchema, MGraph and the various related command line tools.
But that’s not really the interesting part, because that sort of knowledge is specific
to a bunch of unreleased tools and so is transitory.
</p>
        <p>
What is more interesting is learning about the process of building a runtime that
works off metadata. Which leads to learning about what metadata is needed for a runtime.
Which leads to learning about how you get that metadata – where it comes from.
</p>
        <p>
In my simplistic worldview I thought I’d create a single DSL to create metadata for
my runtime. And this is what I’ve done in my MCsla prototype, but it really isn’t
sufficient for any long-term real effort.
</p>
        <p>
Why?
</p>
        <p>
Because my DSL describes business objects. It doesn’t describe details about the UI,
or about the data access layer (DAL) or any data mappings into the database. In my
prototype I am <em>inferring</em> enough information from the metadata to create a
basic UI, a limited DAL and some data mappings, but this is only useful for a prototype.
</p>
        <p>
The conclusion I’ve come to is that any real CSLA .NET application runtime will require
a number of related metadata schemes:
</p>
        <ol>
          <li>
Business object description</li>
          <li>
UI description</li>
          <li>
DAL description</li>
          <li>
Data mapping description</li>
        </ol>
        <p>
If you create a single DSL to cover all these at once I think you’ll be in trouble.
The trouble will come in at least two forms. First, this single DSL will almost certainly
approach the complexity of C# or other 3GLs, and at that point why use a DSL at all?
Second, such a DSL would almost certainly break down walls around separation of concerns.
Let me talk about this second point further.
</p>
        <p>
One of the primary strengths of CSLA .NET is that it encourages clear separation of
concerns. The business layer supports numerous UI layers at one time – Web Forms,
WPF, ASP .NET MVC, Silverlight, Windows Forms, WCF services, Workflows, etc. Similarly,
the business layer doesn’t know or care how or where the DAL gets the data, as long
as the DAL can provide create/read/insert/update/delete operations.
</p>
        <p>
It is a virtual certainty that you’ll need a different DSL for ADO.NET EF than for
raw ADO.NET (connection/command/datareader) data access layers. Similarly, you’ll
probably need a different DSL to describe a web UI, as opposed to a XAML-based UI.
The technology semantics are so different that it is hard to imagine a single DSL
that encompasses both UI styles (at least one that is rich enough to make the end
users happy).
</p>
        <p>
As a result, I suspect we need a different DSL for <em>each technology of each layer
of the application architecture</em>. And that’s OK, because it is a good bet that
Microsoft will create a DSL for ADO.NET EF (as an example), so we don’t need to. That’ll
probably cover at least item number 4 in my earlier list.
</p>
        <p>
The role of the “DAL description DSL” is probably to map the items in the business
DSL to the items in the data mapping DSL.
</p>
        <p>
Already it becomes clear that some DSLs (like any DSL for ADO.NET EF, or for a framework
like MCsla) will exist in their own world, for their own narrow domain. And that’s
fine, because that is the point of a DSL.
</p>
        <p>
And at the same time, it becomes clear that we’ll need to create <em>cross-DSL DSLs</em> to
bridge the gaps between different DSLs. So that hypothetical “DAL description DSL”
would be specific to both MCsla and the data mapping DSL.
</p>
        <p>
To put it another way, it seems to me that we’re looking at two types of DSL. “Real”
domain languages, and “glue” domain languages. Domain languages that target a specific
domain, and domain languages that target the gap between other domain languages.
</p>
        <p>
I suspect the end result, is that to create a comprehensive runtime, the runtime will
need to pull in metadata for each layer of the application, and for the description
on how the layers interact. And a developer will need to learn 4 or more DSLs to describe
the various layers of the application. And tooling will need to evolve to validate
the various inter-connected bits of DSL code so we aren’t left catching mis-matched
bits of DSL input at runtime.
</p>
        <p>
To summarize: this DSL/runtime stuff is very cool, but it seems to me that it will
take years of maturation before everything comes together in a really productive manner.
</p>
        <p>
One caveat: clearly you could limit the flexibility of the architecture/runtime and
simplify the problem space and thus this multi-DSL issue. My fear though, is then
you are no different from CASE and many other similar failed concepts of the past
– so that seems rather uninteresting to me.
</p>
        <img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=8f888072-94d6-476f-a14d-cc93fb55e818" />
      </body>
      <title>Thoughts on M/Oslo DSL/metadata requirements</title>
      <guid isPermaLink="false">http://www.lhotka.net/weblog/PermaLink,guid,8f888072-94d6-476f-a14d-cc93fb55e818.aspx</guid>
      <link>http://www.lhotka.net/weblog/ThoughtsOnMOsloDSLmetadataRequirements.aspx</link>
      <pubDate>Mon, 04 May 2009 17:27:11 GMT</pubDate>
      <description>&lt;p&gt;
In working on MCsla I have learned quite a few things. Obviously I had to learn the
ins and outs of MGrammar, MSchema, MGraph and the various related command line tools.
But that’s not really the interesting part, because that sort of knowledge is specific
to a bunch of unreleased tools and so is transitory.
&lt;/p&gt;
&lt;p&gt;
What is more interesting is learning about the process of building a runtime that
works off metadata. Which leads to learning about what metadata is needed for a runtime.
Which leads to learning about how you get that metadata – where it comes from.
&lt;/p&gt;
&lt;p&gt;
In my simplistic worldview I thought I’d create a single DSL to create metadata for
my runtime. And this is what I’ve done in my MCsla prototype, but it really isn’t
sufficient for any long-term real effort.
&lt;/p&gt;
&lt;p&gt;
Why?
&lt;/p&gt;
&lt;p&gt;
Because my DSL describes business objects. It doesn’t describe details about the UI,
or about the data access layer (DAL) or any data mappings into the database. In my
prototype I am &lt;em&gt;inferring&lt;/em&gt; enough information from the metadata to create a
basic UI, a limited DAL and some data mappings, but this is only useful for a prototype.
&lt;/p&gt;
&lt;p&gt;
The conclusion I’ve come to is that any real CSLA .NET application runtime will require
a number of related metadata schemes:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Business object description&lt;/li&gt;
&lt;li&gt;
UI description&lt;/li&gt;
&lt;li&gt;
DAL description&lt;/li&gt;
&lt;li&gt;
Data mapping description&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
If you create a single DSL to cover all these at once I think you’ll be in trouble.
The trouble will come in at least two forms. First, this single DSL will almost certainly
approach the complexity of C# or other 3GLs, and at that point why use a DSL at all?
Second, such a DSL would almost certainly break down walls around separation of concerns.
Let me talk about this second point further.
&lt;/p&gt;
&lt;p&gt;
One of the primary strengths of CSLA .NET is that it encourages clear separation of
concerns. The business layer supports numerous UI layers at one time – Web Forms,
WPF, ASP .NET MVC, Silverlight, Windows Forms, WCF services, Workflows, etc. Similarly,
the business layer doesn’t know or care how or where the DAL gets the data, as long
as the DAL can provide create/read/insert/update/delete operations.
&lt;/p&gt;
&lt;p&gt;
It is a virtual certainty that you’ll need a different DSL for ADO.NET EF than for
raw ADO.NET (connection/command/datareader) data access layers. Similarly, you’ll
probably need a different DSL to describe a web UI, as opposed to a XAML-based UI.
The technology semantics are so different that it is hard to imagine a single DSL
that encompasses both UI styles (at least one that is rich enough to make the end
users happy).
&lt;/p&gt;
&lt;p&gt;
As a result, I suspect we need a different DSL for &lt;em&gt;each technology of each layer
of the application architecture&lt;/em&gt;. And that’s OK, because it is a good bet that
Microsoft will create a DSL for ADO.NET EF (as an example), so we don’t need to. That’ll
probably cover at least item number 4 in my earlier list.
&lt;/p&gt;
&lt;p&gt;
The role of the “DAL description DSL” is probably to map the items in the business
DSL to the items in the data mapping DSL.
&lt;/p&gt;
&lt;p&gt;
Already it becomes clear that some DSLs (like any DSL for ADO.NET EF, or for a framework
like MCsla) will exist in their own world, for their own narrow domain. And that’s
fine, because that is the point of a DSL.
&lt;/p&gt;
&lt;p&gt;
And at the same time, it becomes clear that we’ll need to create &lt;em&gt;cross-DSL DSLs&lt;/em&gt; to
bridge the gaps between different DSLs. So that hypothetical “DAL description DSL”
would be specific to both MCsla and the data mapping DSL.
&lt;/p&gt;
&lt;p&gt;
To put it another way, it seems to me that we’re looking at two types of DSL. “Real”
domain languages, and “glue” domain languages. Domain languages that target a specific
domain, and domain languages that target the gap between other domain languages.
&lt;/p&gt;
&lt;p&gt;
I suspect the end result, is that to create a comprehensive runtime, the runtime will
need to pull in metadata for each layer of the application, and for the description
on how the layers interact. And a developer will need to learn 4 or more DSLs to describe
the various layers of the application. And tooling will need to evolve to validate
the various inter-connected bits of DSL code so we aren’t left catching mis-matched
bits of DSL input at runtime.
&lt;/p&gt;
&lt;p&gt;
To summarize: this DSL/runtime stuff is very cool, but it seems to me that it will
take years of maturation before everything comes together in a really productive manner.
&lt;/p&gt;
&lt;p&gt;
One caveat: clearly you could limit the flexibility of the architecture/runtime and
simplify the problem space and thus this multi-DSL issue. My fear though, is then
you are no different from CASE and many other similar failed concepts of the past
– so that seems rather uninteresting to me.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=8f888072-94d6-476f-a14d-cc93fb55e818" /&gt;</description>
      <comments>http://www.lhotka.net/weblog/CommentView,guid,8f888072-94d6-476f-a14d-cc93fb55e818.aspx</comments>
      <category>MOslo</category>
    </item>
    <item>
      <trackback:ping>http://www.lhotka.net/weblog/Trackback.aspx?guid=9f439dd2-96fd-4a59-aa53-0ca9a5a279aa</trackback:ping>
      <pingback:server>http://www.lhotka.net/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.lhotka.net/weblog/PermaLink,guid,9f439dd2-96fd-4a59-aa53-0ca9a5a279aa.aspx</pingback:target>
      <dc:creator>Rockford Lhotka</dc:creator>
      <wfw:comment>http://www.lhotka.net/weblog/CommentView,guid,9f439dd2-96fd-4a59-aa53-0ca9a5a279aa.aspx</wfw:comment>
      <wfw:commentRss>http://www.lhotka.net/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=9f439dd2-96fd-4a59-aa53-0ca9a5a279aa</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the issues I’ve been struggling with in building MCsla is that the mgx tool
that is used to compile a DSL into M doesn’t output valid M in all cases.
</p>
        <p>
A couple of the issues are simply unsolvable (I mentioned these in my last blog post
as well).
</p>
        <ol>
          <li>
If your grammar includes any Boolean values, they come out as ‘ true’ and ‘false’
(including the single quotes), when they should come out as true and false (no quotes).</li>
          <li>
If your grammar includes any lists of values, a single-item list generates invalid
M, while multi-item lists generate valid M (though I’m not sure you can describe the
result using an MSchema – but at least the result is “valid”).</li>
        </ol>
        <p>
As I say, these problems are “unsolvable” because the M rendering API is what creates
the bad result, and that’s a black box.
</p>
        <p>
The solution, such as it is, requires taking the text output, the M code, and doing
some text processing to fix the issues. In the olden days I’d have whipped up an awk
script to do this, but these days C# is the tool (even if it is a lot more verbose).
Here’s the code I’m using to fix the two issues – kind of a post-processor to the
mgx tool:
</p>
        <blockquote>
          <p>
public static class MFix 
<br />
{ 
<br />
  /// &lt;summary&gt; 
<br />
  /// Fix single-quote and single-list-item 
<br />
  /// issues with a generated M file. 
<br />
  /// &lt;/summary&gt; 
<br />
  /// &lt;param name="fileName"&gt;Path to the file to fix&lt;/param&gt; 
<br />
  public static void FixFile(string fileName) 
<br />
  { 
<br />
    var output = new System.Text.StringBuilder(); 
<br />
    File.ReadAllLines(fileName).ToList().ForEach((line) =&gt; 
<br />
    { 
<br />
      output.AppendLine(FixQuotes(FixSingleNode(line))); 
<br />
    }); 
<br />
    File.WriteAllText(fileName, output.ToString()); 
<br />
  } 
</p>
          <p>
  /// &lt;summary&gt; 
<br />
  /// Fix single-quote issue with M generated by 
<br />
  /// mgx.exe. 
<br />
  /// &lt;/summary&gt; 
<br />
  /// &lt;param name="input"&gt;One line of text input.&lt;/param&gt; 
<br />
  /// &lt;returns&gt;Fixed line of text from input.&lt;/returns&gt; 
<br />
  private static string FixQuotes(string input) 
<br />
  { 
<br />
    var sb = new System.Text.StringBuilder(input.Length); 
<br />
    int state = 0; 
<br />
    for (int i = 0; i &lt; input.Length; i++) 
<br />
    { 
<br />
      var sub = input.Substring(i, 1); 
<br />
      if (sub == "\"") 
<br />
      { 
<br />
        if (state == 0) 
<br />
          state = 1; 
<br />
        else 
<br />
          state = 0; 
<br />
        sb.Append(sub); 
<br />
      } 
<br />
      else if (sub == "\\" &amp;&amp; state ==
1) 
<br />
      { 
<br />
        sb.Append(sub); 
<br />
        if (i &lt; input.Length - 1) 
<br />
        { 
<br />
          i++; 
<br />
          sb.Append(input.Substring(i,
1)); 
<br />
        } 
<br />
      } 
<br />
      else if (sub == "'" &amp;&amp; state == 0) 
<br />
      { 
<br />
        // do nothing and eat next char if it is
a ' ' 
<br />
        i++; 
<br />
        if (input.Substring(i, 1) != " ") 
<br />
          i--; 
<br />
      } 
<br />
      else 
<br />
        sb.Append(sub); 
<br />
    } 
<br />
    return sb.ToString(); 
<br />
  } 
</p>
          <p>
  /// &lt;summary&gt; 
<br />
  /// Fix single element array issue with M generated by 
<br />
  /// mgx.exe. 
<br />
  /// &lt;/summary&gt; 
<br />
  /// &lt;param name="input"&gt;One line of text input.&lt;/param&gt; 
<br />
  /// &lt;returns&gt;Fixed line of text from input.&lt;/returns&gt; 
<br />
  private static string FixSingleNode(string input) 
<br />
  { 
<br />
    var trm = input.TrimStart(); 
<br />
    if (!trm.StartsWith("=")) return input; 
</p>
          <p>
    var pos = input.IndexOf("="); 
<br />
    var sb = new System.Text.StringBuilder(input.Length); 
</p>
          <p>
    sb.Append(input.Substring(0, pos)); 
<br />
    sb.Append(" {"); 
<br />
    sb.Append(input.Substring(pos + 1, input.Length - pos - 1)); 
<br />
    sb.Append(" } "); 
</p>
          <p>
    return sb.ToString(); 
<br />
  } 
<br />
} 
</p>
        </blockquote>
        <p>
It is kind of ironic that I had to write a subset of an M parser to fix issues with
the M generator API.
</p>
        <img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=9f439dd2-96fd-4a59-aa53-0ca9a5a279aa" />
      </body>
      <title>MCsla - Fixing up output from mgx</title>
      <guid isPermaLink="false">http://www.lhotka.net/weblog/PermaLink,guid,9f439dd2-96fd-4a59-aa53-0ca9a5a279aa.aspx</guid>
      <link>http://www.lhotka.net/weblog/MCslaFixingUpOutputFromMgx.aspx</link>
      <pubDate>Wed, 22 Apr 2009 23:43:02 GMT</pubDate>
      <description>&lt;p&gt;
One of the issues I’ve been struggling with in building MCsla is that the mgx tool
that is used to compile a DSL into M doesn’t output valid M in all cases.
&lt;/p&gt;
&lt;p&gt;
A couple of the issues are simply unsolvable (I mentioned these in my last blog post
as well).
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
If your grammar includes any Boolean values, they come out as ‘ true’ and ‘false’
(including the single quotes), when they should come out as true and false (no quotes).&lt;/li&gt;
&lt;li&gt;
If your grammar includes any lists of values, a single-item list generates invalid
M, while multi-item lists generate valid M (though I’m not sure you can describe the
result using an MSchema – but at least the result is “valid”).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
As I say, these problems are “unsolvable” because the M rendering API is what creates
the bad result, and that’s a black box.
&lt;/p&gt;
&lt;p&gt;
The solution, such as it is, requires taking the text output, the M code, and doing
some text processing to fix the issues. In the olden days I’d have whipped up an awk
script to do this, but these days C# is the tool (even if it is a lot more verbose).
Here’s the code I’m using to fix the two issues – kind of a post-processor to the
mgx tool:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
public static class MFix 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160; /// &amp;lt;summary&amp;gt; 
&lt;br /&gt;
&amp;#160; /// Fix single-quote and single-list-item 
&lt;br /&gt;
&amp;#160; /// issues with a generated M file. 
&lt;br /&gt;
&amp;#160; /// &amp;lt;/summary&amp;gt; 
&lt;br /&gt;
&amp;#160; /// &amp;lt;param name=&amp;quot;fileName&amp;quot;&amp;gt;Path to the file to fix&amp;lt;/param&amp;gt; 
&lt;br /&gt;
&amp;#160; public static void FixFile(string fileName) 
&lt;br /&gt;
&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; var output = new System.Text.StringBuilder(); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; File.ReadAllLines(fileName).ToList().ForEach((line) =&amp;gt; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; output.AppendLine(FixQuotes(FixSingleNode(line))); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; }); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; File.WriteAllText(fileName, output.ToString()); 
&lt;br /&gt;
&amp;#160; } 
&lt;/p&gt;
&lt;p&gt;
&amp;#160; /// &amp;lt;summary&amp;gt; 
&lt;br /&gt;
&amp;#160; /// Fix single-quote issue with M generated by 
&lt;br /&gt;
&amp;#160; /// mgx.exe. 
&lt;br /&gt;
&amp;#160; /// &amp;lt;/summary&amp;gt; 
&lt;br /&gt;
&amp;#160; /// &amp;lt;param name=&amp;quot;input&amp;quot;&amp;gt;One line of text input.&amp;lt;/param&amp;gt; 
&lt;br /&gt;
&amp;#160; /// &amp;lt;returns&amp;gt;Fixed line of text from input.&amp;lt;/returns&amp;gt; 
&lt;br /&gt;
&amp;#160; private static string FixQuotes(string input) 
&lt;br /&gt;
&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; var sb = new System.Text.StringBuilder(input.Length); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; int state = 0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; for (int i = 0; i &amp;lt; input.Length; i++) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; var sub = input.Substring(i, 1); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (sub == &amp;quot;\&amp;quot;&amp;quot;) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (state == 0) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; state = 1; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; else 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; state = 0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sb.Append(sub); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; else if (sub == &amp;quot;\\&amp;quot; &amp;amp;&amp;amp; state ==
1) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sb.Append(sub); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (i &amp;lt; input.Length - 1) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; i++; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sb.Append(input.Substring(i,
1)); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; else if (sub == &amp;quot;'&amp;quot; &amp;amp;&amp;amp; state == 0) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // do nothing and eat next char if it is
a ' ' 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; i++; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (input.Substring(i, 1) != &amp;quot; &amp;quot;) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; i--; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; else 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sb.Append(sub); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; return sb.ToString(); 
&lt;br /&gt;
&amp;#160; } 
&lt;/p&gt;
&lt;p&gt;
&amp;#160; /// &amp;lt;summary&amp;gt; 
&lt;br /&gt;
&amp;#160; /// Fix single element array issue with M generated by 
&lt;br /&gt;
&amp;#160; /// mgx.exe. 
&lt;br /&gt;
&amp;#160; /// &amp;lt;/summary&amp;gt; 
&lt;br /&gt;
&amp;#160; /// &amp;lt;param name=&amp;quot;input&amp;quot;&amp;gt;One line of text input.&amp;lt;/param&amp;gt; 
&lt;br /&gt;
&amp;#160; /// &amp;lt;returns&amp;gt;Fixed line of text from input.&amp;lt;/returns&amp;gt; 
&lt;br /&gt;
&amp;#160; private static string FixSingleNode(string input) 
&lt;br /&gt;
&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; var trm = input.TrimStart(); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; if (!trm.StartsWith(&amp;quot;=&amp;quot;)) return input; 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&amp;#160;&amp;#160; var pos = input.IndexOf(&amp;quot;=&amp;quot;); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; var sb = new System.Text.StringBuilder(input.Length); 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&amp;#160;&amp;#160; sb.Append(input.Substring(0, pos)); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; sb.Append(&amp;quot; {&amp;quot;); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; sb.Append(input.Substring(pos + 1, input.Length - pos - 1)); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; sb.Append(&amp;quot; } &amp;quot;); 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&amp;#160;&amp;#160; return sb.ToString(); 
&lt;br /&gt;
&amp;#160; } 
&lt;br /&gt;
} 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
It is kind of ironic that I had to write a subset of an M parser to fix issues with
the M generator API.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=9f439dd2-96fd-4a59-aa53-0ca9a5a279aa" /&gt;</description>
      <comments>http://www.lhotka.net/weblog/CommentView,guid,9f439dd2-96fd-4a59-aa53-0ca9a5a279aa.aspx</comments>
      <category>MOslo</category>
    </item>
    <item>
      <trackback:ping>http://www.lhotka.net/weblog/Trackback.aspx?guid=3bfac92e-83b5-41c7-819b-bc619a2f7274</trackback:ping>
      <pingback:server>http://www.lhotka.net/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.lhotka.net/weblog/PermaLink,guid,3bfac92e-83b5-41c7-819b-bc619a2f7274.aspx</pingback:target>
      <dc:creator>Rockford Lhotka</dc:creator>
      <wfw:comment>http://www.lhotka.net/weblog/CommentView,guid,3bfac92e-83b5-41c7-819b-bc619a2f7274.aspx</wfw:comment>
      <wfw:commentRss>http://www.lhotka.net/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=3bfac92e-83b5-41c7-819b-bc619a2f7274</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Working with <a href="http://msdn.com/oslo">Microsoft Oslo</a>, the goal is to enable
the creation of a domain specific language (DSL) using MGrammar, so a developer can
write code in that grammar, compile the code into M and then load that M into the
Oslo repository.
</p>
        <p>
This is turning out to be a bigger challenge that you’d expect, though I think that’s
largely because I’m dealing with such early builds of all the Oslo tools.
</p>
        <p>
The tool chain for compiling DSL source into M is this:
</p>
        <ol>
          <li>
Use mg.exe to compile the MGrammar</li>
          <li>
Use mgx.exe to compile the DSL source against the grammar to create M</li>
          <li>
Use m.exe to compile the M</li>
          <li>
Use mx.exe to load the compiled M (an mx file) into the repository</li>
        </ol>
        <p>
Unfortunately this breaks down at step 2, because mgx.exe has some issues.
</p>
        <p>
The first issue I encountered was that mgx creates <em>hierarchical M</em>, not <em>relational
M</em>. What’s the difference?
</p>
        <p>
Relational M is defined by an MSchema where child entities define foreign key relationships
to their parent. This is the normal model you’d find when creating any relational
database.
</p>
        <p>
Hierarchical M is defined by an MSchema where <em>parent</em> entities define relationships
with their children. This is more like what you’d find in XML, and doesn’t completely
map to a normal relational model. While it is true that this type of MSchema can result
in valid SQL table definitions, you can’t define all the relationship restrictions
you’d normally want to have in your database.
</p>
        <p>
The thing is, M code itself must match the shape of the MSchema you want to use. So
if you define your entities using a relational MSchema, the M must also be relational.
Conversely, this means that when mgx generations hierarchical M, you <em>must</em> use
a hierarchical MSchema to map that M metadata into your database (or the Oslo repository).
</p>
        <p>
This is an unfortunate limitation, that hopefully will be resolved at some point.
</p>
        <p>
The second and third issues I encountered appear to be bugs in mgx. But not just in
mgx – they are bugs in the underlying API, so even if you try to write your own “mgx
replacement” (which is what I’m doing btw), the API that helps you generate M will
create invalid M output.
</p>
        <p>
The two bugs are:
</p>
        <ol>
          <li>
When a node has a Boolean value, true comes out as ‘ true’ and false comes out as
‘ false’. The single quotes and space after the first single quote should not be there,
but that’s what gets output. Oddly enough, Int32 and other primitive types work fine
– just Boolean types seem to be broken.</li>
          <li>
When a list of items is output, and that list contains one item, the output is invalid
M. Multiple items or no items in the list work fine – just the single-item case is
broken.</li>
        </ol>
        <p>
The only solution I’ve found for these bugs is to do a post-processing step on the
resulting M – literally doing text processing to identify and fix the issues. Again,
hopefully these issues get resolved in the API itself, so valid M gets produced by
mgx or any other tool using the API.
</p>
        <p>
The fourth issue, and the reason I’m writing my own mgx replacement, is that my MCsla
grammar allows arbitrary placement of various elements, like authorization and business
rules within a property:
</p>
        <blockquote>
          <p>
Public string Name { 
<br />
  Allow Write (“Admin”, “Supervisor”); 
<br />
  Rule StringRequired; 
<br />
  Deny Read (“Guest”); 
<br />
}
</p>
        </blockquote>
        <p>
Because the grammar allows arbitrary placement, the resulting M is a collection of
mixed types of entity. In other words, the compiled M is effectively invalid, because
the M parser can’t figure out whether the collection contains auth rules, or business
rules (because it contains both).
</p>
        <p>
I really have two choices – either change my grammar to put auth rules and business
rules in different block structures, or at least to require one to come before the
other. Or write my own mgx replacement to rearrange the nodes of the compiled DSL
code into discrete collections of homogeneous types.
</p>
        <p>
Since I don’t want to “ruin” my pretty grammar, I’m trying to fix the nodes by creating
my own mgx replacement. And this seems quite realistic, though it doesn’t address
the first three issues in any way – those are still problematic.
</p>
        <img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=3bfac92e-83b5-41c7-819b-bc619a2f7274" />
      </body>
      <title>MCsla &amp;ndash; compiling DSL source into M</title>
      <guid isPermaLink="false">http://www.lhotka.net/weblog/PermaLink,guid,3bfac92e-83b5-41c7-819b-bc619a2f7274.aspx</guid>
      <link>http://www.lhotka.net/weblog/MCslaNdashCompilingDSLSourceIntoM.aspx</link>
      <pubDate>Wed, 22 Apr 2009 01:54:06 GMT</pubDate>
      <description>&lt;p&gt;
Working with &lt;a href="http://msdn.com/oslo"&gt;Microsoft Oslo&lt;/a&gt;, the goal is to enable
the creation of a domain specific language (DSL) using MGrammar, so a developer can
write code in that grammar, compile the code into M and then load that M into the
Oslo repository.
&lt;/p&gt;
&lt;p&gt;
This is turning out to be a bigger challenge that you’d expect, though I think that’s
largely because I’m dealing with such early builds of all the Oslo tools.
&lt;/p&gt;
&lt;p&gt;
The tool chain for compiling DSL source into M is this:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Use mg.exe to compile the MGrammar&lt;/li&gt;
&lt;li&gt;
Use mgx.exe to compile the DSL source against the grammar to create M&lt;/li&gt;
&lt;li&gt;
Use m.exe to compile the M&lt;/li&gt;
&lt;li&gt;
Use mx.exe to load the compiled M (an mx file) into the repository&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Unfortunately this breaks down at step 2, because mgx.exe has some issues.
&lt;/p&gt;
&lt;p&gt;
The first issue I encountered was that mgx creates &lt;em&gt;hierarchical M&lt;/em&gt;, not &lt;em&gt;relational
M&lt;/em&gt;. What’s the difference?
&lt;/p&gt;
&lt;p&gt;
Relational M is defined by an MSchema where child entities define foreign key relationships
to their parent. This is the normal model you’d find when creating any relational
database.
&lt;/p&gt;
&lt;p&gt;
Hierarchical M is defined by an MSchema where &lt;em&gt;parent&lt;/em&gt; entities define relationships
with their children. This is more like what you’d find in XML, and doesn’t completely
map to a normal relational model. While it is true that this type of MSchema can result
in valid SQL table definitions, you can’t define all the relationship restrictions
you’d normally want to have in your database.
&lt;/p&gt;
&lt;p&gt;
The thing is, M code itself must match the shape of the MSchema you want to use. So
if you define your entities using a relational MSchema, the M must also be relational.
Conversely, this means that when mgx generations hierarchical M, you &lt;em&gt;must&lt;/em&gt; use
a hierarchical MSchema to map that M metadata into your database (or the Oslo repository).
&lt;/p&gt;
&lt;p&gt;
This is an unfortunate limitation, that hopefully will be resolved at some point.
&lt;/p&gt;
&lt;p&gt;
The second and third issues I encountered appear to be bugs in mgx. But not just in
mgx – they are bugs in the underlying API, so even if you try to write your own “mgx
replacement” (which is what I’m doing btw), the API that helps you generate M will
create invalid M output.
&lt;/p&gt;
&lt;p&gt;
The two bugs are:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
When a node has a Boolean value, true comes out as ‘ true’ and false comes out as
‘ false’. The single quotes and space after the first single quote should not be there,
but that’s what gets output. Oddly enough, Int32 and other primitive types work fine
– just Boolean types seem to be broken.&lt;/li&gt;
&lt;li&gt;
When a list of items is output, and that list contains one item, the output is invalid
M. Multiple items or no items in the list work fine – just the single-item case is
broken.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The only solution I’ve found for these bugs is to do a post-processing step on the
resulting M – literally doing text processing to identify and fix the issues. Again,
hopefully these issues get resolved in the API itself, so valid M gets produced by
mgx or any other tool using the API.
&lt;/p&gt;
&lt;p&gt;
The fourth issue, and the reason I’m writing my own mgx replacement, is that my MCsla
grammar allows arbitrary placement of various elements, like authorization and business
rules within a property:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
Public string Name { 
&lt;br /&gt;
&amp;#160; Allow Write (“Admin”, “Supervisor”); 
&lt;br /&gt;
&amp;#160; Rule StringRequired; 
&lt;br /&gt;
&amp;#160; Deny Read (“Guest”); 
&lt;br /&gt;
}
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Because the grammar allows arbitrary placement, the resulting M is a collection of
mixed types of entity. In other words, the compiled M is effectively invalid, because
the M parser can’t figure out whether the collection contains auth rules, or business
rules (because it contains both).
&lt;/p&gt;
&lt;p&gt;
I really have two choices – either change my grammar to put auth rules and business
rules in different block structures, or at least to require one to come before the
other. Or write my own mgx replacement to rearrange the nodes of the compiled DSL
code into discrete collections of homogeneous types.
&lt;/p&gt;
&lt;p&gt;
Since I don’t want to “ruin” my pretty grammar, I’m trying to fix the nodes by creating
my own mgx replacement. And this seems quite realistic, though it doesn’t address
the first three issues in any way – those are still problematic.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=3bfac92e-83b5-41c7-819b-bc619a2f7274" /&gt;</description>
      <comments>http://www.lhotka.net/weblog/CommentView,guid,3bfac92e-83b5-41c7-819b-bc619a2f7274.aspx</comments>
      <category>MOslo</category>
    </item>
    <item>
      <trackback:ping>http://www.lhotka.net/weblog/Trackback.aspx?guid=7d196742-5d55-49e8-8798-b59d1bd9f93c</trackback:ping>
      <pingback:server>http://www.lhotka.net/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.lhotka.net/weblog/PermaLink,guid,7d196742-5d55-49e8-8798-b59d1bd9f93c.aspx</pingback:target>
      <dc:creator>Rockford Lhotka</dc:creator>
      <wfw:comment>http://www.lhotka.net/weblog/CommentView,guid,7d196742-5d55-49e8-8798-b59d1bd9f93c.aspx</wfw:comment>
      <wfw:commentRss>http://www.lhotka.net/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7d196742-5d55-49e8-8798-b59d1bd9f93c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’m working on a number of things at the moment. Most notably the <a href="http://download.lhotka.net/Default.aspx?t=SLVid01">CSLA
.NET for Silverlight video series</a> that will be available in the very near future
(it turns out that creating a video series is a lot of work!). And of course I’m prepping
for numerous <a href="http://www.lhotka.net/Presentations.aspx">upcoming speaking
engagements</a>, and I’d love to see you at them – please come up and say hi if you
get a chance.
</p>
        <p>
But I’m also working on some content around <a href="http://msdn.com/oslo">Microsoft
Oslo</a>, MGrammar and related concepts. To do this, I’m creating a prototype “MCsla”
language (DSL) that allows the creation of CSLA .NET business objects (and more) with
very concise syntax. I’ll probably be blogging about this a bit over the next couple
weeks, but the goal is to end up with some in-depth content that really walks through
everything in detail.
</p>
        <p>
My goal is for the prototype to handle CSLA <em>editable root</em> objects, but covers
business rules, validation rules and per-type and per-property authorization rules.
Here’s a conceptual example:
</p>
        <blockquote>
          <p>
            <font face="Courier New">Object foo 
<br />
{ 
<br />
    // per-type authz 
<br />
    Allow Create ("Admin"); 
<br />
    Allow Edit ("Admin", "Clerk" ); 
<br /><br />
    // property definitions 
<br /><br />
    Public ReadOnly int Id; 
<br /></font>
            <font face="Courier New">
              <br />
    Public Integer Value { 
<br />
       // per-property authz 
<br />
       Allow Write ("Clerk" ); 
<br />
       // business/validation rules 
<br />
       Rule MinValue (1 ); 
<br />
       Rule MaxValue (50 ); 
<br />
    } 
<br />
}</font>
          </p>
        </blockquote>
        <p>
But what I’ve realized as I’ve gotten further into this, is that I made a tactical
error.
</p>
        <p>
A lot of people, including myself, have been viewing MGrammar as a way to create a
DSL that is really a front-end to a code generator. My friend <a href="http://www.justnbusiness.com/">Justin
Chase</a> has done a lot of very cool work in this space, and he’s not alone.
</p>
        <p>
But it turns out that if you want to really leverage <em>Microsoft Oslo</em> and not
just MGrammar, then this is not about creating a code generator. And what I’m finding
is that starting with the DSL is a terrible mistake!
</p>
        <p>
In fact, the idea behind MOslo is that the DSL is just a way to get metadata into
the Oslo repository. And you can use other techniques to get metadata into the repository
as well, including the graphical “Quadrant” tool.
</p>
        <p>
But my next question, and I’m guessing yours too, is that if all we do is put metadata
into the repository, what good is that???
</p>
        <p>
This is where a <em>runtime</em> comes into play. A runtime is a program that reads
the metadata from the repository and basically executes the metadata.
</p>
        <p>
I always had a mental picture of MOslo “projecting” the metadata into the runtime.
But that’s not accurate. It is the runtime that “pulls” metadata from the repository
and then uses it.
</p>
        <p>
And that’s OK. The point is that the runtime is this application that interprets/compiles/uses/consumes
the metadata to end up with something that actually does some work.
</p>
        <p>
          <a href="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/ThebeginningsofMCsla_92A7/image_6.png">
            <img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/ThebeginningsofMCsla_92A7/image_thumb_2.png" width="584" height="500" />
          </a>
        </p>
        <p>
What I’m learning through this process, is that the DSL exists to service the metadata
in the repository. But it is the <em>runtime that defines the metadata</em>. The runtime
consumes the metadata, so the metadata exists to serve the needs of the runtime.
</p>
        <p>
In other words, I should have started with the runtime <em>first</em> so I knew what
metadata was required, so I could design a DSL that was capable of expressing and
capturing that metadata.
</p>
        <p>
The example MCsla code you see above is OK, but it turns out that it is missing some
important bits of information that my runtime needs to function. So while the DSL
expresses the important CSLA .NET concepts, it doesn’t express everything necessary
to generate a useful runtime result…
</p>
        <p>
So at the moment I’ve stopped working on the DSL, and am focusing on creating a working
runtime. One that can execute the metadata in a way that the user gets a dynamically
created UI (in WPF) that is bound to a dynamically created CSLA .NET business object,
that leverages a dynamically created data access layer (using the CSLA .NET 3.6 ObjectFactory
concept). I’m not dynamically creating the database, because I think that’s unrealistic
in any real-world scenario. We all have pre-existing databases after all.
</p>
        <p>
Once I get the runtime working (and it is close – here’s a screenshot of a simple
object, showing how the dynamic WPF UI is running against an object with business
rules, buttons bound to the CslaDataProvider through commanding and all the other
nice CSLA features.
</p>
        <p>
          <a href="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/ThebeginningsofMCsla_92A7/image_8.png">
            <img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/ThebeginningsofMCsla_92A7/image_thumb_3.png" width="551" height="480" />
          </a>
        </p>
        <p>
Not that my UI is a work of art, but still :)
</p>
        <p>
I have a lot more to do, but it is now clear that starting with the runtime makes
a lot more sense than starting with the DSL.
</p>
        <img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=7d196742-5d55-49e8-8798-b59d1bd9f93c" />
      </body>
      <title>The beginnings of MCsla</title>
      <guid isPermaLink="false">http://www.lhotka.net/weblog/PermaLink,guid,7d196742-5d55-49e8-8798-b59d1bd9f93c.aspx</guid>
      <link>http://www.lhotka.net/weblog/TheBeginningsOfMCsla.aspx</link>
      <pubDate>Fri, 10 Apr 2009 15:30:07 GMT</pubDate>
      <description>&lt;p&gt;
I’m working on a number of things at the moment. Most notably the &lt;a href="http://download.lhotka.net/Default.aspx?t=SLVid01"&gt;CSLA
.NET for Silverlight video series&lt;/a&gt; that will be available in the very near future
(it turns out that creating a video series is a lot of work!). And of course I’m prepping
for numerous &lt;a href="http://www.lhotka.net/Presentations.aspx"&gt;upcoming speaking
engagements&lt;/a&gt;, and I’d love to see you at them – please come up and say hi if you
get a chance.
&lt;/p&gt;
&lt;p&gt;
But I’m also working on some content around &lt;a href="http://msdn.com/oslo"&gt;Microsoft
Oslo&lt;/a&gt;, MGrammar and related concepts. To do this, I’m creating a prototype “MCsla”
language (DSL) that allows the creation of CSLA .NET business objects (and more) with
very concise syntax. I’ll probably be blogging about this a bit over the next couple
weeks, but the goal is to end up with some in-depth content that really walks through
everything in detail.
&lt;/p&gt;
&lt;p&gt;
My goal is for the prototype to handle CSLA &lt;em&gt;editable root&lt;/em&gt; objects, but covers
business rules, validation rules and per-type and per-property authorization rules.
Here’s a conceptual example:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New"&gt;Object foo 
&lt;br&gt;
{ 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // per-type authz 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Allow Create ("Admin"); 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Allow Edit ("Admin", "Clerk" ); 
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; // property definitions 
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Public ReadOnly int Id; 
&lt;br&gt;
&lt;/font&gt;&lt;font face="Courier New"&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Integer Value { 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // per-property authz 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Allow Write ("Clerk" ); 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // business/validation rules 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Rule MinValue (1 ); 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Rule MaxValue (50 ); 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&lt;br&gt;
}&lt;/font&gt; 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
But what I’ve realized as I’ve gotten further into this, is that I made a tactical
error.
&lt;/p&gt;
&lt;p&gt;
A lot of people, including myself, have been viewing MGrammar as a way to create a
DSL that is really a front-end to a code generator. My friend &lt;a href="http://www.justnbusiness.com/"&gt;Justin
Chase&lt;/a&gt; has done a lot of very cool work in this space, and he’s not alone.
&lt;/p&gt;
&lt;p&gt;
But it turns out that if you want to really leverage &lt;em&gt;Microsoft Oslo&lt;/em&gt; and not
just MGrammar, then this is not about creating a code generator. And what I’m finding
is that starting with the DSL is a terrible mistake!
&lt;/p&gt;
&lt;p&gt;
In fact, the idea behind MOslo is that the DSL is just a way to get metadata into
the Oslo repository. And you can use other techniques to get metadata into the repository
as well, including the graphical “Quadrant” tool.
&lt;/p&gt;
&lt;p&gt;
But my next question, and I’m guessing yours too, is that if all we do is put metadata
into the repository, what good is that???
&lt;/p&gt;
&lt;p&gt;
This is where a &lt;em&gt;runtime&lt;/em&gt; comes into play. A runtime is a program that reads
the metadata from the repository and basically executes the metadata.
&lt;/p&gt;
&lt;p&gt;
I always had a mental picture of MOslo “projecting” the metadata into the runtime.
But that’s not accurate. It is the runtime that “pulls” metadata from the repository
and then uses it.
&lt;/p&gt;
&lt;p&gt;
And that’s OK. The point is that the runtime is this application that interprets/compiles/uses/consumes
the metadata to end up with something that actually does some work.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/ThebeginningsofMCsla_92A7/image_6.png"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/ThebeginningsofMCsla_92A7/image_thumb_2.png" width=584 height=500&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
What I’m learning through this process, is that the DSL exists to service the metadata
in the repository. But it is the &lt;em&gt;runtime that defines the metadata&lt;/em&gt;. The runtime
consumes the metadata, so the metadata exists to serve the needs of the runtime.
&lt;/p&gt;
&lt;p&gt;
In other words, I should have started with the runtime &lt;em&gt;first&lt;/em&gt; so I knew what
metadata was required, so I could design a DSL that was capable of expressing and
capturing that metadata.
&lt;/p&gt;
&lt;p&gt;
The example MCsla code you see above is OK, but it turns out that it is missing some
important bits of information that my runtime needs to function. So while the DSL
expresses the important CSLA .NET concepts, it doesn’t express everything necessary
to generate a useful runtime result…
&lt;/p&gt;
&lt;p&gt;
So at the moment I’ve stopped working on the DSL, and am focusing on creating a working
runtime. One that can execute the metadata in a way that the user gets a dynamically
created UI (in WPF) that is bound to a dynamically created CSLA .NET business object,
that leverages a dynamically created data access layer (using the CSLA .NET 3.6 ObjectFactory
concept). I’m not dynamically creating the database, because I think that’s unrealistic
in any real-world scenario. We all have pre-existing databases after all.
&lt;/p&gt;
&lt;p&gt;
Once I get the runtime working (and it is close – here’s a screenshot of a simple
object, showing how the dynamic WPF UI is running against an object with business
rules, buttons bound to the CslaDataProvider through commanding and all the other
nice CSLA features.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/ThebeginningsofMCsla_92A7/image_8.png"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://www.lhotka.net/weblog/content/binary/WindowsLiveWriter/ThebeginningsofMCsla_92A7/image_thumb_3.png" width=551 height=480&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Not that my UI is a work of art, but still :)
&lt;/p&gt;
&lt;p&gt;
I have a lot more to do, but it is now clear that starting with the runtime makes
a lot more sense than starting with the DSL.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lhotka.net/weblog/aggbug.ashx?id=7d196742-5d55-49e8-8798-b59d1bd9f93c" /&gt;</description>
      <comments>http://www.lhotka.net/weblog/CommentView,guid,7d196742-5d55-49e8-8798-b59d1bd9f93c.aspx</comments>
      <category>CSLA .NET</category>
      <category>MOslo</category>
      <category>Programming</category>
    </item>
  </channel>
</rss>