Exemplo n.º 1
0
        private void BeginDownloading()
        {
            inputData.Input();
            numberOfFiles = inputData.numberOfFiles;

            FileDownloader fileDownloader = new FileDownloader();

            CountDownloadingFiles downloadingFiles = new CountDownloadingFiles();

            fileDownloader.OnDownloaded += CountDownloadedFiles;
            fileDownloader.OnFailed     += CountUndownloadedFiles;

            int index = 1;

            try
            {
                foreach (string url in inputData.fileUrls)
                {
                    fileDownloader.AddFileToDownloadingQueue(Convert.ToString(index), url, inputData.PathToSave);
                    index++;
                }
            }
            catch (Exception exception)
            {
                Log.WriteToLog(exception);
                MessageBox.Show("Ошибка!" + exception.Message);

                return;
            }
        }
Exemplo n.º 2
0
        static async Task Main(string[] args)
        {
            FileDownloader fileDownloader = new FileDownloader();

            fileDownloader.SetDegreeOfParallelism(1);

            fileDownloader.OnDownloaded += OnDownload;
            fileDownloader.OnFailed     += OnFail;
            OnEnd += fileDownloader.OnAllAsync;

            string fileName = $@"{System.IO.Directory.GetCurrentDirectory()}\url.txt";
            int    id       = 0;

            try
            {
                string line;
                using (StreamReader sr = new StreamReader(fileName))
                {
                    while ((line = await sr.ReadLineAsync()) != null)
                    {
                        fileDownloader.AddFileToDownloadingQueue(id.ToString(), line, @"C:\Users\User\Documents\images");
                        files.GetOrAdd(id.ToString(), false);
                        id++;
                    }
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (OnEnd != null)
            {
                await OnEnd().ContinueWith(delegate {
                    Console.WriteLine($"{files.Values.Where(v => v == true).Count()} downloaded successfully");
                    Console.WriteLine($"{files.Values.Where(v => v == false).Count()} was failed");
                });
            }
            Console.ReadKey();
        }
Exemplo n.º 3
0
        private void StartClick(object sender, RoutedEventArgs e)
        {
            if (isFirst)
            {
                var num = (ThreadNumber)this.Resources["threadNum"];

                fileDownloader.SetDegreeOfParallelism(num.Number);

                chngThreads.Visibility = Visibility.Hidden;
                isFirst = false;
            }

            var btn = sender as Button;

            btn.IsEnabled = false;

            var line = urlListGrid.SelectedItem as FileModel;

            var id = urlListGrid.SelectedIndex;

            fileDownloader.AddFileToDownloadingQueue(id.ToString(), line.Url, @"C:\Users\User\Documents\images");
        }
Exemplo n.º 4
0
        public MainWindow()
        {
            InitializeComponent();
            string input;

            using (var stream = File.OpenRead(@"C:\Users\Nypifok\Desktop\TestDownloads\input.txt"))
            {
                byte[] array = new byte[stream.Length];
                stream.Read(array, 0, array.Length);
                string textFromFile = Encoding.Default.GetString(array);
                input = textFromFile;
            }


            var raws       = input.Split("\r\n");
            var downloader = new FileDownloader();

            DataContext = new DownloadProcessViewModel(downloader);
            foreach (string str in raws)
            {
                Task.Factory.StartNew(() => downloader.AddFileToDownloadingQueue(Guid.NewGuid().ToString(), str, @"C:\Users\Nypifok\Desktop\TestDownloads"));
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Введите путь сохранения: ");
            var pathToSave = Console.ReadLine();
            var filesUrl   = new List <string>(80);

            var downloader = new FileDownloader();

            downloader.OnDownloaded += DisplayMessage;
            downloader.OnFailed     += DisplayError;
            using (var sr = new StreamReader("FilesToDownload.txt"))
            {
                while (!sr.EndOfStream)
                {
                    filesUrl.Add(sr.ReadLine());
                }
            }
            for (int i = 0; i < filesUrl.Count; i++)
            {
                downloader.AddFileToDownloadingQueue(i.ToString(), filesUrl[i], pathToSave);
            }
            Console.ReadLine();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            string input;

            using (var stream = File.OpenRead(@"C:\Users\Nypifok\Desktop\TestDownloads\input.txt"))
            {
                byte[] array = new byte[stream.Length];
                stream.Read(array, 0, array.Length);
                string textFromFile = Encoding.Default.GetString(array);
                input = textFromFile;
            }
            var raws       = input.Split("\r\n");
            var downloader = new FileDownloader();

            //downloader.OnFileProgress += ProgressOutput;
            downloader.OnFailed     += ExceptionOutput;
            downloader.OnDownloaded += DownloadedOutput;
            foreach (string str in raws)
            {
                downloader.AddFileToDownloadingQueue(Guid.NewGuid().ToString(), str, @"C:\Users\Nypifok\Desktop\TestDownloads");
            }

            Console.ReadKey();
        }