示例#1
0
    void EnsurePaths()
    {
        const string s3 = "s3://";

        if (!_planPath.StartsWith(s3, StringComparison.OrdinalIgnoreCase))
        {
            _planPath = UtilitiesPathCombine(_bucketName, _planPath);
        }

        if (!_histPath.StartsWith(s3, StringComparison.OrdinalIgnoreCase))
        {
            _histPath = UtilitiesPathCombine(_bucketName, _histPath);
        }

        if (!_splxPath.StartsWith(s3, StringComparison.OrdinalIgnoreCase))
        {
            _splxPath = UtilitiesPathCombine(_bucketName, _splxPath);
        }

        zf.AwsS3ZephyrDirectory s3zd = new zf.AwsS3ZephyrDirectory(_awsClient);

        s3zd.FullName = _planPath;
        if (!s3zd.Exists)
        {
            s3zd.Create();
        }

        s3zd.FullName = _histPath;
        if (!s3zd.Exists)
        {
            s3zd.Create();
        }
    }
    /// <summary>
    /// Case-insensitive search a folder for a list of matching files
    /// </summary>
    /// <param name="path">Folder to search</param>
    /// <param name="searchPattern">Optional suffix to match</param>
    /// <returns>A list of matching files</returns>
    IEnumerable <string> DirectoryGetFiles(string path, string searchPattern = null)
    {
        zf.AwsS3ZephyrDirectory     dir   = new zf.AwsS3ZephyrDirectory(_awsClient, path);
        IEnumerable <zf.ZephyrFile> files = dir.GetFiles();
        List <string> matches             = new List <string>();

        if (!string.IsNullOrWhiteSpace(searchPattern))
        {
            foreach (zf.ZephyrFile z in files)
            {
                if (z.Name.EndsWith(searchPattern, StringComparison.OrdinalIgnoreCase))
                {
                    matches.Add(z.FullName);
                }
            }
        }
        else
        {
            foreach (zf.ZephyrFile z in files)
            {
                matches.Add(z.FullName);
            }
        }

        return(matches);
    }
示例#3
0
        /// <summary>
        /// Gets a ZephyrFile implementation matching the URL type passed in.
        /// </summary>
        /// <param name="url">The Fullname or URL of the directory.</param>
        /// <param name="clients">A collection of connection clients.</param>
        /// <returns>A ZephyrFile implementation.</returns>
        public static ZephyrDirectory GetZephyrDirectory(string url, Clients clients = null)
        {
            ZephyrDirectory dir  = null;
            UrlType         type = GetUrlType(url);

            switch (type)
            {
            case UrlType.LocalDirectory:
                dir = new WindowsZephyrDirectory(url);
                break;

            case UrlType.NetworkDirectory:
                dir = new WindowsZephyrDirectory(url);
                break;

            case UrlType.AwsS3Directory:
                dir = new AwsS3ZephyrDirectory(clients?.aws, url);
                break;

            default:
                throw new Exception($"Url [{url}] Is Not A Known Directory Type.");
            }

            return(dir);
        }
示例#4
0
        public static void Main(string[] args)
        {
            Clients clients = new Clients();

            clients.aws = new AwsClient(RegionEndpoint.EUWest1);
            AwsS3ZephyrDirectory dir = new AwsS3ZephyrDirectory(clients.aws, @"s3://mybucket/");

            foreach (ZephyrDirectory d in dir.GetDirectories())
            {
                Console.WriteLine(d.FullName);
            }

            foreach (ZephyrFile f in dir.GetFiles())
            {
                Console.WriteLine(f.FullName);
            }

            Console.WriteLine("Press <ENTER> To Continue...");
            Console.ReadLine();
        }
    /// <summary>
    /// Case-insensitive search a folder for an exact filename match
    /// </summary>
    /// <param name="path">Folder to search</param>
    /// <param name="fileName">Filename to match</param>
    /// <returns>The matching case-sensitive path or (returns null or throws FileNotFoundException)</returns>
    string DirectoryGetFile(string path, string fileName, bool throwFileNotFoundException = true)
    {
        zf.AwsS3ZephyrDirectory dir = new zf.AwsS3ZephyrDirectory(_awsClient, path);

        List <string> files = dir.GetFiles()
                              .Where(f => f.Name.Equals(fileName, StringComparison.OrdinalIgnoreCase))
                              .Select(f => f.Name).ToList();

        if (files.Count == 1)
        {
            return(UtilitiesPathCombine(path, files[0]));
        }
        else if (throwFileNotFoundException)
        {
            throw new FileNotFoundException($"Could not load {fileName}.  Found {files.Count} name matches.");
        }
        else
        {
            return(null);
        }
    }
 string UtilitiesPathCombine(params string[] paths)
 {
     zf.AwsS3ZephyrDirectory dir = new zf.AwsS3ZephyrDirectory(_awsClient, paths[0]);
     return(dir.PathCombine(paths));
 }