private void UpdateProgress(HelperDownload h) { DirectoryInfo dir = new DirectoryInfo($"{ConfigurationManager.AppSettings["FILE_PATH"]}"); FileInfo[] files = dir.GetFiles(); h(files); }
public void FileWatcher(HelperDownload h, IntenetSlow s) { try { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = ConfigurationManager.AppSettings["FILE_PATH"]; watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size; // Only watch text files. //watcher.Filter = "*.txt"; // Add event handlers. watcher.Changed += ((sender, x) => UpdateProgress(h)); watcher.Created += ((sender, x) => UpdateProgress(h)); //watcher.Deleted += OnChanged; //watcher.Renamed += OnRenamed; // Begin watching. watcher.EnableRaisingEvents = true; }catch (IOException ex) { s("Input/Output Exception"); } }
private void Btn_download_Click(object sender, EventArgs e) { string url = txt_url.Text; downloader = new MultiThreadDownloader(); HelperDownload h = this.UpdateProgress; DownloadComplete d = this.DisplayMessage; downloader.DownloadHelperDownload(url, h, d); }
private void Button1_Click(object sender, EventArgs e) { string url = txt_url.Text; download = new DownloadHelper(); HelperDownload h = this.UpdateProgress; //DownloadComplete d = this.DisplayMessage; IntenetSlow slow = this.PrintMessage; string[] urls = { "https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_1280_10MG.mp4", "https://file-examples.com/wp-content/uploads/2017/10/file_example_ODP_1MB.odp", "https://file-examples.com/wp-content/uploads/2017/02/zip_10MB.zip", "https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_1920_18MG.mp4" }; try { List <Task> threads = new List <Task>(); Task t; try { //foreach (string url1 in urls) //{ // download = new DownloadHelper(); // t = download.DownloadHelperDownloadAsync(url1, slow); //} t = download.DownloadHelperDownloadAsync(url, slow); } catch (UserDefinedException ex) { slow(ex.Message); } download.FileWatcher(h, slow); //downloader.DownloadHelperDownloadAsync(url, h, d, slow); //Task.WaitAll(threads.ToArray()); } catch (ArgumentNullException ex) { slow(ex.ToString()); } catch (WebException ex) { slow(ex.ToString()); } catch (Exception ex) { slow(ex.ToString()); } }
public void DownloadHelperDownload(string url, HelperDownload h, DownloadComplete d) { if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) { WebClient client = new WebClient(); string[] fileParts = url.Split('/'); string fileName = fileParts.Last(); Uri urlDownload = new Uri(url, UriKind.Absolute); client.DownloadFileAsync(urlDownload, $"C:\\Users\\Robin R\\Documents\\{fileName}"); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler((send, ex) => Client_DownloadProgress(send, ex, fileName, h)); client.DownloadFileCompleted += new AsyncCompletedEventHandler((send, ex) => Client_DownloadCompleted(send, ex, fileName, d)); } }
static void Main() { string fileName; fileName = Console.ReadLine(); string[] urls = File.ReadAllLines(fileName); HelperDownload h = DisplayDetails; DownloadComplete d = DonwloadComp; DownloadHelper download = new DownloadHelper(); IntenetSlow e = ErrorHandle; List <Task> tasks = new List <Task>(); Task t = null; foreach (string url in urls) { t = download.DownloadHelperDownloadAsync(url, e); tasks.Add(t); } download.FileWatcher(h, e); Task.WaitAll(tasks.ToArray()); }
public void Client_DownloadProgress(object sender, DownloadProgressChangedEventArgs e, string fileName, HelperDownload h) { double bytesIn = double.Parse(e.BytesReceived.ToString()); double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); double percentage = bytesIn / totalBytes * 100; h(fileName, double.Parse(e.BytesReceived.ToString()), int.Parse(Math.Truncate(percentage).ToString())); }