IHateSpaghetti {code}

VSX, DSL and Beyond by Eyal Lantzman

Syndication

Coding / Architecture

Extensibility /DSL

Projects

Articles

In this post:

1) General overview of the way the toolbox items work in DSL tools for VS2010

2) Toolbox related Changes from VS2008 to VS2010

3) Customization of static toolbox items - how to grouped model elements into single toolbox item

 

In VS 2010 we change the way we manage toolbox items from being set explicitly during package initialization to being partially set(*) before the package has been created and initialized. The toolbox items that are set this way called static toolbox items (vs. dynamic toolbox items in VS2008).

* By partially I mean only the text, tooltip and icon are set (there are few more but they are there for technical reasons) – no action or any DSL-specific information is associated with the toolbox item –practically those toolbox items are stubs until their full initialization.

 

Q: Why did moved to static toolbox items?

A: By using this approach we were able to speed up the overall VS loading time because no package will be created (and initialized) prematurely just because it has some toolbox items.

 

The full initialization will occur when the specific designer will show up and someone will hover the toolbox item and at that point the partial toolbox items will be replaced with ModelingToolboxItem that will be created according to the following sequence diagram:

image

Blue line – VS will use package.GetToolboxItemData(..) to try and get the toolbox item data for each of the toolbox items ids you’ve hovered to replace it with the stub toolbox item and cache it in VS toolbox cache.

Red Line – Toolbox helper will create an instance of ModelingToolboxItem according to the toolbox item id.

 

Q: How would I add custom static toolbox items that are not mapped to a shape or logically group several model elements into single toolbox item?

A: The recommended approach is to add class attribute on partial package class (in DslPackage) and extending the ToolboxHelper class (in Dsl) and supporting the new toolbox item id.

 

Example for language name “MyLanguage”:

Under DslProject project:

   1: // See the generated Package.cs for examples
   2: [ProvideStaticToolboxItem(…, “MyNamesSpace.MyNewToolboxItem”,….)]
   3: partial class MyLangaugePackage : MylLanguagePackageBase
   4: {
   5: }

More info: ProvideStaticToolboxItemAttribute

 

Under Dsl project:

   1: partial class MyLanguageToolboxHelper : MyLanguagelToolboxHelperBase
   2: {
   3:     public override ModelingToolboxItem GetToolboxItem(string itemId, Store store)
   4:     {
   5:         if (store == null)
   6:         {
   7:             return null;
   8:         }
   9:         if (itemId != “MyNamesSpace.MyNewToolboxItem”)
  10:         {
  11:             return base.GetToolboxItem(itemId, store);
  12:         }
  13:  
  14:             
  15:         // return the custom toolbox item instance 
  16:         // see the generated ToolboxHelper.cs code for examples
  17:         return 
  18:             new ModelingToolboxItem(“MyNamesSpace.MyNewToolboxItem”,
  19:                         1, 
  20:                         …,
  21:                         …,
  22:                         …,
  23:                         …,
  24:                         …,
  25:                         …,
  26:                         CreateMyCustomPrototype(store), 
  27:
  28:                         });
  29:     }
  30:  
  31:     private static ElementGroupPrototype CreateMyCustomPrototype (Store store)
  32:     {
  33:         ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
  34:  
  35:         // add all the model elements that create a logical group
  36:         // make sure to set the properties that will be used as defaults
  37:         elementGroup.AddGraph(/*Add model element 1 instance*/, true);
  38:         elementGroup.AddGraph(/*Add model element 2 instance */, true);
  39:         elementGroup.AddGraph(/*Add model element 3 instance */, true);
  40:         return elementGroup.CreatePrototype();
  41:     }
  42: }

More info: ModelingToolboxItem

 

One of the new features for DSL in VS2010 is DSL libraries, in this post I will explain how to use the new feature.

 

Prerequisites: VS SDK 2010 Beta2 and higher + DSL SDK 2010 Beta2 and higher.

 

DslLibrary is a DSL that is used as a library – you can extended it or just use it with you DslLibrary/DSL.

In order to start creating DslLibraries:

 

1. Start VS and then File->New->Project

2. Find the Domain-Specific Language Designer (under Other Project Type->Extensibility)

3. In the wizard choose DslLibrary and click Finish (or proceed with the wizard)

image

4. The wizard will unfold a single project solution with an empty model.

5. In DSL Explorer window right click on the root node and then add a Domain Class

6. Switch to Solution Explore Window and regenerate all (the command with the red rectangles surrounding it)

    Note: For the current example you want be needing the generated code so, just the .dsl file itself.

 image

7. Create another DslLibrary or a DSL.

8. When the second language is unfolded switch to the DSL Explorer Window

9. Right click on the root of the tree and choose Add DSL Library Import

image

10. Select the import and set the file path to the library (relative or absolute), when you hit ENTER, if the path is valid the library will appear in the DSL Explorer Window

image

11. At this point you can use the library in your language.

Note: as soon as you will consume it in your DSL you will create a dependency that will require the library to be present on the specified path.

As of yesterday, you can download the new version of the DSL SDK.

We fixed some bugs and we added some really cool features such as better templates for WPF and Winforms based designers, T4 code generation at build time, domain model extensibility (you can even extend the Dsl designer itself), and DslLibraries and much more. For the full list see Jean-Marc's post.

 

There's a known issue with debugging Dsl designers using F5 - the toolbox items won't appear in the exp hive. In order to work around this (until the RC) you will have to run using CTRL+F5 (without debugging) and after the exphive will showup you will be able to attach the debugger. See this thread of more info.

Have fun

 

Posted by Eyal | with no comments

Jean-Marc has released another sample over the weekend:

Domain Model Extensibility, here is a quote from his post:

"The sample presents a DSL to explain the architecture of a multi-Tiered application. Each tier is made of components, which have ports. Connections are made between output ports and input ports. What is new is that a Domain Model Extension will add a “Security Extension” thus providing to the toolbox new items (an Audit Log), to a Tier new decorators, to Ports three new Domain properties related to the HTTP security, new validation methods, and new rules. I’m pretty sure you’ll like this sample very much."

You can find this sample and the other samples at: http://code.msdn.microsoft.com/DslTools

Posted by Eyal | with no comments

Check out the new WPF toolkit that was released today on WPF codeplex site.

The new stuff:

  • Chart Controls
  • Bug fixes for common issues, including:
     - DataGrid.DeleteCommand requires a current cell (as reported here)
     - DataGridColumn DisplayIndex ArgumentOutOfRange exception (as reported here)
     - DatePicker IsEnabled=False does not gray out (as reported here)
     - DatePicker Enter, Escape, and Spacebar inputs do not correctly commit/cancel edits and close the popup
     - VSM steady state animations fail to run

WPFToolkitBinaries WPFToolkitBinariesAndSource

Posted by Eyal | with no comments

The first DSL SDK 2010 Beta1 was just added by Jean-Marc and it demonstrates the usage of our new feature - ModelBus, used for model referencing.

The code and the documentation is available here: http://code.msdn.microsoft.com/DslTools

Side note: check out my first feature as MS employee - the ModelBus Picker - the WPF-based reference picker that pops when you click on the ellipsis for ModelBusReference typed properties ;-)

Feedback is appreciated

Posted by Eyal | with no comments

Jean-Marc has just announced about our release of DSL SDK for VS2010 Beta1 !

In that posts he covers about the new features we've added, sample and more!

We have a new code gallary page that is worth checking out: http://code.msdn.microsoft.com/DslTools (I planning to write a sample regarind our new WPF databinding features in the next week or two).  You can download the SDK here.

Cheers

Posted by Eyal | with no comments
Today, we are releasing Beta 1 of Visual Studio 2010 and .NET FX 4.  If you are a MSDN subscriber, you can download the Beta today from here.  For the rest of the world, the Beta will be publicly available on Wednesday. To find out how to download the beta and where to share your feedback, please visit the Visual Studio 2010 Product Page.
Posted by Eyal | with no comments

Windows 7 specific APIs include demo , labs and presentaions:

Windows 7 Sensor and Location .NET Interop Sample Library

Windows 7 Multitouch .NET Interop Sample Library

Windows 7 Taskbar and Libraries .NET Interop Sample Library

Have fun

Posted by Eyal | 1 comment(s)
תגים:, , ,

 

Are you intrigued by multi touch? The Windows Engineering team just posted a great article on how Touch was implemented in Windows 7 and on how software developers can tap into this: http://blogs.msdn.com/e7/archive/2009/03/25/touching-windows-7.aspx#comments
Check out these labs to find out how you can use Windows 7 touch with WPF 3.5 SP1: http://code.msdn.microsoft.com/WindowsTouch
This WPF 4.0 session from PDC shows you what you can expect next: http://channel9.msdn.com/pdc2008/PC03/

 

And here’s another cool thing this is the official quote from the WPF Tree Services & Controls Team:

We shipped some great new updates to the WPF Toolkit and WPF Futures on Codeplex earlier this week.  These included an updated version of the WPF Toolkit with over 20 high-priority bug fixes for DataGrid, DatePicker, & Calendar, and also a package of WPF Themes (matching those shipped with the Silverlight Toolkit) as a new addition to the WPF Futures.  We’ve also added a pointer to David Anson’s blog post with a preview of the WPF Chart Controls which are being written by the Presentation Platform Controls (PPC) team (the team who produces the Silverlight Toolkit).

Found this useful post you might want to know how to add tracing information for System.Net namespace:

<configuration>
    <system.diagnostics>
        <trace autoflush="true" />
                <sources>
                <source name="System.Net">
                        <listeners>
                <add name="System.Net"/>
                        </listeners>
                </source>
                <source name="System.Net.HttpListener">
                        <listeners>
                <add name="System.Net"/>
                        </listeners>
                </source>
        <source name="System.Net.Sockets">
                        <listeners>
                <add name="System.Net"/>
                        </listeners>
                </source>
        <source name="System.Net.Cache">
                        <listeners>
                <add name="System.Net"/>
                        </listeners>
                </source>
                </sources>
        <sharedListeners>
                <add
                 name="System.Net"
                 type="System.Diagnostics.TextWriterTraceListener"
                  initializeData="System.Net.trace.log"
                 traceOutputOptions = "ProcessId, DateTime"
                />
        </sharedListeners>
    <switches>
        <add name="System.Net" value="Verbose" />
        <add name="System.Net.Sockets" value="Verbose" />
        <add name="System.Net.Cache" value="Verbose" />
        <add name="System.Net.HttpListener" value="Verbose" />
    </switches>
    </system.diagnostics>
</configuration>

I was investigate a GDI/GDI+ related bug the other day and I found out that GDI+ doesn’t render RTL text very well. In order to render it correctly you need to render it using GDI.

GDI+ Text rendering

This is done by Graphics.DrawString(…) / Graphics.MeasureString(..)

GDI Text rendering

This is done by TextRenderer.DrawText(..) / TextRenderer.MeasureText(…)

The interesting thing about GDI text measuring is that it sometimes the measured size might be larger than the maximum size so be aware of that!

Another point is to be aware of the GraphicsUnit in the Graphic.PageUnit instance vs. Font.Unit if one in pixels and the other is inches than it’s like comparing melons to oranges.

Test application

I've created this test application that might help you to see the differences between the two rendering technologies.

 Additional resources

Check out the article in McKinsey and the World Economic Forum:

"McKinsey has partnered with the World Economic Forum to create an “Innovation Heat Map,” by identifying factors that are common to successful innovation hubs. As part of this effort, we have examined the evolution of hundreds of such clusters around the world and analyzed over 700 variables, including those driving innovation (business environment, government and regulation, human capital, infrastructure, and local demand) along with proxies for innovation output (for example, economic value added, journal publications, patent applications) to identify trends among the success stories. In the process, we have found patterns that suggest the critical ingredients required to grow, nurture, and sustain innovation hubs. At the same time, we have compiled thousands of data points that may be used to identify bottlenecks and benchmark the performance of cities, regions, and countries by measuring how they are evolving."

Check out Haifa and Tel Aviv (almost) – they are in the  hot spring sector!

image

Posted by Eyal | with no comments
תגים:,

Infostrat has taken VE3D and wrapped it up in a WPF control that you can just drop right into your XAML, they also put this project, including the source, onto CodePlex under LGPL.

You just need VS 2008 and .NET 3.5 SP1.

Very cool !

Some of the features:

  • Ability to use <include> tags within Xml header documentation to pull docs from external files.
  • Get accessor in property required to appear before set accessor
  • .generated.cs files ignored by default

 

Bugfixes:

  • 18: Partial methods not handled correctly
  • 31: Documentation rules should understand <include> element
  • 56: Require get accessor before set accessor
  • 63: When documenting a generic class, only allows <see cref="MyClass"/> and not <see cref="MyClass`1"/>.
  • 70: Analysis of files in websites crashes Visual studio 2005 and 2008
  • 74: SA1623 and SA1624 warnings appears in wrong situations
  • 82: 'using' statement does not require curly brackets
  • 88: Class without explicit access modifier marked as "public" instead of "internal"
  • 90: False warning: SA1119: The line contains unnecessary parenthesis
  • 93: Ignore .generated.cs files
  • 94: Style Cop Crashes With A Blank Definition File
  • 95: SA1101 isn't raised in method calls when the return value of the method is used.
  • 98: VS crashed for webservices.
  • 121: False syntax error with a nullable generic type reference.
  • 124: LINQ operator "let" cause SA0101 when used with "condition ? true : false" syntax
  • 151: False syntax error with a defaulted array.

 

Install link: https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sourceanalysis&ReleaseId=1425

Discussions: http://code.msdn.microsoft.com/sourceanalysis/Thread/List.aspx

Bugs: http://code.msdn.microsoft.com/sourceanalysis/WorkItem/List.aspx

More Posts Next page »