Semantic Web and Legacy Web

There is much ado about the coming Semantic Web and the dream of objectifying all the data in the world allowing machines to exchange mindshare, yada, yada, yada. But what happens to old web pages when they die? Do they go to HTTP heaven? And when this glorious web for machines supplants the Legacy Web (that messy old WWW), what will we all do with our fancy browsers? Where will we find the fuel to power our AJAX rocket engines? And how will humans survive the rising tide of <tag><mytag>
drive by taggings?

The truth is that while the semantic web will find some heavy hitters to knock it out of the park in a variety of industrial and scientific arenas, I'm not sure the messy old WWW is ready for retirement just yet. I doubt the content switch will occur very rapidly in most corners of the world given that most users of the web currently are human and they use the mundane web browser occasionally flicking the AJAX booster switch and dreaming of the connected client days of yore.

We humans like messes. Just look around your office if you don't believe me. Four out of five dentists recommend a messy desk for a healthy work life. And if you don't believe me, Google it.

Still, the semantic web bears some level of intrigue beyond its obvious usefulness in some areas of business and science. In fact, I'd love to have a browser that would help me make more sense of the mess on the WWW or even the mess on my desk.

My New Year's resolution is to explore that idea and determine whether or not it can be done in the messy old WWW world without holding a gun to the head of all those gumbah's with an HTML six shooter in their belt.

Simple XML to DTO and Back Again

Data transfer objects, especially in this disconnected world we live in, have become quite popular and highly useful. Here's one way I've found to create XML file based DTOs with quick and easy loading and saving from and back to the original XML format. All you need is a schema and a little gem from thinktecture.

A couple of months ago I began working on a project that would require reading and modifying a number of XML based configuration files. I had previously used thinktecture's Web Services Contract First (WSCF) plugin for Visual Studio created by Christian Weyer and Buddhike de Silva to create contract-first web services. At the time I had discovered how convenient it was to use the web service client code generation to generate simple DTO object code as well, but it had to be done in a clever way to allow me to throw away the web service code and just use the DTO object code.

A quick visit to thinktecture's web site and I found that version 0.7 had just been released on October 25, 2006. And to my delight, the major new feature in version 0.7 was the ability to generate data transfer object or data contract code from the UI plugin for Visual Studio 2005. Just install WSCF version 0.7 and then in Visual Studio 2005 create a schema file like the one below. Then right click the XSD file in the solution explorer and select "Generate Data Contract Code" from the menu. A simple dialog like this one pops up.

This will produce a partial class and give you everything you need except a Load and Save method to store the DTO in XML format. It was a simple matter to add the following partial class and the static support class called Serializer as shown below. If you need something like this, I hope this helps.

partial class:

    public partial class Parser
        private static string targetNamespace = "http://mynamespace/v1/parser.xsd";
        public static Parser Load(string fileName)
            if (fileName == null) return null;
            return (Parser)Serializer.Load(fileName, typeof(MyNamespace.Parser), Parser.targetNamespace);
        public void Save(string fileName)
            Serializer.Save(fileName, this, this.GetType(), Parser.targetNamespace);

Serializer class:

    public static class Serializer
        private static XmlSerializerNamespaces GetNamespaces(string targetNamespace)
            XmlSerializerNamespaces ns;
            ns = new XmlSerializerNamespaces();
            ns.Add("", targetNamespace);
            ns.Add("xs", "");
            return ns;

        public static object Load(string fileName, System.Type objType, string targetNamespace)
            string xml = File.ReadAllText(fileName);
            object obj = Serializer.FromXml(xml, objType, targetNamespace);
            return obj;

        public static void Save(string fileName, object obj, System.Type objType, string targetNamespace)
            string xml = Serializer.ToXml(obj, objType, targetNamespace);
            File.WriteAllText(fileName, xml);

        public static string ToXml(object obj, System.Type objType, string targetNamespace)
            XmlSerializer ser;
            ser = new XmlSerializer(objType, targetNamespace);
            MemoryStream memStream;
            memStream = new MemoryStream();
            XmlTextWriter xmlWriter;
            xmlWriter = new XmlTextWriter(memStream, Encoding.UTF8);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.Indentation = 1;
            xmlWriter.IndentChar = '\t';
            xmlWriter.Namespaces = true;
            ser.Serialize(xmlWriter, obj, Serializer.GetNamespaces(targetNamespace));
            string xml;
            xml = Encoding.UTF8.GetString(memStream.GetBuffer());
            xml = xml.Substring(xml.IndexOf('<'));
            xml = xml.Substring(0, (xml.LastIndexOf('>') + 1));
            return xml;

        public static object FromXml(string xml, System.Type objType, string targetNamespace)
            XmlSerializer ser;
            ser = new XmlSerializer(objType, targetNamespace);
            StringReader stringReader;
            stringReader = new StringReader(xml);
            XmlTextReader xmlReader;
            xmlReader = new XmlTextReader(stringReader);
            object obj;
            obj = ser.Deserialize(xmlReader);
            return obj;

example schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="parser"
    <xs:element name="Parser">
                <xs:element ref="ColumnWidths" minOccurs="0" maxOccurs="1" />
                <xs:element name="ExpectedColumnCount" type="xs:int" />
                <xs:element name="MaxBufferSize" type="xs:int" />
                <xs:element name="MaxRows" type="xs:int" />
                <xs:element name="SkipDataRows" type="xs:int" />
                <xs:element name="FirstRowHasHeader" type="xs:boolean" />
                <xs:element name="TrimResults" type="xs:boolean" />
                <xs:element name="IncludeFileLineNumber" type="xs:boolean" />
                <xs:element name="FixedWidth" type="xs:boolean" />
                <xs:element name="RowDelimiter" type="xs:string" />
                <xs:element name="ColumnDelimiter" type="xs:string" />
                <xs:element name="TextQualifier" type="xs:int" />
                <xs:element name="EscapeCharacter" type="xs:int" />
                <xs:element name="CommentCharacter" type="xs:int" />
    <xs:element name="ColumnWidths">
                <xs:element name="ColumnWidth" minOccurs="0" maxOccurs="unbounded" type="xs:int" />


Beware the Arbitration Agreement

I've been busy. Yeah. Sad excuse, but true.
On November 7, 2006, about two months after I was hired, my employer "invited" me to resign my position because I refused to sign a mandatory arbitration agreement which among other things included the following language: "I understand that by agreeing to this binding arbitration provision, both I and [company name] give up our respective rights to a trial by jury."

I told my employer that I didn't think I should have to waive my constitutional right to petition the government for redress just because so many others abuse that right. I had researched the issue on the Internet and found that these agreements are enforced by the courts and that in about 99% of all cases, the employee loses, regardless of the issues and facts.

I was annoyed. More at the law than at my employer. I know the law stands behind employers on this issue. And I even support the idea of arbitration as a first option, but I cannot abide the idea of just waiving my right to go to court just to keep a job. I don't think the law should allow an employer to require such a concession upon employees, but it does. Specifically, as long as both parties give up the same rights, the contract is enforceable.

This would be just fine except for the fact that in arbitration, the little guy is viewed by most arbiters (usually retired judges) as the money grubbing whiner and the employer as the victim of the evil, greedy employee. So you give up the same rights but you put yourself, as an employee, at a significant disadvantage if you run into some dispute with an employer.

All that said, I've never been sued by an employer and I've never sued an employer. Still, if I had to, I'd like to preserve the option of having a real court and a real jury hear my case rather than an arbiter who answers to no one regardless of his or her conduct and decisions in the face of the evidence. Take those odds? No thanks.

I was lucky. I found another job the same day I was "asked" to leave which happily pays even better. And I've been super busy with the new gig ever since. Not everyone has the same opportunity and flexibility that I enjoy, so I recognize this development as a true blessing.

Since that day, I've spent an hour or so contacting legislators about the issue. They are generally either indifferent or completely ignorant or in some cases both. Senator Hatch sent me a nice, completely off-base form letter reply referring me to legal counsel despite the fact that I had just asked for his opinion on whether employers should be allowed to continue this practice and whether he would support legislation to prohibit it. Many others just never responded. It's pretty sad when elected officials care so little about the way that employers are now forcing their employees to give up their constitutionally protected rights just because they are afraid of employees who abuse those rights.

It's typical fare for our culture. Punish those who have done nothing wrong in the false hope of protecting yourself from the real bad guys. Similar examples are not difficult to find. Such draconian practices are not needed. If you're going to get sued by employees, you're going to get sued. And if it happens a lot, you might want to consider changing your behavior and/or changing who and how you hire.

If you're reading this and you've signed employment documents without really reading them, you may have signed a similar document. I recommend reading every document your employer "invites" you to sign. Despite your excitement to have a new job and your high opinion of the people you'll be working for, you may be surprised at what they've asked you to agree to. There's only one way out of such an agreement. Don't sign it in the first place. I really liked the people at the former job, but regardless of my regard for them, I was not about to give up my rights in order to work for them.

Of course, everything I've said here is my own opinion. I'm sure my former employer sees it completely differently. I bear them no ill will and certainly have no plans to waste time and energy on the lawsuit that so many of my friends have recommended that I bring against them. I would just hope that they would see their actions for the paranoia I believe it to be and revise their agreements with their existing employees. I think it would be the right and moral thing to do. But that's up to them.

With that all said, I'll get back to coding and promise some real .NET coding posts here in the future.

ManagedThreadPool - Managing the Thread Pool

Where's the response?
I couldn't figure out why I was not getting an immediate response. I ran through my code several times before I realized I was missing a key test at a crucial decision making point. I was failing to check whether or not the ManagedThreadPool in my application could get to my request now or whether the request would be pooled.

ManagedThreadPool.ActiveThreads < ManagedThreadPool.MaxThreads - 2

Simple as that. A simple test in a more complex if statement. Why the - 2? Well, I needed a margin to allow for the fact that other threads would be jamming their own jobs in. So I figured a margin of 2 unused threads would give me that. We'll see how it does in the real world.

Lesson Learned
If you plan to use a thread pool, be sure to pay attention to how many babies are in the water at the moment you decide to jump in. Otherwise, you may not get what you expect when you expect, especially in a system like I have been working on where hundreds or even thousands of items might be queued up.

(Note: This is being reposted because I inadvertently allowed trackbacks and the previous post got hammered with spam trackbacks and dasBlog would log me out when I tried to go to the post to delete them. Go figure...)

The .NET Developer Search Engine - Google CoOp

Thanks to Google CoOp, is now my personal .NET developer search engine. With the help of a few friends, the list of domains searched remains relevant to .NET development. This helps eliminate all the clutter I get when hitting Google directly.

Thanks to Paul Allen for alerting me to this very cool feature. And if you use it, don't be afraid to click on the ads. :)

Refactoring Utah County Dot Net Users Group

Today I attended my first UCNUG meeting. It was great. Easy location. Perfect size crowd. Great presentation by Aaron Zupancic on refactoring.

Previous meetings have been held at UVSC, but fortunately they got kicked out of there. I'm lazy by nature and didn't want to bother with finding the room on a campus I don't know. This one was hosted gratiously by NuSkin at the East Bay location and that was easy to find.

Aaron gave a well thought out, cogent presentation on the ins and outs of refactoring. I actually learned some things. And for me, that makes any presentation valuable. But it was a good presentation as much for what Aaron did not do as what he did do. He did not just read from the book. Martin Fowler is great but the presentation was really valuable because Aaron pulled examples and ideas into slides with even better code examples.

I've attended the Utah .NET Users Group, where Aaron is the president, a few times. The presentations are generally good, including Aaron's, but this one was much better. I'm trying to convice a buddy of mine to present on CruiseControl.Net, NUnit and automated build and testing in general. I'll post it here if I can get him to commit.

IE7 So Far So Good

Installed IE7 (7.0.5730.11) over the top of the beta. Everything working well so far. Ah, but now, because of the increasing clutter on my drive, I'm running out of space and will soon be rebuilding my machine. Just another chance to install, install, install.

Point, click, wait. Repeat.

Google and Warez - Why?

It's been less than a week and my site has caught up by many RegNow affiliates, hacked by some warez hackers in the UK, Israel, and Australia, and indexed by Google. The question I have is why does Google continue to index warez sites whose primary purpose is to sabotage the shareware and commercial software industry.

So, Google, why? Why do you help promote these low lifes whose only goal seems to be to troll for software thieves susceptible to the enticements of porn in order to make money from the click flips to the real porn sites. Why? These sites don't use AdSense, so there does not seem to be a monetary motive. What else can it be?

Does anyone have a clue?