Dan Rigsby – Coding Up Style

Developer.Speaker.Blogger

Archive for May, 2009

Oslo May 2009 CTP: Intellipad Changes

Posted by Dan Rigsby on 27th May 2009

oslo_thumb3The May 2009 CTP of “Oslo” introduces a lot of new features and enhancements to the existing toolset.  As a developer, my primary “Oslo” tool has been Intellipad.  It does seem much faster and more stable after a little over an hour of use.  Previous CTPs were memory hogs and would occasionally crash.  I will be upgrading all of my demos and work projects over to the latest CTP over the next week, so I will get to see how much more stable it really is.  Here is an overview of some of the UI Change:

Shell

For the most part we have the same familiar interface.  You have the same basic layout shell which is a mixture of a standard application frame and menu bar in one.  Everything else in Intellipad is a workspace window which can be docked any number of ways inside this shell.  The shell itself has a couple of new features:

  1. A new icon  (same icon used by Quadrant)
  2. The build number is now displayed next to the control box
  3. Menu items now appear to use much less white space, display proper “…” labels on items that open new windows, and a few other UI adjustments

image_thumb11

Workspace Window

Each workspace window has its own title bar as always.  The title bar appears to be the same.  We still have the document name, zoom level, a drop down to change “Modes” and a close button.  However, now the the active workspace window is highlighted in “Oslo Green”.  This is a minor change, but really comes in hand when working with multiple documents.

The “Edit” menu item for windows has a number of new features.  Check out the list of commands:

image_thumb14

We have our standard Undo/Redo/Cut/Copy/Paste/Delete/Find/Replace/GotoLine options which we had before, but now we have:

  1. Disable External Changes:Behaviors
    1. Selection Highlight: This is really neat! With this option as you select text in the document, it will be highlighted in “Oslo Green” and other uses of that same text in the same document will also be highlighted in blue.
    2. Error Squiggles: Whether or not to show the red squiggle under errors.  if you turn this off, you will still see errors in the error window, but you will have no visual indicator on the document, nor will you have the error tooltips
    3. Column Indicator:
    4. Link Navigation:
    5. Work Wrap: Wraps the text at the end of the line
    6. Line Numbers: Provides line numbers to the left of the document

This screenshot shows the “error squiggle” and “selection highlighting” in action:
image_thumb16 

There is new a View menu item which generously gives us support for quickly launching the three most important developer windows: Minibuffer, Errors, and Notifications.
image_thumb26

There is also a new Help menu item for displaying an “Intellipad Primer” document in Rich Text mode:
image_thumb25

Mini-Buffer

The mini buffer has change dramatically.  It use to pop up a kind of modal WPF dialog which allowed you to enter in commands.  This would occasionally cause Intellipad to crash on me.  In May CTP, it is now a standard document window where you can enter in commands and see previous commands much like if it were a command line window.

image_thumb18

Some people may dislike this little change, but personally I like this change as it is more consistent with the rest of the UI and user friendly.

DSL Authoring Mode

The “DSL Authoring Mode” is a 3-Windows view inside of Intellipad which contains:

  1. The document containing the DSL
  2. The input: some document were you could enter in data to test against the DSL
  3. The output: The AST tree that was generated from the input via the DSL

This mode is the preferred way to write a DSL as you can see how changes affect the schema in real time.

In previous CTPs you had to launch a Intellipad with special command line options to be able to work in what was known as “DSL Authoring Mode”.  This usually meant selecting “Intellipad (Samples Enabled)” from the start menu instead of just “Intellipad”.  This was annoying at best.  In the May CTP however, you can now enter “DSL Authoring Mode” from the standard launch of Intellipad.  Just open a document in “DSL Grammar Mode”, and there is a new DSL menu item called “Split New Input and Output Views” which launches the 3-Window view.

image_thumb21

image_thumb22

DotNetKicks Image

Posted in Oslo | No Comments »

Oslo May 2009 CTP: Released

Posted by Dan Rigsby on 27th May 2009

oslo It’s been many long months since the last drop of Oslo (January 2009).  Last night, Chris Sells and others announced the May 2009 CTP of Oslo (version 0.4.2).  Each new CTP brings more features, more documentation, and more stability.  The May CTP holds true with many new features including:

  1. The first public release of Quadrant
  2. Major updates to Intellipad (including a built in authoring mode)
  3. A unified tool set for all “M” languages
  4. A new installer (themed like Intellipad and Quadrant)
  5. UML Domain support (Use Case, Activity, Class, Sequence, Component diagrams, etc) and a loader to import UML diagrams in XMI format into the repository
  6. CLR Domain support and a loader to import .NET assemblies into the repository

I was told that we would have support for most of the command line tools in Intellipad for this release such as being able to compile and deploy to the repository. However, after having played with Intellipad for 30 minutes this morning, I can’t find any of these commands.  They should be some simple customizations via python scripts and modifying some xml files.  Hopefully the team will release these additions as well.

Download the CTP here: http://www.microsoft.com/downloads/details.aspx?FamilyID=827122a5-3ca0-4389-a79e-87af37cbf60d&displaylang=en

Install Experience

The install experience has been greatly improved. (Be sure to install any previous versions first) Here are some screenshots:

image image image
image image image

image

   
DotNetKicks Image

Posted in Oslo | No Comments »

Visual Studio 2010: Extension Manager

Posted by Dan Rigsby on 21st May 2009

Since PDC 2008 we have been hearing about the Managed Extensibility Framework (MEF) support in Visual Studio 2010.  Now that the Beta has been released, we can start to see how it is coming together.  To access the MEF extensions, just open the Extension Manager from the menu bar: Tools –> Extension Manager.

5-21-2009 1-15-49 PM

It appears that we will have a host of categories for different types extensions.  You can choose from “Installed Extensions” or browse the “Online Gallery”. The major categories are:

  1. Controls
    1. ASP.Net Controls
    2. Framework & Libraries
    3. Sharepoint Controls
    4. Silverlight Controls
    5. Windows Forms Controls
    6. WPF Controls
  2. Templates
    1. Windows Forms
    2. WPF
  3. Tools
    1. Build
    2. Coding
    3. Data
    4. Documentation
    5. Modeling
    6. Other
    7. Performance
    8. Programming & Languages
    9. Reporting
    10. Setup & Deployment
    11. Source Control
    12. Team Development
    13. Testing
    14. Web

Currently there are only 12 extensions available, and none appear to be new UI controls. Some of them are pretty interesting, but I am excited about what this could lead to. You seem to be able to extend quite a few areas of Visual Studio now!

Some of the more interesting existing extensions are:

Intellisense Presenter
A new way to view your intellisense in a WPF fashion.
image
RegEx Editor
Regular expression syntax highlighting, intellisense, in place testing, and more right from your code.
image
Image Insertion
This allows you to insert images into code files.  Great for adding developer documentation, but not sure what else it would be useful for.
image

 

I haven’t been able to find the WPF xml document visualizer that they showed off at PDC 2008. Hopefully this will show up in the gallery soon along with other useful nuggets.

I wonder if this will turn into a platform for pushing out new controls to use in our applications in between releases.  It was disappointing to not find any new controls in the toolbox when working with WinForms or WPF.  It is also unclear about how a developer can submit new extensions that be browsed through the gallery.

DotNetKicks Image

Posted in Visual Studio | 1 Comment »

Entity Framework 4.0: Scalar and Void Functions

Posted by Dan Rigsby on 20th May 2009

One feature that was sorely missing in the first version of Entity Framework was the automated ability to work with stored procedures that didn’t return back entities.  This could have been sprocs that returned void, a scalar value, or some other custom construct. 

Entity Framework v1

In Entity Framework v1 you could create a “Function Import” from these stored procedures types, but there would be no generated code that would give you access to them directly in the ObjectContext object.  You could only access them via pure Entity SQL.

To add a “Function Import” you would just add the sproc to your entity model as your normally would, then right-click on the “Function Imports” in the “Model Browser”, and select “Add Function Import…”.  This would bring up the following screen which would allow you to add your function.

5-20-2009 10-32-34 AM

If you selected that the function returned an Entity, then you would be able to access that entity in the ObjectContext. However, if you selected scalar or void, then you would have to manually write some kind of Entity SQL.  It would be nice if these “Function Imports” appeared as operations in the ObjectContext as well.

Entity Framework 4.0 Solution

Microsoft finally completed the story for “Function Imports” in Entity Framework 4.0. As you can see in the image below, the “Add Function Import” dialog is virtually the same except for the new option to return a complex type.

5-20-2009 5-42-25 PM

You can select the None and Scalar return types as you could before.  However, when the “Function Import” is created, some new code is injected into the Model code behind file that materializes the stored procedure into an operation on the ObjectContext itself:

public ObjectResult<Nullable<global::System.Int32>> GetProductCountByCategoryId(

    Nullable<global::System.Int32> categoryID)

{

 

    ObjectParameter categoryIDParameter;

    if (categoryID.HasValue)

    {

        categoryIDParameter = new ObjectParameter("CategoryID", categoryID);

    }

    else

    {

        categoryIDParameter = new ObjectParameter(

            "CategoryID", 

            typeof(global::System.Int32));

    }

    return base.ExecuteFunction<Nullable<global::System.Int32>>(

        "GetProductCountByCategoryId", 

        categoryIDParameter);

}

 

A couple of nice things about this are:

  1. No matter what we select as the return type, it wraps it as a Nullable type since a database value can always be null
  2. The results are wrapped in an ObjectResult which makes it consistent with all other queries.

And as we expect, we can directly access these operations in our code:

using (var context = new NorthwindEntities())

{

    ObjectResult<int?> result =

        context.GetProductCountByCategoryId(1);

    

    MessageBox.Show(

        result.FirstOrDefault().Value.ToString());

}

 

New “Execute” operations

If you look at the last line of the code generated by “Add Function Import”, you might notice is making a call to a new method called ExecuteFunction<T>.  This method isn’t marked public, but there are two new methods on ObjectContext that we can use to execute functions:

  1. int ExecuteStoreCommand

    This method seems to work like “ExecuteCommand” and returns in int representing the result

  2. T ExecuteStoreQuery<T>

    This appears to be more of a combination of “ExecuteScalar”, “ExecuteNonQuery”, and “ExecuteReader”.

These methods give us the ability to run any imported stored procedure in a variety of ways.  Most users, will want to just stick with the generated operations, but its always good to have options!

DotNetKicks Image

Posted in Entity Framework | 3 Comments »

New Screencast: Custom Sprocs in Entity Framework

Posted by Dan Rigsby on 20th May 2009

screencast1thumb-thumb I have a new 8 min 35sec training webcast up over using custom stored procedures in Entity Framework.  This video introduces how to use custom sprocs in your Entity Framework model for inserts, updates, deletes, and custom sprocs for searching.  The video briefly talks about how to work with void and scalar sprocs, but doesn’t get far into these as this is a feature that is getting more attention in the next version of Entity Framework.

The video is available through JupiterMedia and can be viewed at http://www.internet.com/video/. Just look for the "Developer Video" titled "Custom Sprocs in Entity Framework".

Direct links are:
http://www.internet.com/player/index.php?bcpid=1534611832&bclid=1433966034&bctid=22915014001

DotNetKicks Image

Posted in Entity Framework, Webcast | No Comments »

New Webcast: ADO.Net Data Services

Posted by Dan Rigsby on 19th May 2009

screencast1thumb-thumbI have a new 7 min 55 sec training webcast up over developing ADO.Net DataServices.  This video demonstrates how to create and consume  a simple ADO.Net Data service.

The video is available through JupiterMedia and can be viewed at http://www.internet.com/video/. Just look for the "Developer Video" titled "ADO.Net Data Services".

Direct links are:
http://www.internet.com/video/?bcpid=1534611832&bclid=1433966034&bctid=13662214001

DotNetKicks Image

Posted in Webcast | No Comments »

Entity Framework 4.0: Pluralization

Posted by Dan Rigsby on 19th May 2009

One of the new features in Entity Framework 4.0 (EF v2) is a service call “Pluralization”.  This service is used to convert names of objects form singular and/or plural forms.  For instance, if you have a table in the database that has a plural name such as “Customers”, then Entity Framework will automatically generate both object Name and Entity Set Name to “Customers” as well.  The result is that in your code, the name will look like this:
 
Customers c = new Customers();

Ideally, it would have been nice for EF to see that the table was a plural name and set the object Name to a singular form.

Now, you may be thinking that this is pretty trivial since you can manually change the generated name, but when when you have dozens or hundreds of tables this can be tedious at best.

To use the PluralizationService when generating an Entity Framework model, you just select the option"Pluralize or singularize generated object names”:

Pluralization

Or if you are using the EDMGen.exe tool, you can opt in using the /pluralize option.

Example

In the Northwind database, all the tables have plural names. (Note: It is typically recommended to name your tables in the singular form).

 Pluralization3

When this database is generated using the PluralizationService, the names are set correctly.

Pluralization1 Pluralization2 

Manually using the PluralizationService

The PluralizationService is in the System.Data.Entity.Design.dll under the System.Data.Entity.Design.PluralizationServices namespace.

Pluralization4

It is an abstract class and hence, can’t be directly instantiated.  However, there is a static CreateService method on the class to access instances of the service for various cultures.  At this time, the only culture implemented is “en-us”.

It would have been very nice if this were implemented at a more core level of .Net since this could potentially be useful for a lot more than just for Entity Framework design.  Here are some examples using the service:

// Create an instance of the service for

// a particular culture (only 'en-us' atm)

PluralizationService ps =

    PluralizationService.CreateService(

         CultureInfo.GetCultureInfo("en-us"));

 

// Convert strings to plural or singular

string pluralName = ps.Pluralize("Goose");

string singularName = ps.Singularize("Territories");

// Note: Correctly returns Geese and Territory

 

// Check if strings are plural or singular

bool isPluralName = ps.IsPlural("Sheep");

bool isSingularName = ps.IsSingular("Sheep");

// Note: Correctly sees both of these as true

Adding your own pluralization mapping

There is an interface using by the PluralizationService called ICustomPluralizationMapping that isn’t publicly exposed.  However, since it is implemented, you can cast the service to this interface and make use of the AddWord method to add your own mapping.Pluralization5

In this example, we add a new word called “Foo” with the plural version being “Foos”:

// Create an instance of the service for

// a particular culture (only 'en-us' atm)

PluralizationService ps =

    PluralizationService.CreateService(

        CultureInfo.GetCultureInfo("en-us"));

 

// Cast to the mapping interface

ICustomPluralizationMapping mapping =

    ps as ICustomPluralizationMapping;

 

// Add a new word mapping

mapping.AddWord("Foo", "Foos");

You could then use the service to generate the metadata or use it in some other context:
EntityModelSchemaGenerator generator =

    new EntityModelSchemaGenerator(

        entityContainer,

        ps);

 

var edm = generator.GenerateMetadata(); 

DotNetKicks Image

Posted in Entity Framework | 3 Comments »