www.jlion.com

Wednesday, July 26, 2006

I've been commuting an hour to work each day now for about a month now. In that span of time, I've "read" these audio books:

"The Art of War". I liked this and found it thought provoking even though I had read it previously (some time ago) in paperback form.

An abridged version of "The Hobbit". Most enjoyable.

Most of "The Silmarillion". I found this to be somewhat boring. It reads like notes that Tolkien took in preparation for writing Lord of the Rings, not a story in itself.

"Napalm and Silly Putty". Ordinarily I don't like George Carlin very much but I enjoy this and found some of his observations to be very humorous. He always seems to return to the subject of airline attendants for some reason?!?

"The Hitchhiker's Guide to the Galaxy". I liked this. A long time ago I'd read the paperback. More recently I'd watched the movie.

"Science Fiction Radio Classics Volume 1". This is a terrific collection of older (60s?) science fiction short stories. I had read many of these stories as a boy. It's wonderful to hear them brought to life as an audio book.

I'm now listening to a Harry Potter novel. This is the first Harry Potter novel that I've read although I've seen most (all?) of the movies. There's an additional layer of detail in the novel that adds a dimension to the story that's absent from the films. After finishing this I will probably go back and watch the movie again as it's been a while since I've seen it.

This world of audiobooks and podcasts is huge. I've just signed up for www.simplyaudiobooks.com which is a service similar to Netflix. For a monthly fee you can rent all the audio books (one at a time) that you can listen to. The New York Times also offers a lot of content in audio format (for subscribers only).

So much great reading, and only two hours a day. Almost makes one want a longer commute! :)

Friday, July 14, 2006

On illegal immigration:
I noticed in the news today that a small city in Pennsylvania has passed some of the strictest anti-illegal-immigrant laws in the nation. The article quotes a police officer as saying that the new legislation would reduce crime rates.

This saddens me. I've had the fortune to meet some very smart and hard working small business people who were, at least for some small time, illegal immigrants. It's my belief that the source of America's strength and her success is that she has always attracted the best and the brightest, the strongest and the most restless from every country. If we lock our doors to the world, we'll become weak and inbred.

The problem isn't illegal immigrants, in my opinion--it's those who don't bother to immigrate. We need to pursuade the most talented artists and hardest working masons from China and Croatia, the smartest scientists and entrepeneurs from El Salvador and from Equitorial Guinea that their best chance of success is if they can find a way, any way, to be an American. Building walls and passing restrictive laws doesn't make us safer, it thins our blood and dims our luster.

DotNet serialization is really easy to use. I've come to that conclusion lately, after converting a event logging class that I use to make it message queue compatable. Before converting the class I did a bit of research and found that Dot Net serialization gets mixed reviews, mostly it seems, because of how it handles (or fails to handle) complicated classes. But my class is simple and for me it has worked just fine.

Serialization is the process of converting an object into some sort of generic format (say, for example, XML), then converting it back again into the object. This allows objects to be stored in databases (or message queues).

Here's what I had to do to make my event class serializable:

1) I added the <Serializable> tag above the declaration of the class that I wished to serialize, as shown here:

<Serializable()> _
Public Class _Event
'---class body goes here

End Class


2) I then created a function to serialize the object. Objects can be serialized to streams such as text streams or memory streams. I just want to create a standard XML version of the object, so a memory stream works fine for me here. Once I've serialized the object to the memory stream, I then need to convert the contents of the memory stream to a string. Thus the reference to ASCIIEncoding.

The function that performs the serialization looks like this:

Protected Function SerializeMe(ByVal oObject As _Event) As String
Dim oMS As New MemoryStream
Dim oSXML As New System.Xml.Serialization.XmlSerializer(GetType(_Event))
oSXML.Serialize(oMS, oObject)

Dim oEncoding As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding
Dim sXML As String = oEncoding.GetString(oMS.GetBuffer)

Return sXML
End Function


Here's what an _event class that's been serialized using the above function looks like:


"<?xml version="1.0"?>
<_Event xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>-1</ID>
<Application>testapp</Application>
<Procedure>testproc</Procedure>
<Exception>myexception</Exception>
<Source>testsource</Source>
<CreateDate>7/14/2006 4:23:39 PM</CreateDate>
</_Event>"


3) To deserialize the XML back into the class, the string has to be converted back into a memory stream and the serializer has to be told what type of class to generate. Then just call "Deserialize" an you're done! The subroutine to unserialize the object looks like this:

Protected Sub DeserializeMe( _
ByVal sXML As String, _
ByRef oObject As _Event)

Dim oEncoding As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding
Dim oByteArray As Byte() = oEncoding.GetBytes(sXML)

Dim oMS As New MemoryStream(oByteArray)

Dim oSXML As New System.Xml.Serialization.XmlSerializer(GetType(_Event))
oObject = oSXML.Deserialize(oMS)
End Sub