Class DownloadManager
- Namespace
- CapCognition.Maui.Core.Shared
- Assembly
- CapCognition.Maui.Core.dll
Use this class to download files from the internet and store them in a local cache directory.
public class DownloadManager
- Inheritance
-
DownloadManager
- Inherited Members
Constructors
DownloadManager(string)
Creates a new instance of the DownloadManager.
public DownloadManager(string cacheDirectoryName)
Parameters
cacheDirectoryNamestringThe subdirectory name to use to store the downloaded files
Fields
CacheDirectoryName
Returns the name of the cache subdirectory.
public readonly string CacheDirectoryName
Field Value
Properties
Files
Returns all files that are managed by the DownloadManager.
public DownloadManagerFile[] Files { get; }
Property Value
MaximumFileSizeInBytes
Optional maximum size for a single downloaded or copied file. Null disables the size limit.
public long? MaximumFileSizeInBytes { get; set; }
Property Value
- long?
Methods
AddFile(DownloadManagerFile)
Adds a file to the download manager.
public void AddFile(DownloadManagerFile file)
Parameters
fileDownloadManagerFile
AddFile(Stream, string, Func<string>?)
Adds a file from a stream
public void AddFile(Stream stream, string filename, Func<string>? decryptionPWFunc = null)
Parameters
streamStreamthe file to save locally
filenamestringdecryptionPWFuncFunc<string>A function to return the password to decrypt the downloaded file, If null no decryption is used
AddFile(Stream, string, Func<string>?, string?)
Adds and validates a file from a stream.
public void AddFile(Stream stream, string filename, Func<string>? decryptionPWFunc, string? hash)
Parameters
streamStreamThe file to save locally.
filenamestringThe local file name.
decryptionPWFuncFunc<string>A function returning the decryption password, or null for an unencrypted stream.
hashstringSHA-256 hash of the source stream.
AddFile(string, string?, Func<string>?)
Adds a file to the download manager.
public void AddFile(string uri, string? hash = null, Func<string>? decryptionPWFunc = null)
Parameters
uristringUrl of the file to download
hashstringSHA-256 hash of the downloaded source file (the encrypted file when decryption is enabled). If null, no hash validation is used.
decryptionPWFuncFunc<string>A function to return the password to decrypt the downloaded file, If null no decryption is used
AllFilesDownloaded()
Checks if all files are downloaded and valid.
public bool AllFilesDownloaded()
Returns
ClearAll(bool)
Clears all files from the download manager.
public void ClearAll(bool deleteFromFileSystem = false)
Parameters
deleteFromFileSystemboolIf true, the file is deleted as well from the cache
DeleteAllFilesExcept(string, List<string>)
Delete all files in the cache directory that match the deletePattern.
public void DeleteAllFilesExcept(string deletePattern, List<string> exceptFiles)
Parameters
DownloadAllFiles()
Downloads all files.
public bool DownloadAllFiles()
Returns
DownloadAllFilesAsync(CancellationToken)
Downloads all files asynchronously.
public Task<bool> DownloadAllFilesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
RemoveFile(DownloadManagerFile, bool)
Removes a file from the download manager.
public void RemoveFile(DownloadManagerFile file, bool deleteFromFileSystem = false)
Parameters
fileDownloadManagerFileThe file to be removed
deleteFromFileSystemboolIf true, the file is deleted as well from the cache
Events
DownloadProgressEvt
Raised during the download of a file to report the progress.
public event DownloadManager.ProgressDelegate? DownloadProgressEvt