VB9和Atom

原文: VB9 and Atom


VB9和Atom

我最近在试图说明C#所具有的高素养语言特点时,我的一大帮朋友都给我发来悲哀的信息。

为了吸引我们中所有的软件蓝领,我想我应该用一小段VB9程序来清洗调色板,演示Erik & Co. 放在语言中对Xml的支持功能。

这个程序是一个Console,提供一个Atom服务,这个服务包含了有关运行主机进程的数据。

如果你运行的是Xp,那么一定要改变端口号或者停止IIS5,因为这个程序要使用HTTP.SYS而IIS5却不(IIS6或更高版本使用HTTP.SYS,因此每个人都可以打80端口的注意。)

欣赏这段代码吧!

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



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1428842


你可能感兴趣的:(vb)