Rockford Lhotka's Blog

Home | Lhotka.net | CSLA .NET

 Friday, April 10, 2009

I’m working on a number of things at the moment. Most notably the CSLA .NET for Silverlight video series 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 upcoming speaking engagements, and I’d love to see you at them – please come up and say hi if you get a chance.

But I’m also working on some content around Microsoft Oslo, 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.

My goal is for the prototype to handle CSLA editable root objects, but covers business rules, validation rules and per-type and per-property authorization rules. Here’s a conceptual example:

Object foo
{
    // per-type authz
    Allow Create ("Admin");
    Allow Edit ("Admin", "Clerk" );

    // property definitions

    Public ReadOnly int Id;

    Public Integer Value {
       // per-property authz
       Allow Write ("Clerk" );
       // business/validation rules
       Rule MinValue (1 );
       Rule MaxValue (50 );
    }
}

But what I’ve realized as I’ve gotten further into this, is that I made a tactical error.

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 Justin Chase has done a lot of very cool work in this space, and he’s not alone.

But it turns out that if you want to really leverage Microsoft Oslo 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!

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.

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???

This is where a runtime comes into play. A runtime is a program that reads the metadata from the repository and basically executes the metadata.

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.

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.

image

What I’m learning through this process, is that the DSL exists to service the metadata in the repository. But it is the runtime that defines the metadata. The runtime consumes the metadata, so the metadata exists to serve the needs of the runtime.

In other words, I should have started with the runtime first so I knew what metadata was required, so I could design a DSL that was capable of expressing and capturing that metadata.

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…

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.

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.

image

Not that my UI is a work of art, but still :)

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.

Friday, April 10, 2009 9:30:07 AM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Thursday, April 9, 2009

VS Live Las Vegas is coming up soon, and as a speaker I am able to provide a special discount code – kind of a perk for you reading my blog I guess :)

09_VSLive_LV_728x90

If you register for VS Live using code S9V03 you’ll get the all-access passport package for $400 off the standard price.

The conference has great content for developers, covering core .NET, VSTS/TFS, Silverlight, WPF, ASP.NET, Azure, Oslo and more. VS Live is one of the most respected independent technical conferences in the Microsoft space.

I’ll be talking about parallel and concurrent programming (from a practical, real-world perspective), techniques you can use to deal with the rapid pace of change in technology, and giving a workshop on building distributed applications using .NET 3.5 SP1 (so WPF, Silverlight, WCF, Windows Workflow – and of course a liberal dose of CSLA .NET).

As a nice bonus, the conference has a block of rooms at the Venetian Hotel for $99/night. This is one of the nicest hotels in Vegas, and normally you couldn’t touch a room for anywhere near this rate!

Thursday, April 9, 2009 5:17:42 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Tuesday, April 7, 2009

Leveraging the Multi-Core Revolution

April 21, 11:00 PT, 1:00 CT, 2:00 ET
CPU Speeds are not doubling every 18 months anymore. Are we stuck? Not at all! Learn how you can increase your processing speed using systems, languages, and tools. We will cover how functional development techniques can deliver a competitive advantage to companies who are smart enough to see these changes coming. read more ...

 

Planning for Successful Outsourcing

April 30, 11:00 PT, 1:00 CT, 2:00 ET
Outsourcing is a popular strategy for decreasing the cost of supporting and maintaining business applications. Done right, it can be a successful strategy. Join Magenic as we discuss and dissect why outsourcing has gained the attention and approval of business and IT managers and how to navigate a pain-free transition.  read more ...

Tuesday, April 7, 2009 2:09:47 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Tuesday, March 31, 2009

CSLA .NET 3.6.2 is now available for download.

This is the second point release of CSLA .NET 3.6, and it includes a number of bug fixes, but more importantly there are a number of new features and enhancements based on feedback from users of version 3.6 over the past four months.

Highlights include:

  • For both Windows and Silverlight
    • New methods on the ObjectFactory base class to better enable creation of a DAL object
    • Better support for lazy loaded fields, where an exception is thrown if the field is mis-used accidentally (thus reducing bugs)
    • ErrorDialog control for WPF and Silverlight to enable XAML-only handling of exceptions from CslaDataProvider
    • CslaDataProvider now has a Saved event to simplify some UI scenarios
    • RegisterProperty() now accepts a lambda expression to identify the property name, allowing the compiler to check the name, and avoiding the use of the string literal
    • MobileDictionary type, so you can create a dictionary that serializes between Silverlight and .NET
  • For Silverlight only
    • Better type name resolution, so you can now specify a type by "Namespace.Class, Assembly" without supplying the generic "Version=..." text
    • New InventoryDemo sample project (C# only right now - it is a work in progress)
    • Code snippets for async factory and data access methods
  •  

    On a related note, the first segment of my CSLA .NET for Silverlight video series is complete, and I’m nearly done with the web infrastructure for the download site. You can get a summary of the video series content on the CSLA .NET for Silverlight video download page.

    Once I get the store and download site complete, you’ll be able to purchase “early adopter'” access to the series – which means you’ll get access to each video segment as soon as it comes online. Look for this in the next couple weeks!

    Tuesday, March 31, 2009 3:59:43 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
     Thursday, March 26, 2009

    Andrew Hallmark, a passionate user of CSLA .NET from the UK, gave a user group presentation introducing CSLA .NET and the presentation was recorded.

    The presentation is available for download from

    http://www.vbug.com/members/pastevents.aspx

    Thank you for sharing your content Andrew!

    Thursday, March 26, 2009 10:01:34 AM (Central Standard Time, UTC-06:00)  #    Disclaimer
     Wednesday, March 25, 2009

    Google tells me that issues with the Silverlight ComboBox control are widespread and well known. It also tells me that there are few solid solutions out there if you want data binding to work with the Silverlight ComboBox in a simple, reliable manner.

    Perhaps the best post on the topic is this one, but this particular code example doesn’t work in all cases (specifically not inside a DataTemplate, and as a form loads and gets async data).

    After wasting more time than I care to consider, I believe I have a more complete solution. Though it isn’t perfect either, it does appear to work nicely with CSLA .NET NameValueListBase objects, and inside DataTemplate elements, which is really what I was after.

    As others have pointed out, the solution is to subclass ComboBox and add SelectedValue and ValueMemberPath properties to the control. The trick is to catch all the edge cases where these new properties, and the pre-existing SelectedItem and Items properties, might change. I may not have them all either, but I think I handle most of them :)

    To use the new control, you need to bring in the namespace containing the control, and then use XAML like this:

    <this:ComboBox Name="ProductCategoryComboBox"
                   ItemsSource="{Binding Source={StaticResource ProductCategories},Path=Data}"
                   SelectedValue="{Binding Path=CategoryId, Mode=TwoWay}"
                   ValueMemberPath="Key"
                   DisplayMemberPath="Value"/>

    At least in my code, you must set the ValueMemberPath, though I’m sure the code could be enhanced to avoid that requirement. The bigger thing is that the SelectedValue binding must have Mode=TwoWay or the binding won’t work reliably. Even if you are using the ComboBox for display-only purposes, the Mode must be TwoWay.

    Also I should point out that this XAML is using the CslaDataProvider control to get the data for the ItemsSource property. You could use other techniques as well, but I like the data provider model because it shifts all the work into XAML, so there’s no code required in the presentation layer. The ProductCategories resource is a CslaDataProvider control that retrieves a NameValueListBase object containing a list of items with Key and Value properties.

    Here’s the control code:

    public class ComboBox : System.Windows.Controls.ComboBox
    {
      public ComboBox()
      {
        this.Loaded += new RoutedEventHandler(ComboBox_Loaded);
        this.SelectionChanged += new SelectionChangedEventHandler(ComboBox_SelectionChanged);
      }

      void ComboBox_Loaded(object sender, RoutedEventArgs e)
      {
        SetSelectionFromValue();
      }

      private object _selection;

      void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
      {
        if (e.AddedItems.Count > 0)
        {
          _selection = e.AddedItems[0];
          SelectedValue = GetMemberValue(_selection);
        }
        else
        {
          _selection = null;
          SelectedValue = null;
        }
      }

      private object GetMemberValue(object item)
      {
        return item.GetType().GetProperty(ValueMemberPath).GetValue(item, null);
      }

      public static DependencyProperty ValueMemberPathProperty =
        DependencyProperty.Register("ValueMemberPath", typeof(string), typeof(InventoryDemo.ComboBox), null);

      public string ValueMemberPath
      {
        get
        {
          return ((string)(base.GetValue(ComboBox.ValueMemberPathProperty)));
        }
        set
        {
          base.SetValue(ComboBox.ValueMemberPathProperty, value);
        }
      }

      public static DependencyProperty SelectedValueProperty =
        DependencyProperty.Register("SelectedValue", typeof(object), typeof(InventoryDemo.ComboBox),
        new PropertyMetadata((o, e) =>
        {
          ((ComboBox)o).SetSelectionFromValue();
        }));

      public object SelectedValue
      {
        get
        {
          return ((object)(base.GetValue(ComboBox.SelectedValueProperty)));
        }
        set
        {
          base.SetValue(ComboBox.SelectedValueProperty, value);
        }
      }

      private void SetSelectionFromValue()
      {
        var value = SelectedValue;
        if (Items.Count > 0 && value != null)
        {
          var sel = (from item in Items
                     where GetMemberValue(item).Equals(value)
                     select item).Single();
          _selection = sel;
          SelectedItem = sel;
        }
      }

      protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
      {
        base.OnItemsChanged(e);
        SetSelectionFromValue();
      }
    }

    It seems strange that the standard control doesn’t just do the right thing – but we must live in the world that is, not the world we would like to see…

    Wednesday, March 25, 2009 10:01:05 AM (Central Standard Time, UTC-06:00)  #    Disclaimer
     Sunday, March 22, 2009

    I have made CSLA .NET 3.6.2 RC0 available for download.

    Version 3.6.2 includes a number of bug fixes, but more importantly includes a number of new features and enhancements based on feedback from users of version 3.6. Highlights include:

  • For both Windows and Silverlight
    • New methods on the ObjectFactory base class to better enable creation of a DAL object
    • Better support for lazy loaded fields, where an exception is thrown if the field is mis-used accidentally (thus reducing bugs)
    • ErrorDialog control for WPF and Silverlight to enable XAML-only handling of exceptions from CslaDataProvider
    • CslaDataProvider now has a Saved event to simplify some UI scenarios
    • RegisterProperty() now accepts a lambda expression to identify the property name, allowing the compiler to check the name, and avoiding the use of the string literal
    • MobileDictionary type, so you can create a dictionary that serializes between Silverlight and .NET
  • For Silverlight only
    • Better type name resolution, so you can now specify a type by "Namespace.Class, Assembly" without supplying the generic "Version=..." text
    • New InventoryDemo sample project (C# only right now - it is a work in progress)
    • Code snippets for async factory and data access methods

    Hopefully this is the final test release of 3.6.2, and I am planning for a final release on March 30 or 31 (before April Fool’s Day :) ). If you are using 3.6.0 or 3.6.1, please download and test this release and let me know if you encounter any issues.

  • Sunday, March 22, 2009 5:33:41 PM (Central Standard Time, UTC-06:00)  #    Disclaimer

    Many people have asked me for the status of a CSLA .NET for Silverlight ebook. I may yet write such an ebook, but I am trying something new and different first – a 7 part video series covering CSLA .NET for Silverlight.

    Each video will be roughly 40 minutes in length, and the topics include:

    1. Introduction to CSLA .NET for Silverlight
    2. Creating a basic Silverlight and CSLA .NET for Silverlight application
    3. Implementing client-only architectures (calling remote services)
    4. Implementing n-tier archtiectures (using a remote data portal)
    5. Implementation of all CSLA .NET business object stereotypes
    6. Data Access in n-tier applications
    7. Authentication and authorization in CSLA .NET for Silverlight

    This totals to nearly 5 hours of content, with a mix of lecture and demo (though heavy on the demo).

    My current plan is to sell the videos through my online store, allowing purchasers to download the videos so they can be watched offline. The files will be quite large, but once downloaded, you’ll be able to watch them offline and I think that’s preferable to a streaming approach (though I’m open to feedback – would streaming be better?).

    While allowing downloads of the files may invite piracy, I’ll take that risk. I’m sure my ebooks have suffered from some piracy (some people are simply immoral), but I strongly believe that most counter-measures are easily defeated by the criminals and they absolutely complicate the lives of honest customers. The videos will cost more than the ebooks, as I’m basing my pricing on comparable video training, but I am hopeful that this won’t make the piracy issue worse. Unlike stealing from a “big publisher”, a lot of piracy and lack of actual sales just means I won’t be able to afford to create more videos or other content – the linkage between the criminal and me is direct – so I’m hopeful that the “casual pirate” will at least think twice before stealing from the guy who created the framework they are trying to learn :)

    As always though, I believe that most people are basically decent, and that this video series will have very real, tangible value to users of CSLA .NET for Silverlight (and CSLA .NET in general to some degree).

    To create the video series, I’ve hired a video producer and they’ll be doing the editing and production work. They also did all the lighting and camera work to film the live lecture parts of each segment, and what I’ve seen so far looks and sounds very nice! I’m using Camtasia to record the demo parts of each segment, and they’ll merge the lecture and demo content together to create each final segment. The live lecture parts were filmed in one of Magenic’s conference rooms, and I’m pretty pleased with the visual layout (it is somewhat like being in a classroom or at a conference).

    My current train of thought is to offer early adopters a discount, allowing you to download the segments as they become available. I think a discount is warranted, as the segments will be completed over a period of a few weeks, so there’s an element of "paying for future content” involved for any early adopters.

    Watch for the announcement of availability in the next very few short weeks!

    Sunday, March 22, 2009 5:33:34 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
     Friday, March 13, 2009

    I recently did a webcast on CSLA .NET 3.6 through Mike Benkovich’s Benkotips website.

    You can see all Mike’s webcasts, or you can go directly to the CSLA .NET webcast recording.

    This webcast is an overview of CSLA .NET, and includes about 35 minutes of demo where I walk through a CSLA .NET for Silverlight application.

    Friday, March 13, 2009 2:07:58 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
     Thursday, March 12, 2009

    Dunn Training is offering their excellent five day training class on CSLA .NET in San Francisco on May 4-8. They have some seats open, so if you are looking for training on CSLA .NET, and you are near San Francisco (or would like to be :) ), now’s the time to sign up!

    Thursday, March 12, 2009 8:15:23 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
    On this page....
    Search
    Archives
    Feed your aggregator (RSS 2.0)
    April, 2019 (2)
    January, 2019 (1)
    December, 2018 (1)
    November, 2018 (1)
    October, 2018 (1)
    September, 2018 (3)
    August, 2018 (3)
    June, 2018 (4)
    May, 2018 (1)
    April, 2018 (3)
    March, 2018 (4)
    December, 2017 (1)
    November, 2017 (2)
    October, 2017 (1)
    September, 2017 (3)
    August, 2017 (1)
    July, 2017 (1)
    June, 2017 (1)
    May, 2017 (1)
    April, 2017 (2)
    March, 2017 (1)
    February, 2017 (2)
    January, 2017 (2)
    December, 2016 (5)
    November, 2016 (2)
    August, 2016 (4)
    July, 2016 (2)
    June, 2016 (4)
    May, 2016 (3)
    April, 2016 (4)
    March, 2016 (1)
    February, 2016 (7)
    January, 2016 (4)
    December, 2015 (4)
    November, 2015 (2)
    October, 2015 (2)
    September, 2015 (3)
    August, 2015 (3)
    July, 2015 (2)
    June, 2015 (2)
    May, 2015 (1)
    February, 2015 (1)
    January, 2015 (1)
    October, 2014 (1)
    August, 2014 (2)
    July, 2014 (3)
    June, 2014 (4)
    May, 2014 (2)
    April, 2014 (6)
    March, 2014 (4)
    February, 2014 (4)
    January, 2014 (2)
    December, 2013 (3)
    October, 2013 (3)
    August, 2013 (5)
    July, 2013 (2)
    May, 2013 (3)
    April, 2013 (2)
    March, 2013 (3)
    February, 2013 (7)
    January, 2013 (4)
    December, 2012 (3)
    November, 2012 (3)
    October, 2012 (7)
    September, 2012 (1)
    August, 2012 (4)
    July, 2012 (3)
    June, 2012 (5)
    May, 2012 (4)
    April, 2012 (6)
    March, 2012 (10)
    February, 2012 (2)
    January, 2012 (2)
    December, 2011 (4)
    November, 2011 (6)
    October, 2011 (14)
    September, 2011 (5)
    August, 2011 (3)
    June, 2011 (2)
    May, 2011 (1)
    April, 2011 (3)
    March, 2011 (6)
    February, 2011 (3)
    January, 2011 (6)
    December, 2010 (3)
    November, 2010 (8)
    October, 2010 (6)
    September, 2010 (6)
    August, 2010 (7)
    July, 2010 (8)
    June, 2010 (6)
    May, 2010 (8)
    April, 2010 (13)
    March, 2010 (7)
    February, 2010 (5)
    January, 2010 (9)
    December, 2009 (6)
    November, 2009 (8)
    October, 2009 (11)
    September, 2009 (5)
    August, 2009 (5)
    July, 2009 (10)
    June, 2009 (5)
    May, 2009 (7)
    April, 2009 (7)
    March, 2009 (11)
    February, 2009 (6)
    January, 2009 (9)
    December, 2008 (5)
    November, 2008 (4)
    October, 2008 (7)
    September, 2008 (8)
    August, 2008 (11)
    July, 2008 (11)
    June, 2008 (10)
    May, 2008 (6)
    April, 2008 (8)
    March, 2008 (9)
    February, 2008 (6)
    January, 2008 (6)
    December, 2007 (6)
    November, 2007 (9)
    October, 2007 (7)
    September, 2007 (5)
    August, 2007 (8)
    July, 2007 (6)
    June, 2007 (8)
    May, 2007 (7)
    April, 2007 (9)
    March, 2007 (8)
    February, 2007 (5)
    January, 2007 (9)
    December, 2006 (4)
    November, 2006 (3)
    October, 2006 (4)
    September, 2006 (9)
    August, 2006 (4)
    July, 2006 (9)
    June, 2006 (4)
    May, 2006 (10)
    April, 2006 (4)
    March, 2006 (11)
    February, 2006 (3)
    January, 2006 (13)
    December, 2005 (6)
    November, 2005 (7)
    October, 2005 (4)
    September, 2005 (9)
    August, 2005 (6)
    July, 2005 (7)
    June, 2005 (5)
    May, 2005 (4)
    April, 2005 (7)
    March, 2005 (16)
    February, 2005 (17)
    January, 2005 (17)
    December, 2004 (13)
    November, 2004 (7)
    October, 2004 (14)
    September, 2004 (11)
    August, 2004 (7)
    July, 2004 (3)
    June, 2004 (6)
    May, 2004 (3)
    April, 2004 (2)
    March, 2004 (1)
    February, 2004 (5)
    Categories
    About

    Powered by: newtelligence dasBlog 2.0.7226.0

    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    © Copyright 2019, Marimer LLC

    Send mail to the author(s) E-mail



    Sign In