Monday, April 23, 2007

I just spent more time than I care to think about chasing down a silly config error in the Visual Studio codename "Orcas" Beta 1 VPC image.

I wanted to run a pre-existing web site, so I copied it to the VPC, aimed a virtual directory at it in IIS and BOOM! 404 errors.

I figured it was directory permissions, incorrect paths, all sorts of things.

Eventually, in frustration I opened VS and created a new ASP.NET web project at localhost/test. Guess what? VS kindly informed me that ASP.NET wasn't enabled for IIS on this machine, and asked if I'd like to enable it. Of course I said yes - and instantly my pre-existing web site started working.

So if you decided to use the Beta 1 VPC (which is a nice way to go), be aware that ASP.NET is not enabled for IIS, and you'll need to enable it before doing any work with ASP.NET or WCF.

Monday, April 23, 2007 1:43:31 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [1]  | 

 Thursday, April 19, 2007

I was out of touch for a while there, and so I couldn't post about this.

But there's a recent .NET Rocks TV (DNR TV) show where I discuss various data access options for use with CSLA .NET. These include:

  1. Using the approach from my books: the datareader directly in the object
  2. Separating the database connection/command code into a different assembly
  3. Separating the whole data access into a different assembly and using data transfer objects (DTOs) to transfer the data into the business objects
  4. Calling a web service to get the DTOs into the objects (so putting the data access not only in a different assembly, but putting them behind a web service)

Click here to get to the DNR TV show page. I also showed this demo at VS Live in San Franscisco, and will show it again in Orlando in May.

Subsequent to that DNR TV show, I've enhanced the demo to also use LINQ to create the DTOs, and to use VB's late binding capability to make it possible to load the business object with data from the local DTO, the web service DTO and the LINQ DTO without any change to code (remember that web service proxies and LINQ create their own DTO types - so even though they are the same shape, they are actually different types - this is exactly where dynamic language features come in very handy!)

I haven't put the LINQ code online yet, but I will within the next few weeks as I catch up on everything.

Thursday, April 19, 2007 8:44:40 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  | 

 Wednesday, April 18, 2007

The next Twin Cities Codecamp is coming up fast: April 28!

The last one was really good, and this one looks to be even better, with more time between sessions and more time to interact with others in the community.

See you there!

Wednesday, April 18, 2007 9:03:49 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  | 

 Wednesday, April 11, 2007

We're really not that far away from some major new technology. Visual Studio "Orcas" is slated to ship this fall, and will include .NET 3.5; which includes new compilers. And new compilers always means fun! :)

The VB team is running a series of webcasts to bring everyone up to speed on the language changes and the resulting capabilities.

Wednesday, April 11, 2007 3:09:12 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [5]  | 

 Wednesday, April 04, 2007

Two weeks ago today I boarded a flight to San Francisco to speak at a couple conferences. I travel a fair amount, probably 17 trips a year on average. But I never expected how this one would turn out.

This blog post is also an explanation for why I haven’t been responding to emails, forum posts or any other communications, no matter how important, and why I’ll be extremely slow to respond for a few weeks now as well.

I spoke at SD West Thur and Fri. I moved to downtown San Francisco and gave my one day CSLA-related workshop on Sunday.

Monday I attended a Magenic company function in the evening and had a great time – nothing like getting together with a bunch of friendly geeks J

Monday around 11 PM I got sick. I mean sick! Serious stomach pains. I tried various things, but ultimately my wife (via phone) got me to go to the ER.

They put me on an IV for a few hours and got me feeling adequate. The assumption was that this was a very bad intestinal virus (read: stomach flu). If only that were true.

I ended up speaking at only one of my three VS Live sessions, and I really regret that in retrospect. I hate to let people down, but if I’d know what was going on I wouldn’t have stressed my body like that. Professional speakers may make it look relatively easy, and like they are having a fun time (and I think most of us really do enjoy it), but it is really a lot of work to deliver even an hour long session.

Anyway, that night and the next day were worse. So bad I couldn’t see my way to flying, but I still assumed it was the flu, so I rested and drank a lot. Thursday I staggered to SFO and flew home. I knew I must look sick, because I got a lot of odd looks from people in the airport and the plane.

My wife took me home, and I figured I’d be on the mend. She’s so very good at taking care of me and the kids if we’re sick. But by morning I asked her to get me to a doctor.

(pause, writing the above wore me out – I’ll be back later)

To make a long story short, my gall bladder had a gall stone. That stone (probably Monday) had blocked the bile duct. The gall bladder got infected, and the infection had caused swelling, irritating the liver and other nearby organs. I was lucky it didn’t burst due to the infection.

The pressure had caused an old hernia to pop too, just to make things more fun.

The surgeon removed the gall bladder and fixed the hernia Saturday.

I’m still really sick, but at least I’m getting better instead of worse each day, and I feel good about that.

In  a couple weeks things should be well on their way to getting back to normal, so hopefully I’ll start showing up on email and forums more over time. But please be patient. If there’s one thing I learned out of this, it is to keep my priorities straight.

You can also click here for one of my wife’s blog posts recounting some of this from her perspective.

(final note – who’d think you could work up a sweat (twice) just typing in a page of text…)

Wednesday, April 04, 2007 6:40:56 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [29]  | 

 Monday, March 26, 2007

I have put an early test version of CSLA .NET version 3.0, along with some updates to the ProjectTracker app online for download at www.lhotka.net/cslanet/download.aspx.

At this time the code is C# only. I'll port to VB once I'm more comfortable that the code is stable. And that statement alone should reinforce that this is early test code!! :)

The CSLA framework code includes WCF and WPF support. I have not yet found a case where I've needed to do anything to CSLA itself to support WF - invoking workflows and using CSLA objects in activities works as-is. You can look at the change log document to see what I've done for WCF and WPF.

The ProjectTracker folder now has a PTWpf project and a PTWorkflow project.

Neither of these are in the solution! The reason they are not in the solution is because PTWpf is a March 2007 Orcas CTP project, and so it won't load under VS 2005, and PTWorkflow requires the WF additions for VS 2005, which not everyone has installed. To put this another way: if you have the WF additions installed on VS 2005, you can open the workflow project. But to open the PTWpf project you need to be running the March 2007 Orcas CTP.

That said, if you want to play with the WPF forms under 2005, you can certainly use the xaml and cs files - just grab the bits you need and use them in whatever tool you are using (xamlpad, notepad, the Dec CTP or whatever). The PTWpf project isn't complete, but the ProjectList and ProjectEdit forms both work and illustrate a couple ways to interact with CSLA-style business objects for both read-only and read-write purposes.

If you do try the 3.0 version, please let me know of any issues you find. I'm actively working on this code, and appreciate any bug reports or other input!

Monday, March 26, 2007 12:18:02 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [2]  | 

 Thursday, March 15, 2007

I’ve been spending a lot of time in WPF-land over the past few weeks, and thought I’d share some of what I’ve learned. I haven’t been learning styles or UI layout stuff – Microsoft says that’s the job of the turtleneck-wearing, metrosexual GQ crowd, so I’ll just roll with that. Instead, I’ve been learning how to write data source provider controls, and implement Windows Forms-like behaviors similar to the ErrorProvider and my Csla.Windows.ReadWriteAuthorization control.

You know, manly programming J

The data source provider control is, perhaps, the easiest thing I’ve done. Like ASP.NET, WPF likes to use a data control concept. And like ASP.NET, the WPF data provider controls are easy to create, because they don’t actually do all that much at runtime.  (I do want to say thank you to Abed Mohammed for helping to debug some issues with the CslaDataProvider control!)

I’m sure, as designer support for data provider controls matures in tools like Visual Studio and Expression Blend, that life will get far more complex. Certainly the Visual Studio designer support for Csla.Web.CslaDataProvider has been the single most time consuming part of CSLA .NET, though I was able to create the runtime support in an afternoon…

What I have today, is a Csla.Wpf.CslaDataProvider control that works similar to the ObjectDataProvider. The primary difference is that CslaDataProvider understands how to call Shared/static factory methods to get your objects, rather than calling a constructor method. The result is that you can create/fetch CSLA .NET business objects directly from your XAML.

The really cool part of this, is that CslaDataProvider supports asynchronous loading of the data. To be fair, the hard work is done by the WPF base class, DataSourceProvider. Even so, supporting async is optional, and requires a bit of extra work in the control – work that is worth it though. If you construct a form that has multiple DataContext objects for different parts of the form, loading all of them async should give some nice performance benefits overall.

On the other hand, if your form is bound to a single business object the value isn’t clear at all. Though the data load is async, the form won’t actually display until all the async loads are complete, so for a single data source on a form my guess is that async is actually counter-productive.

The validation/ErrorProvider support is based on some work Paul Stovell published on the web. I conceptually based my work on similar concepts, and have created a ValidationPanel control that uses IDataErrorInfo to determine if any bindings of any controls contained in the panel are invalid.

The panel control loops through all the controls contained inside the panel. On each control it loops through the DependencyProperty elements defined for that control (in WPF controls, normal properties aren’t bindable, only dependency properties). And it then loops through any Binding objects attached to each DependencyProperty. I discovered that those Binding objects are complex little buggers, and that there are different kinds of binding that I need to filter out. Specifically relative bindings and control-to-control bindings must be ignored, because they don’t represent a binding to the actual business object.

To optimize performance the panel does a bunch of caching of binding information, and is relatively sparing in how often it refreshes the validation data – but it is comparable to ErrorProvider, in that changing one business object property does trigger rechecking of all other properties bound within the same ValidationPanel. I think this is necessary, because so many data source objects are constructed around the Windows Forms model. Not following that model would cause a lot of headache when moving to WPF.

The authorization support is implemented in a manner similar to the validation. Csla.Wpf.AuthorizationPanel uses the CSLA .NET IAuthorizeReadWrite interface and scans all bindings for all controls contained in the panel to see if the business object will allow the current user to read or write to the bound property. If the user isn’t allowed to read the property, the panel either hides or collapses the data bound control (your choice). If the user isn’t allowed to write to the property, the panel sets the control’s IsReadOnly property to true, or if the control doesn’t have IsReadOnly, it sets IsEnabled to false.

AuthorizationPanel doesn’t include the same level of caching as ValidationPanel, but I don’t think it is necessary. Where ValidationPanel refreshes on every property change, AuthorizationPanel only refreshes if the data source object is changed (replaced) or if you explicitly force a refresh – probably because the current user’s principal object has changed.

I want to pause here and point out that I’ve had a lot of help in these efforts from Paul Czywczynski. He’s spent a lot of time trying these controls and finding various holes in my logic. And the next control addresses one of those holes...

The IsValid, IsDirty, IsSavable, IsNew and IsDeleted properties on a CSLA .NET business object are marked as Browsable(false), meaning they aren’t available for data binding. In Windows Forms you can work around this easily by handling a simple event on the BindingSource object. But in WPF the goal is to write no code – to do everything through XAML (or at least to make that possible), so such a solution isn’t sufficient.

Enter the ObjectStatusPanel, which takes the business object’s properties and exposes them in a way that WPF can consume. Using this panel, your object’s status properties (single object or collection) become available for binding to WPF controls, and if the object’s properties change those changes are automatically reflected in the UI. The most common scenario here is to bind a button’s enabled status to the IsSavable property of your editable root business object.

Most recently I’ve started refactoring the code in these controls. For the most part, I’ve now consolidated the common code from all three into a base class: Csla.Wpf.DataPanelBase. This base class encapsulates the code to walk through and find relevant Binding objects on all child controls, and also encapsulates all the related event handling to detect when the data context, data object, object property, list or collection have changed. It turns out that a lot of things can happen during data binding, and detecting all of them means hooking, unhooking and responding to a lot of events.

I wrote all these controls originally using the Dec 2006 CTP, and just started using them in the Mar 2007 CTP. As a pleasant surprise there was no upgrade pain – they just kept working.

In fact, they work better in the MarCTP, because the Cider designer (WPF forms designer) is now capable of actually rendering my custom controls. What I find very interesting, is that the designer actually runs the factory method of the CslaDataProvider control, so the form shows real data from the real objects right there in Visual Studio. I’m not sure this is a good thing, but that’s what happens.

There’s no doubt that I’ll find more issues with these controls, and they’ll change over the next few weeks and months.

But the exciting thing is that I’m now able to create WPF forms that have functional parity with Windows Forms, including validation, authorization and object status binding. And it can all be done in either XAML or code, running against standard CSLA .NET business objects.

People attending VS Live at the end of this month will be the first to see these controls in action – both in my workshop on Sunday the 25th and in my sessions during the week. And I plan to put a test version of CSLA .NET 3.0 online that week as well, so anyone who wants to play with it can give it a go.

Right now, if you aren’t faint of heart, you can grab the live code from my svn repository. Keeping in mind, of course, that this is an active repository and so the code in trunk/ may or may not actually work at any given point in time.

Thursday, March 15, 2007 9:37:24 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [4]  | 

 Tuesday, March 13, 2007

String formatting in .NET is a pain. Not that it has ever been easy - even COBOL formatting masks can get out of hand, but there's no doubt that the .NET system is harder to grasp and remember than the VB 1-6 scheme...

I just had a need to format an arbitrary value using a user-supplied format string. You'd think that

obj.ToString(format)

would do the trick. Except that System.Object doesn't have that override of ToString(), so that's not a universal solution. So String.Format() is the obvious next choice, except that I need to somehow take a format string like 'N' or 'd' and make it into something valid for String.Format()...

Brad Abrams has some good info. But his problem/solution isn't quite what I needed. Close enough to extrapolate though:

outValue = string.Format(string.Format("{{0:{0}}}", format), value);

Given a format string of 'N', the inner Format() returns "{0:N}", which is then used by the outer Format() to format the actual value.

Tuesday, March 13, 2007 9:30:21 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [7]  | 

I've been working with the Visual Studio Orcas CTP from March 2007 for a few days now. My focus had been around WCF and WPF and ensuring my CSLA .NET 3.0 development worked in the new CTP.

Then earlier today I tried building a workflow. And the workflow designer wouldn't open. Instead I got a concise little error dialog saying "Microsoft.VisualStudio.Shell.WindowPane.GetService(System.Type)". This was the case with both C# and VB projects.

Worse, attempting to close VS after that point caused a complete VS crash. It turns out that other designers (like project properties) fail as well, with similar errors.

In talking to some people at Microsoft, I discovered that the problem wasn't universal. But in talking to more people, the root of the issue appeared.

I downloaded the huge 9 part VSTS/TFS edition of the Orcas VPC. Other people downloaded the smaller 7 part VSTS-only edition. The problem only occurs in the big 9 parter, and is due to a side-by-side issue. Some VS 2005 components are in the bigger VPC to support SQL Server, and they are causing the issue. The 7 part VPC doesn't have that functionality, or those components, and so the SxS problem doesn't occur.

So I'm about 80% done downloading the 7 parter, then I can get back to work.

Tuesday, March 13, 2007 9:15:14 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [1]  |