wcf, net comments edit

Came across an issue today where we want to be able to read WCF service and client configuration from a custom location. That’s actually more difficult than you’d think.

By default, WCF configuration is stored in your app.config (or web.config) file in the <system.serviceModel> section. When you create a client (like with ChannelFactory<T>) or a service host, the application configuration file gets read, the contents get parsed into the appropriate strong types, and “magic happens” - the appropriate object is created.

In our situation, we wanted to do exactly that, but in a Powershell script… and that’s a problem, because the only way we could get WCF to see the configuration was to actually create a Powershell.exe.config file in the Powershell installation directory, run the script, and then remove the configuration. Not so great. We needed the ability to say, “Hey, WCF, use the configuration file that we explicitly specify.”

That, as I said, is a little more difficult than you’d think.

A lot of searching led me to two articles:

I agree, the titles don’t necessarily sound like they’d help much, but they do. They even include source for how to do this so you can see what I’m talking about. That said, I’ll summarize the steps here.

For service hosting, what it boils down to is:

For clients, it’s slightly more work:

  • Create a custom class deriving from ChannelFactory<T>.
  • Override the protected CreateDescription method. In the override, you need to…
    • Call base.CreateDescription().
    • Read in your custom configuration.
    • Create a custom ServiceEndpoint based on your configuration. Don’t forget the bindings, behaviors, etc. (That’s what makes this hard.)
    • Return that custom ServiceEndpoint.

Once you do that, you’re set - you can create a standalone XML configuration file with the <system.serviceModel> section and point WCF at that rather than having to store the configuration in the default app.config/web.config. You are limited to using your custom service host and client classes, but then, if you’re getting into things this deep you’re probably not afraid of getting your hands dirty.

Again, both of those articles contain full source to the solutions so you can see how it works. Check ‘em out.

sharepoint, testing, net comments edit

The folks over at Typemock have done something special to help address the needs of the SharePoint development community and have released a special version of their Isolator mocking framework specifically to help with testing SharePoint solutions: Isolator for SharePoint.

Isolator for SharePoint is the same Isolator we know and love, but will only work on SharePoint-specific classes. (Of course, if you get sucked in, like I know you will, then you can upgrade to the full Isolator with no issue and mock objects outside SharePoint.)

For a limited time, they’re even offering a few free licenses to folks in the blogosphere, so if you want one, check out how to get one. (If you don’t get one of the free ones, the full retail price of Isolator for SharePoint is $149, and they’re offering a discount for a while so you can get it for $99 - a great deal.)

I did quite a bit of SharePoint development in my last job and something like this would have been amazing to have. If you’re doing SharePoint work right now, you owe it to yourself to give it a look.

media, music, windows, vbscript comments edit

I’m a huge stickler for metadata in my iTunes library and for the most part, I can find incorrect or missing data by using the iTunes smart playlists - I have one, for example, that checks for “Year is 0” so I can find tracks that don’t have a year associated with them.

One of the missing features in there is that you can’t set up a smart playlist that tells you which tracks don’t have artwork. So, to fill that gap, I wrote a script that does it for you. This little JScript, when run, will create a regular playlist called “Missing Artwork” with any tracks that it finds that don’t have any artwork items associated (a track can have multiple pieces of artwork, not just one).

Just ran it myself on my library and it works like a champ. Standard disclaimers apply: use at your own risk, YMMV, I’m not responsible for what happens if something goes awry, etc.

    var ITTrackKindFile = 1;
    var iTunesApp = WScript.CreateObject("iTunes.Application");
    var numTracksWithoutArtwork = 0;
    var mainLibrary = iTunesApp.LibraryPlaylist;
    var tracks = mainLibrary.Tracks;
    var numTracks = tracks.Count;
    var foundTracks = new Array();

    WScript.Echo("Checking " + numTracks + " tracks for missing artwork...");
    while (numTracks != 0)
    {
      var  currTrack = tracks.Item(numTracks);

      if (currTrack.Kind == ITTrackKindFile)
      {
        if(currTrack.Artwork == null || currTrack.Artwork.Count == 0)
        {
          numTracksWithoutArtwork++;
          foundTracks.push(currTrack);
        }
      }

      numTracks--;
    }

    if (numTracksWithoutArtwork > 0)
    {
      WScript.Echo("Found " + numTracksWithoutArtwork + " tracks missing artwork. Creating playlist...");

      var playList = iTunesApp.CreatePlaylist("Missing Artwork");
      for(var trackIndex in foundTracks)
      {
        var currTrack = foundTracks[trackIndex];
        playList.AddTrack(currTrack);
      }
      WScript.Echo("Playlist created.");
    }
    else
    {
      WScript.Echo("No tracks missing artwork were found.");
    }

GeekSpeak comments edit

As mentioned in an earlier post, I got my XO laptop up and running on Ubuntu so I can do a little more useful work with it. (Firefox is a far-and-away superior web browser to the built-in browser that comes with Sugar.) Of course, never satisfied, I noticed there were a few simple applications I’d like to have on there (like a calculator), so I went to install them.

I fired up the “Add/Remove” app in XFCE to see what apps were available. It got to a stage where it said, “Building dependency tree…” and disappeared. Tried a few more times and got the same result. I dropped to the command line, ran gnome-app-install (it took a while to figure out that’s what the app was called) and saw there was a segmentation fault occurring. Then I tried apt-get and got a message about a “segmentation faulty tree.” Very clear.

Doing an additional, oh, hour of searching, I found that this happens when certain cache files get corrupted. The fix?

sudo rm /var/cache/apt/*.bin

Basically, delete a set of cached files that the installation system uses because they’ve gotten corrupted. Re-running the apt-get commands will then work, as will the “Add/Remove” program.

I had updated the OS and installed packages after getting things working, so I know for a fact apt-get was correctly working. I’m not really sure where/how these files got corrupted, but it’s fixed now.

Before I get off on a tiny rant, let me be clear: I started my career on a LAMP stack. I used to be a huge Linux guy, loved me some Perl, and lived life on the FOSS side. I still like Perl, though I haven’t written any for a few years. It’s been a while since I’ve been in that world so it’s taking a little getting used to getting back in. I’ve been there, and I appreciate what’s available.

That said, this, right here, is precisely why Linux will never overtake Windows or MacOS on consumer desktops. There is precisely zero chance that any member of my family would have had the time, patience, or wherewithal to figure out what the name of the “Add/Remove” app is, run it at the command line, figure out that it’s just a wrapper for apt-get, run that from a command line, and then figure out what the cryptic “segmentation faulty tree” error message meant. And my family is chock full of smart folks. They’re just not computer geeks, and investing the time to get into it at this level isn’t something they’re interested in doing. They shouldn’t have to be.

Windows and MacOS definitely have their problems. Windows, sure, maybe more so than MacOS. That said, I have never once had an inexplicable failure in Windows on something so critically low-level as the installation system, and any time there is a problem, there’s a single, central event log I can go look at to see what happened. Even if it doesn’t tell me exactly what happened, it’s at least got enough information that if I literally copy and paste the error into Google, I’ll come out with a pretty good chance of getting the answer in the first few hits. Blue Screen of Death? Sure, I’ve had my fill. Weird glitches? Absolutely. Usually, though, it’s because I’m installing and uninstalling all nature of things, combined with the fact that I’m a developer, so I’m always tweaking and changing and updating and doing all sorts of unconventional stuff - unlike the standard user.

Anyway, rant over. I’ll probably disable comments on this one because I’m really not interested in getting into a religious OS war here; I just needed to vent my frustrations in getting what I feel should be a simple thing up and running. I’m excited to get back into the Linux world and to have the XO as an excuse to mess around with it. We’ll see how the journey continues.

GeekSpeak comments edit

About a year ago now, I participated in the “Give One, Get One” program for the One Laptop Per Child foundation. As part of that, I got one of the little XO laptops. They’re neat little machines, 433MHz processors with 256MB RAM - not a lot of computing power, but fun to play with.

I messed around with the Sugar OS for a while, but admittedly got a little tired of it since there’s not a lot you can do in it - it’s an educational item, after all, not a little netbook or something. To that effect, it sat dormant in my office for a few months… until now.

I got the urge to get an alternate OS working on there so I could use Firefox and browse the web - actually use it like a mini notebook for light tasks. I found some instructions on the OLPC wiki that explain how to get Ubuntu installed on the XO, but after trying several times, it just wasn’t working for me. I couldn’t get past the step where you set up the Ubuntu image using QEMU. The image would always boot poorly or, in some cases, not at all… and, frankly, while I used to be a Linux guy, my skills in that arena are a bit too rusty to adequately troubleshoot those issues. Plus, the way they explain it, you’re actually putting Ubuntu right on the system - no going back to the original Sugar OS.

Thankfully, I found another set of instructions - how to install Ubuntu on an SD card and boot the XO from that. While the setup takes some time, it was super simple and worked like a charm. Plus, it’s non-destructive: if you mess anything up, you can always just remove the SD card and you’re back to Sugar OS.

I have my XO booting Ubuntu now and it’s in the process of running system updates. I’m excited to put it back to use! If you have an XO and are interested in getting it running more interesting applications than what’s available on Sugar, try booting Ubuntu from an SD card. It’s worth it.

UPDATES!

I’m going to post updates to this entry as I get experience with the XO using Ubuntu and include additional things you may want to do, or gotchas you might run into.

  • Make sure to read the comments on that blog article that explains the SD card installation of Ubuntu. There are some things in there that you’ll need to know or might help you out.
  • Check out this wiki entry about customizing Ubuntu on XO. It has a lot of things you might want to do to this base install.
  • Change your hostname. The default hostname for the installation is “OLPC” - a little generic, and if you have more than one at home, problematic. In order to do this, edit your /etc/hostname file to have your new hostname. Also, edit the /etc/hosts file, find the line in there for “OLPC,” and replace “OLPC” with your new hostname. Yes, you have to do it in both places. Reboot and you’re good.
  • Some settings you change won’t persist across reboots. I think this boils down to my not understanding where various settings get updated. For example, the touch pad speed was super slow for me and no matter how many times I changed the setting in the control panel, it wouldn’t persist the setting. Turns out there’s a .xfce4_startup file in the OLPC user’s home directory that specifies the mouse speed - and it overrides any setting you may have put in the control panel. You can change the mouse setting by modifying the xset m 6/10 15 line to be something more appropriate. According to the wiki entry, this will differ based on your firmware verson. For me, xset m 5 12 seems to work really well. I assume you could just remove the line and have it fall back to use the settings from the control panel… but I didn’t try it.