2009-02-12 55 views
2

從Windows命令行我希望能夠發佈到RSS提要。我想象這樣的事情:從命令行發佈到RSS

rsspub @builds "Build completed without errors." 

然後,有人可以去我的電腦:

http://xp64-Matt:9090/builds/rss.xml

還有會是日期和時間以及簡單的文本的新條目「構建完成沒有錯誤。」

我希望飼料本身可以在不同的端口上運行,所以我不會與IIS或Apache戰鬥,或者我需要在計算機上每天運行其他任何操作。

這樣的事情是否存在?

回答

3

這裏有一個簡單的.NET 3.5的C#程序,將創建一個可以在你的IIS Web根目錄存放的RSS XML文件:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml; 
using System.IO; 

namespace CommandLineRSS 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      var file = args[ 0 ]; 
      var newEntry = args[ 1 ]; 

      var xml = new XmlDocument(); 

      if (File.Exists(file)) 
       xml.Load(file); 
      else 
       xml.LoadXml(@"<rss version='2.0'><channel /></rss>"); 

      var xmlNewEntry = Create((XmlElement)xml.SelectSingleNode("/rss/channel"), "item"); 
      Create(xmlNewEntry, "title").InnerText = newEntry; 
      Create(xmlNewEntry, "pubDate").InnerText = DateTime.Now.ToString("R"); 

      xml.Save(file); 
     } 

     private static XmlElement Create(XmlElement parent, string tag) 
     { 
      var a = parent.OwnerDocument.CreateElement(tag); 
      parent.AppendChild(a); 
      return a; 
     } 
    } 
} 

然後,你可以這樣調用:

CommandLineRSS.exe c:\inetpub\wwwroot\builds.xml "Build completed with errors."