Added support for downloading input files directly from the web.
This commit is contained in:
parent
20dbff2b88
commit
2ab2af9e95
1 changed files with 20 additions and 1 deletions
|
@ -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<XElement> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue