/// <summary> /// Asynchronously downloads file from the specified url to the specified path /// </summary> /// <param name="url"></param> /// <param name="filePath"></param> /// <param name="callback">A <see cref="DownloadImageCompletedCallback"/> to be invoked when the request is completed</param> /// <param name="progressCallback"></param> /// <returns></returns> public object DownloadFileAsync(string url, string filePath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback) { string urlValidationError; if (!IsValidURL(url, out urlValidationError)) throw new ArgumentException(urlValidationError); FileRequestAsyncState state = new FileRequestAsyncState(filePath, callback, progressCallback, DownloadFileAsyncCompleted); HttpWebServiceRequest request = GetRequest(); request.GetResponseAsync(url, new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None), IMAGE_ACCEPT, null, state); return request; }
public static DownloadSession BeginDownload(this PSCmdlet cmdlet, ISearchResult searchResult) { UpdateSession session = new UpdateSession(); UpdateDownloader downloader = session.CreateDownloader(); downloader.Updates = searchResult.Updates; downloader.Priority = DownloadPriority.dpExtraHigh; ProgressAdapter adapter = new ProgressAdapter(cmdlet, downloader); DownloadProgressChangedCallback progressCallback = new DownloadProgressChangedCallback(adapter); DownloadCompletedCallback completedCallback = new DownloadCompletedCallback(downloader); object state = new object(); downloader.BeginDownload(progressCallback, completedCallback, state); return(DownloadSession.From(completedCallback)); }
/// <summary> /// Asynchronously downloads file from the specified url to the specified path /// </summary> /// <param name="url"></param> /// <param name="filePath"></param> /// <param name="callback">A <see cref="DownloadImageCompletedCallback"/> to be invoked when the request is completed</param> /// <param name="progressCallback"></param> /// <returns></returns> public object DownloadFileAsync(string url, string filePath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback) { string urlValidationError; if (!IsValidURL(url, out urlValidationError)) { throw new ArgumentException(urlValidationError); } FileRequestAsyncState state = new FileRequestAsyncState(filePath, callback, progressCallback, DownloadFileAsyncCompleted); HttpWebServiceRequest request = GetRequest(); request.GetResponseAsync(url, new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None), IMAGE_ACCEPT, null, state); return(request); }
public FileRequestAsyncState(string filepath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback, WebRequestAsyncCallback webRequestCallback) : base(webRequestCallback, progressCallback) { _filePath = filepath; _downloadFileCompleted = callback; }
public WebRequestAsyncState(WebRequestAsyncCallback callback, DownloadProgressChangedCallback progressCallback) { _callback = callback; _progressCallback = progressCallback; }