Silverlight 4 Book Discount Codes!

If you plan on pre-ordering Silverlight 4 Business Application Development – Beginner's Guideuse the following codes to save some money!

MsSilver15 – Save 15% off hard copy of the book

MsSilver30 – Save 30% off the eBook

If you are looking to get into Silverlight this is a great intro book. Frank Lavigne starts the book out by getting you involved in the code right away and we try and keep the working code methodology through out. If you learn by doing then you will benefit from the book!

2/2/2010


System.Xml.Linq Extensions

I thought I would some extension methods I have been using for a little while now for Linq to Xml. When loading and retrieving the attribute values from XML nodes via Linq there is a bit of code to write to make sure the attribute exists and that the value is a valid data type. Rather than having a bunch of code to do this I simply wrote some extensions that operate on an XElement and are targeted at returning the value of an XAttribute.

Usage:

var element = XElement.Parse("<value x="50.5"/>");var value = element.GetDoubleValue("x");
.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt{ background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt{ background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }

Anyway, here is the class for the extensions:

   1:  using System;
   2:  using System.Xml.Linq;
   3:   
   4:  namespace System.Xml.Linq
   5:  {
   6:      public static class XLinqEx
   7:      {
   8:          /// <summary>
   9:          /// Gets a short value for the specified attribute.
  10:          /// </summary>
  11:          /// <param name="element">The element to parse.</param>
  12:          /// <param name="attributeName">The XName of the attribute to parse.</param>
  13:          /// <returns>A short value representation of the attribute value.</returns>
  14:          public static short GetInt16Value(this XElement element, XName attributeName)
  15:          {
  16:              var attribute = element.Attribute(attributeName);
  17:              if (attribute == null)
  18:                  return 0;
  19:   
  20:              short result = 0;
  21:              Int16.TryParse(attribute.Value, out result);
  22:              return result;
  23:          }
  24:   
  25:          /// <summary>
  26:          /// Gets an int value for the specified attribute.
  27:          /// </summary>
  28:          /// <param name="element">The element to parse.</param>
  29:          /// <param name="attributeName">The XName of the attribute to parse.</param>
  30:          /// <returns>An int value representation of the attribute value.</returns>
  31:          public static int GetInt32Value(this XElement element, XName attributeName)
  32:          {
  33:              var attribute = element.Attribute(attributeName);
  34:              if (attribute == null)
  35:                  return 0;
  36:   
  37:              int result = 0;
  38:              Int32.TryParse(attribute.Value, out result);
  39:              return result;
  40:          }
  41:   
  42:          /// <summary>
  43:          /// Gets a long value for the specified attribute.
  44:          /// </summary>
  45:          /// <param name="element">The element to parse.</param>
  46:          /// <param name="attributeName">The XName of the attribute to parse.</param>
  47:          /// <returns>A long value representation of the attribute value.</returns>
  48:          public static long GetInt64Value(this XElement element, XName attributeName)
  49:          {
  50:              var attribute = element.Attribute(attributeName);
  51:              if (attribute == null)
  52:                  return 0;
  53:   
  54:              long result = 0;
  55:              Int64.TryParse(attribute.Value, out result);
  56:              return result;
  57:          }
  58:   
  59:          /// <summary>
  60:          /// Gets a double value for the specified attribute.
  61:          /// </summary>
  62:          /// <param name="element">The element to parse.</param>
  63:          /// <param name="attributeName">The XName of the attribute to parse.</param>
  64:          /// <returns>A double value representation of the attribute value.</returns>
  65:          public static double GetDoubleValue(this XElement element, XName attributeName)
  66:          {
  67:              var attribute = element.Attribute(attributeName);
  68:              if (attribute == null)
  69:                  return 0;
  70:   
  71:              double result = 0;
  72:              Double.TryParse(attribute.Value, out result);
  73:              return result;
  74:          }
  75:   
  76:          /// <summary>
  77:          /// Gets a bool value for the specified attribute.
  78:          /// </summary>
  79:          /// <param name="element">The element to parse.</param>
  80:          /// <param name="attributeName">The XName of the attribute to parse.</param>
  81:          /// <returns>A bool value representation of the attribute value.</returns>
  82:          public static bool GetBooleanValue(this XElement element, XName attributeName)
  83:          {
  84:              var attribute = element.Attribute(attributeName);
  85:              if (attribute == null)
  86:                  return false;
  87:   
  88:              bool result = false;
  89:              Boolean.TryParse(attribute.Value, out result);
  90:              return result;
  91:          }
  92:   
  93:          /// <summary>
  94:          /// Gets a string value for the specified attribute.
  95:          /// </summary>
  96:          /// <param name="element">The element to parse.</param>
  97:          /// <param name="attributeName">The XName of the attribute to parse.</param>
  98:          /// <returns>A string value representation of the attribute value.</returns>
  99:          public static string GetStringValue(this XElement element, XName attributeName)
 100:          {
 101:              var attribute = element.Attribute(attributeName);
 102:              if (attribute == null)
 103:                  return String.Empty;
 104:   
 105:              return attribute.Value;
 106:          }
 107:   
 108:          /// <summary>
 109:          /// Gets a byte array from the base 64 encoded value of the current element.
 110:          /// </summary>
 111:          /// <param name="element">The element to parse.</param>
 112:          /// <returns>A byte array of the base 64 encoded element value.</returns>
 113:          public static byte[] GetByteArray(this XElement element)
 114:          {
 115:              var value = element.Value;
 116:              if (!String.IsNullOrEmpty(value))
 117:              {
 118:                  return Convert.FromBase64String(value);
 119:              }
 120:              return null;
 121:          }
 122:      }
 123:  }
.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt{ background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }

1/19/2010


Silverlight 3 Book

As Frank LaVigne mentions in this post about a Silverlight 3 Book, I have been asked to co-author the book with him. I am honored that he asked me to help with completing the book and will work to deliver a solid book for any .NET developers out there getting their feet wet in the world of Silverlight business development. The book should give you some proof that Silverlight is a viable business tool and not just something for game developers to play with or to make web sites pretty.

Having already had the privilege of peer reviewing the first few chapters this is going to be a great intro to Silverlight, Frank is all about getting right into code!

9/11/2009


LINQ Queries

I have spent the last three days writing LINQ qeueries over object collections and have to come to rely on LINQ pretty heavily for most query operations. I have played around some with LINQ to SQL and LINQ to Entities but I mostly use it to just query over some good old fashion collections like so:

 

var groups = proposal.Lines.Where(kvp => kvp.Key.Equals(key.Quarter))
                                           .Select(kvp => kvp.Value.Where(l => l.AvailType.Spot == "N" && l.AvailType.Type == "RE"))
                                           .FirstOrDefault()
                                           .GroupBy(l => new { l.NetworkId, l.UnitLength, l.BrandId });

            List<TimePeriod> weeks = proposal.GetWeeksFromOrderFlightDates(key.Quarter);
            foreach (var group in groups)
            {
                BudgetRow row = AddBudgetRow(budgetDefinition,
                    new List<string>(new string[] { group.Key.NetworkId.ToString(), group.Key.UnitLength.ToString(), group.Key.BrandId.ToString() }),
                    budgetRows, BudgetDefinitionType.WeeklyNetworkAvailTypeImps);

                foreach (var week in weeks)
                {
                    var units = group.SelectMany(l => l.Units.Where(u => week.contains(u.AirDate)));

                    row.setRawValue(week, units.Sum(u => (decimal?)u.Demo1Imps));

                    row.setLockedValue(week, units.Where(u => u.IsLockedOutOfUnitAllocation).Sum(u => (decimal?)u.Demo1Imps));
                }
            }

5/7/2009


Perenthia Blog

I have started a Perenthia Blog which will be the official blog of the game, however, I will still probably end up blogging code snippets and the like here and keep the Perenthia blog a little more high level and focused on information the actual players may want to know.

4/16/2009


Blog Engine 1.3.1

The BlogEngine.NET folks have released a security update to BlogEngine. I would recommend downloading it ASAP.

Thanks to Mads for the heads up!

4/28/2008


My Buddy Clifford

From the moment you came into our home you were always daddy's buddy. We would sit in my chair and watch TV and you always helped me out in the garage when I was working on something for mommy.
You loved to be "The Ranger" when we went out back or to the park. You would run ahead on trails; exploring and taking in all the sights and smells of the forest.
You and Sydney loved "Playtime" out back, especially in the snow. She loved chasing you around the yard and loved being chased.
You had a gentle soul and an overabundance of patience with the smaller residents of our home. Always easy going and always happy to have a comfortable place to nap.

I know I will see you again someday but until that time I will hold your memory in my heart and all the joy you brought to our home. Rest in peace Clifford, you will always be "daddy's bestest buddy".

2/19/2008