Scott Hanselman

Real World Apps in Days not Weeks

January 16, 2009 Comment on this post [26] Posted in ASP.NET | Windows Client | WPF
Sponsored By

imageI've given a number of presentations on ADO.NET Data Services (formerly codenamed: "Astoria") and I'm still convinced that if what it does fits your scenario, you can get a metric ass-load of work done in a short period of time.

Here's a real world example. A buddy of mine gives me a call and says he's been asked to do an application for a large clothing manufacturer. It'll run on the client machine and need to retrieve Apparel details over the web. He tells me he was thinking of using Web Services, maybe ASMX Web Services.

I asked him if it was primarily going to be CRUD (Create, Read, Update, Delete) type operations, nothing too fancy. He said yes, there'd be some sorting and filtering, but that'd be it. Should I write an HttpHandler and just return an Xml document? Some format I'll make up? he says. (Sound familiar? Kind of 2004, eh?)

Does it need an administrative console?, I ask. He says that'd be nice, but it wasn't spec'ed out. He figured this would be pretty low rent. The client even suggested (gasp) that they could just maintain a local XML file. After I threw up in my mouth a little, I made a few suggestions. ;)

Remembering that the goal here is for the solution to be simple, clean, and robust. It's also to under-promise to the client, but over-deliver. It's also worth noting my friend did a fixed bid for the work, so he just wanted to get it done.

We busted out the napkins and pens over lunch and scribbled some ideas, lovingly reproduced above in Paint.NET.

In about an hour, he described the Domain Model and we created a database using LINQ to SQL. We filled it with temp data and created a new Visual Studio Solution. We added a WPF app and an ASP.NET Website.

To the website we put in our LINQ to SQL .dbml so we had our Data Context. We added a new ADO.NET Data Service and hooked it up to the Data Context. I then showed him how he could query the entity model with HTTP calls. Then we moved based the browser-based examples and added a Service Reference to our WPF app and I showed him "LINQ to REST."

Next, we created a ASP.NET Dynamic Data website, but ended up combining it with our previous site, so we had a single ASP.NET website that was both a Dynamic Data site that also included an ADO.NET Data Service. The out of the box ASP.NET DD experience gave him a complete admin site that he'll wrap in either Windows Auth or ASP.NET Forms Auth - both things he already knows how to do as an ASP.NET developer.

We were able to get a nice working skeleton for his application in an hour. He used the ObjectDataProvider in WPF to bind the entities returned from ADO.NET Data Service to lists and combos in his client app. He got a free admin site that he can skin with CSS or change the markup to taste.

He's spent the last few weeks, on and off, going back and forth with the designer who wants the WPF app to look this way or that way, and he's changed the data model a few times, but the work in that first hour over lunch set the tone for his whole project.

Hopefully I'll get his client to agree to let me use the app as a case study or something and I'll be able to give you, Dear Reader, a LOT more detail about that first hour.

A reminder, also. All this stuff, everything we used ships today in .NET 3.5 SP1. We didn't use anything beta.

For now, though, here's some links:

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Seattle/Redmond/Bellevue Nerd Dinner - Jan 19, 2009

January 16, 2009 Comment on this post [24] Posted in Musings
Sponsored By

Unfortunately http://www.nerddinner.com/ just isn't ready yet (we're still doing daily builds and it's really buggy. I hope we'll get it out as a sample soon and open it up so folks can use it to promote their own dinners.

However, that doesn't mean we can't have a Nerd Dinner just the same!

Are you in King County/Seattle/Redmond/Bellevue Washington and surrounding areas? Are you a huge nerd? Perhaps a geek? No? Maybe a dork, dweeb or wonk. Maybe you're in town for an SDR (Software Design Review) visiting BillG. Quite possibly you're just a normal person.

Regardless, why not join us for some Mall Food at the Crossroads Bellevue Mall Food Court on Monday, January 19th around 6:30pm?

Here's some links to help you remember and add this to your calendar, or head over to http://nerddinner.events.live.com. There's photos of previous Nerd Dinners up on Flickr thanks to Orcmid.

Add to your calendar

I hope to see you there!

NOTE: RSVP by leaving a comment here and show up on January 19th at 6:30pm! Feel free to bring friends, kids or family. Bring a Ruby or Java person!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

MouseEnter and MouseLeave loops in WPF

January 12, 2009 Comment on this post [20] Posted in Windows Client | WPF
Sponsored By

Sorry for the cheesy blur effect, but my buddy hasn't gotten permission from the company he's working with to blog about his project yet. When we get permission I'll blog in more detail about all the fun stuff we've learned.

I'm helping a friend of mine occasionally with WPF-related questions as he works on a really good looking application that features clothing from a large US apparel manufacturer. There's a nice animation as you roll over transparent PNGs of two shirts. The shirt you're rolling over zooms to the forefront with a nice blur and zoom animation. Below the shirts is a styled Radio Button with "Mens" and "Womens" text.

There's MouseEnter and MouseLeave events hooked up

We found ourselves in a really strange situation where there was a tiny strip of pixels that, when moused over, caused an apparently Enter/Leave loop.

The screenshot below shows the System.Diagnostics.Debug.WriteLine() calls showing the output from the application. Notice that the mouse is just approaching the second men's shirt. At this point the application would freak out as it got stuck in a loop until I moved the mouse away.

image 

This was really confusing and my knee-jerk reaction was that was somehow a bug in WPF, but then I remembered something an engineer smarted than I said:

"My code runs exactly as I wrote it."

If I go on the assumption that I haven't found a major bug in WPF, then the problem must be me. The code must be running as I wrote it.

It turns out that if you change the element that is underneath the mouse, like hiding it or changing its Z-order, you'll get a MouseLeave for the changed element and a MouseEnter for the new element that appears.

We'd gotten ourselves in a loop because we'd pushed the elements so close to together that they overlapped. One element would leave, the one underneath would popin, and the swapping would continue.

The solution was as simple as zooming in on the XAML view in the designer and moving the elements away from each other so they didn't overlap.

It was such a frustrating bug and we fought with this for an hour before we stepped back and reminded ourselves that it might just be the way we wrote it.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselminutes Podcast 145 - SOLID Principles with Uncle Bob - Robert C. Martin

January 09, 2009 Comment on this post [8] Posted in Learning .NET | Podcast | Programming
Sponsored By

photo_martin_r My one-hundred-and-forty-fifth podcast is up. Scott sits down with Robert C. Martin as Uncle Bob (@unclebobmartin) helps Scott understand the SOLID Principles of Object Oriented Design.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show!

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET and Windows Forms. Enjoy the versatility of our new-generation Reporting Tool. Dive into our online community. Visit www.telerik.com.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

Technorati Tags: ,,,,

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Be Aware of DPI with Image PNGs in WPF - Images Scale Weird or are Blurry

January 06, 2009 Comment on this post [28] Posted in Windows Client | WPF
Sponsored By

Is that enough TLAs (Three Letter Acronyms) in the title there? I continue to mentally deny the existence of DPI (dots per inch) as a concept. It's my own fault. I have been living on PCs at 96dpi for so many years, I just stopped caring. This problem we ran into is SO obvious after the fact, but it flummoxed us for a half-hour.

I've been helping a buddy on a super-cool super secret WPF application and the window has multiple states - regular, compact, and minimized. We've got three transparent PNGs for these three buttons. The designer created them and sent them along.

However, with one of them, it kept showing up at the wrong size, and was blurry. Even if we set the width and height ourselves, it looked totally wrong.

Here's wrong:

wrong

Unrelated to the scaling issue, I saw that the file was 3099 bytes, which I thought was a little large. I opened it up in the Visual Studio binary hex editor and noticed that I could see strings like "Photoshop ICC profile" in the header. PNGs are lossless (they are like Bitmaps, not JPEGs) and while they compress, there are may ways they can compress, like removing crap from headers.

I like to run PNGOUT on all my PNGs as it'll try different techniques to make the PNG as small as possible without losing any data (without changing the way the PNG looks). I ran PNGOUT on the wrong file and it went from 3099 bytes to 292 bytes. It also just happened it look right afterwards.

Here's right:

right

So why did it look right suddenly? Turns out that PNGOUT also changes the DPI, without asking, to 96dpi. Here's a little C# program I wrote to test:

static void Main(string[] args)
{
Image i = Image.FromFile(@"c:\users\scott\desktop\collapse-wrong.png");
Console.WriteLine(i.HorizontalResolution + " " + i.VerticalResolution);
Console.WriteLine(i.Width + " " + i.Height);

Image i2 = Image.FromFile(@"c:\users\scott\desktop\collapse.png");
Console.WriteLine(i2.HorizontalResolution + " " + i2.VerticalResolution);
Console.WriteLine(i2.Width + " " + i2.Height);
}

The output of this is:

72.009 72.009
56 10
96 96
56 10

Both files are 56x10 in dimension, but the first is 72.009 dpi and the second is 96 dpi. WPF defaults to 96 dpi so when it encounters the 72 dpi image it scales it up. If you can't change the image, there are funky ways around it. Personally, I believe if you are running into this because of a designer/developer mismatch, then just coordinate between each other and decide on a DPI, probably 96. In our case, DPI didn't really matter as the designer was developing pixel-accurate images, so we just run PNGOUT on all the images.

I usually run PNGOUT from Powershell, but there is a nice free .NET app called PNGGaunlet from Ben Hollis that provides a nice GUI frontend.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

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