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); }
public void GetDownloadClient_SupportedType_ReturnsIDownload(string url, string downloadLocation) { var fi = new FileConnInfo(url, downloadLocation); var client = DownloadClientFactory.GetDownloadClient(fi); Assert.IsInstanceOf <IDownloader>(client); }
//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); }
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>()); }
public FTPClient(FileConnInfo fInfo) { _fileConnInfo = fInfo; if (fInfo.Extension == "zip") { UseBinary = true; } else { UseBinary = false; } UsePassive = false; }
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); } }
public SFTPClient(FileConnInfo fInfo) { _fileConnInfo = fInfo; }