Dev2.PathOperations.ActivityIOFactory.CreateOperationEndPointFromIOPath C# (CSharp) Method

CreateOperationEndPointFromIOPath() public static method

Return the approperate operation end point based upon the IOPath type
public static CreateOperationEndPointFromIOPath ( IActivityIOPath target ) : IActivityIOOperationsEndPoint
target IActivityIOPath
return IActivityIOOperationsEndPoint
        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 = typeof (IActivityIOOperationsEndPoint).Assembly.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++;
            }

            // will throw exception if cannot find handling type
            IActivityIOOperationsEndPoint result =
                (IActivityIOOperationsEndPoint) Activator.CreateInstance(_endPoints[pos]);
            result.IOPath = target;
            

            return result;
        }

Usage Example

示例#1
0
        void ValidateSourceAndDestinationContents(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args)
        {
            if (!args.Overwrite)
            {
                var srcContentsFolders = src.ListFoldersInDirectory(src.IOPath);
                foreach (var sourcePath in srcContentsFolders)
                {
                    var            sourceEndPoint      = ActivityIOFactory.CreateOperationEndPointFromIOPath(sourcePath);
                    IList <string> dirParts            = sourceEndPoint.IOPath.Path.Split(sourceEndPoint.PathSeperator().ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    var            directory           = dirParts.Last();
                    var            destinationPath     = ActivityIOFactory.CreatePathFromString(dst.Combine(directory), dst.IOPath.Username, dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile);
                    var            destinationEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(destinationPath);
                    if (destinationEndPoint.PathExist(destinationEndPoint.IOPath))
                    {
                        ValidateSourceAndDestinationContents(sourceEndPoint, destinationEndPoint, args);
                    }
                }

                var srcContents          = src.ListFilesInDirectory(src.IOPath);
                var dstContents          = dst.ListFilesInDirectory(dst.IOPath);
                var sourceFileNames      = srcContents.Select(srcFile => GetFileNameFromEndPoint(src, srcFile)).ToList();
                var destinationFileNames = dstContents.Select(dstFile => GetFileNameFromEndPoint(dst, dstFile)).ToList();
                if (destinationFileNames.Count > 0)
                {
                    var commonFiles = sourceFileNames.Where(destinationFileNames.Contains).ToList();
                    if (commonFiles.Count > 0)
                    {
                        var fileNames = commonFiles.Aggregate("",
                                                              (current, commonFile) =>
                                                              current + "\r\n" + commonFile);
                        throw new Exception(string.Format(ErrorResource.FileExistInDestinationFolder, fileNames));
                    }
                }
            }
        }
All Usage Examples Of Dev2.PathOperations.ActivityIOFactory::CreateOperationEndPointFromIOPath