From 2ab2af9e9576d9e24ac09553aa7dddc9c3dbe644 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Thu, 14 Oct 2010 20:14:27 +0000 Subject: [PATCH] Added support for downloading input files directly from the web. --- Source/Converter/Parser.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Source/Converter/Parser.cs b/Source/Converter/Parser.cs index 4e8f336a..e9346886 100644 --- a/Source/Converter/Parser.cs +++ b/Source/Converter/Parser.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.IO; +using System.Net; using System.Xml.Linq; namespace CHeaderToXML @@ -41,7 +42,25 @@ namespace CHeaderToXML public IEnumerable Parse(string path) { - return Parse(File.ReadAllLines(path)); + string[] contents = null; + if (path.StartsWith("http://") || path.StartsWith("https://")) + { + // Download from the specified url into a temporary file + using (var wb = new WebClient()) + { + string filename = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); + wb.DownloadFile(path, filename); + contents = File.ReadAllLines(filename); + File.Delete(filename); + } + } + else + { + // The file is on disk, just read it directly + contents = File.ReadAllLines(path); + } + + return Parse(contents); } } }