Beispiel #1
0
        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");
            }
        }
Beispiel #2
0
        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());
            }
        }
Beispiel #3
0
        public async Task DownloadHelperDownloadAsync(string url, IntenetSlow s)
        {
            // DisplayClass disp = null;
            if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                try
                {
                    WebClient client    = new WebClient();
                    string[]  fileParts = url.Split('/');
                    string    fileName  = fileParts.Last();

                    Uri urlDownload = new Uri(url, UriKind.Absolute);

                    DisplayClass disp = new DisplayClass();
                    disp.FileName = fileName;
                    NetworkChange.NetworkAvailabilityChanged += (sx, ex) => AvailabilityChanged(sx, ex, s, fileName);

                    await Task.Run(() => client.DownloadFile(urlDownload, $"{ConfigurationManager.AppSettings["FILE_PATH"]}\\{fileName}"));
                }
                catch (ArgumentNullException ex)
                {
                    s(ex.Message);
                }
                catch (WebException wb)
                {
                    s(wb.Message);
                }
                catch (Exception ex)
                {
                    s(ex.Message);
                }
            }
            else
            {
                s("Enter valid URL");
            }
        }
Beispiel #4
0
        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());
        }
Beispiel #5
0
 public void AvailabilityChanged(object sender, NetworkAvailabilityEventArgs e, IntenetSlow s, string filename)
 {
     if (e.IsAvailable)
     {
         s($"Connection Established : {filename}");
     }
     else
     {
         s($"Connection Not Available : {filename}");
     }
 }