コード例 #1
0
        public void CustomSchema_FileConnObjProps_ParseAsNormal(String remoteUri, String baseDownloadLoc)
        {
            FileConnInfo fi       = new FileConnInfo(remoteUri, baseDownloadLoc);
            string       uniqueId = fi.UniqueId;

            Assert.IsNotEmpty(uniqueId);
            Assert.NotNull(uniqueId);

            //Get Combine Strategy into its own class
            string filename = uniqueId + "_" + "srfc959.txt";

            Assert.AreEqual(new Uri(remoteUri), fi.Url);
            Assert.AreEqual(remoteUri, fi.RemoteUrl);
            Assert.AreEqual("myftp", fi.Scheme);
            Assert.AreEqual("localhost", fi.Host);
            Assert.AreEqual(-1, fi.Port);
            Assert.AreEqual("/a/b/srfc959.txt", fi.RemoteFilePath);
            Assert.AreEqual("srfc959.txt", fi.RemoteFilename);


            Assert.AreEqual(baseDownloadLoc, fi.LocalBasePath);

            //TODO: Get Filename strategy out of FileConn class
            Assert.AreEqual(Path.Combine(baseDownloadLoc, filename), fi.LocalFilePath);
            Assert.AreEqual("test", fi.Username);
            Assert.AreEqual("test", fi.Password);
            Assert.AreEqual(filename, fi.Filename);
            Assert.AreEqual(".txt", fi.Extension);
        }
コード例 #2
0
        public void GetDownloadClient_SupportedType_ReturnsIDownload(string url, string downloadLocation)
        {
            var fi     = new FileConnInfo(url, downloadLocation);
            var client = DownloadClientFactory.GetDownloadClient(fi);

            Assert.IsInstanceOf <IDownloader>(client);
        }
コード例 #3
0
        //Get Download client based on schema
        //It returns concrete class based on schema
        //This function should be extended whenever we add concrete class supporting new schema
        public static IDownloader GetDownloadClient(FileConnInfo fileConnInfo)
        {
            IDownloader client = null;

            if (fileConnInfo == null)
            {
                throw new ArgumentNullException($"Please provide non-null FileConnInfo object");
            }

            SupportedDownloadSchema dc;
            var isSupported = Enum.TryParse(fileConnInfo.Scheme, true, out dc);

            if (!isSupported)
            {
                throw new NotSupportedException($"Not supported {fileConnInfo.Scheme} download schema  ");
            }

            switch (dc)
            {
            case SupportedDownloadSchema.FTP: client = (IDownloader) new FTPClient(fileConnInfo);
                break;

            case SupportedDownloadSchema.SFTP: client = (IDownloader) new SFTPClient(fileConnInfo);
                break;

            default: throw new NotSupportedException($"Scheme {dc.ToString()} Not Supported");
            }


            return(client);
        }
コード例 #4
0
        public void GetDownloadClient_NullFieConnInfo_Throws()
        {
            ActualValueDelegate <object> testDelegate =
                () =>
            {
                FileConnInfo fi     = null;
                var          client = DownloadClientFactory.GetDownloadClient(fi);
                return(client);
            };

            Assert.That(testDelegate, Throws.TypeOf <ArgumentNullException>());
        }
コード例 #5
0
        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>());
        }
コード例 #6
0
        public FTPClient(FileConnInfo fInfo)
        {
            _fileConnInfo = fInfo;
            if (fInfo.Extension == "zip")
            {
                UseBinary = true;
            }
            else
            {
                UseBinary = false;
            }

            UsePassive = false;
        }
コード例 #7
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);
            }
        }
コード例 #8
0
 public SFTPClient(FileConnInfo fInfo)
 {
     _fileConnInfo = fInfo;
 }