/// <summary> /// Cancels the download request. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege>http://tizen.org/privilege/download</privilege> /// <remarks> /// The canceled download can be restarted with Start(). /// </remarks> /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception> public void Cancel() { int ret = Interop.Download.CancelDownload(_downloadId); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Failed to cancel download request"); } }
private void UnregisterProgressChangedEvent() { int ret = Interop.Download.UnsetProgressCallback(_downloadId); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Unsetting ProgressChanged callback failed"); } }
/// <summary> /// Pauses the download request. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege>http://tizen.org/privilege/download</privilege> /// <remarks> /// The paused download request can be restarted with Start() or canceled with Cancel(). /// </remarks> /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception> public void Pause() { int ret = Interop.Download.PauseDownload(_downloadId); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Failed to pause download request"); } }
/// <summary> /// Sets the directory path of a temporary file used in a previous download request. /// This is only useful when resuming download to make the HTTP request header at the client side. Otherwise, the path is ignored. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege>http://tizen.org/privilege/download</privilege> /// <remarks> /// If the ETag value is not present in the download database, it is not useful to set the temporary file path. /// When resuming the download request, the data is attached at the end of this temporary file. /// </remarks> /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception> public void SetTemporaryFilePath(string path) { int ret = Interop.Download.SetTempFilePath(_downloadId, path); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Failed to set TemporaryFilePath"); } }
private void RegisterProgressChangedEvent() { _downloadProgressChangedCallback = (int downloadId, ulong size, IntPtr userData) => { ProgressChangedEventArgs eventArgs = new ProgressChangedEventArgs(size); _downloadProgressChanged?.Invoke(this, eventArgs); }; int ret = Interop.Download.SetProgressCallback(_downloadId, _downloadProgressChangedCallback, IntPtr.Zero); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Setting ProgressChanged callback failed"); } }
private void RegisterStateChangedEvent() { _downloadStateChangedCallback = (int downloadId, int downloadState, IntPtr userData) => { StateChangedEventArgs eventArgs = new StateChangedEventArgs((DownloadState)downloadState); _downloadStateChanged?.Invoke(this, eventArgs); }; int ret = Interop.Download.SetStateChangedCallback(_downloadId, _downloadStateChangedCallback, IntPtr.Zero); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Setting StateChanged callback failed"); } }
/// <summary> /// Starts or resumes the download. /// Starts to download the current URL, or resumes the download if paused. /// </summary> /// <since_tizen> 3 </since_tizen> /// <privilege>http://tizen.org/privilege/download</privilege> /// <remarks> /// The URL is the mandatory information to start the download. /// </remarks> /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception> public void Start() { int ret; foreach (KeyValuePair <string, string> entry in _httpHeaders) { ret = Interop.Download.AddHttpHeaderField(_downloadId, entry.Key, entry.Value); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Failed to set HttpHeaders"); } } ret = Interop.Download.StartDownload(_downloadId); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Failed to start download request"); } }
/// <summary> /// Creates a Request object. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="url">The URL to download.</param> /// <privilege>http://tizen.org/privilege/download</privilege> /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception> public Request(string url) { if (String.IsNullOrEmpty(url)) { DownloadErrorFactory.ThrowException((int)DownloadError.InvalidParameter, "url cannot be null or empty"); } int ret = Interop.Download.CreateRequest(out _downloadId); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Request creation failed"); } ret = Interop.Download.SetUrl(_downloadId, url); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Setting Url failed"); } _notificationProperties = new Notification(_downloadId); _httpHeaders = new Dictionary <string, string>(); }
/// <summary> /// Creates a Request object. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="url">The URL to download</param> /// <param name="destinationPath">The directory path where downloaded file is stored.</param> /// <param name="fileName">The name of the downloaded file.</param> /// <param name="type">The network type which the download request must adhere to.</param> /// <privilege>http://tizen.org/privilege/download</privilege> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <feature>http://tizen.org/feature/network.wifi.direct</feature> /// <feature>http://tizen.org/feature/network.telephony</feature> /// <exception cref="ArgumentException">Thrown when it is failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when it is failed due to an invalid operation.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when a permission is denied.</exception> /// <exception cref="NotSupportedException">Thrown when a feature is not supported.</exception> public Request(string url, string destinationPath, string fileName, NetworkType type) { if (String.IsNullOrEmpty(url)) { DownloadErrorFactory.ThrowException((int)DownloadError.InvalidParameter, "url cannot be null or empty"); } int ret = Interop.Download.CreateRequest(out _downloadId); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Request creation failed"); } ret = Interop.Download.SetUrl(_downloadId, url); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Setting Url failed"); } ret = Interop.Download.SetDestination(_downloadId, destinationPath); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Setting DestinationPath failed"); } ret = Interop.Download.SetFileName(_downloadId, fileName); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Setting FileName failed"); } ret = Interop.Download.SetNetworkType(_downloadId, (int)type); if (ret != (int)DownloadError.None) { DownloadErrorFactory.ThrowException(ret, "Setting NetworkType failed"); } _notificationProperties = new Notification(_downloadId); _httpHeaders = new Dictionary <string, string>(); }