Wednesday, December 19, 2007

Design and Implementation - Episode 1

Update: I managed to mess up the permissions on the MP3 file, resulting in a few "access denied" errors. Ironically, I did this while trying to fix the Content-Type. Anyway, it should be working again. Sorry!

 

(For the impatient: link to episode 1 (MP3).)

 

For a long time now, Tim and I have called each other up on the phone whenever we have an interesting or difficult technological decision to make. The conversations have often been very interesting, and are in a large part responsible for the way I think about software. A while back, I was thinking to myself, "Man, we should record these - I bet other people would be interested in this stuff as well."

 

So we did.

 

Announcing the first episode of "Design and Implementation", a podcast by Craig Andera and Tim Ewald. You can grab the MP3 here. In our inaugural episode, we explore the topic of web service architectural styles, such as REST, SOAP, RPC, and Resource-Orientation. If you read our blogs, you'll know it's something we've both been thinking a lot about recently.

 

At some point in the future, we'll get a proper landing page together, with a feed and everything, but until then just watch here or on Tim's blog for announcement of new episodes.

 

We've already got a few more shows planned out, but with two and a half kids between us and the usual demands of life, I don't think we're going to be able to post more often than once a month. After all, (apparently unlike Scott Hansel(Super)man), I need to sleep. :)

 

We had a great time doing the first show, and I think you'll enjoy it. That said, I know we have a lot to learn about recording and producing a show, so if you have any advice/compliments/complaints, please drop a comment here!

 

Once again, here's the link to episode 1.

Wednesday, December 5, 2007

FlexWiki 2.0 Release Candidate 1 Available

I just posted the files for FlexWiki 2.0 Release Candidate 1. Woohoo! You can get it here.

 

Here are the release notes:

 

This is Release Candidate 1 of FlexWiki 2.0. Assuming we don't find any major bugs, this release will become the final FlexWiki 2.0 version: the Released To Web (RTW) version.

 

This version sports many, many improvements and enhancements over 2.0 Beta 2. Among these are:

 


  • Vastly improved performance

  • New tools for editing the configuration files via the web interface

  • Automated table-of-contents generation (via WikiTalk)

  • Page locking (a security feature)

  • Threaded message support for blog/forum-type behavior

  • An all-new default stylesheet for a fresh look

  • Support for file upload and page attachments

  • Improved XHTML compliance

  • Tons of bugfixes

 

This is not a complete list - there's lots more.

 

Thanks to Derek, John, and Nathan for all the great code, and to the FlexWiki community in general for all the excellent suggestions and feedback.

 

Enjoy!

 

Wednesday, November 21, 2007

Temporarily Bypass Popup Blocking in IE7

I read over on ZMan's blog the other day about how he was having some serious issues with downloading VS2008. The list of problems is extensive, but I'll quote a bit of it here:

 

You have to turn off your pop up blocker. "You will also need to allow pop-ups (at least temporarily)." - and they REALLY mean turn it off. You can't ctrl-click. You can't wait for the yellow bar and then say allow it because the site does multiple redirects and so you never get to see the page with the yellow bar. Remember that pop up blocker is ON by default in IE. You would think MS could make this a little easier in their own browser.

 

I rarely use IE myself (preferring Firefox), but I do know a few people on the MSDN team, so I made them aware of it. One of them posted this little workaround on ZMan's blog in response, but I think ZMan has comment moderation turned on and hasn't gotten around to approving the comment yet, so I'll put it here in case it saves someone some grief:

 

From your comments, it sounds like you are running IE7 on Vista.  If this is the case, to temporarily bypass the pop-up blocking functionality of IE7, you need to hold down Ctrl-Alt and click the link (Ctrl-click was how IE6 behaved). 

 

ZMan also had some issues with download location - read the rest of his post for the details. I'll reprint the response to that part here as well.

 

The second issue you had regarding the controlling of where downloads can be saved by an ActiveX control and the message prompts you received is a feature of IE7’s protected mode.  You can adjust these settings by clicking on the “Protected Mode” text in the lower right area of IE7.  Finally, to draw attention to the fact that downloads are being launched with a pop-up, our content team bolded the text on the download control to ensure it stands out a little better.

Friday, November 2, 2007

Simple Filename Wildcarding

I was writing a command-line application for a client the other day, and I found myself wanting to support syntax like this:

 

foobar *.foo *.bar foo*bar

 

which is to say, "run foobar against files that end with .foo, end with .bar, or that start with foo and end with bar." This is a fairly familiar thing for command-line apps to do.

 

One way to approach this is to interpret things like "*.foo" as regular expressions. I don't particularly like this solution, since a) it makes people learn regular expressions to use my app effectively, and b) the common patterns like *.foo don't really work like you want them to - "*.foo" is a regular expression meaning "anything that contains 'foo'" rather than "anything that ends with '.foo'".

 

Another way to deal with this is to use Directory.GetFiles. If you read the documentation, however, there are two issues. The first is that the caveats called out in the notes make the behavior pretty weird. For example, "*1*.txt" matches "LongFileNameHere.txt". Ick. The other issue is that this approach doesn't allow multiple patterns, so I have to scan the directory multiple times and merge the results to do the "*.foo *.bar foo*bar" example above.

 

I hit what I think is a fairly elegant solution, and I wanted to share it with you. The basic idea is to use string.Split, string.Join, and Regex.Escape to create a regular expression that supports exactly one "operator": the asterisk, which matches zero or more of any character. Here's the code:

internal static bool IsMatch(string name, string pattern)
{
// Short-circuit common cases
if (string.IsNullOrEmpty(pattern)) {
return false;
}
if (string.IsNullOrEmpty(name)) {
return false;
}
if (pattern.Equals("*")) {
return true;
}
if (pattern.Equals(name, StringComparison.CurrentCultureIgnoreCase)) {
return true;
}


// Bust the pattern apart at the asterisks
string[] parts = pattern.Split('*');
List patternParts = new List();
foreach (string part in parts) {
patternParts.Add(Regex.Escape(part));
}
// Then put it back together with .*, which matches
// any sequence of characters, and surround it with
// the start-of-string (^) and end-of-string ($) patterns
// so we don't match on things that only start or end
// with what we're after.
string newPattern = "^" + string.Join(".*", patternParts.ToArray()) + "$";
Regex expression = new Regex(newPattern, RegexOptions.IgnoreCase);
return expression.IsMatch(name);
}

Which, I think, is pretty nice, if I do say so myself. Best of all, it has semantics that make it match what I expect file patterns to do.

 

Using it is a simple matter of calling Directory.GetFiles to get all the files in the directory, and then filtering it via a looped call to this method.

 

You'll note that I haven't put in support for the ? operator (match exactly one character), because a) I hardly ever use this myself, and b) it would be pretty simple to bodge in if I ever needed to. It would just take a second call to Split/Join over each patternPart.

 

Hope this helps someone. It was fun to write.  

Thursday, October 11, 2007

How to Improve Collection Initializers

I think I'm starting to traverse the Linq/Orcas circle of (software) life, because I finally hit something that I don't like and that I couldn't work around. So far, anyway - maybe someone out there can tell me where I'm going wrong.

 

You may know that in the Orcas version of C#, they've added support for initializing collections via the funky new object initialization syntax. You can read about it here. The issue that I'm running into has to do with the fact that I'd like to initialize a collection in an object initialization expression, but I'm using XLinq to do it, and as a result I'm getting a compiler error.

 

See, I can get this to work:

 

Person craig = new Person

{

  Name = "Craig",

  Age = 35

  Children =

  {

     new Person

     {

        Name = "Ellen",

        Age = 2.9

     },

     new Person

     {

        Name = "TBD",

        Age = -0.4

     }

  }

}

 

But because this is just a simple example and in my real code I don't know the collection items at compile time, what I really want to do something is like this:

 

Person craig = new Person

{

  Name = "Craig",

  Age = 35,

  Children =

  {

     GetProgeny("Craig Andera")

  }

}

 

Where the Person class is the obvious implementation, and GetProgeny returns IEnumerable<Person>. Without doing anything else, I get a compiler error saying that Collection<Person> does not contain an overload of Add that accepts an IEnumerable<Person>, which makes perfect sense given that the collection initialization syntax is just shorthand for a bunch of calls to Add.

 

The part that sucks is that I can't get this to compose with extension methods to get what I want. That is, I'd like it if I were able to define an extension method like this:

 

public static void Add(this ICollection<Person> collection, IEnumerable<Person> items)

{

   foreach (Person item in items)

   {

      collection.Add(item);

   }

}

 

But that doesn't work. I'm not sure why, but here's the list of things I hope it is, in decreasing order of desirability:

 


  1. I'm doing something wrong.

  2. It doesn't work and there's a good reason.

  3. It doesn't work and there's no good reason.

 

Anyone have any idea which it is?

 

Update: I should have said right up front that Children is a read-only property of Person. I always make my collections read-only, and would prefer to do so in this case as well.

Tuesday, October 9, 2007

Add Using Statement in Visual Studio 2008

Update: Apparently this has been available since VS2005. Who knew? Other than the people that commented, of course. Certainly not me. :)

 

Update #2: So, the "organize usings" menu item that I happened to show in the screenshot alphabetizes the using statements. Also very nice, although I'd like it better if it didn't remove the line breaks I put between groupings. Still, nice. You can also remove unused using statements. Here's the menu:

 


 

Jon Flanders showed this to me the other day. In Visual Studio 2008, if you've just added a class for which you haven't yet added the corresponding using statement to bring the namespace into scope, you can hit control-dot, and up pops the following menu:

 


 

And sure it enough it pops a "using System.Collections;" in up at the top of the file. Very nice. Better still if it would put it in alphabetical order, but I seem to recall that the order of using statements is significant when Linq is in play, so maybe they couldn't do that.

 

You can also access it via the right-click menu:

 

Tuesday, September 25, 2007

HashSet&amp;lt;T&amp;gt; - Finally a Set Implementation in the .NET Class Libraries

Update: Despite what the documentation says, this class is new to .NET 3.5, and is not present in the .NET 3.0 libraries.

 

Update: Fixed typo - HashSet does not allow duplicate members, just as you'd expect.

 

I was poking around the other day and I noticed System.Collections.Generics.HashSet<T>. Sure enough, it's a collection class with the semantics of a set: there are no duplicates no matter how many times you add an item to the set, it is unordered, and it supports intersection, union, and subset operations.

 

It's part of .NET 3.0 3.5, so it's been around for a little while not quite out yet. I doubt I'm the last (although I'm even more sure I'm not the first :) to hear of it, though. Go check it out, because a set is one of those data structures that gets used all the time. If you've ever instantiated a Dictionary<T, bool> just to keep track of if you've seen something, you know what I mean.

 

Thanks, CLR team!