Let’s try this again…


So it’s been a really long time since I consistently blogged on my previous ASP.NET blog (and, let’s be honest, it wasn’t that consistent to begin with!)  With the mainstream use of microblogging sites like Facebook and Twitter, I’ve been able to post more frequent updates (http://www.facebook.com/scott.vanvliet & http://twitter.com/scottvanvliet) but haven’t really authored any good content lately.

Well, I decided it’s time for me to try again!

I’ve relocated my blog from the ASP.NET weblogs site to my new home here at http://geekswithblogs.net (thanks @jjulian and @jalexander!)  I hope to be posting musings on here about Silverlight, motion graphics, digital media, digital supply chain, and even personal/fun stuff.

Stay tuned!

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

author: svanvliet | Posted On Tuesday, March 23, 2010 7:17 PM | Feedback (0)

IDataReader Extension Methods


First of all -- I'm a total liar.  I was supposed to offer up some great insight from Tech•Ed.  But alas, I had to leave early and fly to Seattle for a meeting.  So, I wasn't able to share any fun stuff :(

We'll, I actually have a tiny bit of time to write, and I thought I'd share the result of recent code review.

I'm currently teaching .NET (Framework fundamentals, C#, et al.) to some of my clients who are preparing to take over the support of a very large application (we're going on 2 years of development and deployment!) As we were looking at some of the code, I came across some stuff from our offshore team that slipped by my team's radar. In this particular project, we found hundreds of lines that looked like this:

theatre.ID = (reader["theatre_id"] is DBNull) ?
   
0 : Convert.ToInt32(reader["theatre_id"]);

theatre.Code = (reader["theatre_code"] is DBNull) ?
   
String.Empty : reader["theatre_code"].ToString();

Ick!  I was very bummed to come across this while teaching my clients about best practice -- was a bit 'the fool'.  Not wanting to let this pass, I quickly redirected the discussion to talk about refactoring and reuse (which was kind of a nice segue to some OO topics.)  In this discussion, we wrote an Extension Method to the IDataReader class to clean-up this code.  The new code looked pretty:

theatre.ID = reader.GetValueOrDefault<int>("theatre_id");

theatre.Code = reader.GetValueOrDefault<string>("theatre_code");

The details of this Extension Method are as follows:

/// <SUMMARY>
/// Contains extension methods for the IDataReader interface.
/// </SUMMARY>
public static class DataReaderExtender
{
  /// <SUMMARY>
  /// This method will return the value of the specified columnName, cast to
  /// the type specified in T. However, if the value found in the reader is
  /// DBNull, this method will return the default value of the type T.
  /// </SUMMARY>
  /// <TYPEPARAM name="T">The type to which the value found in the reader should be cast.</TYPEPARAM>
  /// <PARAM name="reader">The reader in which columnName is found.</PARAM>
  /// <PARAM name="columnName">The columnName to retrieve.</PARAM>
  /// <RETURNS>The column value within the reader typed as T.</RETURNS>
 
public static T GetValueOrDefault<T>(this IDataReader reader, string columnName)
  {
   
object columnValue = reader[columnName];
    T returnValue = default(T);
    if (!(columnValue is DBNull))
    {
     
returnValue = (T)Convert.ChangeType(columnValue, typeof(T));
    }
    return returnValue; 
  
}
}

Enjoy! (I've posted the code here: DataReaderExtender.zip)

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

author:  | Posted On Wednesday, June 18, 2008 11:55 PM | Feedback (10)

Hello from Tech·Ed


Hey everyone -- just got out of the Tech·Ed 2008 keynote and learned that this was Bill's last keynote as chairman of Microsoft... kind of cool to witness.  Was a good session, outlining SQL Server Data Services and some other stuff -- but nothing "new", per se.  But hopefully we'll see some good stuff in the sessions...

 I'm off to a WPF session, and will be posting some tibdits as I find them.  Talk soon.

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

author: svanvliet | Posted On Tuesday, June 03, 2008 2:55 PM | Feedback (2)

Live Search -- Cashback Infinite Redirect


Classic... try it yourself: http://search.live.com/cashback

And I was all excited about getting some of that proverbial "fat cash". (And yes, I tried this on both PC and Mac -- IE, Firefox and Safari!)

Update

Working now -- must have been some last-minute host header redirect from msn.com to live.com (see the screenshot.)
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

author:  | Posted On Thursday, May 22, 2008 9:09 PM | Feedback (3)

Tom Brokaw -- C# or VB.NET?


Not sure why this hasn’t been covered yet on the blogosphere, but yesterday at Microsoft 2008 Launch Event, Tom Brokaw gave a ~15 minute monologue about technology to introduce Steve Ballmer , the plight of our planet, and how technology (and those who deploy it) should be used for the greater good.

Tom Brokaw!  That’s right – TB; to introduce Visual Studio 2008 and other products.  Relevance?  I wonder if he’s a C# guy, or perhaps more of an IT Pro.  LMAO.  It was a cool experience, and quite different from the usual (a la Christopher Lloyd as Doc Brown in a De Lorean), which set the stage for this *unique* event.

I’ve been to my share of launches and airlifts – and the most bizarre part about this one was – surprisingly not Brokaw – but the spandex-wearing “living art” performers that graced the walkway from the Nokia Live Theatre to the LA Convention Center.  It was something from an episode of The State.

What did you think about the event?  Hyper-V does look awesome, and of course Visual Studio 2008 is bliss (we’ve been using it since RTM last November!)  Cheers.

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

author:  | Posted On Thursday, February 28, 2008 3:02 PM | Feedback (0)

Looking for a Consulting Career in the Entertainment Industry?


Does working on projects for a movie studio sound exciting to you? Do you want to parlay your consulting job into an acting career? Do you have a garage band and want to drop your demo tape at your record label client's desk? If you answered 'yes' to any of these questions, please read on! (All in jest, of course)

We're currently looking for highly-skilled Microsoft Solution Developers to work on projects at our entertainment clients throughout Southern California. Specifically, we're looking for go-getters with the following skillsets:

  • Solutions Developers (all levels) – C#, WinForms, ASP.NET, Web Service, WCF, SCSF (CAB), EntLib
  • Database Developers (all levels) – SQL Server 2005 Integration Service (SSIS), Reporting Service (SSRS)

If you are interested, please send your resume ASAP to svanvliet[at]gmail[dot]com. I will follow-up with a full job description and more details on our firm (one of the largest technology consulting and outsourcing companies in the world!) Local candidates only, please.

I look forward to hearing from you!

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

author:  | Posted On Thursday, September 27, 2007 11:55 PM | Feedback (0)

Gaming Crosses Over to Real Life


So I've boarded my flight to DFW (en route to Orlando.) Having been upgraded to First Class, (thank you elite status) I started getting comfortable in my bulk head isle seat (my favorite, of course.) Just as I'm about to buckle-up, a gentleman asks if I'm too attached to my seat to move so that he and his buddy can sit together. Now, I'm very cognizant of people who are jerks and can't move so that families and friends can sit together (I'll post on my recent Amsterdam to Los Angeles flight with wife and kids in tow later.) Thus, I acquiesced and offered my seat to this gentleman.

With a gracious "thank you," the guys proceeded to take their seats. It was at this time that I noticed their shirts and bags, which donned the "BlizzCon" logo. This brought me back to earlier, as I waited to board, when I heard some fellas talking about "the Horde" as if it were real life. Knowing a little about World of Warcraft (WoW,) I quipped, "Just take it easy on me in WoW." This is where it started.

"You play?!" responded the gent. "A little," I responded, which evoked, "What faction? Alliance or Horde"

"Uh, Alliance, I think?"

"AAAAAAHHHHH… Take your seat back!" was the response from the two men, as the laughed out loud.

Now, I'm a geek – no doubt. But this was just crazy! Nevertheless, I quickly put on my headphones and closed my eyes to escape the conversation I was not interested in having.

About 5 minutes later, the man was rubber-necking to try and get my attention.

"What server do you play on? I'd like to give you some Gold for your seat."

Holy shit… I couldn't believe that I was being offered FAKE money as a gift for my kindness!

"Uh, I don't know."

I had only signed up for a 14-day trial to WoW, and don't really have time to play any games these days. But it just goes to show how gaming is widely becoming part of everyday life, and in some cases bleeding the edge of reality.

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

author:  | Posted On Monday, August 06, 2007 9:03 PM | Feedback (3)

UTF8 Encoding Changes in Vista (Hashing Gotcha)


If you've used hashing to store passwords for your application, you may want to double-check you code to ensure it works on Vista.

Thanks to information found in Shawn Steele's post from almost a year ago, it seems Microsoft made changes in the .NET Framework for Vista to comply with the Unicode 5.0 specification, which requires invalid characters previously omitted in earlier versions of the .NET Framework for Windows XP, Server 2003, etc. As such, hashes computed on previous versions of Windows may not match hashes created on Vista.

For example, if you hash the string 'Password' on Windows XP using MD5CryptoServiceProvider, the hashed UTF8 string result would be 'd~^g◄U7R↑!+9d'. Now, hashing the same value on Vista (without the fore mentioned solution) would result in '�d~�^g_�U7R_!+9d' as the UTF8 string output. Note the addition of the Unicode Replacement Character (\xFFFD) interspersed in the latter output. This is due to the fact that the Unicode 5.0 specification requires this character be provided rather than omitted, as allowed in Unicode 4.1 (implemented in the aforementioned previous versions of the .NET Framework for Windows.)

Now, as noted in Shawn's post, you can yield the same results on Vista as previous versions of Windows using EncoderFallback derived classes. These will allow you to specify non-default characters to use in place of the Unicode Replacement Character. For example, consider the following setup:

Encoding encoding = Encoding.UTF8.Clone() as Encoding;
encoding.EncoderFallback = new EncoderReplacementFallback(string.Empty);
encoding.DecoderFallback = new DecoderReplacementFallback(string.Empty);

Based on the snippet above, the encoding will use an empty string for encoding/decoding; thus, the result would be the same as that from Windows XP in the previous example (which simply omitted by default.)

While this solution will work (had to make things work in an existing codebase,) I would recommend using Base64-encoding strings to store hashes, as they would not suffer from the same issues of invalid UTF8 characters. The same string, 'Password', hashed using bytes obtained from Encoding.UTF8.GetBytes(byte[]) with or without the fallbacks yields '3GR+tl5nEeFVN1IYISs5ZA==' using Convert.ToBase64String(byte[]).

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

author:  | Posted On Wednesday, May 02, 2007 3:45 AM | Feedback (0)

How-to: Change Windows Hostname and Keep Oracle 10g Running


So I realize it seems like I'm posting a bunch of stuff on Oracle and little on .NET, but it's all related to a large Smart Client application we're developing for our client, using Oracle 10g; thus, it's relative J

In a geographically-diverse team structure, it can be quite difficult to manage the development environment used by each team member (especially when you have little control over the workstation configuration of your offshore team.) Thus, for many of our engagements we heavily leverage virtualization – specifically Virtual PC 2007 – to help minimize the cost of environment setup and configuration.

One of the challenges we've faced with leveraging Virtual PC, specifically a shared image, is the unique naming of virtual machines. Now, in many cases it is acceptable to keep the virtual machine name the same across developer environments; however, for our purposes, unique machine names are required based on the following:

  • TFS Workspace names rely on machine name for unique naming (in combination with username)
  • Using our host VPN connection and Internet Connection Sharing (ICS), we provide our guest VPN access; although through NAT, the machine name (NetBIOS) still passes through when accessing corporate network resources, thus causing issues with the same
  • When using local network access directly on the guest, name conflicts occur; furthermore, two guest machines have issues accessing each other due to similar NetBIOS naming issues as outlined above (we often communicate guest-to-guest from different developer environments)

For all intents and purposes, this is a trivial matter. However, when dealing with Oracle, reliance on the installation-time hostname – at least from my experience and research – is critical. Thus, changing the hostname can cause problems.

Consequently, we've learned to deal with this process by following the steps outlined below.

Step 1 – Create Hosts Entry for Old Hostname

Locate your hosts file, typically located at %WINDIR%\system32\drivers\etc\hosts and add an entry for the old (current) hostname.

#
# HOSTS file
#

win2k3r2    172.16.10.10


Note the IP address – this is the address of a Loopback Adapter installed on the guest machine. As outlined by the Oracle Installer, a Loopback Adapter is required on systems that do not have a static IP address (as do virtual machines using NAT, etc.)

Step 2 – Uninstall Enterprise Manager Console

Because there are configuration settings stored with Enterprise Manager Console that reference the hostname, the same must be uninstalled.

emca -deconfig dbcontrol db -repos drop


Note, before executing this command, ensure that the Oracle instance is running – it has to be in order for Enterprise Manager Configuration Assistance to drop the repository and de-configure the Console.

Step 3 – Stop All Oracle Services

Once the uninstall of Enterprise Manage Console has completed, stop all Oracle Services on the guest machine.

  • iSQL*Plus Service – typically named Oracle<OracleHomeName>iSQL*Plus
  • Oracle Listener Service – typically named Oracle<OracleHomeName>TNSListener
  • Oracle Database Instance Service – typically named OracleServer<SID>

Step 4 – Update listener.ora and tnsnames.ora

Once all the Oracle services have stopped, update the listener.ora and tnsnames.ora files, located in %ORACLE_HOME%\network\admin to reflect the desired (new) hostname.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = win2k3r2)(PORT = 1521))
)
)

DEVBOX =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = win2k3r2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = devbox)
)
)

Step 5 – Rename Host and Restart

Now, rename the computer and restart the guest machine.

Step 6 – Ensure Oracle Instance is Running

Once the guest machine has started up, log in and ensure the Oracle instance is running using the following command line (typically required, unless the instance, not the Windows Service, is configured to auto-start.)

oradim -startup –sid devbox

Step 7 – Reinstall Enterprise Manager Console

After ensuring the Oracle instance is running, reinstall Enterprise Manager Console using the following command line:

emca -config dbcontrol db -repos create

Step 8 – Validate Enterprise Manager Console Installation

Lastly, after the successful installation of Enterprise Manager Console, validate the installation by navigating to the logon page – typically http://<hostname>:1158/em/.

At this point, you should be crankin' away with your Oracle instance running as it should! We spent a lot of time working on this issue, so hopefully this post helps you out in some way – I wished there was an article like this when I was scouring OTN with no results!

Thanks to Mike Huffine for the initial pointers.

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

author:  | Posted On Tuesday, April 03, 2007 8:41 PM | Feedback (43)

こんにちは東京から / Hello from Tokyo!


This is my first time visiting Japan, and it's already been an incredible experience. Dinner tonight was an interesting blend of Japanese fare, most of which tasted completely unfamiliar. And the long ride from Narita to the Westin Tokyo allowed me to view some of the city's multifaceted beauty.

Tokyo is the start of my mini World Tour of client meetings; I'm off to Hong Kong in a couple days, then to Mumbai only a day later. Stay tuned for more interesting musings.

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

author:  | Posted On Sunday, March 25, 2007 12:48 PM | Feedback (0)