Search
On this page
Archives
RSS 2.0 Categories
Blogroll
Disclaimer
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Send mail to the author(s) E-mail
Painless Free Annual Credit Reports#

There is finally a (relatively) painless way to receive your Free Annual Credit Report from the Big 3 Credit Agencies.  It is a really good idea to keep your eye on your credit report these days.  The folks at AnnualCreditReport.com have integrated the registration processes for the three Credit Agencies into a seamless wizard type experience.  I was able to print all three of mine in less than 10 minutes.

Friday, January 25, 2008 6:30:24 PM (GMT Standard Time, UTC+00:00)
  Comments [1]  | 
Weather Widget now in the Silverlight.net Showcase#

The Silverlight Weather Widget made it to the Silverlight.net Showcase and is mentioned in the News section of the Home Page.  WooHooo. 

Friday, January 25, 2008 8:07:29 AM (GMT Standard Time, UTC+00:00)
  Comments [1]  | 
The New Generic Kid on the Block - HashSet<T>#

In mathematics, a Set is typically thought of as a collection of distinct objects that is usually defined by some rule that determines whether they are a member of that particular Set.  For example, a Set could be defined to contain "all the odd numbers under 100" or "every number divisible by 2" or whatever.  The main points here being that the objects in a Set are distinct (i.e. NO duplicate objects are allowed) and the objects are not ordered or sorted in any way.  (If you really feel the need to geek out on Set Theory, be my guest).

According to the MSDN Documentation for HashSet, "a set is a collection that contains no duplicate elements, and whose elements are in no particular order."  Sound familiar?  In the .NET Base Class Library, there has never been a true Set class until now with the release of .NET 3.5 and the brand-spanking-new System.Collections.Generic.HashSet<T> class. 

In the past, when we needed to implement a Set in .NET, we sort of bastardized the List<T> or other unsuspecting Collection classes into something like this:

int[] intArray = new int[]{ 1, 2, 5, 7, 4, 1, 7, 9, 8};
List<int> intList = new List<int>();
foreach(int theInt in intArray)
{
  // checking to make sure that the object is not in our List before adding
  //  so we are calling Contains() and then Add() on every time through the loop
  if (!intList.Contains(theInt))
    intList.Add(theInt);
}

What we needed was a Set that would let us just keep adding objects to it and free us from having to worry about it being there first.  A recent example of when I really needed a true Set class was while working on the Weather WidgetThe Weather Channel provides some 40+ images for use in their SDK, yet in the Weather Widget I never need more than maximum of 11 (and usually less as there is usually duplication).  So, I had the idea to dynamically zip the images that I actually needed for a given Zip Code and use that file for my image assets in Silverlight via CreateXamlFromDownloader.  Obviously, I don't want these images duplicated in the zip file.  So, I came up with this:

HashSet<string> assets = new HashSet<string>();
foreach (ForecastDay day in forecast.Days)
{
  // no Exception here if duplicate...it just doesn't add it.
  assets.Add(Server.MapPath(String.Format("~/images/{0}", day.IconDay)));
}
Utility.WriteZipFile(assets.ToArray<string>())

This just scratches the surface of what HashSet<T> is capable of.  There are member methods available for most Set operations, such as IntersectWith(), UnionWith(), IsSubsetOf(), IsSupersetOf(), RemoveWhere(), etc.   Here's a link to all of the HashSet<T> Members.

Recall that being a member of a set depends on some rule that determines this membership.  With the HashSet<T>, you can define your own rule of what it means to be in a Set.  For a good example of defining your own EqualityComparer, see Introducing HashSet<T> from Kim Hamilton on the BCL Team Blog.

So, welcome the New Kid on the Block to the Generic Collections. 

One last random link I had on the subject for those interested in LINQ:
Good side-by-side comparison of the HashSet and LINQ Set Operations

Friday, January 25, 2008 7:53:51 AM (GMT Standard Time, UTC+00:00)
  Comments [0]  | 
A Better Way to Remove a Trailing Slash from a Path#
C#

How many times have you written this to trim a trailing slash from a path:

if (myPath.EndsWith("\\"))   /* or "/" in the case of a URI  */
  myPath = myPath.Substring(0, myPath.Length-1);

Next time, try this:

myPath = myPath.TrimEnd(new char[]{'\\', '/'});

In addition to String.TrimStart() and String.TrimEnd(), there is an overload on String.Trim() that accepts a character array. There are good examples of usage in the MSDN Library.  Here are the links:  

System.String    Trim(char[])    TrimStart(char[])    TrimEnd(char[])

 

Friday, January 18, 2008 5:32:41 AM (GMT Standard Time, UTC+00:00)
  Comments [0]  | 
Back from the Silverlight Tour#

I had a chance to attend the recent Atlanta stop of Wildermuth Consulting’s Silverlight Tour this past week and wanted to offer some quick comments about it here for anyone considering the class. 

Going into the class, I had about 3 weeks of heads-down knowledge of Silverlight 1.0, but I had spent no time at all with Silverlight 1.1 (now 2.0).  I had also read Silverlight 1.0 Unleashed, watched a lot of the webcasts available and I had just (mostly) completed my first Silverlight 1.0 project.   

The 3-day Silverlight Tour begins with Day 1 of mostly concepts and terminology and an introduction into the Expression Suite.  This was mostly review for me, but I still managed several “a-ha” moments during the day as the presenter, Shawn Wildermuth, explained the “why” behind a lot of the concepts and decisions that were made in regards to Silverlight.  It was a good “shoring up” of my skills in the foundations of Silverlight. 

Day 2 was all about the code.  We spent about ½ the day on Silverlight 1.0 and the other ½ on Silverlight 1.1.  We had several labs, lecture, and discussion throughout the day.  (A good mix of the three, in my opinion).  One of the strengths of the class was that when questions would come up, we had the flexibility in the schedule to actually go off on short tangents and explore different ideas as a class.  I walked away from this day with a much better understanding of how the code side of Silverlight works with the design side, as well as, a lot of anticipation for Silverlight 2.0.  

Day 3 was the main reason I had taken the class and Shawn did not disappoint.  One of the things I struggled most with while working through the Weather Widget was how to organize projects and where do I use this method from the AJAX assemblies and where do I use Silverlight, etc.  These are the types of things that just aren’t in books yet, but Shawn has been there, done that and you are getting it first-hand.  We learned about the integration points with ASP.NET Ajax and Silverlight, and even newer technologies such as ASP.NET Data Services and the Entity Framework.   Further, we talked about packaging of Silverlight controls and other ways of thinking about the generation of XAML…ways I hadn’t thought about until then.  Very cool stuff from someone that truly understands the subject matter and takes the time to explain things in such a way as to really help everyone “get it”. 

So, I walk away with a head full of knowledge about all kinds of fun things that will be filling my life over the next year (and dying to tear my entire project for the Weather Widget apart and do it with all the new Best Practices I managed to acquire over the past 3 days)!  

Friday, January 18, 2008 3:49:55 AM (GMT Standard Time, UTC+00:00)
  Comments [1]  | 
Squeeze Your ASP.NET Applications Until They Scream#

A couple of weeks ago, I had the good fortune of catching a webcast from Jeff Prosise of Wintellect entitled:  "Squeeze Your ASP.NET Applications Until They Scream".  I was really impressed with the content and with Jeff's presentation of same.  The event was sponsored by Compuware and they have given me permission to post a link to the presentation. 

Squeeze Your ASP.NET Applications Until They Scream

Friday, January 11, 2008 4:50:52 PM (GMT Standard Time, UTC+00:00)
  Comments [0]  | 
My First Look at the (Silver)Light#

Over the holidays, I was finally able to catch up on some reading and take some time to play with Silverlight 1.0.  The two books that I spent the most time with are ASP.NET Ajax in Action and Silverlight 1.0 Unleashed.  Both of these, I HIGHLY recommend! 

My first project is a Silverlight 1.0 application that I call Weather Widget (for lack of a more exciting moniker).  The Weather Widget will accept a 5-digit US Zip Code and return a 5-day forecast from The Weather Channel.   You can see it in action here:  Weather Widget.  (Note:  This will require the Silverlight 1.0 plug-in).

I also took the time in this project to use (experiment) with a lot of new toys such as: 

·         LINQ to XML (and the XDocument/XElement classes)

·         New C# language enhancements including Automatic Properties, Object Initializers, Implicitly typed variables, etc. 

·         Javascript key events – some hard-learned (and forgotten and now painfully re-learned) lessons to share here

·         Integration of ASP.NET Ajax and Silverlight – my implementation here is rudimentary right now as I’m still sorting through the most efficient blending of these two technologies

·         Integration of DOM Elements with Silverlight (good post from Keith on that topic here)

·         Expression Studio (mostly Blend) -  I have much to say about this (some of which you can read in this discussion in Shawn’s comments here).  Overall, I really like a lot of things about Blend.  I am finding myself there more these days though I miss a lot of things about working in Macromedia (now Adobe) Fireworks (which I have used for MANY years for all of my design work).  One upcoming post I’m working on here is “Top 10 Things I miss from Fireworks while working in Blend”. 

·         Using JSON – I had never used it so now I have

Guess that about covers it.  I’ll link back to the above points as I blog about each. 

I have several things I’m planning to add (and am open to suggestions), but wanted to get it out there in its current state.  Once I am happy with it, I’ll post it to the gallery on the Silverlight.net site. 

Let me know if the Widget blows up…at this point, I’ve tested only on IE7 and Firefox on my laptop (Windows Vista64). 

 

Monday, January 07, 2008 5:25:20 AM (GMT Standard Time, UTC+00:00)
  Comments [8]  | 
All content © 2010 , Rik Robinson