Scott Hanselman

Learn How to use NHibernate with the Summer of NHibernate Screencast Series

July 22, '08 Comments [19] Posted in Screencasts
Sponsored By

I'm a huge fan of screencasts for learning. There are an increasing number of increasingly sophisticated tools and libraries that we as developers have available and I'm leaning on screencasts to learn them. I really like the screencasts that Rob Conery is doing and I've got really positive response from the ASP.NET MVC Screencasts.

I'm starting to think that all technical books should come with a accompanying screencast series. You typically have to watch closely and pay attention, and it's hard to watch a screencast in double speed (unlike a podcast) but a well-done screencast is the next-best thing to letting an expert take over your computer and show you.

There are many tools that support the fundamental tenets, beliefs, and preferred processes in the ALT.NET space. Certainly ALT.NET isn't "all about the tools," but there are certainly preferred tools.

One of those is NHibernate, a sophisticated Object Relational Mapper. I used NHibernate as my Data Layer recently when I got ASP.NET MVC running under .NET 2.0 using NHibernate examples from Davy Brion (who has an NHibernate Category on his blog).

NHibernate is very flexible, but it's a little overwhelming (for me, at least) to get started. Davy has a good "code-heavy" walkthrough of the concepts. Some NHibernate write-ups assume too much, IMHO.

Perhaps to combat this, Stephen Bohlen has created the Summer of NHibernate Screencast Series as a learning tool to educate engineers at his company. Stephen says:

"Often, our strategy for bringing people up to speed on [NHibernate] has been to rely on word-of-mouth and osmosis (often via pair-programming) to get the points across, but now we have a planned staffing ramp-up of a magnitude that will likely make that approach unwieldy."

He's releasing these screencasts to the public and you can check them out at http://www.summerofnhibernate.com/ or subscribe to the feed and get them downloaded automatically like podcasts! Stephen's also including Code Downloads with each screencast.

If you like them, remember that Stephen's doing this for free, while bandwidth isn't, so you can donate via Paypal to help him out. You can visit Stephen's blog with comments and suggestions. My primary suggestions to him would be to drop his resolution to 1024x768 or even 800x600 (what I do) and raise his font size to Lucida Console 16. Right now, you'll need a high-res (1280) monitor to watch his screencasts.

These small nits aside, I think it's great that NHibernate is getting more screencasts that really help folks get started and augment NHibernate's excellent documentation.

Related Links

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The Weekly Source Code 30 - Spark and NHaml - Crazy ASP.NET MVC ViewEngines

July 21, '08 Comments [20] Posted in ASP.NET | ASP.NET MVC | Source Code
Sponsored By

I've been getting more and more interested in how folks extend their applications using plugins and things. In my new ongoing quest to read source code to be a better developer, Dear Reader, I present to you thirtieth in a infinite number of posts of "The Weekly Source Code."

Spark

I'm really enjoying the extensibility points in ASP.NET MVC, but not as much as some people. Spark is a really promising ViewEngine from Louis DeJardin. You can download Spark here and join the mailing list here. Not only is it promising, it's also freaky. Freaky in that good, makes-you-think way.

Louis says "The idea is to allow the html to dominate the flow and the code to fit seamlessly." When he says HTML should dominate the flow, he's not kidding. Check this out:

<ul>
<li each='var p in ViewData.Model.Products'>
$p.Name; $Html.ActionLink[[ProductController]](c=>c.Edit(p.Id), "Edit");
</li>
</ul>

See the "each" attribute on the UL? Freakly. ;)

Remember this is NOT WebForms. That <li> and the each attribute are not controls, or parts of controls or runat=server or whatever. This is a complete ViewEngine. It's a templating language in and of itself. (As are most ViewEngines, although it's not an obvious point to a lot of folks getting started with ASP.NET MVC or any MVC Framework)

That means that Louis has complete control of what the syntax is, and as you can see, it's somewhere in between HTML and Something Else. He's still changing the syntax based on feedback, so this is your chance to get involved.

Here's Louis' Northwind "Listing By Category" page:

<viewdata 
model="IList[[Product]]"
CategoryName="string"/>

${PageTitle(CategoryName)}

<CategoryMenuItems category="ViewData.Model.Select(p=>p.Category).FirstOrDefault()"/>

<ul class="productlist">
<var styles='new[] {"odd", "even"}'/>
<li each="var product in ViewData.Model" class="${styles[productIndex%2]}">
<ProductImage style='"float:left;"'/>
<p>
<a href="/Products/Detail/${product.ProductID}">${product.ProductName}</a>
<br />
Price: ${String.Format("{0:C2}", product.UnitPrice)}
<span class="editlink">
(${Html.ActionLink[[ProductsController]](c=>c.Edit(product.ProductID), "Edit")})
</span>
</p>
<div style="clear:both;"></div>
</li>
</ul>

imageNotice  not only that the iterators live on the markup tags like <li> but also that you can create variables. See how an array called styles is created to hold the strings odd and even, then used to set the class on the <li> on the next line. The "jump into code block" is usually ${ } rather than <% %> which I find nice visually.

However, Spark is all about choice, so you can use EITHER ${ } or <% %>. Whatever makes you happy.

Also, check out the <CategoryMenuItems> tag. What's that? That's a partial view-file that gives you clean partial rendering.

If you have a partial view file that are starts with an underscore, then you can call that from a regular view using its name as a tag. You can see two partial view files in the screenshot at right. It's really just a really pretty syntactic sugar over include files. Neat though!

Go check out Spark and hear more at Louis' Blog.

NHaml

The deeply awesome Andrew Peters created NHaml (part of MVCContrib), an ASP.NET View Engine using the Haml syntax from Ruby. I've been showing Andrew's stuff as an extreme example of what a ViewEngine could look like.

For example, here's a standard "Listing by Category" page using the built-in WebForms ViewEngine, written using NHaml. Notice the lack of angle brackets. Notice that the UL tag never ends...it just leaves scope. The whitespace is significant. Haml users feel strongly about not repeating themselves, even in markup. They want "Markup Haiku."

#foo
- foreach (var product in ViewData)
- if (product.Category.CategoryName != null)
%h2=product.Category.CategoryName
- break
%ul.productlist
- foreach (var product in ViewData)
%li
= Html.Image("/Content/Images/" + product.ProductID + ".jpg", product.ProductName)
.productdetail
=Html.ActionLink(product.ProductName, "Detail", new { ID=product.ProductID })
%br
Price:
=String.Format("{0:C2}", product.UnitPrice)
%span.editlink
(
=Html.ActionLink("Edit", "Edit", new { ID=product.ProductID })
)

Other cool View Engines include Castle's Fork of NVelocity and Brail (in MVCContrib).

Related Links

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Adding OpenSearch to your website and getting in the Browser's Search Box

July 21, '08 Comments [18] Posted in Musings | Tools | Web Services
Sponsored By

I was over at http://search.twitter.com earlier today and I noticed the Search Box in Firefox had a blue lit-up dealie:

image

Hm...OK. What's that? I hit another site and didn't see it. Weird. Ok, View-Source then, what drives you little blue thing?

<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Twitter Search">

Hey, that's not something I've seen before. What's in it...http://search.twitter.com/opensearch.xml...

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Twitter Search</ShortName>
<Description>Realtime Twitter Search</Description>
<Url type="text/html" method="get" template="http://search.twitter.com/search?q={searchTerms}"/>
<Image width="16" height="16">http://search.twitter.com/favicon.png</Image>
<InputEncoding>UTF-8</InputEncoding>
<SearchForm>http://search.twitter.com/</SearchForm>
</OpenSearchDescription>

Ah! I totally get it. Excellent. I shall make my own immediately! I added this file to my website and added a <link> line as seen in the first example above that pointed to it.

<?xml version="1.0" encoding="UTF-8" ?> 
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Hanselman Search</ShortName>
<Description>Search Scott Hanselman's Blog</Description>
<Url type="text/html" method="get" template="http://www.hanselman.com/blog/...snip...q={searchTerms}"/>
<Image width="16" height="16">http://www.hanselman.com/blog/favicon.ico</Image>
<InputEncoding>UTF-8</InputEncoding>
<SearchForm>http://www.hanselman.com/</SearchForm>
</OpenSearchDescription>

Bam.

image

I wonder if it works in IE7?

image

Pow! I wonder if Live.com supports it?

  image

Eek! FAIL. I'll mention that to someone at Live.com

OpenSearch is a really easy feature that you can add to your website in literally minutes. Seconds if you type fast. Check me out noticing this only three years late. :)

Give it a try!

IMPORTANT NOTES: Make sure you include the first line of the XML file (the XML declaration) or IE will ignore it and nothing will happen when you add it. Also, make sure you include the default XML namespace or Firefox will give you an error: "Firefox could not download the search plugin"

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Learning WPF with BabySmash - Making a Transparent Window with Substance

July 19, '08 Comments [9] Posted in BabySmash | Windows Client | WPF
Sponsored By

NOTE: If you haven't read the first post in this series, I would encourage you do to that first, or check out the BabySmash category. Also check out http://windowsclient.net/ for more developer info on WPF.

BACKGROUND: This is one of a series of posts on learning WPF. I wrote an application for my 2 year old using WPF, but as I'm a Win32-minded programmer, my working app is full of Win32-isms. It's not a good example of a WPF application even though it uses the technology. I'm calling on community (that's you, Dear Reader) to blog about your solutions to different (horrible) selections of my code. You can get the code http://www.codeplex.com/babysmash. Post your solutions on your blog, in the comments, or in the Feedback and we'll all learn WPF together. Pick a single line, a section, or subsystem or the whole app!

Someone wanted the BabySmash Window to have the option to be transparent. I figured, hey, WPF must be good at that, transparency at all. I bet it'll be like one line of code.

I went into my MainWindow.xaml and added these attributes:

Background="Transparent" AllowsTransparency="True" WindowStyle="None" 

Bam! Right? Well, kind of. This made the Window Transparent, but "hollow" in that I couldn't click on it. It was totally invisble, except for my little bit of text at the top. I could "click through" the application to the desktop below.

image

Well, here's why, and if I'd read 4 chapters into Chris Sell's book, I'd have figured this out. ;)

Per Dwayne Need on the WPF Team:

"Windows treats fully transparent layered-windows windows as hollow."

This was interesting because everywhere else in WPF if you have a Brush that is null, that's "hollow" and Transparent is solid. Again, Dwayne:

"This is because a layered window is represented to the OS as a bitmap, so all it can do is look at the pixel values.  It [Windows] cannot differentiate between null and Transparent."

Ah, makes sense. This is where WPF meets the rest of Windows. Ok, but I have complete control over my Brushes and their colors. I can make a Brush that is not just #000000 (Black) but also #01000000 (really really transparent black. Like 1/255th transparent). You've got not just RGB, you've got an Alpha Channel PLUS RGB.

Now if I set my Window's background to this Brush:

new SolidColorBrush(Color.FromArgb(1,0,0,0))

I get the look of transparency, except the Window is still there and I can click on it.

"Your almost-transparent brush fails the Windows transparency test, so windows delivers events to it. If something is 100% transparent then hit testing is bypassed.  If you want transparency and hit testing, define a color with minimal alpha just as you have done.

This was an interesting edge class where WPF's definition of Transparent didn't quite line up with Window's definition.

Once you've created a Window that is transparent like my funky full-screen one,,,

MainWindow m = new MainWindow(this)
{
WindowStartupLocation = WindowStartupLocation.Manual,
Left = s.WorkingArea.Left,
Top = s.WorkingArea.Top,
Width = s.WorkingArea.Width,
Height = s.WorkingArea.Height,
WindowStyle = WindowStyle.None,
Topmost = true,
AllowsTransparency = Settings.Default.TransparentBackground,
Background = (Settings.Default.TransparentBackground ? new SolidColorBrush(Color.FromArgb(1,0,0,0)) : Brushes.WhiteSmoke)
};

...you can't change the Transparency after you've shown it...or else...

image

Chris Sells suggested I set my Window to AllowsTransparency = True all the time, then make a Canvas over the top of it that had an opaque Brush with color and transparency I could change as I liked as it'd be "inside" WPF world and not have to deal with any underlying limitations in Win32.

For now, my not-quite-transparent brush got me the feature I wanted - BabySmash over an existing desktop.

image

Cool.

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Learning WPF with BabySmash and Back to Basics - Making Assumptions and When to Turn to Books

July 18, '08 Comments [12] Posted in BabySmash | Back to Basics | Windows Client | WPF
Sponsored By

NOTE: If you haven't read the first post in this series, I would encourage you do to that first, or check out the BabySmash category. Also check out http://windowsclient.net/ for more developer info on WPF.

BACKGROUND: This is one of a series of posts on learning WPF. I wrote an application for my 2 year old using WPF, but as I'm a Win32-minded programmer, my working app is full of Win32-isms. It's not a good example of a WPF application even though it uses the technology. I'm calling on community (that's you, Dear Reader) to blog about your solutions to different (horrible) selections of my code. You can get the code http://www.codeplex.com/babysmash. Post your solutions on your blog, in the comments, or in the Feedback and we'll all learn WPF together. Pick a single line, a section, or subsystem or the whole app!

image I hung out with Chris Sells at the Mall Food Court today. He had trouble finding a parking spot and I felt bad. But I didn't REALLY start feeling bad until I started showing him the code for BabySmash.

He had a number of ideas for ways to make BabySmash better, but what was interesting was that he was using his own book as reference. He'd say, "oh, we did that in Chapter 4" and "ya, that does suck, check out this call out where I explain why." After this happened about four or five times he said (I think in jest, but you can never tell with famous dudes. ;) )

"Did you invite me here to read my book to you?"

After I picked my ego off the ground, unfolded it, dusted it off, and smoothed it out, I said, "I don't think so."

Chris had a really good point. It turned out that even though I have a three WPF books at my house, I haven't read them all deeply and thoughtfully. I hadn't even made it though the first few chapters. Mostly I skipped around, looking for answers to my specific questions.

Through my questioning, Chris noticed that I had some fundamental misunderstandings about some the basics of WPF. Things I thought worked one way, worked another or in reverse. Some concepts that were WPF 101 I had overlooked completely because I hadn't least made it through ~5 chapters and cemented the fundamentals.

I am not saying that we need to read every book all the way through, but I did learn a useful lesson. Don't assume you know how it works. Just a few hours of covering the fundamentals would have saved me a lot of time.

In the last post I said I was starting to grok WPF. Looks like less than I thought. I had left pretty significant gaps in my understanding by skipping around and assuming "oh, this works like that."  Those gaps in my knowledge led to some interesting directions in BabySmash. I'll post about some of those things I learned from Chris soon, but suffice it to say, I completely misunderstood how events moved around a WPF application.

Thanks Chris for setting me straight! Sorry about the parking!

OK, page one, "Hello, WPF."

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

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