示例#1
0
        public void AddDate(List <String> listPathsFiles, Boolean delete, Encoding encoding, Int32 countTask = 1)
        {
            Boolean parallel = countTask <= 1 ? false : true;

            if (!parallel)
            {
                foreach (String _file in listPathsFiles)
                {
                    AddDate(_file, encoding);
                    if (delete)
                    {
                        File.Delete(_file);
                    }
                }
            }
            else
            {
                arf_Distributor <String> distributor = new arf_Distributor <String>(AddDate, listPathsFiles, encoding);
                distributor.Start(countTask);
                if (delete)
                {
                    foreach (String _file in listPathsFiles)
                    {
                        File.Delete(_file);
                    }
                }
            }
        }
        public List <String> Download(String pathFileWithURI, Encoding encoding, Int32 countThread = 1)
        {
            List <String> listPathsURI = new List <String>();

            using (StreamReader _reader = new StreamReader(pathFileWithURI, encoding))
            {
                String uri;
                while ((uri = _reader.ReadLine()) != null)
                {
                    listPathsURI.Add(uri);
                }
            }

            String        appRoot            = AppDomain.CurrentDomain.BaseDirectory;
            List <String> listPathsDownFiles = new List <String>();

            if (countThread == 1)
            {
                WebClient webClient = new WebClient();
                foreach (String uri in listPathsURI)
                {
                    var buff     = uri.Split('\\');
                    var nameFile = "arf_new" + buff[buff.Length - 1];
                    try
                    {
                        webClient.DownloadFile(uri, nameFile);
                    }
                    catch (WebException webException)
                    {
                        throw new arf_Exception($"\t-> An error occurred while downloading data. <-\n");
                    }
                    catch (Exception exception)
                    {
                        throw new Exception(exception.Message);
                    }
                    listPathsDownFiles.Add(appRoot + nameFile);
                }
            }
            else
            {
                void dwn(String uri)
                {
                    WebClient webClient = new WebClient();
                    var       buff      = uri.Split('\\');
                    var       nameFile  = "arf_new" + buff[buff.Length - 1];

                    try
                    {
                        webClient.DownloadFile(uri, nameFile);
                    }
                    catch (WebException webException)
                    {
                        throw new arf_Exception($"\t-> An error occurred while downloading data. <-\n");
                    }
                    catch (Exception exception)
                    {
                        throw new Exception(exception.Message);
                    }
                    lock (l_k)
                        listPathsDownFiles.Add(appRoot + nameFile);
                }

                arf_Distributor <String> distributor = new arf_Distributor <String>(dwn, listPathsURI);
                distributor.Start(countThread, true);
            }
            return(listPathsDownFiles);
        }