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