public void GetDownloadClient_SupportedType_ReturnsIDownload(string url, string downloadLocation)
        {
            var fi     = new FileConnInfo(url, downloadLocation);
            var client = DownloadClientFactory.GetDownloadClient(fi);

            Assert.IsInstanceOf <IDownloader>(client);
        }
        public void GetDownloadClient_NullFieConnInfo_Throws()
        {
            ActualValueDelegate <object> testDelegate =
                () =>
            {
                FileConnInfo fi     = null;
                var          client = DownloadClientFactory.GetDownloadClient(fi);
                return(client);
            };

            Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>());
        }
        public void GetDownloadClient_NotSupportedType_Throws(string url, string downloadLocation)
        {
            ActualValueDelegate <object> testDelegate =
                () =>
            {
                var fi     = new FileConnInfo(url, downloadLocation);
                var client = DownloadClientFactory.GetDownloadClient(fi);
                return(client);
            };

            Assert.That(testDelegate, Throws.TypeOf <NotSupportedException>());
        }
Exemple #4
0
        public virtual void ProcessSource(string downloadLocation, string src)
        {
            Log.Info($"Download Start: {src}");

            if (downloadLocation == null)
            {
                throw new ArgumentNullException("Download Location can't be null");
            }
            if (src == null)
            {
                throw new ArgumentNullException("Source can't be null. Nothing to process.");
            }

            FileConnInfo fInfo = null;

            try
            {
                //Get New File Info object
                fInfo = new FileConnInfo(src, downloadLocation);

                //Get New Downloader Client
                IDownloader downloader = DownloadClientFactory.GetDownloadClient(fInfo);

                //Process Download
                if (downloader != null)
                {
                    downloader.CreateRequest();
                    downloader.GetResponse();
                }

                Log.Info($"Download Done: {src} ");
            }
            catch (Exception ex)
            {
                //Delete Partially Downloaded File
                if (fInfo != null)
                {
                    Helper.TryToDeleteFile(fInfo.LocalFilePath);
                }

                Log.Error($"Download Error: {src}", ex);
            }
        }