VB9 and Atom

Don Box's Spoutlet

Syndication

A lot of my friends have been giving me grief over my recent attempts to show how C# is getting features from high-brow languages.
 
In an attempt to appeal to the blue collar programmer in all of us, I thought I'd cleanse the palette with a little VB9 program that demonstrates the XML support that Erik & Co. are putting into the language.
 
This program is a console app that serves up an ATOM feed containing data about the running processes of the host machine.
 
If you're running XP, be sure to either change the port # or stop IIS5, as this program uses HTTP.SYS and IIS5 doesn't (IIS6 or greater do use HTTP.sys so everyone can live the port 80 dream).
 
Enjoy
 
Imports System
Imports System.Net
Imports System.Diagnostics
 
Module Module1
 
  Sub Main()
    ' start listening on /bob/
    Dim listener = New HttpListener()
    listener.Prefixes.Add("
http://+:80/bob/")
    listener.Start()
 
    ' pump requests
    Dim done = False
    While Not done
      Dim context = listener.GetContext()
      If (context Is Nothing) Then
        done = True
      Else
        context.Response.ContentType = "application/atom+xml"
        Dim data = _
                    <feed xmlns="
http://www.w3.org/2005/Atom">
                        <title>My Processes</title>
                        <link href="
http://localhost/bob/"/>
                        <updated><%= DateTime.Now %></updated>
                        <author>
                            <name>Don Box</name>
                        </author>
                        <id>urn:uuid:<%= Guid.NewGuid() %></id>
 
                        <%= From proc In Process.GetProcesses() _
                            Where proc.WorkingSet64 > 10000 _
                            Select _
                                <entry xmlns="
http://www.w3.org/2005/Atom">
                                    <title><%= proc.ProcessName %></title>
                                    <id>urn:uuid:<%= Guid.NewGuid() %></id>
                                    <updated><%= DateTime.Now %></updated>
                                    <summary><%= String.Format("{0} MB, {1} threads", proc.WorkingSet64 / 1024 / 1024, proc.Threads.Count) %></summary>
                                </entry> _
                        %>
                    </feed>
 
          Dim writer = XmlWriter.Create(context.Response.OutputStream)
          Data.WriteTo(writer)
          writer.Close()
          context.Response.Close()
        End If
      End While
    End Sub
End Module

Posted May 18 2006, 04:27 AM by don-box

Comments

Graham wrote re: VB9 and Atom
on 05-18-2006 5:32 AM
Your code is bloody awful:

http://www.intertwingly.net/blog/2006/05/18/VB9-and-Atom
Erwyn van der Meer wrote Don Box does VB9 too
on 05-18-2006 5:36 AM
Don Box coded up a nice little VB 9.0 program that serves up an ATOM feed containing data about the running...
Scott Rudy wrote re: VB9 and Atom
on 05-18-2006 7:37 AM
I can't wait to see VB10 and XML.Net when folks can seperate content from code using a code behind page ;o) I feel icky just looking at this code.
Don Box wrote re: VB9 and Atom
on 05-18-2006 9:24 AM
Sam: I'll update the ATOM to be kosher per your blog entry.

My bad - I cut and pasted from the spec (a variation on design by "View Source") - I'd fix it in real time but the VB syntax is making .TEXT's editor go nuts.

Scott: Having literals for structured data in code is a controversial feature. Sorry you don't like it - I'm guessing a lot of the Java folks will have a problem with this style of programming.
Judah wrote re: VB9 and Atom
on 05-18-2006 5:33 PM
So we have inline XML documents combined with Visual Basic. Methinks this is a recipe for some crazy ugly code! :-p

Glad I'm a C# guy myself. :c)
Ex-Reader wrote re: VB9 and Atom
on 05-26-2006 7:35 PM
You are an arrogant fool!
Visual Studio Blog wrote For all of you VB fans out there: Don Box does VB9
on 05-29-2006 3:33 AM
Technorati Profile
Well it caught my eye that Don Box is doing LINQ and VB9&nbsp;
That will give VBers...
Maurice wrote re: VB9 and Atom
on 05-29-2006 5:53 AM
Nice, been talking to Erik Meyer?
Doug Holton wrote re: VB9 and Atom
on 06-01-2006 6:42 PM
I agree, this looks very ugly. The main problem I have is the use of underscores all over the place, right int the middle of the XML even!

Barrett Shiff wrote re: VB9 and Atom
on 06-11-2006 1:36 AM
Hey Don:

It is nice to see that you quit moving all your comment to the left margin.

I suffered through the COM and DCOM courses where you had all the comments on the left.

I had to reformat a program before I could read it.

Yes, I'm dyslexic and far sighted.

LOL,

Barrett
dbox wrote VB9和Atom
on 12-03-2006 7:52 PM
??????????????,?????????VB9????????,??Erik

Add a Comment

(required)  
(optional)
(required)  
Remember Me?