mike-obrien.net Resume Blog Labs
Tuesday, November 14, 2006

I ran into an issue where I could not enable the VMRC in MS Virtual Server 2005. I would check the box and save the settings but it would revert right back to being disabled. Turns out that VNC server happens to run on the same port, 5900, as the VMRC. So if you are running VNC you have to change the port for either VNC or VMRC. I wish the control panel would have just thrown an error but it's those sort of things that keep life interesting... ;-)

Tuesday, November 14, 2006 4:41:01 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [1]  | 
Friday, November 10, 2006

One of the shortcuts of C# (And now in VB.NET 2005) I love is the using statement. For those not familiar with it, it allows you to create objects within the scope of the using block and then once the block completes execution, calls the Dispose method on all the specified objects if they implement IDisposable. This occurs even if an exception is thrown. From what I understand, the using block in the resulting IL is a try/finally block, where the object disposal takes place in the finally.

This is perfect for working with a DataReader and instances where we want to make sure a database connection is closed right after a call. Since the Dispose method on a DataReader and Connection object call their own Close method they will be implicitly closed when we exit the using block, regardless of errors.

string ConnectionString = "server=127.0.0.1;database=duwamish7vb;Trusted_Connection=true";

using (SqlConnection Conn = new SqlConnection(ConnectionString))
{

    Conn.Open();

    SqlCommand Command = new SqlCommand("SELECT Name FROM Authors",Conn);

    using (SqlDataReader Reader = Command.ExecuteReader())
    {

        Authors.DataTextField = "Name";
        Authors.DataSource = Reader;
        Authors.DataBind();

    }

    Command = new SqlCommand("SELECT Subject FROM Books", Conn);

    using (SqlDataReader Reader = Command.ExecuteReader())
    {

        Books.DataTextField = "Subject";
        Books.DataSource = Reader;
        Books.DataBind();

    }

}

.NET | C# | VB.NET
Friday, November 10, 2006 9:17:27 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 

I have seen a lot of debate about VB.NET and C# and which one is "better". Before I started coding in C# I had some prejudice about it, but it’s interesting to see how my viewpoint has in some cases changed, and in others not changed after making the switch.

My viewpoint before switching over:

  • .NET languages are as MS put it a "lifestyle choice".
  • Many C# programmers think a little too much of themselves, projecting an elitist status as if a VB.NET developer knows nothing about OOD/OOP, design patterns and are just script kiddies.
  • Case sensitivity within a language is moronic, inelegant and causes ambiguity.
  • VB.NET is a very expressive language, like reading a book whereas C# looks like a bunch of ugly symbols.
  • And what’s with that stupid semi-colon anyway??

My viewpoint after switching over:

  • I still think it’s a lifestyle choice. I’m sure some C# purists will probably say I "don’t know enough about C#" or "that sounds like something a VB programmer would say". :-) The power of the .NET framework is, in my opinion, expressed well in both languages except for a few things here and there. Especially now with the release of v2.0 it’s not about whether or not you use a particular language syntax, it’s really about knowing how to develop .NET applications and about programming and design principles.
  • I still think some C# programmers think too much of themselves. I do realize however that the majority of VB.NET programmers come from the VB6/VBScript world, a world I am from. Many of those individuals carry a lot of baggage with them and do not have a good grasp of OO, design patterns, etc and are just not skilled developers. Many of them are the script kiddie type because it was so easy to pound out code in those languages, didnt require a whole lot of skill. But don’t judge a book by its cover. I think there are a lot of developers who came from that world who have embraced the principles, now present in the .NET framework (Not just a particular language syntax), that Java and C++ programmers have practiced and enjoyed for years.
  • I've not noticed the case sensitivity in C#… In fact in cases where I have not had VS prettying up my VB code I manually format my code anyway. Not even an issue. Ambiguity is definitely a possibility but I think a good developer would avoid that for clarity.
  • I actually now like all those "ugly symbols" over the expressive and verbose VB syntax… Very strange because that was one of my biggest prejudices aside from case sensitivity. It’s just a lot simpler and once you get used to it it’s not hard to read. If you are only familiar with the expressive syntax of VB it is hard to follow. I feel like I have much more flexibility over how I structure my code. Even going back to do maintenance on VB.NET code is less than enjoyable now that I have been working with C#.
  • Ok, the semi-colon is a little annoying at first but you get to the point where you don’t even think about it. It’s actually very nice in instances where you have a large string literal or a long line of code.

Bottom line is, "...just listen to your heart. That's what I always do". Dont be caught up in the hype that coding in VB.NET makes you a script kiddie. But I would seriously recomend, if you are a VB.NET developer who has not learned C#, to at least give it a try. You might be very surprised at how much you like the syntax over VB.

.NET | C# | VB.NET
Friday, November 10, 2006 8:25:01 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 
Wednesday, November 08, 2006

Previously (Prior to v1.4) the Subversion server (svnserve.exe) couldn’t be natively run as a Windows service. You had to use a wrapper such as srvany.exe from the Windows res kit to host it. Well now as of v1.4 it will run as a service but you have to manually install it. Doing this is pretty simple; just use the sc utility to add it at the command line as follows. The first svnserve switch (--service) notifies it that it should communicate with the SCM. The second (-r), which is optional, allows you to specify the root repository path.

C:\>sc create SubversionServer binpath= "\"C:\Program Files\Subversion\bin\svnserve.exe\" --service -r  e:\Subversion\RootRepo" displayname= "Subversion Server" depend= Tcpip start= auto

C:\>sc start SubversionServer

You can find the release notes about this new feature here.

Wednesday, November 08, 2006 12:01:14 AM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 
Tuesday, November 07, 2006

I ran into an issue today where I was coding in a class under a particular namespace but couldn’t access a class in another namespace that only differed by its namespace root. Here is what it looked like:

MyApp.Common.MyClass // Class I want to reference (For a unit test)

TestSuite.MyApp.Common.MyClass // the class I'm coding in (A unit test...)

When I referenced MyApp.Common.MyClass it was actually resolving to TestSuite.MyApp.Common.MyClass. So if you want to reference the former, you need to use the "global::" prefix as follows:

global::MyApp.Common.MyClass

.NET | C#
Tuesday, November 07, 2006 8:49:11 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 
Sunday, October 15, 2006

In OOP, type variance refers to the difference between a class and its descendant or ascendant. For example lets say we have three classes; Vehicle, Spacecraft and Shuttle. Shuttle inherits from Spacecraft which inherits from Vehicle. They all vary by type. Vehicle is the contravariant of Spacecraft since Vehicle is Spacecraft’s ancestor whereas Shuttle is the covariant of Spacecraft since Shuttle is a descendant of Spacecraft. Invariance simply refers to a lack of variance. For example a parameter or return type that must be invariant cannot respectively accept or return an ancestor or descendant of the type specified, they can only accept or return the specified type.

Sunday, October 15, 2006 6:33:35 AM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 
Wednesday, October 11, 2006

The following is a breakdown of 4 basic bitwise operators; NOT, OR, XOR and AND.

NOT

NOT produces the inverse of a binary value. For example:

1 will be 0 and 0 will be one. In C# NOT operations are only allowed on Boolean values. The NOT operator is an exclamation point (!).

bool i = true;

Console.WriteLine(!i);

// returns false

OR

OR produces a 1 if either corresponding bit is 1. This means that if both are one or if only one is 1 the result is 1. If both are zero then the result is zero. For example:

In C# the OR operator is the pipe (|).

int i = 23; // 010111
int z = 45; // 101101

Console.WriteLine(i | z);

// 63 - 111111

XOR

XOR (Or Exclusive OR) produces a 1 if either corresponding bit is 1 but not both, in other words mutually exclusive. This means that 1 and 0 or 0 and 1 will be 1. 0 and 0, 1 and 1 will produce 0. For example:

In C# the XOR operator is the caret (^).

int i = 23; // 010111
int z = 45; // 101101

Console.WriteLine(i ^ z);

// 58 - 111010

AND

AND produces a 1 only if both corresponding bits are 1, otherwise it produces a 0. For example:

In C# the AND operator is the ampersand (&).

int i = 23; // 010111
int z = 45; // 101101

Console.WriteLine(i & z);

// 5 - 000101


 

.NET | Binary | C#
Wednesday, October 11, 2006 8:07:13 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 

Unary operations only have one input while binary operations have two inputs. For example ++i is a unary operation since this statement only has one input value, i. On the other hand i + n is a binary operation (Not to be confused with the binary numeral system) since there are two inputs, i and n. i + n + z is still binary since it is actually 2 binary operations; i + n = x, then x + z = y or (i + n) + z.

Wednesday, October 11, 2006 6:16:27 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 
Tuesday, October 10, 2006

I recently had the opportunity to work with a 2d area scanner (aka Bar Code Reader) in a .NET application. Previously our client used proprietary software that just plain stunk so we decided to write our own software. One very cool thing I discovered while working on this project was that many USB devices (Like bar code scanners, joysticks, game pads, mice, keyboards, etc) sport a Human Interface Device (HID) interface. This interface communicates using the standard HID protocol defined by the USB Implementers Forum. The cool thing about this is that one standard device driver can be written and used for all USB HID devices on a particular platform. Normally you would have to write your own device driver or use an existing one to communicate with a USB device, ouch! USB HID eliminates that requirement. Windows ships with a standard USB HID device driver and automatically makes the HID interface available when a USB HID device is plugged into the system. Nothing to install, no device driver to write, yay! Windows also has a fairly easy to use API (Although a little quirky) for communicating with HID devices. This site, run by Jan Axelson, has a lot of good information on communicating with USB HID devices. His book, USB Complete, is also an invaluable resource, I would definitely recommend it if you will be doing HID development on any platform.

I have an HID .NET library available here if you want to skip most of the gory details and get right down to business. I have used this library in production and have not had any issues, please let me know if you have any feedback. Using this library, while encapsulating most of the underlying details, will require you to understand the format of data contained in the payload of the reports sent to and from the device. HID’s communicate using "reports" which are analogous to packets in network terminology. The reports themselves are a standard USB HID data structure although the payload of these reports will be specific to the device or device type. Usually the payload data format can be found in the device SDK and/or by simply analyzing the payload data the device sends.

The following library, developed for the HHP IT4600/IT4800 area scanner, uses the aforementioned HID library.

IT4XXXScanner.zip (1.98 MB)
Tuesday, October 10, 2006 8:15:40 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [4]  | 

Have you ever wanted to embed an HTTP server into your application? For example let’s say you have a Windows service that you want to administer or monitor (Google desktop is a good example of this). Or let’s say you have an application that requires an alternate interface such a kiosk application. Wouldn’t it be great to have an embedded HTTP server that would allow you to provide a web interface for your application without requiring IIS and without requiring you to write a web server? If so then Lomez is your friend!

Lomez is an in-process HTTP server that allows you to create virtual directories, serve static content from a file or embedded resource and expose any object by implementing the HTTPHandler interface. It loosely resembles ASP.NET to allow you to use it with ease.

Ok, enough of the spiel… Basically I have a number of applications I work with that I would love to have HTTP access to, especially Windows services. I have looked high and low but have not found a library to allow me to do this. So at that point I figured I would have to develop something myself and Lomez was born. I have successfully used this library in a production kiosk framework (At 2 tradeshows so far) and it has worked like a champ. The current version of the library can be found here. I would love to hear any feedback you might have on it.

I consider the current version more of a proof of concept and would really like to rewrite it from the ground up. So hopefully I can begin doing that soon. I would really like to include basic authentication, challenge/response and SSL in the next version. I would also like to optimize the HTTP pipeline so it is lean -n- mean. It’s definitely not right now.

Anyways, if you end up on this page because you are looking for an in-process HTTP server for .NET please let me know your thoughts. And if you decide to use the library, let me know what you think of it.

Thanks!

The Management

Tuesday, October 10, 2006 7:04:45 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [1]  | 

Interesting TechEd presentation on SaaS by Gianpaolo Carraro.

Tuesday, October 10, 2006 4:34:04 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 

So I needed to setup build, dev and staging servers on a limited budget. Getting 3 new servers in a small company is not always feasible as you probably already know. The solution? Microsoft Virtual Server 2005. Although I was familiar with the concept of running virtual servers I had not actually done it before (Shame on me!). So I was very surprised with just how easy it was to setup and configure MSVS! The configuration is so intuitive that I literally didn’t read a word of documentation (Which really appealed to my male, "I don’t need to read the directions" side… ;-)) and had a virtual server up and running in no time. The other thing that really surprised me was performance. I’m running Windows Server 2003 Standard on a 2.0 GHz AMD Athlon XP 2400+ box with 1 GB of memory (Not a very beefy box). The host system is acting as the build server and two virtual servers are running as a development and staging servers (Both running Svr 2003). I’m very surprised how "zippy" the virtual instances run.

Our network admin had a great suggestion; first create a template server which can be copied for new instances. That way you can create new instances with out having to start from scratch. When you create the new instance you need to give Windows a unique SID. Sysinternals has a free SID changer tool called NewSID which will do this. You can then take it a step further and create instance specific copies. For example I can get our dev and staging server’s setup exactly how I want them and make a copy of those instances. Then if either one of those servers gets hosed I can wax them and copy out a fresh version literally within a few minutes.

MSVS installs a net driver that allows all instances to share a single NIC. From what I have read, each instance is assigned a random MAC address. The NIC is put into promiscuous mode and packets are filtered and routed to the virtual servers.

All in all I'm very impressed with MSVS. And I'm pretty hyped about how easy it is to setup complex test and R&D environments with minimal hardware. I would be curious to see how it compares with VMWare. I guess I'll save that for another weekend... ;-)

Microsoft offers Virtual Server 2005 as a free download here.

Tuesday, October 10, 2006 3:31:10 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  | 
Thursday, October 05, 2006

Some interesting peices on interviewing developers:

http://www.joelonsoftware.com/articles/fog0000000073.html

http://www.hanselman.com/blog/WhatGreatNETDevelopersOughtToKnowMoreNETInterviewQuestions.aspx

Among the many good points Joel makes, one that really struck me was on "illeagal questions" to ask an interviewee. I think some are pretty obvious but I think one really needs to be careful about questions asked in an attempt to take an interest in the person and/or be friendly. For example I love to learn about and understand different cultures, and most people love to talk about their culture and where they are from. So I usually have no qualms about engaging people in this type of conversation. But on an interview this is off limits since it could be taken, not as friendly conversation, but as discriminatory questions regarding race.The following FAQ covers these issues.

http://www.eeoc.gov/facts/qanda.html

Thursday, October 05, 2006 3:14:34 PM (GMT Standard Time, UTC+00:00)  #   |  Comments [0]  |