mirror of
https://github.com/winsw/winsw.git
synced 2025-12-10 18:37:28 +08:00
Introduce the Download#FailOnError option. (#195)
* Introduce the Download#FailOnError option. The change also adds logging of download operations to the wrapper log * Add documentation for the failOnError flag
This commit is contained in:
26
src/Core/WinSWCore/Download.cs
Normal file → Executable file
26
src/Core/WinSWCore/Download.cs
Normal file → Executable file
@@ -20,11 +20,22 @@ namespace winsw
|
||||
public readonly string Username;
|
||||
public readonly string Password;
|
||||
public readonly bool UnsecureAuth = false;
|
||||
public readonly bool FailOnError;
|
||||
|
||||
public Download(string from, string to, bool failOnError = false)
|
||||
{
|
||||
From = from;
|
||||
To = to;
|
||||
FailOnError = failOnError;
|
||||
}
|
||||
|
||||
internal Download(XmlNode n)
|
||||
{
|
||||
From = Environment.ExpandEnvironmentVariables(n.Attributes["from"].Value);
|
||||
To = Environment.ExpandEnvironmentVariables(n.Attributes["to"].Value);
|
||||
|
||||
var failOnErrorNode = n.Attributes["failOnError"];
|
||||
FailOnError = failOnErrorNode != null ? Boolean.Parse(failOnErrorNode.Value) : false;
|
||||
|
||||
string tmpStr = "";
|
||||
try
|
||||
@@ -80,6 +91,12 @@ namespace winsw
|
||||
request.Headers["Authorization"] = "Basic " + authInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads the requested file and puts it to the specified target.
|
||||
/// </summary>
|
||||
/// <exception cref="System.Net.WebException">
|
||||
/// Download failure. FailOnError flag should be processed outside.
|
||||
/// </exception>
|
||||
public void Perform()
|
||||
{
|
||||
WebRequest req = WebRequest.Create(From);
|
||||
@@ -106,6 +123,15 @@ namespace winsw
|
||||
File.Move(To + ".tmp", To);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces the XML configuuration entry.
|
||||
/// </summary>
|
||||
/// <returns>XML String for the configuration file</returns>
|
||||
public String toXMLConfig()
|
||||
{
|
||||
return "<download from=\"" + From + "\" to=\"" + To + "\" failOnError=\"" + FailOnError + "\"/>";
|
||||
}
|
||||
|
||||
private static void CopyStream(Stream i, Stream o)
|
||||
{
|
||||
byte[] buf = new byte[8192];
|
||||
|
||||
Reference in New Issue
Block a user