/// <summary> /// Fires the <see cref="ProgressBegin"/> event. /// </summary> /// <param name="maxSteps">The number of maximum steps required for the current operation to complete. This argument is optional.</param> protected virtual void OnProgressBegin(int maxSteps = 1) { _progressValue = 0; if (this.ProgressBegin != null) { try { var e = new DownloadEventArgs() { ProgressMaximum = maxSteps }; if (_syncRoot != null && _syncRoot.InvokeRequired) { _syncRoot.Invoke(this.ProgressBegin, new object[] { this, e }); } else { this.ProgressBegin(this, e); } } catch { } } }
/// <summary> /// Fires the <see cref="FileSaved"/> event. /// </summary> /// <param name="name">The name of the saved file.</param> /// <param name="url">The URL of the saved file.</param> /// <param name="data">The downloaded content that was saved into the file.</param> /// <param name="msg">The message to include. This argument is optional.</param> protected virtual void OnFileSaved(string name, string url, byte[] data, string msg = null) { if (this.FileSaved != null) { var e = new DownloadEventArgs() { Data = data, Message = msg, SavedFileName = name, Url = url, TotalBytes = _totalBytesDownloaded }; if (_syncRoot != null && _syncRoot.InvokeRequired) { _syncRoot.Invoke(this.FileSaved, new object[] { this, e }); } else { this.FileSaved(this, e); } } }
/// <summary> /// Fires the <see cref="ProgressStep"/> event. /// </summary> /// <param name="msg">The message to include in the event data. This argument is optional.</param> protected virtual void OnProgressStep(string msg = null) { if (this.ProgressStep != null) { var e = new DownloadEventArgs() { ProgressValue = ++_progressValue, Message = msg }; if (_syncRoot != null && _syncRoot.InvokeRequired) { _syncRoot.Invoke(this.ProgressStep, new object[] { this, e }); } else { this.ProgressStep(this, e); } } }
/// <summary> /// Fires the <see cref="FileSaving"/> event. /// </summary> /// <param name="name">The name of the file to save.</param> /// <param name="url">The URL of the file to save.</param> /// <param name="data">The downloaded content that should be saved.</param> /// <param name="msg">The message to include. This argument is optional.</param> /// <returns> /// 0, if the event is not cancelled; /// 1, if the event is cancelled but was handled by the user; /// -1, if the event is cancelled and was not handled by the user. /// </returns> protected virtual int OnFileSaving(string name, string url, byte[] data, string msg = null) { if (FileSaving != null) { var e = new DownloadEventArgs(false) { Data = data, Message = msg, SavedFileName = name, Url = url, TotalBytes = _totalBytesDownloaded }; if (_syncRoot != null && _syncRoot.InvokeRequired) { _syncRoot.Invoke(this.FileSaving, new object[] { this, e }); } else { this.FileSaving(this, e); } if (e.Cancel) { return((e.Handled) ? 1 : -1); } } return(0); }