VB9和Atom

来源:互联网 发布:php html if else 编辑:程序博客网 时间:2024/05/22 06:31

原文: 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 = _
                   
                        My Processes
                       
                        <%= DateTime.Now %>
                       
                            Don Box
                       
                        urn:uuid:<%= Guid.NewGuid() %>
 
                        <%= From proc In Process.GetProcesses() _
                            Where proc.WorkingSet64 > 10000 _
                            Select _
                               
                                    <%= proc.ProcessName %>
                                    urn:uuid:<%= Guid.NewGuid() %>
                                    <%= DateTime.Now %>
                                   

<%= String.Format("{0} MB, {1} threads", proc.WorkingSet64 / 1024 / 1024, proc.Threads.Count) %>
                                _
                        %>
                   
 
          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