Friday, September 28, 2007

Join Microsoft, Get a Harley

Josh Holmes, a long-time friend who’s had a number of significant (positive) impacts on my career, joined Microsoft last year as the region’s Architect Evangelist.  Josh has a way with working deals.  Like managing to get a Harley for his job.

OK, so it’s not just Josh getting a Hog, it’s Josh coming up with a terrific concept for a great Channel 9 show: Code To Live.  He and Steve Loethen are travelling around on a Hog doing shows about passionate folks who develop code because it’s something central to their personas.  As Josh says, “Coding isn’t just a paycheck, it’s who we are.”

The show looks terrific, and with Josh behind it you can rest assured the shows will be full of great content.

Great stuff, Josh — keep it up!

Tuesday, September 25, 2007

Blogroll Shoutout

The folks at NuSoft Solutions where I worked for a short bit have made some of their blogs publicly available.  NuSoft has a bunch of smart folks and I’m glad to see they’re rolling out a public facing site.  I tried fighting for a public blog while I was there but got no traction, but I was the new kid on the block and was in Cincinnati far away from the rest of the collective.  I’m really glad to see that Chris Woodruff got the project pushed forward!

In any case, you might pay attention to that set of blogs!

Friday, September 21, 2007

CoolCommands for VS 2005

CoolCommands is perhaps one of my favorite add-ins for Visual Studio 2005 — perhaps even more so than TestDriven.NET.  Check out Gaston’s post for some of the details of its goodness.  Suffice it to say that I use features from it on a nearly hourly basis as I’m coding.

The URL for the tool is wrong on the post page, though.  You can find CoolCommands’ installer here now.

Thursday, September 20, 2007

Good (Older) Series on the /3GB Switch

Raymond Chen, author of the great book The Old New Thing, has a nice series of posts back in August, 2004, laying out what exactly the /3GB switch does for your addressing in 32–bit versions of server operating systems.

There’s an awful lot of misunderstanding around on what that switch does, and a lot of people don’t really consider the consequences of flipping that switch.

Chen’s blog isn’t a regular read of mine, but it’s a great source of information when I’m looking for anything deep level about operating systems, memory, and a host of other things.

(Go read his book, too.)

Nice HOW-TO for Creating Site Collections in a Specific Content DB

A very nice HOW-TO with pictures, even, on the steps needed for creating site collections in a specific content DB.  There’s also a bit at the bottom on how you carve off sites in an existing content DB and move them off to their own DB.

Wednesday, September 19, 2007

Finding the Length of an Image Field in SQL 2005

Problem: I need to know the size in bytes of an image stored in an Image column in SQL 2005.

Solution: SELECT DATALENGTH(image) FROM schematicsimage WHERE [schematicsid] = 527

(Courtesy of Bruce the DBA)

Wednesday, September 12, 2007

Working With LZ-Compressed Files in .NET

I’m needing to deal with some files compressed with the COMPRESS.EXE utility which packs targeted files in the Lev-Zimpel algorithm via the lz32.dll system library.  That means playing with PInvoke which is something I’d rather not do since it’s generally a huge PITA. 

To uncompress files you’ll need to open the zipped file, copy it to another file (expanding it enroute), then close your source and target files.  Three different calls from lz32.dll: LZOpenFile, LZCopy, and LZClose.  PInvoke means you need to reference those calls with DllImport statements:

[DllImport("lz32.dll", EntryPoint = "LZOpenFile", SetLastError = true,

    CharSet = CharSet.Ansi)]

public static extern int LZOpenFileA(

    string lpszFile,

    [Out, MarshalAs(UnmanagedType.LPStruct)] OFSTRUCT lpOf,

    int mode);

 

[DllImport("lz32.dll")]

public static extern int LZCopy(int hfSource, int hfDest);

 

[DllImport("lz32.dll")]

public static extern int LZClose(int hfFile);

A couple things about the first call, LZOpenFileA: The CharSet declaration makes sure that the unmanaged code gets things correctly marshalled from the CLR’s native Unicode over to the unmanaged world’s ANSI.  Secondly, the OFSTRUCT structure in the Win32 world needs defining as a .NET class in our world:

[StructLayout(LayoutKind.Sequential)]

public class OFSTRUCT

{

    public const int OFS_MAXPATHNAME = 128;

    public byte cBytes;

    public byte fFixedDisc;

    public UInt16 nErrCode;

    public UInt16 Reserved1;

    public UInt16 Reserved2;

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=OFS_MAXPATHNAME)]

    public string szPathName;

}

The string szPathName gets some MarshalAs love to deal with the transition from managed to unmanaged code.

Finally, we’ll set a couple constants for the mode we’re opening the files in:

private const int OF_READ = 0x0;

private const int OF_CREATE = 0x1000;

Now the code to actually deal with the calls:

public static string ExpandLZCompressedToTempFile(FileInfo file)

{

    OFSTRUCT sourceStruct = new OFSTRUCT();

 

    int handleSource = 0;

    int handleTarget = 0;

    string tmpFile = "";

 

    handleSource = LZOpenFileA(file.FullName, sourceStruct, OF_READ);

    OFSTRUCT targetStruct = new OFSTRUCT();

    tmpFile = FileSystem.GetTempFileName();

    handleTarget = LZOpenFileA(tmpFile, targetStruct, OF_CREATE);

 

    LZCopy(handleSource, handleTarget);

 

    LZClose(handleSource);

    LZClose(handleTarget);

 

    return tmpFile;

}

I’ll use another method to read the expanded file and stream that into a GZip-compressed format since that’s supported in .NET’s managed world.

Check out Natty Gur’s article on Code Project if you’re interested in some very, very deep PInvoke details.  His article solved a couple issues for me, but is written about sharing and caching data between processes using some interesting trickery. 

Tuesday, September 11, 2007

Visual Studio Tip of the Day

If you’re not reading it already, hop over to Sara Ford’s blog and subscribe PDQ.  She’s got an ongoing series of daily tips for VS 2005/2008.  There’s a lot of serious gold therein!

Saturday, September 08, 2007

Extreme Model-View-Presenter

ARCast has a very interesting three-part series on Presenter-First development.  There’s a lot of thought-prevoking discussion on breaking out responsibilities in a MVP pattern approached from the presenter first.  Mocks, interfaces, single responsibility principle, adapters, and an interesting take on what they see as the model. 

The folks at Atomic Object wrote a good white paper on the topic that I’ve been slowly working through. What I found interesting was their approach of having all communication to the presenter based on events spawned from the view or model.  I disagree with the algorithm (steps) they use for approaching the development (they stub out the presenter with interfaces and mocks before they even hit the user stories), but there’s an awful lot of useful info therein.

Listen to episode 1, #2, and the final installment and check out the paper.  Good stuff.

Shout Out: Web Standards Meetup Group

Who knew?  Dayton’s got its own web standards meetup group.  Interested in doing your web work in a non-craplike fashion?  Check ‘em out.

(Updated: The reason I ran across this is because Justin, one of the two guys foolish enough to sign up for helping me run the .NET User Group here, is speaking there later this month.)

Thursday, September 06, 2007

Toggling All Cells in a DataGridViewCheckBoxColumn

Problem: Need to toggle all cells in a DataGridViewCheckBoxColumn.  We’re using a dynamically generated set of checkbox columns starting after two static columns.

Solution: 

private void dataGridView1_ColumnHeaderMouseClick(object sender,

                                              DataGridViewCellMouseEventArgs e)

{

    int colNumber = e.ColumnIndex;

    if (colNumber > ROLE_COLUMN_START_POSITION)

    {

        bool selectAll = (bool) dataGridView1.Rows[1].Cells[colNumber].FormattedValue;

        foreach (DataGridViewRow row in dataGridView1.Rows)

        {

            row.Cells[colNumber].Value = !selectAll;

        }

    }

}

Adapted from a couple Google hits.  Yes, it’s based off the value already extant in row one, but hey, it’s just ducky.

(Thanks to Kramer for getting the grid built and populated in short order today!)  (Now I wish he’d just start blogging so he could write this stuff himself.)

Monday, September 03, 2007

MOSS & WSS SDKs Updated

This is almost a week old, but critically important if you’re working in the MOSS or WSS space: Go grab the new SDKs for MOSS and WSS.

The SharePoint Team Blog lays out a lot of the updates on their blog.  One of the most critical is the holes they’ve filled in the documentation.  This is an area that’s been brutally, horrifically, pathetically terrible in the initial release.  I’ve ranted about this a number of times already, so I’ll just leave this part off with another small one: the state of the initial documentation was unconscionable.  It’s taken far too long for them to clean it up, but at least they’ve applied more resources and are closing the gap.

Rant off.

Now go get v1.2 of the SDKs!

Sunday, September 02, 2007

Getting Rid of Dialog Boxes So You Can Test

If you’re doing any sort of UI work you seriously need to read Jeremy Miller’s killer series on Writing Your Own CAB.  One of the best gems in there (and there are many) is the piece on humble dialog boxes.

Miller’s clear text shows how to pull that out of your presenter, toss it back to the view, and write solid tests using Rhino.Mocks (yay!) to validate everything.

Gold.  Sheer gold.

Saturday, September 01, 2007

CodeMash Call For Speakers Open

CodeMash is now accepting submissions for speakers.

Got game?  Submit an abstract!  We’re looking for unique, educational sessions on a wide range of topics.

Subscribe (RSS)

The Leadership Journey