/// <summary> /// Return the appropriate operation end point based upon the IOPath type /// </summary> /// <param name="target"></param> /// <returns></returns> public static IActivityIOOperationsEndPoint CreateOperationEndPointFromIOPath(IActivityIOPath target) { lock (EndPointsLock) { // load end-points if need be... aka first load if (_endPoints == null) { _endPoints = new List <Type>(); _referenceCheckers = new List <IActivityIOOperationsEndPoint>(); var type = typeof(IActivityIOOperationsEndPoint); List <Type> types = Assembly.GetExecutingAssembly().GetTypes() .Where(t => type.IsAssignableFrom(t)) .ToList(); foreach (Type t in types) { if (t != typeof(IActivityIOOperationsEndPoint)) { _endPoints.Add(t); _referenceCheckers.Add((IActivityIOOperationsEndPoint)Activator.CreateInstance(t)); } } } } // now find the right match ;) int pos = 0; while (pos < _referenceCheckers.Count && !_referenceCheckers[pos].HandlesType(target.PathType)) { pos++; } IActivityIOOperationsEndPoint result; if (_endPoints != null && _endPoints.Count > 0) { result = (IActivityIOOperationsEndPoint)Activator.CreateInstance(_endPoints[pos]); result.IOPath = target; } else { result = new Dev2FileSystemProvider { IOPath = target }; } return(result); }
public void Dev2FileSystemProvider_GetDirectoryOperation_NonExistingPath_FriendlyError() { bool pass = false; Dev2FileSystemProvider testProvider = new Dev2FileSystemProvider(); IActivityIOPath path = ActivityIOFactory.CreatePathFromString("C:/dadsdascasxxxacvaawqf", false); try { testProvider.ListDirectory(path); } catch(Exception ex) { Assert.AreEqual("Directory not found [ C:/dadsdascasxxxacvaawqf ] ", ex.Message); pass = true; } if(!pass) { Assert.Fail("The corrrect error wasnt returned"); } }
public void Dev2FileSystemProvider_ListFilesInDirectory_Normal_AllFilesInDirectoryReturned() { //------------Setup for test-------------------------- var dev2FileSystemProvider = new Dev2FileSystemProvider(); //string baseFolderDirectory = Path.GetTempPath() + @"\ListDirectoryTestFolder"; string tmpFolderLocal = Path.GetTempPath() + @"\ListDirectoryTestFolderNormal_AllFilesInDirectoryReturned\Folder1"; string tmpFolderLocal2 = Path.GetTempPath() + @"\ListDirectoryTestFolderNormal_AllFilesInDirectoryReturned\Folder2"; string tmpFileLocal1 = Path.GetTempPath() + @"\ListDirectoryTestFolderNormal_AllFilesInDirectoryReturned\File1.txt"; string tmpFileLocal2 = Path.GetTempPath() + @"\ListDirectoryTestFolderNormal_AllFilesInDirectoryReturned\File2.txt"; CreateDirectory(tmpFolderLocal); CreateDirectory(tmpFolderLocal2); CreateLocalPath(tmpFileLocal1); CreateLocalPath(tmpFileLocal2); IActivityIOPath path = ActivityIOFactory.CreatePathFromString(Path.GetTempPath() + @"\ListDirectoryTestFolderNormal_AllFilesInDirectoryReturned", "", ""); //------------Execute Test--------------------------- IList<IActivityIOPath> fileList = dev2FileSystemProvider.ListFilesInDirectory(path); //------------Assert Results------------------------- Assert.AreEqual(2, fileList.Count); Assert.IsTrue(fileList[0].Path.EndsWith("File1.txt")); Assert.IsTrue(fileList[1].Path.EndsWith("File2.txt")); DeleteDirectory(Path.GetTempPath() + @"\ListDirectoryTestFolderNormal_AllFilesInDirectoryReturned"); }