コード例 #1
0
 /// <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;
 }
コード例 #2
0
        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));
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
 public FileRequestAsyncState(string filepath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback, WebRequestAsyncCallback webRequestCallback)
     : base(webRequestCallback, progressCallback)
 {
     _filePath = filepath;
     _downloadFileCompleted = callback;
 }
コード例 #5
0
 public WebRequestAsyncState(WebRequestAsyncCallback callback, DownloadProgressChangedCallback progressCallback)
 {
     _callback = callback;
     _progressCallback = progressCallback;
 }
コード例 #6
0
ファイル: WebRequestAsyncState.cs プロジェクト: Almamu/evemon
 public WebRequestAsyncState(WebRequestAsyncCallback callback, DownloadProgressChangedCallback progressCallback)
 {
     _callback         = callback;
     _progressCallback = progressCallback;
 }
コード例 #7
0
 public FileRequestAsyncState(string filepath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback, WebRequestAsyncCallback webRequestCallback)
     : base(webRequestCallback, progressCallback)
 {
     _filePath = filepath;
     _downloadFileCompleted = callback;
 }