Show / Hide Table of Contents

Class DownloadFile

Downloads a file from a specific internet address to a stream.

Inheritance
Object
TaskBase
DownloadFile
Implements
ITask
Inherited Members
TaskBase.CancellationToken
TaskBase.CredentialProvider
TaskBase.Run(CancellationToken, ICredentialProvider, IProgress<TaskSnapshot>)
TaskBase.Tag
TaskBase.CanCancel
TaskBase.PreventIdle
TaskBase.State
TaskBase.UnitsProcessed
TaskBase.UnitsTotal
Namespace: NanoByte.Common.Net
Assembly: NanoByte.Common.dll
Syntax
public class DownloadFile : TaskBase, ITask

Constructors

DownloadFile(Uri, Action<Stream>, Int64)

Creates a new download task.

Declaration
public DownloadFile(Uri source, Action<Stream> callback, long bytesTotal = -1L)
Parameters
Type Name Description
Uri source

The URL the file is to be downloaded from.

Action<Stream> callback

Called with a stream providing the download content.

Int64 bytesTotal

The number of bytes the file to be downloaded is long. The file will be rejected if it does not have this length. -1 if the size is unknown.

DownloadFile(Uri, String, Int64)

Creates a new download task.

Declaration
public DownloadFile(Uri source, string target, long bytesTotal = -1L)
Parameters
Type Name Description
Uri source

The URL the file is to be downloaded from.

String target

The local path to save the file to. A preexisting file will be overwritten.

Int64 bytesTotal

The number of bytes the file to be downloaded is long. The file will be rejected if it does not have this length. -1 if the size is unknown.

Properties

BytesMaximum

The maximum number of bytes to download.

Declaration
public long BytesMaximum { get; set; }
Property Value
Type Description
Int64

ContentStarted

Indicates whether the server has started sending content.

Declaration
public bool ContentStarted { get; }
Property Value
Type Description
Boolean

Name

A name describing the task in human-readable form.

Declaration
public override string Name { get; }
Property Value
Type Description
String
Overrides
TaskBase.Name

NoCache

Set to true to add a No-Cache header to the request for any intermediate proxy servers.

Declaration
public bool NoCache { get; set; }
Property Value
Type Description
Boolean

Source

The URL the file is to be downloaded from.

Declaration
public Uri Source { get; }
Property Value
Type Description
Uri
Remarks

This value may change once Data has been reached, based on HTTP redirections.

UnitsByte

true if UnitsProcessed and UnitsTotal are measured in bytes; false if they are measured in generic units.

Declaration
protected override bool UnitsByte { get; }
Property Value
Type Description
Boolean
Overrides
TaskBase.UnitsByte

Methods

Execute()

The actual code to be executed.

Declaration
protected override void Execute()
Overrides
TaskBase.Execute()
Remarks

State is automatically set to Started before calling this method, to Complete after a successful exit and to an appropriate error state in case on an exception. You can set additional TaskStates during execution.

Exceptions
Type Condition
OperationCanceledException

The operation was canceled.

IOException

The task ended with IOError.

WebException

The task ended with WebError.

Implements

ITask

Extension Methods

UpdateUtils.To<TIn, TOut>(TIn, Func<TIn, TOut>)
JsonStorage.SaveJson<T>(T, Stream)
JsonStorage.SaveJson<T>(T, String)
JsonStorage.ToJsonString<T>(T)
JsonStorage.ReparseAsJson<T>(Object)
JsonStorage.ReparseAsJson<T>(Object, T)
XmlStorage.SaveXml(Object, Stream, String)
XmlStorage.SaveXml<T>(T, String, String)
XmlStorage.ToXmlString(Object, String)
ConversionUtils.ConvertToString<TType>(TType)
In This Article
Back to top Copyright Bastian Eicher