Thursday, November 05, 2009

Long Live the Guid!

Guid generation came up earlier today and it struck me, as someone who loves automation, Guid generation is still a very manual process for me.

It seems like forever that I have used the Visual Studio Tools | Create GUID tool to generate new Guid’s, using the Registry Format option, and then removing the squiggy braces from the end product.

Today I learned from Mr. Anderson that my Guid string can keep the squiggy braces:

var g = new Guid("{10246A29-8E88-46DC-925A-6F4BCB31EB56}");

This code for Guid generation is just as valid as:

var g = new Guid("10246A29-8E88-46DC-925A-6F4BCB31EB56");

I would have sworn there was a time not so long ago that the squiggy braces would have caused an issue.

I also learned that ReSharper has a built-in live template for generating GUID’s called ‘nguid’, much like a snippet. However, it doesn’t generate the Guid with quotes around it – which is my 99.999% usage scenario when creating Guid’s. Outside of COM IDL work, I haven’t had to generate a Guid that wasn’t a string in as long as I can remember. Fortunately, ReSharper gives me a nice little UI editor for modifying their templates (snippets) and now ‘ngen’ works the way I wanted it to by inserting the text:

"10246A29-8E88-46DC-925A-6F4BCB31EB56".

Of course, this got me to thinking surely Visual Studio can do this? Of course it can. Here is the macro I created to do the same thing, which I then promptly mapped to the keyboard shortcut CTRL-N,CTRL-G.

Public Module CodeGeneration

Sub CreateGuid()
Dim ts As TextSelection = DTE.ActiveDocument.Selection
ts.Insert("""" + Guid.NewGuid().ToString() + """")

End Sub

End Module

So now I can burn through Guids with wild abandon and so can you!

Tuesday, October 27, 2009

MSMQ.VBS – Manage Private MSMQ Queues

I have been migrating some scripts and what nots to hosting at github

This script allows some very basic management of MSMQ private queues.  I typically use this from some sort of controlling script, either MSBuild or Nant, using their respective ‘shell’ tasks to cscript.exe.

  1. Set your default scripting engine to cscript.exe
    1. cscript //X:CScript
  2. Run msmq from the command line to get syntax

 

Tuesday, October 06, 2009

Bitmasking – A Blast From the Past

The topic of bitmasking came up recently and nearly made me fall out of my chair!  Had to whip something up to see if I could remember how...haven't done it in years (since my C/C++ days).  This code snippet below is in C# and is not nearly as elegant as it was in C/C++, but then again I never really cared for bit masking.  :)  There is some awkward casting I have to do because of language constraints, but the end result is pretty much who we did it in 'the good old days'.  I can't remember the last time I had to worry about bits, or bytes.  In hindsight I can clean that up using const values instead of an enum, but there you go.

Vipan Singala has an excellent article titled Bitwise Operators and Masks which I can recommend if your interested in this sort of thing.

The output of the sample below is as follows:

We are moving...
We are moving faster...
Not moving faster than light yet.
NOW we are moving faster than the speed of light...
Uh oh, looks like we've dropped out of faster than light travel!
But we are still moving moving fast...
We are still moving...
Removing all other flags..
Now we have stopped.

using System;

namespace BitMasking
{
    class Program
  
{

        enum SpeedFlags : byte
      
{
            Stopped = 0x00000000,
            Moving = 0x00000001,
            Faster = 0x00000002,
            FTL = 0x00000004
        }

        static void Main(string[] args)
        {

            bytestatus = (byte)SpeedFlags.Stopped;

            // set the 'Moving' bit
            //
          
status |= (byte)SpeedFlags.Moving;
           
            // set the 'Faster' bit
            //
          
status |= (byte) SpeedFlags.Faster;
           

            // status AND'ed with 'Moving' bit equals our 'Moving' bit, then its set
            //
          
if( (status & (byte)SpeedFlags.Moving) == (byte)SpeedFlags.Moving )
            {
                Console.WriteLine("We are moving...");
            }

            // check if faster bit is set
            //
          
if( (status & (byte)SpeedFlags.Faster) == (byte)SpeedFlags.Faster)
            {
                Console.WriteLine("We are moving faster...");
            }

            // our FTL bit is not set yet!!
            //
          
if((status & (byte)SpeedFlags.FTL) == (byte)SpeedFlags.FTL)
            {
                Console.WriteLine("We are moving faster than the speed of light...");
            }
            else
          
{
                Console.WriteLine("Not moving faster than light yet.");
            }

            // set the bit
            //
          
status |= (byte) SpeedFlags.FTL;

            // check to see if we've got the bit set
            //
          
if((status & (byte)SpeedFlags.FTL) == (byte)SpeedFlags.FTL)
            {
                Console.WriteLine("NOW we are moving faster than the speed of light...");
            }

            status ^= (byte) SpeedFlags.FTL;

            if((status & (byte)SpeedFlags.FTL) == (byte)SpeedFlags.FTL)
            {
                Console.WriteLine("We are still moving faster than the speed of light...");
            }
            else
          
{
                Console.WriteLine("Uh oh, looks like we've dropped out of faster than light travel!");
            }

            // check if faster bit is set
            //
          
if((status & (byte)SpeedFlags.Faster) == (byte)SpeedFlags.Faster)
            {
                Console.WriteLine("But we are still moving moving fast...");
            }
           
            // status AND'ed with 'Moving' bit equals our 'Moving' bit, then its set
            //
          
if((status & (byte)SpeedFlags.Moving) == (byte)SpeedFlags.Moving)
            {
                Console.WriteLine("We are still moving...");
            }

            Console.WriteLine("Removing all other flags..");
            status ^= (byte) SpeedFlags.Faster;
            status ^= (byte) SpeedFlags.Moving;

            if((status & (byte)SpeedFlags.Stopped) == (byte)SpeedFlags.Stopped)
            {
                Console.WriteLine("Now we have stopped.");
            }
        }
    }
}

Monday, September 28, 2009

IDisposable is a Developer Convention

Given the following bit of code, when does the Dispose method of Trash get called?

using System;

namespace Dispose
{
public class Trash : IDisposable
{

#region IDisposable Members

public void Dispose()
{
Console.WriteLine("I am being disposed");
}

#endregion
}


class Program
{
static void Main(string[] args)
{

var c = new Trash();


}
}
}


 



Answer



Never



The IDisposable interface is a developer convention and is not enforced by the .NET runtime.  IDisposable is not called by the .NET runtime on the developer behalf (at the time of this writing).  IDisposable exists to help model a more explicit (deterministic) method for releasing of memory for .NET developers.  See Implementing Finalize and IDisposable to Clean Up Unmanaged Resources



Some might say that it was a warm and fuzzy blanket used to swathe all the C++ programmers in as they transitioned into .NET.  That may be the case, but inevitably, as a developer, you will need a way to declare your intent that your class has resources that need to be cleaned up now. Traditionally, this has been to represent unmanaged resources but it doesn’t have to be.  So, if you see a class that implements IDisposable, consider it good form to go ahead and invoke Dispose as soon as your finished with the object. 



An Exception for Every Rule



The exception to the rule is when working with WCF proxies.  This well known design pattern of IDisposable is broken in a bad way. For some good information as to why try a search WCF IDisposable is broken.  The nut of which is if you call Dispose on a WCF proxy, and the channel has already been faulted, you’ll never see the originating fault because of the proxies implementation of Dispose just tries to Close the channel, which throws a new exception, and stomps all over the call stack of the original exception. 



Your damned if you do call Dispose (might lose useful error information) and your damned if you don’t (hold server resources open longer than required).  Many of the links in the search query will return useful ways to get around the problem, but it would be nice if, as a community, we adopted one of these solutions.



This has been a .NET public service announcement.  You may now return to your regularly scheduled programming.

Saturday, September 26, 2009

Reviewing Beginning Xml with C# 2008: From Novice to Professional

First off, I would like to thank Apress Books for their supporting local user group communities by donating copies of their titles for review!  

I would like to be upfront before jumping into the review: the first time I read the book, I did not like it.  There was not enough time spent with Xml best practices, not enough space dedicated to more Xml centric terminology and with a book weighing in at 600 pages, way too much information that is readily available via your favorite search engine.  So, I put the book down.

After a bit of reflection though I realized what should have been obvious: I was not the target market for this book.  While I am likely not familiar with some of the more esoteric features of Xml, I am very comfortable with the day to day application of Xml, and Xml related technologies, so I re-read Beginning Xml with C#: From Novice to Professional with a different perspective.

 

Xml can be a very wide topic just as ‘development’ can be a broad, as well as deep, topic. For sure, if you are a .NET developer today, you are virtually surrounded by Xml goo and its closing fast!  Xml might not always be in your face though, and its easy to ignore for a while.  It might be hiding behind some tooling, or buried in a configuration file, but its there nonetheless, just waiting to jump out of the shadows and club you over the head!  You can’t ignore Xml for forever, so don’t be a victim of xml, learn how to defend yourself today!

 

The Good

The author does a good job of uncovering all the nooks and crannies your likely to find Xml hiding: configuration files, serialization formats, Sql Server, and Windows Communication Foundation (WCF).

There was well presented information around when to use XmlDocument v. XmlReader which was nice.  XmlDocument is so easy that its simple to overlook the fact that if you really only need read-only access to the data, then XmlReader is your better choice.  I even find myself doing this on many occasions.

The chapter on using Xml with Sql Server was done well.

I was puzzled that DTD (document type definitions) received as much attention as they did.  However, there is a remote possibility you might run into them, so +1 for covering them.

 

The Bad

The author appears to make the assumption that Xml, without a namespace, is considered 'the norm'.  I say ‘appears’, as xml namespaces were pretty much ignored, and can’t be found in the index.  I'm reviewing to see if I just missed it, but working with Xml and Xml Namespaces are probably the first big hurdle a developer will run into.

I, unfortunately, am pretty militant around namespaces, believing if your not using namespaces, well then that's analogous to C# without a namespace, and only acceptable in the most trivial examples.  How many Employee schema's do you think are out there?  How do you tell your Employee schema from another companies Employee schema?  Heck, most companies will have multiple schema's for similar types across departments (Orders, Inventory, Shipment, Customer, etc..).  Namespaces are how you tell yours from someone else's and give you a pivotal piece of metadata to key off of in your versioning strategy.

 

The Ugly

My biggest complaints about the book, is also one mostly driven by yet another personal opinion, and that is the examples.  I’m not a fan of WinForm examples, unless your showing me an example that centers around WinForm development.  The best way to to show me Xml centric examples is with the good, old fashioned, console application.  Otherwise, there is too much technology mixing going on and key points might get lost in demo goo, not to mention consuming valuable page real estate that could be better used for more in-depth coverage of the topic. 

 

Summary

One might think that xml in the .NET world is ubiquitous enough that everyone who picks up Visual Studio will just learn through osmosis what they need to know about xml.  Some of this may even be true.  However, if you are new to developing for the .NET platform, having this book available could help jumpstart your development and keep you on task.

Friday, September 04, 2009

Observable Property Code Snippet

I’ve been using the a new code snippet to create an ‘observable’ property when working with WPF and the Model-View-ViewModel pattern.  This is really only useful if your class implements INotifyPropertyChanged, which our ViewModel base does.

The snippet generates the following block of code:

private string _name;
public string Name
{
get
{
return _name;
}
set
{

if (_name != value)
{
_name = value;
OnPropertyChanged("Name");
}

}
}

 


..and here is the snippet.  See my previous post on [DataMember] Code Snippet on how to install snippets.

<?xml version="1.0" encoding="utf-8" ?>
<
CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<
CodeSnippet Format="1.0.0">
<
Header>
<
Title>oprop</Title>
<
Shortcut>oprop</Shortcut>
<
Description>Code snippet for an automatically implemented observable property for any class that implements INotifyPropertyChanged.</Description>
<
Author>Your name here</Author>
<
SnippetTypes>
<
SnippetType>Expansion</SnippetType>
</
SnippetTypes>
</
Header>
<
Snippet>
<
Declarations>
<
Literal>
<
ID>type</ID>
<
ToolTip>Property type</ToolTip>
<
Default>int</Default>
</
Literal>
<
Literal>
<
ID>field</ID>
<
ToolTip>Backing Field Name</ToolTip>
<
Default>_myProperty</Default>
</
Literal>
<
Literal>
<
ID>property</ID>
<
ToolTip>Property name</ToolTip>
<
Default>MyProperty</Default>
</
Literal>
</
Declarations>
<
Code Language="csharp">
<![CDATA[

private $type$ $field$;
public $type$ $property$
{
get
{
return $field$;
}
set
{

if ( $field$ != value )
{
$field$ = value;
OnPropertyChanged("$property$");
}

}
}
$end$


]]>
</
Code>
</
Snippet>
</
CodeSnippet>
</
CodeSnippets>
 

Saturday, July 11, 2009

Ft. Walton Beach Vacation Summary

Our family spent a week in Ft. Walton Beach, Florida, this year.  Below are my notes of each day’s events – Sally has kept her own journal, so there is no telling what additional detail I’ve left out!

From FtWaltonBeach2009

 

 

The pictures can be found by following this link for Fort Walton Beach Vacation pictures.

Ft. Walton Beach Vacation, Day 6

July 10th, 2009

 

Up at 7:00AM, check out is at 10:00AM.   We eat breakfast, finish packing, clean the condo and leave Gulf Dunes by 9:30AM!

We stop at a “Tropical Department Store”, aka another tourist trap, for souvenirs. 

On the road back to Texas by 10:00AM.  We wave bye to Ft. Walton Beach. 

Stop in Covington, LA for lunch @ 2:00PM (right on schedule) – hey, its Chick-fil-a!

Stop for gas, potty break, and change drivers in Alexandria, LA – but forgot the gas!  Of course, Josh had to try out the bathroom there.  Actually, very clean bathroom in the downtown Alexandria (we got lost – err, took the wrong exit).  Kudo’s to McDonalds!  I think its a first!

Finally get gas on the other side of Shreveport, LA – nervously watching the gas gauge the whole way. 

We pull into our driveway at 10:30PM. 

Ft. Walton Beach Vacation, Day 5

July 9th, 2009

 

This morning over coffee, I got to see some lifeguard trainees.  All girls.  Yay!

Southern Star Dolphin Cruise today from 9AM – 11AM in Destin!  Destin is only 8 miles east of Ft. Walton Beach.  We parked in the public parking of the Emerald Grand and located the Southern Star’s stand along the harbor wall.

From FtWaltonBeach2009

The dolphin cruise was awesome!  Saw quite a few dolphins and a spotted eagle ray – I think I saw a shark, but I missed the sea turtle (wrong side of the boat).  The glass bottom feature of the cruise was a bit overrated, even when you see fish, you can’t see colors, etc.  Usually the boat is moving too fast to see anything through the small port holes.

From FtWaltonBeach2009

 

Unfortunately, both kids got sea sick.  Boo.  They didn’t throw up though, and didn’t really fuss much.  Very proud of what troopers they were considering it was a somewhat difficult situation.

We ate at Pat O'Brien's (Destin) – had crawfish tacos, muffalata sandwich and the best caesar salad ever!  I think it was the freshly grated parmesan cheese that made it pop.  The kids, of course, had chicken fingers.

We spend the afternoon on the beach, but pick up supplied for a movie and real popcorn (Rico’s Popcorn) for bedtime. 

Kids decided they wanted tattoos to remind them of the trip, so we walked down to Fudpuckers to get inked!  Hannah got a bear with hearts and Josh got a tank.  Sally’s tattoo washed off in the sudden downpour we got caught in while there.  This was the first real rain we’ve had since arriving at Ft. Walton Beach.  We wait it out under a patio umbrella until its light enough to walk back.

From FtWaltonBeach2009

 

This is our last night here.

Ft. Walton Beach Vacation, Day 4

July 8th, 2009

 

First one up – before 8AM this time.  I go to the local stores looking for ‘sun shirts’ – those shirts that have some UV blocker in them and are basically 50 SPF by themselves.  Find one for Josh, but no one else.

We spend the day playing in the surf, building sandcastles and picking up sea shells.

Hannah and Josh really took to riding the “Gnarly Board”.  Hannah can go the distance on it, all the way to the beach!  Josh just makes it look good!

I tried to help Josh with the board, explaining he had to lay down on it instead of just sitting on it like he wanted, but he wouldn’t listen.  First wave tipped him face first into the (soft) sand and rolled him in sand and water.  He refused to ride the board for a while stating that it was my fault (meaning Dad) for his wipe out.  He later rode the board again, but laying down on the board, and was successful in catching some waves!  He later came over to me and told me “Dad, you were right, I was wrong” – priceless!

From FtWaltonBeach2009

The sea shells were really nothing more than fragments of sand dollars, but Hannah did manage to find a really nice one – looked like a conch shaped shell that a hermit crab might have lived in.

From FtWaltonBeach2009

Dad burns more but Josh is fine by slathering him in sunscreen and making him wear his shirt.  Hannah and Sally continue to work on their tans.

Threatening rain today, but we don’t see any.

Walk to Fudpuckers for dinner – its a complete tourist trap.  Not like I didn’t expect it.  There was also some questionable TV on in the background considering half the crowd there was under 10.  Commercials for the HBO series “Hung” is not appropriate.  I don’t want to explain to my 8 year old what that is – luckily, she didn’t see it.

From FtWaltonBeach2009

We got our picture taken with a baby alligator – pretty cool.  Though you kind of feel sorry for the alligators.

Everyone was crashed after dinner, but I had been seeing flashlights on the beach at night and I wanted to see what they were seeing.  So I hit the beach around 9:30PM with my flashlight.  Turns out that the whole event was probably started by someone who lost their watch – everyone I passed the conversation went like this:

Me - “What are you looking for”?

Them – '”Same thing you are, I guess”.

Me - “I”m not sure what I’m looking for”?

Them - “Oh, OK.  Have a good night”!

I did see 3 crabs…kind of like horseshoe crabs, but they are very fast!

Oh, yeah…Capital One disabled my credit card.  Seems I forgot to tell them I was travelling – since I’ve used this credit card all over the world (ok – China and US) and never had a problem it never occurred to me. I was fine with them disabling my card, appreciative really.   What I was not happy with is that there was no easy way to re-enable it without navigating 5 levels deep of menu options on a crappy Black Jack II phone.  Once I got someone on the phone, it took confirming a few charges and we were back in party mode!

Ft. Walton Beach Vacation, Day 3

July 7, 2009

 

Up at 8am – first one up.  Trend that continues for the rest of the week.  Spend every morning with coffee on the patio and listen to the surf and people watch.

Sally took a walk on the beach while I waited for Josh to wake up so we can hit the beach!

Spent all day on the beach, except for coming back up to the condo for lunch.  We had sandwiches for lunch and pizza for dinner, followed by a movie and popcorn.  Don’t think we went to bed until after 10PM every night.

While on the beach, we built walls and imaginary castles and moats, only to have a rogue wave come in and tear it all down.  Fun!

From FtWaltonBeach2009

Kids and Sally bury me in the sand, which evidently exhausted me because I was first in bed.

Josh and I got sunburn on places we missed with sunscreen.  Ouch!   Hannah and Sally just got deeper tans.

Ft. Walton Beach Vacation, Day 2

July 6th, 2009

 

Woke by 9am, but got downstairs too late for the continental breakfast.  Ate breakfast at the Chick-fil-a in Covington, LA.

We left Covington in the pouring rain!  It was seriously, stop on the side of the road (we didn’t) kind of rain.  Which probably explains why I ran over a tree top that had snapped off and blown onto the highway.  This went on for about 30 minutes of driving rain travelling between 10 and 20 mph.

Before we knew it, we were finally out of Louisiana and in Mississippi.  There is an awesome bridge in Mississippi that I wish I had a picture of. 

We blinked our eyes and less than 100 miles later we are in Alabama.

Alabama was notable for the tunnel in Mobile and the U.S.S. Alabama, visible from the highway.

From FtWaltonBeach2009

We hit Florida by 2:30PM and Ft. Walton Beach by 3:30PM via exit 56!

From FtWaltonBeach2009

Checked into the Gulf Dunes complex (#406) which was pretty nice – didn’t know what to expect beyond 1980’s style furniture!

From FtWaltonBeach2009

We didn’t bother to unpack, except for swimsuits and hit the beach. 

The sand is everything that we’ve been told…talcum powder by the dunes and sugar by the water.  It was great!  Water was very clear but had little green algae looking organisms in the water that gave it a really green tint.

 

From FtWaltonBeach2009

We play on the beach until after dark 30.  We are starving at this point and try Fudpuckers but there is a 1 hour wait (there is always a 1 hour wait) so we head up the highway and find Floyd’s.  We ordered anything that sounded good off the menu:

  • Coco Loco Shrimp (sweet)
  • Kicker Shrimp (spicy)
  • Corn and Shrimp Chowder
  • Tuna Rolls
  • Shrimp Rolls
  • Emerald Coast (adult beverage)
  • Raspberry Daiquiri's
  • Miller Light
  • Chicken Fingers (of course)

 

We then hit Publix, a grocery store chain, and bought groceries for the week ($200 – ouch!). 

Ft. Walton Beach Vacation, Day 1

July 5th, 2009

 

Packed and left the house by 10:15am, which is no mean feat for our family!

Took Hwy 75 to I-20E and hit Shreveport, LA by 2PM.  Seems like it took forever to leave Texas…that is, until we entered Louisiana, where we took I-49S towards Alexandria, LA.  There are NO bathrooms off of I-49 between Shreveport and Alexandria.  Well, there is one.  In Natchitoches.  Don’t pass this one up!  Its the best place for a bathroom before Alexandria.

Since we missed Natchitoches exit, we wound up stopping in a backwater gas station well off the freeway – it was essentially a mobile home (no wheels) and a gas pump.   We had to buy something to use the restroom – silly me bought gas.  Of course, Josh can’t resist the Pavlovian response to a public bathroom and had to poop.  I could hear banjos the whole while…my only regret is that we didn’t get pictures.

Stopped in Alexandria, LA at a McDonalds – bleh.

Made it to Covington, LA by 6:30PM.  We stayed at a Courtyard by Marriot, room #311 and used points for it.  Total cost: $0.

Ate at Acme for dinner…the red beans and rice were phenomenal, but the Bloody Mary sucks. 

From FtWaltonBeach2009

We spent a fortune here.

Wednesday, June 10, 2009

How Windows Defender Helped Me Save Face

This morning I received a direct message from my brother on Facebook (warning #1) with a link to a url that just looked 'crazy', I clicked (mistake #1).

I was redirected to a site that appeared to be hosting a video, but prompted that it "Required Adobe Flash Player 10" to continue and attempted a download of file "setup.exe".  I downloaded the file and ran it (mistake #2).

Luckily, I am running Windows Defender, which detected changes to my system and prompted me for approval before committing them.  Windows Defender prompting me after an install is not unusual, however, it gave me a critical moment to collect my thoughts (first cup o'coffee this am, after all) and review what was about to occur.  That's when I noticed that the "Adobe Flash Setup" had installed several Windows driversDrivers?  Nothing from the browser should EVER install a Windows driver?!

I'm now suspicious (sharp as a spoon, I am) and decide to investigate a little further.

I reviewed the "setup.exe", and viewed its details, there was no manufacturer data.  I then navigated to Adobe and downloaded its installation program for Adobe Flash 10.  The file name is "install_flash_player.exe" and when viewing the file details is stamped repeatedly that its from Adobe.

Windows Defender reported the following changes to my system.

Windows Defender Report

Description:
This program has potentially unwanted behavior.

Advice:
Permit this detected item only if you trust the program or the software publisher.

Resources:
driver:
podmenadrv

file:
C:\Program Files\podmena\podmena.sys

Category:
Not Yet Classified

Description:
This program has potentially unwanted behavior.

Advice:
Permit this detected item only if you trust the program or the software publisher.

Resources:
regkey:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run\\sysfbtray

runkey:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run\\sysfbtray

file:
c:\windows\freddy46.exe

Category:
Not Yet Classified

Description:
This program has potentially unwanted behavior.

Advice:
Permit this detected item only if you trust the program or the software publisher.

Resources:
regkey:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run\\sysldtray

runkey:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run\\sysldtray

file:
c:\windows\ld09.exe

Category:
Not Yet Classified

 

That's enough for me...I deny the changes in Windows Defender, which requires a reboot to rollback.  After the reboot, all is well in the 'verse.

Shortly afterwards this morning I got an email from my brother warning me about it - he wasn't so lucky.

This is not the first time Windows Defender has saved my bacon. If your running Vista, or Windows XP SP2/3, make sure your running Defender, or a good virus scanner.  Defender seems to be less intrusive than the actual virus scanners I've tried over the years.

Wednesday, May 06, 2009

[DFWCSUG] WCF and Silverlight

The Dallas/Fort Worth Connected Systems User Group presentation this month is titled "WCF and Silverlight".  Come join us as Amir Rajan (Sogeti) talks about:

  • Silverlight (crash course)
  • Walk-through of a simple Silverlight application using WCF
  • Pros and Cons of using WCF with Silverlight
  • Walk-through of a more complicated budgeting application that leverages Silverlight and WCF
  • As always, there will be free food and prizes!

    Hope to see you there!

    Z

    Tuesday, January 20, 2009

    MSBuild

    Recently I posted a little about what I was calling the MSBuild Blahs, but probably more aptly titled “How I spent my Christmas Vacation”, and thought that it needed a follow up.

    I continued to [1] twiddle with MSBuild until I was able to build something that met our needs for deployment – ok, should meet our needs. It goes into our development environment this week to work any kinks out.  I’ve definitely reached the ‘stage’ of learning that you could call (0ver) confidence with the language (is it a language, or a tool?).  You definitely have to change the way you think about accomplishing a task.

    The push that got me ‘over the hump’ (besides just head banging)?  I read on a blog/MSDN post about XSLT being “the language of XML” and that “MSBuild was built on XML”, so therefore, the “idea of batching targets was taken from XSLT”.

    Once I started thinking of everything as ‘batching’ targets, things started falling into place.   I found the post that helped me make the leap, by Jeff C. in the MSBuild v. Nant in the MSDN MSBuild forum.  Other helpful articles/posts I can be linked back to Sayed Ibrahim Hashimi or the MSBuild Team.

    You can be successful with either tool.  If your just starting to develop your package and deployment scripts,  and target the Windows platform, then checkout MSBuild.   If you’ve got existing Nant scripts, target non-Windows platforms, or use open source tools, your likely to get better synergy out of using Nant.  With anything, your mileage may vary.

    Con

    Yes, I’m starting with the Cons, sue me.

    • Learning Curve – I personally had a higher learning curve for MSBuild than I did with Nant.  This is primarily due to lack of intuitiveness about batching, and transformations – two important concepts in MSBuild, which leads to…
    • Batching – this concept is reportedly borrowed from XSLT – really?  Because of the 30 developers I could probably name off the top of my head only two are what I’d call well versed in XSLT, and one is technically a manager now so I’m not sure he counts!  My XSLT skills are the equivalent of using flint to start a fire.  Yeah, I can do it but its probably going to take a while and I might even get hurt along the way.
    • Quirky Syntax – @ is for collections (ItemGroup), % is to address an item in that collection (ItemGroup) and $ is for addressing a value in a PropertyGroup.  Ok, then lets throw in that % is really like using an MSBuild transform which uses the syntax of @(property->’%(itemmetadata)’).  Do we need to say more? 
    • PropertyGroup trumps ItemGroup – if you happen to have an ItemGroup name that collides with a PropertyGroup, the PropertyGroup takes precedent, so you may spin wheels trying to figure out why that shiny new target you just built is spitting out the wrong information (or none at all).
    • ItemGroup Scope – I discovered that if I created an item group at a ‘global’ level called ‘Servers’ and then used the CreateItem task to create another group (or as an Output from a custom task) and it, too, was named ‘Servers’ then the values were appended to the global instance of ‘Servers’.  I’d like to be able to have variable declarations be aware of scope.   This cuts down on me having to be too creative on variable naming.

    Pro

    These Cons are offset by the absolute coolness of:

    • ItemMetadata – Creating an ItemGroup and then applying pieces of metadata as necessary to describe the item, thats nice.  The one thing is that there is no real enforcement of separation of ‘data’ and ‘logic’, which I’ve tried to do in our scripts.  I didn’t like that my item metadata (e.g. servers collection, or services collection) might be mixed in with the ‘logic’ of working with that collection.  This is true regardless of using MSBuild or Nant and both have constructs for allowing separation.
    • Batching – Ok, I know I listed this in ‘Cons’ column, but there is something to be said about eliminating foreach loops, which is what batching does, at the cost of some intuitiveness.  It did shorten my scripts somewhat.   Again, while nice, it requires getting over a learning curve that I’m not sure is worth it – maybe its more mentionable as a side effect?

    At the end of the day, I’ve come to like MSBuild (yes, me eating crow), but things could definitely be done to help smooth out the learning curve. 

    When asked why don’t you use batch files, PowerShell, etc…and why use MSBuild, or NAnt, at all, think of it like this:  MSBuild, or NAnt, is like your workflow runtime.  You get richer error handling, conditional decisions and some other gooey goodness that make it worth your while to adopt one, or the other.  Your Targets are then akin to activities.  If you want your activity to invoke a batch file, power shell script, vbscript, you absolutely can. 

    Don’t forget to take advantage of the community supported MSBuild Task libraries out there.  There are three that I’ve found which are fairly solid – my only complaint is that the help files don’t always match up to the Task (e.g. property names), but a quick dive into Reflector and your good to go.  As always, if the shoe doesn’t fit, don’t hesitate to jump in and make a better shoe, err custom task.

     

    [1] – twiddle, a polite term for a the Thunderdome style cage fight between myself and MSBuild.  Since I’m here to write this story, you know I’m clearly the winner.  Ignore the new eye patch, its just a flesh wound.

    Monday, January 05, 2009

    Lords of Dus: Lawrence Watt-Evans

    This is one of the classic trilogies that fed the imagination growing up.    I think I picked these up about the same time I found the “Wizard of Earthsea” trilogy – way back in the day.  Anyway, flood, friends, and the ravages of time had destroyed my copies but through the wonders of the Internet I was able to pick up copies of all three (in excellent condition).

    The “Lure of the Basilisk” image below is not the original cover art that I remember from my collection, but the rest are.  This series spawned many adventurous subplots in various worlds across the (sometimes seemingly empty) expanse of my mind.  They are excellent, easy reads if you can find them.