Generics in XML comments


I completely forgot how to reference generic classes within <see/> and <seealso/> tags this morning, call it a total lack of caffeine (which I haven’t had a significant amount of for a month now).

Figured someone else may have a similar brain fart, so remember it’s curly braces, not &lt; and &gt; tags which made more sense.

    /// <summary>
    /// Used by <see cref="MyGenericClass{T}"/>.
    /// </summary>

And not to go on a tangent, but shouldn’t decaf coffee be at least half the price?

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

author: Brian | Posted On Tuesday, June 22, 2010 8:28 AM | Feedback (1)

Tip for Cleaning up Visual Studio Usings


I love to keep my class files clean, and often times that means not using the suggested using statements that visual studio inserts for me based on the template. I love the Organize Usings functionality, especially Remove and Sort, but by default there isn't a keyboard chord setup for it.

When you visit the options for visual studio under Environment >> Keyboard, you'll see all of the possible commands. Typing "Organize" into the filter box will get to what we want.

Finding the command

Then we just need to assign a shortcut key. Luckily it didn’t take long for me to find a shortcut chord that was available, CTRL+R, CTRL+S. Hold the Control key and type R then S into the shortcut keys box and then click assign (assuming that no other command is using the shortcut in your environment).

Setting the keyboard shortcut

And there you have it. So anytime you make changes or if you just want to clean up a new class just type CTRL+R, CTRL+S and unused usings are removed and the rest are sorted.

Speaking of shortcuts, I’ll never understand why there isn’t one to close a file by default. I always assign ALT+C to the File.Close command so I can quickly cleanup several open files at a time.

If anyone has a better way (other than third party tools) I’d love to hear about it.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

author: Brian | Posted On Friday, June 18, 2010 3:34 PM | Feedback (1)

Tykie


Here’s the obituary my mother wrote for Tykie, I still miss the little guy quite a bit. Anyone who’s interested in further information on hearing dogs should check out the IHDI website. I cannot begin to express how helpful a hearing dog can be for the hearing impaired. If you feel so inclined, please make a donation.

In Memoriam, Tykie 1993-2010

Tykie after retirement

The American Legion Post 401, South Wichita, KS, supported one of its members and commander by sponsoring a service dog for him. Unlike most service dogs this one was for the hearing impaired.

Both Ocie and Betty Sims had hearing loss – Ocie more than Betty.

The Post and Auxilliary had garage sales, auctions and other fund-raising endeavors to get donations for the dog. Betty made Teddy bears with growlers that were auctioned for donations to bring a hearing dog from International Hearing Dog, Henderson, Colorado.

clip_image004

Tykie, a small wiry, salt and pepper terrier, arrived September 1, 1994 to begin his work that included attending Post 401 meetings and celebrations as well as raising more money to be donated to IHD to help others have hearing dogs.

Tykie was a young dog less than a year old when he came to Wichita. He was always anxious to please and seldom barked, though he did put out a kind of cry when he was giving his urgent announcement that someone was at the door or the telephone was ringing. He also enjoyed chasing squirrels in the backyard garden that Ocie prized.

In 1995, Betty almost died of a lung infection. Tykie was at the hospital with Ocie when he could visit. Several weeks after she was able to come home after a miraculous recovery, Tykie and Ocie went to a car show in downtown Wichita. Ocie’s retina tore loose in the only eye he could see out of and he almost blind was in great pain. How Ocie and Tykie got home is still a mystery, but the family legend goes that Tykie added seeing eye dog to his repertoire and helped drive him home.

Health problems continued for Ocie and when he was placed in a nursing home, Tykie was moved to be Betty’s hearing dog. No problem for Tykie, he still saw his friends at the post and continued to help with visitors at the door.

The night of May 3, 1999, Betty and Tykie were in the bedroom watching TV when Tykie began hitting her with both front paws as he would if something were urgent. She said later she thought he wanted to go out.

As she and the dog walked down the hall towards the back of the house, Tykie hit her again with his front paws with such urgency that she fell into a small coat closet.

That small 2-by-2 closet became their refuge as that very second the roof of her house went off as the f4 tornado raced through the city. Betty acquired one small wound on her hand from a piece of flying glass as she pulled Tykie into the closet with her.

Tykie was a hero that day and a lot of days after.

He kept Betty going as she rebuilt her home and after her husband died April 15, 2000. Tykie had to be cared for so she had to take him outside and bring him inside. He attended weddings of grandchildren and funerals of Post friends.

Ocie and Betty's grave markerWhen Betty died February 17, 2002 Tykie’s life changed again. IHD gave approval for his transfer and retirement to Betty and Ocie’s grandson, Brian Laird, who has a similar hearing loss to his grandfather.

A few days after the funeral Tykie flew to his new home in Rutherford, NJ where he was able to take long walks for a couple of years before moving back to the Kansas City area.

He was still full of adventure. He was written up in a book about service dogs and his story of the tornado and his picture appeared. He spent weekends at Brian’s mother’s farm to get muddy and be afraid of cats and chickens. He also took on an odyssey as he slipped from his fenced yard in Lenexa one day and walked more than seven miles in Overland Park traffic before being found by a good Samaritan who called IHD to find out where he belonged.

Tykie was deaf for about the last two years of his long life and became blind as well, but he continued to strive to please.

Tykie was 16 years and 4 months when he was cremated. His ashes were scattered on the graves of Betty and Ocie Sims at Greenwood Cemetery west of Wichita on the afternoon of March 21, 2010, with about a dozen family and Post 401 members.

It is still the rule. Service dogs are the only dogs allowed inside the Post home.

Submitted by Linda Laird, daughter of Betty and Ocie and mother of Brian Laird.

Tykie's service Tykie's service

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

author: Brian | Posted On Friday, March 26, 2010 10:03 AM | Feedback (3)

OData where art thou?


Douglas Purdy explains. I think the best part will be the governmental aspect. All public record should be available in a way that’s easy to query IMHO. From the article:

Many of us at Microsoft believe the OData protocol can help usher in a more open and programmable Web by creating a common funnel to expose rich data, thereby creating a world of customized consumer mash-ups; a world where government data is transparent and accessible to any citizen; a world where you can ask a question and know, “There’s a feed for that.”

Do check out www.odata.org, and while you’re at it, check out codename Dallas. For all those government IT workers out there, consider the savings. No need to pay someone to format the data for a specific department or constituent. Just put it online and point them there.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

author: Brian | Posted On Wednesday, March 17, 2010 8:20 AM | Feedback (0)

Basic WCF Unit Testing


Coming from someone who loves the KISS method, I was surprised to find that I was making something entirely too complicated. I know, shocker right?

Now I'm no unit testing ninja, and not really a WCF ninja either, but had a desire to test service calls without a) going to a database, or b) making sure that the entire WCF infrastructure was tip top. Who does? It's not the environment I want to test, just the logic I’ve written to ensure there aren't any side effects.

So, for the K.I.S.S. method:

Assuming that you're using a WCF service library (you are using service libraries correct?), it's really as easy as referencing the service library, then building out some stubs for bunking up data.

The data contract

I’ve used the default “CompositeType” that is in the template, handy only for examples like this. I’ve added an Id property and overridden ToString and Equals.

[DataContract]
public class CompositeType
{
    bool boolValue = true;
    string stringValue = "Hello ";

    [DataMember]
    public int Id { get; set; }

    [DataMember]
    public bool BoolValue
    {
        get { return boolValue; }
        set { boolValue = value; }
    }

    [DataMember]
    public string StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }

    public override bool Equals(object obj)
    {
        if (null != obj && obj is CompositeType)
        {
            var o = obj as CompositeType;
            return Id == o.Id && BoolValue == o.BoolValue && StringValue == o.StringValue;
        }
        return false; 
    }

    public override string ToString()
    {
        return string.Format("Id:{0};BoolValue:{1};StringValue:{2};",
            Id, BoolValue, StringValue); 
    }
}

The service contract

We’ll use a very basic service contract, just for getting and updating an entity.

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    CompositeType GetCompositeType(int id);

    [OperationContract]
    CompositeType SaveCompositeType(CompositeType item);

    [OperationContract]
    CompositeTypeCollection GetAllCompositeTypes();
}

The implementation

When I implement the service, I want to be able to send known data into it so I don’t have to fuss around with database access or the like. To do this, I first have to create an interface for my data access:

public interface IMyServiceDataManager
{
    CompositeType GetCompositeType(int id);
    CompositeType SaveCompositeType(CompositeType item);
    CompositeTypeCollection GetAllCompositeTypes();
}

For the purposes of this we can ignore our implementation of the IMyServiceDataManager interface inside of the service. Pretend it uses LINQ to Entities to map its data, or maybe it goes old school and uses EntLib to talk to SQL. Maybe it talks to a tape spool on a mainframe on the third floor. It really doesn’t matter. That’s the point.

So here’s what our service looks like in its most basic form:

public CompositeType GetCompositeType(int id)
{
    //sanity checks 
    if (id == 0) throw new ArgumentException("id cannot be zero."); 
    return _dataManager.GetCompositeType(id); 
}

public CompositeType SaveCompositeType(CompositeType item)
{
    return _dataManager.SaveCompositeType(item); 
}

public CompositeTypeCollection GetAllCompositeTypes()
{
    return _dataManager.GetAllCompositeTypes();
}

But what about the datamanager? The constructor takes care of that. I don’t want to expose any testing ability in release (or the ability for someone to swap out my datamanager) so this is what we get:

        IMyServiceDataManager _dataManager;

        public MyService()
        {
            _dataManager = new MyServiceDataManager();
        }

#if DEBUG
        public MyService(IMyServiceDataManager dataManager)
        {
            _dataManager = dataManager;
        }
#endif

The Stub

Now it’s time for the rubber to meet the road… Like most guys that ever talk about unit testing here’s a sample that is painting in *very* broad strokes. The important part however is that within the test project, I’ve created a bunk (unit testing purists would say stub I believe) object that implements my IMyServiceDataManager so that I can deal with known data. Here it is:

internal class FakeMyServiceDataManager : IMyServiceDataManager
{
    internal FakeMyServiceDataManager()
    {
        Collection = new CompositeTypeCollection();
        Collection.AddRange(new CompositeTypeCollection {
            new CompositeType { Id = 1, BoolValue = true, StringValue = "foo 1", },
            new CompositeType { Id = 2, BoolValue = false, StringValue = "foo 2", },
            new CompositeType { Id = 3, BoolValue = true, StringValue = "foo 3", },
        });
    }
    CompositeTypeCollection Collection { get; set; }
        
    #region IMyServiceDataManager Members

    public CompositeType GetCompositeType(int id)
    {
        if (id <= 0) return null;
        return Collection.SingleOrDefault(m => m.Id == id); 
    }
    
    public CompositeType SaveCompositeType(CompositeType item)
    {            
        var existing = Collection.SingleOrDefault(m => m.Id == item.Id);
        if (null != existing)
        {
            Collection.Remove(existing);
        }        
        if (item.Id == 0)
        {
            item.Id = Collection.Count > 0 ? Collection.Max(m => m.Id) + 1 : 1;
        }    
        Collection.Add(item);
        return item; 
    }

    public CompositeTypeCollection GetAllCompositeTypes()
    {
        return Collection;
    }

    #endregion
}

So it’s tough to see in this example why any of this is necessary, but in a real world application you would/should/could be applying much more logic within your service implementation. This all serves to ensure that between refactorings etc, that it doesn’t send sparking cogs all about or let the blue smoke out. Here’s a simple test that brings it all home, remember, broad strokes:

[TestMethod]
public void MyService_GetCompositeType_ExpectedValues()
{
    FakeMyServiceDataManager fake = new FakeMyServiceDataManager();
    MyService service = new MyService(fake);
    CompositeType expected = fake.GetCompositeType(1);
    CompositeType actual = service.GetCompositeType(1);

    Assert.AreEqual<CompositeType>(expected, actual, "Objects are not equal. Expected: {0}; Actual: {1};", expected, actual);
}

Summary

That’s really all there is to it. You could use software x or framework y to do the exact same thing, but in my case I just didn’t really feel like it. This speaks volumes to my not yet ninja unit testing prowess.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

author: Brian | Posted On Tuesday, March 16, 2010 3:45 PM | Feedback (0)

w00t! First post!


So, I busted my old blog and hadn't been keeping up with it. Decided it would be easier on me to use software that I didn't maintain, so several months ago I signed up for a GWB account. You are a witness to procrastination at its finest! 

I was remarking to my friend Abby that I hadn't written anything in ages, that I've typed a bunch in the last 5 years or so, but that the typing belonged to someone else as work product, was boring technical mumbo jumbo, or was only good before it spoiled, that project/job/technology/tweet based freshness window that us geeks have to deal with. In short, I just didn't feel like it. So forgive the rambling sentences and my grammatical failures, you have Abby to thank ;)

On the technology front I've been working with WPF, WCF and a whole lot of other alphabet soup in terms of patterns. I'm starting to get spoiled on Visual Studio 2010, and may have made a mistake by evaluating the ultimate version.

Because I'm a .NET geek and an outdoor geek, expect a hodgepodge. It's nearly Easter, which for the garden means a whole lot of things. I've already started getting seed out, and started working soil. It feels good to get real dirt on your hands.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

author: blaird | Posted On Friday, March 12, 2010 2:17 PM | Feedback (0)