コード例 #1
0
 /// <summary>
 /// Standard download for a file, note proxy download will be slow and appear unresponsive for a while
 /// </summary>
 /// <param name="url">The url to download from</param>
 /// <param name="name">File name to save to plus extension</param>
 /// <param name="proxyAddress">A string url to a Glype proxy</param>
 public async void StandardDownload(string url, string name, string proxyAddress)
 {
     cAWebClient = new CookieAwareWebClient();
     cAWebClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
     cAWebClient.DownloadFileCompleted   += WebClient_AsyncCompletedEventHandler;
     if (proxyAddress != "")//If they suplied a proxy
     {
         //Add standard post headers
         cAWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
         //Referer since it might not like requests from elsewhere
         cAWebClient.Headers.Add("referer", proxyAddress);
         try
         {
             //Make a blank request to example.com for cookies
             await cAWebClient.UploadStringTaskAsync(proxyAddress + "/includes/process.php?action=update", "POST", "u=" + "example.com" + "&allowCookies=on");
         }
         catch (Exception e)
         {
             Console.WriteLine(e.StackTrace);
             ButtonRetry.Visibility        = Visibility.Visible;
             taskBarDownload.ProgressState = TaskbarItemProgressState.Error;
             dwBinding.DownloadProgress    = "Download failed, could not find glype proxy";
             return;
         }
         //Download the file
         cAWebClient.DownloadFileAsync(new Uri(proxyAddress + "/browse.php?u=" + url + "&b=12&f=norefer"), name);
     }
     else // no proxy, download normally
     {
         cAWebClient.DownloadFileAsync(new Uri(url), name);
     }
 }
コード例 #2
0
 void DownloadFileInternal()
 {
     if (!asyncDownload)
     {
         webClient.DownloadFile(downloadAddress, downloadPath);
         DownloadFileCompletedCallback(webClient, new AsyncCompletedEventArgs(null, false, null));
     }
     else if (userToken == null)
     {
         webClient.DownloadFileAsync(downloadAddress, downloadPath);
     }
     else
     {
         webClient.DownloadFileAsync(downloadAddress, downloadPath, userToken);
     }
 }
コード例 #3
0
 public override void Download()
 {
     using (_downloader = new CookieAwareWebClient())
     {
         AddHandlers();
         _downloader.DownloadFileAsync(new Uri(_URI, UriKind.Absolute), _DestinationFile);
     }
 }
コード例 #4
0
 public override void Download()
 {
     using (_downloader = new CookieAwareWebClient())
     {
         AddHandlers();
         _downloader.DownloadFileAsync(new Uri(_URI, UriKind.Absolute ), _DestinationFile);
     }
 }
コード例 #5
0
    private void DownloadFileInternal()
    {
        if (!asyncDownload)
        {
            webClient.DownloadFile(downloadAddress, downloadPath);

            // This callback isn't triggered for synchronous downloads, manually trigger it
            DownloadFileCompletedCallback(webClient, new AsyncCompletedEventArgs(null, false, null));
        }
        else if (userToken == null)
        {
            webClient.DownloadFileAsync(downloadAddress, downloadPath);
        }
        else
        {
            webClient.DownloadFileAsync(downloadAddress, downloadPath, userToken);
        }
    }
コード例 #6
0
        /// <summary>
        /// Downloads the specified mp4 url via a HTTP proxy
        /// </summary>
        /// <param name="url">The url to download</param>
        /// <param name="name">The filename to save as an (no extension, mp4 added)</param>
        /// <param name="httpProxy">The HTTP proxy</param>
        public void HTTPProxyDownload(string url, string name, string httpProxy)
        {
            WebProxy wp = new WebProxy(httpProxy);

            cAWebClient       = new CookieAwareWebClient();
            cAWebClient.Proxy = wp;
            cAWebClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
            cAWebClient.DownloadFileCompleted   += WebClient_AsyncCompletedEventHandler;
            cAWebClient.DownloadFileAsync(new Uri(url), name + ".mp4");
        }
コード例 #7
0
ファイル: SaveFileEX.cs プロジェクト: shoff/Hawk
        public override IEnumerable <IFreeDocument> Execute(IEnumerable <IFreeDocument> documents)
        {
            foreach (var document in documents)
            {
                var path          = document.Query(SavePath);
                var directoryInfo = new DirectoryInfo(path);
                var folder        = directoryInfo.Parent;
                if (folder == null)
                {
                    continue;
                }
                if (!folder.Exists)
                {
                    folder.Create();
                }
                var url = document[Column].ToString();
                if (string.IsNullOrEmpty(url))
                {
                    continue;
                }
                try
                {
                    CookieAwareWebClient webClient = new CookieAwareWebClient();
                    if (!IsAsync)
                    {
                        webClient.DownloadFile(url, path);
                    }
                    else
                    {
                        webClient.DownloadFileAsync(new Uri(url), path);
                    }
                    //HttpStatusCode code;
                    //var bytes = helper.GetFile(crawler.Http, out code, url);
                    //if (bytes != null)
                    //    File.WriteAllBytes(path, bytes);
                }
                catch (Exception ex)
                {
                    XLogSys.Print.Error(ex);
                }

                yield return(document);
            }
        }
コード例 #8
0
ファイル: SaveFileEX.cs プロジェクト: CHERRISHGRY/Hawk
        public override IEnumerable<IFreeDocument> Execute(IEnumerable<IFreeDocument> documents)
        {
            foreach (var document in documents)
            {
                var path = document.Query(SavePath);
                var directoryInfo = new DirectoryInfo(path);
                var folder = directoryInfo.Parent;
                if (folder == null)
                    continue;
                if (!folder.Exists)
                {
                    folder.Create();
                }
                var url = document[Column].ToString();
                if (string.IsNullOrEmpty(url))
                    continue;
                try
                {
                    CookieAwareWebClient webClient = new CookieAwareWebClient();
                    if (!IsAsync)
                    {

                        webClient.DownloadFile(url,path);
                    }
                    else
                    {
                        webClient.DownloadFileAsync(new Uri( url), path);
                    }
                    //HttpStatusCode code;
                    //var bytes = helper.GetFile(crawler.Http, out code, url);
                    //if (bytes != null)
                    //    File.WriteAllBytes(path, bytes);
                }
                catch (Exception ex)
                {
                    XLogSys.Print.Error(ex);
                }

                yield return document;
            }
        }
コード例 #9
0
ファイル: SaveFileEX.cs プロジェクト: zxm679/Hawk
        public override IEnumerable <IFreeDocument> Execute(IEnumerable <IFreeDocument> documents)
        {
            foreach (var document in documents)
            {
                var path          = document.Query(SavePath);
                var directoryInfo = new DirectoryInfo(path);
                var isdir         = IsDir(path);
                var url           = document[Column]?.ToString();
                if (string.IsNullOrEmpty(url))
                {
                    yield return(document);

                    continue;
                }
                DirectoryInfo folder = null;
                if (!isdir)
                {
                    folder = directoryInfo.Parent;
                }
                else
                {
                    folder = directoryInfo;
                }

                if (folder == null)
                {
                    yield return(document);

                    continue;
                }
                if (!folder.Exists)
                {
                    folder.Create();
                }
                if (isdir)
                {
                    path = folder.ToString();
                    if (path.EndsWith("/") == false)
                    {
                        path += "/";
                    }
                    path += url;
                    path  = getFileName(path);
                    //path += getFileName(url);
                }
                if (File.Exists(path))
                {
                    yield return(document);

                    continue;
                }


                try
                {
                    var webClient = new CookieAwareWebClient();
                    if (!IsAsync)
                    {
                        webClient.DownloadFile(url, path);
                    }
                    else
                    {
                        webClient.DownloadFileAsync(new Uri(url), path);
                    }
                    //HttpStatusCode code;
                    //var bytes = helper.GetFile(crawler.Http, out code, url);
                    //if (bytes != null)
                    //    File.WriteAllBytes(path, bytes);
                }
                catch (Exception ex)
                {
                    XLogSys.Print.Error(ex);
                }

                yield return(document);
            }
        }