# 21 Nisan 2008 Pazartesi
Some time ago, Stuart Kent published the roadmap for DSL Tools. The idea of Dsl extensibility and WPF-based design surface mentioned there easily make someone drool. In the comments to the same post, he also mentions a way to provide your own editor instead of the built-in one. Here's my take on using that technique to provide a custom editor-wannabe in WPF.
  • Create a new Domain-Specific Language Designer (File \ New \ Project \ Other Project Types \ Extensibility)
    Name the project as WPFDSLDesigner
  • Select Class Diagrams template and click Finish to accept the defaults.
  • On the DSL Explorer tool window, click on the Editor node. Make a note of the FileExtension property in the Properties Window. Right click Editor node and Delete it.
  • Right click on the WPFDSLDesigner root node and select Add New Custom Editor. Set the FileExtension property. Set Root Class property to ModelRoot.

  • Transform All Templates using the rightmost button on top of the Solution Explorer.
  • Try building the project. The compiler error will lead you to the customization point. The cool thing with the DSL Tools is that, it clearly marks customization points expected by the developer with appropriate comments, all the time. We will add a partial class to supply our own getter in this case, as described by the comment in the code.
  • Add a project reference to WindowsFormsIntegration assembly (The last element in the dialog, most probably)
  • Add a class named WPFDesignerDocView to the DSLPackage project. (I created a DocView folder to group added files in a single place.) Change the code as follows:

    namespace Company.WPFDSLDesigner.DslPackage

    {

        using System.Windows.Forms;

        using System.Windows.Forms.Integration;

     

        internal partial class WPFDSLDesignerDocView

        {

            private ElementHost host;

            public override IWin32Window Window

            {

                get

                {

                    if (host == null)

                    {

                        host = new ElementHost { Dock = DockStyle.Fill };

     

                        WPFDesigner designer = new WPFDesigner(this);

                        host.Child = designer;

                    }

     

                    return host;

                }

            }

     

            protected override bool LoadView()

            {

                bool result = base.LoadView();

                if (result)

                {

                    ((WPFDesigner)host.Child).DocumentLoaded();

                }

     

                return result;

            }

        }

    }

  • Add a User Control (WPF) item to the project, name it WPFDesigner. Change the Xaml code of the UserControl as follows:

    <UserControl x:Class="Company.WPFDSLDesigner.DslPackage.WPFDesigner"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

        <UserControl.Resources>

            <Style TargetType="{x:Type ListBox}">

                <Setter Property="ItemsPanel">

                    <Setter.Value>

                        <ItemsPanelTemplate>

                            <StackPanel />

                        </ItemsPanelTemplate>

                    </Setter.Value>

                </Setter>

                <Setter Property="ItemTemplate">

                    <Setter.Value>

                        <DataTemplate>

                            <Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Margin="6">

                                <Label Content="{Binding Path=Name}"></Label>

                            </Border>

                        </DataTemplate>

                    </Setter.Value>

                </Setter>

            </Style>

        </UserControl.Resources>

     

        <Grid>

            <ListBox Name="modelClassViewer" ItemsSource="{Binding Mode=OneWay}" />

        </Grid>

    </UserControl>

  • And change the code of the UserControl to:

    namespace Company.WPFDSLDesigner.DslPackage

    {

        using Microsoft.VisualStudio.Modeling.Shell;

        using System.Collections.Generic;

     

        public partial class WPFDesigner

        {

            public ModelingDocView DocView { get; set; }

            protected ModelRoot root;

     

            public WPFDesigner()

            {

                InitializeComponent();

            }

     

            public WPFDesigner(ModelingDocView docView)

                : this()

            {

                DocView = docView;

            }

     

            public void DocumentLoaded()

            {

                if (DocView != null && DocView.DocData.RootElement != null)

                {

                    // Had some problems binding to ModelRoot.Types directly. Using a custom list instead.

                    var list = new List<ModelType>();

                    list.AddRange(((ModelRoot)DocView.DocData.RootElement).Types);

                    modelClassViewer.DataContext = list;

                }

            }

        }

    }


  • Your final project structure should be looking something like this:

  • Run the solution to open the Debugging project. Open the Sample.mydslx file. That's all.
And the result is:



Nothing fancy at the moment, but it's pure WPF. Add some compartment shapes and connectors, layout the entities rather than using a StackPanel and you're almost done. Nested shapes and such should be a breeze to implement.

Thank god they're working on this some future version of DSL Tools, WPF is so powerful to customize. I'm expecting that in the final version, we'll optionally be able to provide our own templates instead of the generated ones for customize-like-hell experiences.

Here are some future research points for the implementation above:
  • We can write a code generator to create shapes based on the Diagram Element properties in DslDefinition.dsl. Compartments, decorators, appearance properties etc. Why enumerate a bunch of types at runtime when we're already generating the rest design time?
  • Databinding to LinkedElementCollection failed pretty bad, VS kept crashing in every single case. Hey, I want to use built-in collections. Any INotifyCollectionChanged, by the way?
  • We should be mapping WPF menu items to package menus (VSCT). Add new property, validate etc.
  • We should either use the original .designer file structure to persist the layout etc. or find a way to store that data somewhere. (Designer file is the best)
  • Performance is not so great. I tried some 3D and it's even worse, much worse. There's something fishy going-on when you host a WPF control on top of a win32 container, or in VS, or both.
posted on 21 Nisan 2008 Pazartesi 14:55:54 UTC  #   
# 08 Nisan 2008 Salı
At last. Preview 4 is here. Spread the word :)

I'm very sorry that I couldn't be able to align this release with the Visual Studio 2008 release back in November. I failed to allocate time and couldn't be able to organize people trying to help. Won't do that again.

There are still lots of thing to do but AW is getting much better with each release, thanks to patch submissions and suggestions. Here's the complete what's new list:

New:
  • Added support for Flush for ManyToOneRelation
  • Added partial Oracle drag and drop support. (Patch: Yavor Shahpasov)
  • Generates metadata about properties to be used in queries (as in ICriterion selectCriterium = Expression.Eq(User.Properties.Name, name); )(Thanks: Rudi van den Belt)
  • Contrib-30: Add flag to property to mark it with the DefaultMemberAttribute (or do it by default for primary key fields) (Thanks: Michael Hawksworth)
  • Contrib-50: (Revised description) Allow user defined imports to replace generated imports. (Thanks: Michael Hawksworth)
  • Contrib-54: Integrate NHibernateQueryGenerator into ActiveWriter (Thanks: Steve Degosserie)
  • Contrib-81: Added list relation type. (Patch: Grimace of Despair)
  • Moved all to vS2008
  • Moved binaries license from "as is" to Apache v2. We don't need DSL Tools redistributables in setup package anymore.
Fixed:
  • ManyToOne SourceNotNull is now working propertly
  • Incorrectly generates Some pascal case fields as camel case.
  • Contrib-52: (Revised description) Generic types are incorrectly generated if the given type name already includes generic parameters. (Thanks: Hugo Burm)
  • CONTRIB-59: (Revised description) Problems with NHQG integration when the temporary path, used for out argument, contains spaces. (Patch: Steve Degosserie)
  • Contrib-56: When creating a many-one relation, the generation of the Ilist should always be generic, independent of the generic settings for the objects. (Thanks: Robert van Hoornaar)
  • Contrib-61: (If the namespace cannot be retrieved from the VS project system) When a class is added to a model, the .hbm.xml file that is added as a nested file is missing the first character of the class name in the filename. (Thanks: David Gardiner)
  • Contrib-63: VB projects can have a default root Namespace. ActiveWriter should take this into account when generating the mapping files. It currently appears to only use the model's Namespace property. (Patch: David Gardiner)
  • Contrib-66: The private field used by the relation properties should be initialised with a constructor (Patch: David Gardiner) (Added as a model level option, defaults to false)
  • Contrib-69: Generated VB code should respect project's Option Strict setting (Patch: David Gardiner)
  • Contrib-70: Using a custom type that is defined in a user project fails (Partial patch: David Gardiner)
  • Contrib-72: Option to remove prefix from generated property names.(Patch: David Gardiner) (Implemented as model level RegEx)
  • Contrib-73: Look for Castle.ActiveWriter and NHibernate in project references. (Patch: David Gardiner)
  • Oracle support is now fully working (Patch: Marjan Flis)
There are some bug fixes and improvements in the DSL Tools itself, which directly affects AW. Most notably, the giant red X problem happening time to time when you drag-drop items from Server Explorer is gone with the 2008 release. Another improvement is, DSL Tools redistributables are now included in the IDE, so they're not included in the AW setup, resulting in a smaller download.

Preview 4 will be the last release for VS 2005. It's very hard for me to maintain both 2005 and 2008 versions, so I'm planning to continue with 2008-only releases. But if you encounter a show-stopper bug in 2005 release, I'll fix it.

As always, you can mail me using "gokhan (a) altinoren.com" with all your suggestions and patches.

posted on 08 Nisan 2008 Salı 10:11:14 UTC  #   
# 03 Nisan 2008 Perşembe
It appears that people are having trouble finding templates for some of the documents mentioned in MSF Deliverables Matrix. Here is the Initial Risk Assessment template I created for a client, an excel representation of the ideas in MSF Risk Management Discipline v1.1 document. Enjoy.

Initial Risk Assessment.xlsx (21.81 KB)
posted on 03 Nisan 2008 Perşembe 07:34:26 UTC  #