Scott Hanselman

How-To: New ASP.NET 3.5 Extensions Video Screencasts

December 21, '07 Comments [17] Posted in ASP.NET | ASP.NET MVC | Microsoft | Programming | Screencasts | Speaking
Sponsored By

Release today are four new screencasts about the ASP.NET 3.5 Extensions by various members of the ASP.NET team. You can get them immediately at the same page as before, at the bottom: http://www.asp.net/Downloads/3.5-extensions/.

Every video is available in numerous formats, and note that this also includes re-encoded versions of my Intro to MVC Screencast in a pile of formats including an iPod/iTouch compatible format, as well as ones for the Zune and PSP and a utterly unwatchable ;) 40 meg 3GP one for 3G Phones.

We also have included Audio-Only downloads in five different formats, so complain not, Dear Reader! We've got your back. I expect to wait less than 5 minutes before my first snarky reader lives the obligatory "what about Ogg Vorbis?" comment. :)

Here they are:

Enjoy!

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

aideRSS - Now things are getting smarter

December 19, '07 Comments [9] Posted in
Sponsored By

Scott Hanselmans Computer Zen - AideRSS - Windows Internet Explorer This is clever. AideRSS is an smart RSS filterer gives just the Good, Great, Best or Top 20 posts given any RSS Feed. How does it measure quality? Well, since it can't really measure quality it infers it indirectly by creating a metric based on the number of del.icio.us bookmarks, diggs, Blogger references, Technorati references, Google BlogSearch reference, IceRocket references and a few others.

Of course, this assumes your blog is being read because it's interesting and these external references are a quantitative metric that implies quality. There, of course, are lots of great blogs with great content that haven't been discovered yet, but this is still a pretty neat way to apply these metrics.

So what do they do with these numbers? They create alternative feeds that you can subscribe to in lieu of the blog's main feed so as to just read about the "great posts" or "just the hits." Sounds like a great idea, but then you'd miss all the posts about my kids!

Here is one of their active widgets showing me the percentage of my posts that don't suck (so say their metrics. ;) )

Check it out. (Yes, "well recieved" is incorrectly spelled in their Javascript widget. If it's not anymore, it's because they fixed 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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Moq: Linq, Lambdas and Predicates applied to Mock Objects

December 19, '07 Comments [13] Posted in ASP.NET | Learning .NET | LINQ | Musings | Programming
Sponsored By

iStock_000004250790XSmall Kzu and friends have a new pet project called Moq, which may be the coolest derivative open source project name ever. But, before I get into that...

There's lots of interesting Mock Object Frameworks out there. The ones that you'll always hear about (because they are awesome) are Rhino.Mocks and TypeMock (Full Disclosure: we used TypeMock at Corillian, my last job. Here's a Case Study that was done.)

Both frameworks are very powerful. Here's Phil Haack's post on mocking IHttpRequest and IHttpReponse in the new MVC Framework using Rhino Mocks. Here's Travis Illig using TypeMock to mock the actual HttpContext (not the MVC interface) earlier this year.

One of the things that often comes up when comparing Mock Frameworks, after their core capabilities, is their syntax.

Early Mocking frameworks like NMock (which isn't really used much anymore) mock interfaces and use a quasi-fluent interface that breaks down when you start referring to methods and properties using strings. Why is this bad? Well, for one it means when you refactor using tools like CodeRush or Resharper the system doesn't realize that a string referring to "Foo" means the method x.Foo(). For example, here's a snippet from NMock:

   mocks = new Mockery();
   ITransferFundsView mockView = mocks.NewMock<ITransferFundsView>();
   Expect.Once.On(mockView).GetProperty("Amount").Will(Return.Value(200.00));

You get the idea. We're referring to a property "FromAccount" via a string passed into GetProperty, rather than in a strongly typed way.

RhinoMock is smarter, and might look like this snippet:

mockView = (ITransferFundsView)mocks.CreateType(typeof(ITransferFundsView));

SetupResult.For(mockView.Amount).Return(200.00);

See how much clearer it is to just call the property?

TypeMock is implemented as a profiler under the covers so it can do some pretty powerful stuff like "recording" your expectations do you can Tivo them back. So with TypeMock you'd do this using their "Natural TypeMock" syntax.:

 using (RecordExpectations recorder = RecorderManager.StartRecording())
{
double foo = mockView.Ammount;
recorder.Return(200.00);
}
//the next time you call mockView.Ammount, it will return 200.00.

Either way, you can see why both RhinoMocks and TypeMock's syntaxs would be refactoring tool friendly. They compile against the real method signatures and properties so they can been "seen" by the tool. As for which one you like, that's a religious argument I won't get into, but depending on what you need, both are fine choices and they each have a very friendly syntax.

Why all this background? There's a new Mocking Framework in town, and it's C# 3.0 specific using LINQ Expression Trees and Lambda Expressions.

The same snippet in Moq might look like this:

var mockView = new Mock<ITransferFundsView>;
mockView.Expect(x => x.Amount).Returns(200.00);

Note the use of Generics for the Type ITransferFundsView and the interesting use of a Lambda expression to indicate a mocked call to the Amount property. Check out the Moq QuickStart for more interesting examples.

Here's another deeper, more interesting example that shows how lambdas might really be a great feature for any .NET Mock Framework. It's the "It" class combined with the power of predicates.

The It class provides for a kind of wildcard support. There's an IsAny, IsInRange and IsRegex. The coolest one though is the plain It.Is method that receives a predicate!

mock.Expect(x => x.DoInt(It.Is<int>(i => i % 2 == 0))).Returns(1);

Here the mocked object will return the value 1 only if the integer passed to the DoInt method is an even number.

The cool thing about this approach is that you don't need the mocking library to provide all the filters you need, as you can simply pass a predicate for any condition you can dream of.

Slick. Moq is definitely a project to watch.

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

Wiring the house for a Home Network - Part 6 - Identifying Performance Factors of Home Gigabit Networks

December 19, '07 Comments [9] Posted in Musings
Sponsored By

Here's the colophon for my home wiring series. Everything is working great. Here's what I learned.

  • Cat 6 was very likely overkill for my house, but I still feel better doing it and would do it again, if only for the sense of future-proofness (future-proofocity?) that I have. Cat 5e would very likely have been fine, but the difference in cost was minimal.
  • I should have got a wiring closet that was twice as wide as what I got. My closet is large by home standards - it's 4 feet tall - but it's cramped. It's not as tidy as the ones you see in the literature because I used my own switch. Unfortunately it's a 1U switch so it's ridiculously Velcro-ed to the back of the panel, making the whole thing look kind of less-than-sanitary.
  • Once you get a really reliable wireless router, don't ever flash the firmware, or even look at it crooked. I've got a new Verizon FIOS ActionTec router and it's rock solid. It's perfect. It's so good I'm shocked how bad the original old one I had was. The wireless performance is stellar and complete, with coverage throughout the whole house (it's a big house). The signal is strong and every single laptop - even the ones that I thought of as finicky - connect perfectly to it. If you're having wireless problems, it's probably your router.
  • WPA (AES) is a nice simple and very secure way to setup your wireless if you've got Vista or Mac clients throughout. I am also able to get my Wii and PSP hooked up to the wireless easily. Seriously, take the time and give up on WEP and go update your whole house to WPA today.
  • Unless you're like me, a 100 megabit network is likely all you need and you'll probably not max its bandwidth out. It was very challenging to get a file copy to 60-80 megs a second and how often does one do that really? My network runs between 0% and 1% utilization. ;) That said, I'm still happy it's done.

Tim Heuer pointed me to Anthony Park's blog today as he's done a VERY VERY detailed analysis of Identifying Performance Factors of Home Gigabit Networks with a in-depth PDF explaining their methodology. They did 192 different scenarios and the conclusion is amazing enough that you have to read it for yourself.

Anyway, here's the full series of posts on home wiring so far:

  • Wiring the house for a Home Network
  • Wiring the house for a Home Network - Part 2 - Design Q&A
  • Wiring the house for a Home Network - Part 3 - ISP Hookup
  • Wiring the house for a Home Network - Part 4 - Thank You Cat 6 Gigabit Ethernet
  • Wiring the house for a Home Network - Part 5 - Gigabit Throughput and Vista
  • Enjoy.

    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

    How to make Vista Taskbar Previews and ALT-TAB Thumbnails Bigger

    December 18, '07 Comments [5] Posted in Musings | Tools
    Sponsored By

    As monitor resolutions get higher and higher I wish I could scale certain things in Vista more and more. I run with Large Icons, but I still have to look at tiny ALT-TAB Preview Windows and tiny Taskbar Previews.

    Turns out both these problems have been solved. One with a registry key, and one with a deliciously evil (in a good way) hack.

    How to make ALT-TAB Thumbnails Bigger

    Jeff solved this one for me with this registry file. Save it to a .reg file and run as Administrator:

    Windows Registry Editor Version 5.00[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AltTab]
    "OverlayIconPx"=dword:00000023
    "OverlayIconDXPx"=dword:00000000
    "OverlayIconDYPx"=dword:00000000
    "ThumbSpacingXPx"=dword:00000004
    "ThumbSpacingYPx"=dword:00000004
    "SideMarginPx"=dword:00000004
    "BottomMarginPx"=dword:0000000a
    "MinThumbSizePcent"=dword:00000064
    "MinWidthPx"=dword:0000012c
    "TopMarginPx"=dword:00000020
    "MaxThumbSizePx"=dword:000000dc
    "MaxIconSizePx"=dword:0000015e
    "TextBottomPx"=dword:000001f4

    I've also tightened up the borders and margins a bit, to make room for larger thumbnails. However, before importing this into your registry you must edit the MaxThumbSizePx to a size that works on your monitor first! The current value, above, is DC hex or 220 decimal, which works on my 1600 x 1200 primary monitor. The maximum row size is 7, so each row is 7 x 220 = 1540, right under the 1600 width.

    Stunning. Thanks. That's Problem #1.

    How to make Taskbar Thumbnail Previews Bigger

    Unfortunately it seems that Explorer has hardcoded the Taskbar Preview Thumbnail size, but you can use Andreas Verhoeven's Thumbnail Sizer to change the internal value at runtime by loading his DLL into Explorer where he will overwrite that spot in memory. I didn't say it wouldn't hurt, but it works great on my machine and he has both 32-bit and 64-bit versions.

    He also includes source, but if you want to build it on Visual Studio 2005 or 2008 you'll need to download WTL 8.0 (his app is in C++) and change both the include paths and the resource include paths. Also note he's hardcoded the output path for the app if you find yourself hunting for it. Of course, you can always just go to his site and download the binaries. Click on the picture of each app for the associated zip. Also note his PayPal Donation button at the top of his page if you like his stuff!

    Here's a taste of his very simple source. Ah, the good old days. Of course, the magic here is the value of THUMBNAIL_MAX_CX_OFFSET that I'm sure took a long while to find.

    // sets the maximum thumbnail size.
    BOOL CThumbnailSizer::putThumbnailSizes(DWORD maxCX, DWORD maxCY)
    
    {     // idem as getThumbnailSizes(), but for writing the size instead     // of reading.

        HWND hwnd = getTaskBandHandle();     if(NULL == hwnd)
            return FALSE;

        BYTE* data = (BYTE*)GetWindowLong(hwnd, 0);
        if(NULL == data)
            return FALSE;

        DWORD dwPid = -1;
        GetWindowThreadProcessId(hwnd, &dwPid);
        if(dwPid <= 0)
            return FALSE;

        HANDLE hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, NULL, dwPid);
        if(NULL == hProc)
            return FALSE;

        SIZE_T numWritten=0;
        WriteProcessMemory(hProc, data + THUMBNAIL_MAX_CX_OFFSET, &maxCX, sizeof(DWORD), &numWritten);
        WriteProcessMemory(hProc, data + THUMBNAIL_MAX_CY_OFFSET, &maxCY, sizeof(DWORD), &numWritten);

        CloseHandle(hProc);

        return TRUE;
    }

    Fabulous. Problem #2 solved. By the way, while you're over there, pick up his 3D User Picture applet - it almost needs to be seen to be believed. Brilliant.

    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.