private static IEnumerable <string> GetStreamsRecurse(string baseDirectory, Regex regex, int recurseDir) { List <StreamInfo> streams = null; int maxRetryAttempts = 5; TimeSpan pauseBetweenFailures = TimeSpan.FromSeconds(2); RetryHelper.RetryOnException(maxRetryAttempts, pauseBetweenFailures, () => { streams = VC.GetDirectoryInfo(baseDirectory, false); }); foreach (var streamInfo in streams) { var uri = new Uri(streamInfo.StreamName); if (recurseDir == 1 && streamInfo.IsDirectory) { foreach (var subStream in GetStreamsRecurse(streamInfo.StreamName, regex, recurseDir)) { yield return(subStream); } } else if (!streamInfo.IsDirectory && regex.IsMatch(uri.Segments[uri.Segments.Length - 1])) { yield return(streamInfo.StreamName); } } }
public static void DeleteCosmosDirectoryFiles(string directoryName, bool recursive = false) { if (string.IsNullOrEmpty(directoryName)) { return; } directoryName = directoryName.TrimEnd(new char[] { '/' }); List <StreamInfo> streamInfos = null; try { streamInfos = VC.GetDirectoryInfo(directoryName, false); } catch (VcClientException) { // the directory doens't exist } if (streamInfos != null) { foreach (StreamInfo streamInfo in streamInfos) { if (streamInfo.IsDirectory && recursive) { DeleteCosmosDirectoryFiles(streamInfo.StreamName, recursive); } else if (!streamInfo.IsDirectory) { DeleteCosmosFile(streamInfo); } } } }
} //end Main /* * private static IEnumerable<string> GetStreamsRecurse(string baseDirectory, Regex regex) * { * foreach (var streamInfo in VC.GetDirectoryInfo(baseDirectory, true)) * { * if (streamInfo.IsDirectory) * { * foreach (var subStream in GetStreamsRecurse(streamInfo.StreamName, regex)) * { * yield return subStream; * } * } * else if (regex.IsMatch(streamInfo.StreamName)) * { * yield return streamInfo.StreamName; * } * } * } */ private static IEnumerable <string> GetDirectories(string baseDirectory) { foreach (var streamInfo in VC.GetDirectoryInfo(baseDirectory, true)) { if (streamInfo.IsDirectory) { yield return(streamInfo.StreamName); } } }
public static bool DirectoryExists(string directoryPath) { try { VC.GetDirectoryInfo(directoryPath, false); return(true); } catch (VcClientException) { return(false); } }
public static List <JToken> GetStreamInfos(string directoryPath) { var certificate = CertificateGenerator.GetCertificateByThumbprint(); VC.Setup(null, certificate); List <JToken> streamInfoJTokens = new List <JToken>(); List <StreamInfo> streamInfos = VC.GetDirectoryInfo(directoryPath, true); foreach (var streamInfo in streamInfos) { streamInfoJTokens.Add(JToken.Parse(JsonConvert.SerializeObject(streamInfo))); } return(streamInfoJTokens); }
static IEnumerable <string> GetStreamsRecurse(string baseDirectory, Regex regex) { foreach (var streamInfo in VC.GetDirectoryInfo(baseDirectory, true)) { if (streamInfo.IsDirectory) { foreach (var subStream in GetStreamsRecurse(streamInfo.StreamName, regex)) { yield return(subStream); } } else if (regex.IsMatch(streamInfo.StreamName)) { yield return(streamInfo.StreamName); } } }
public static int MoveFolderFiles(string dirSource, string dirTarget, bool recursive = false) { dirSource = dirSource.TrimEnd(new char[] { '/' }); dirTarget = dirTarget.TrimEnd(new char[] { '/' }); int fileCount = 0; List <StreamInfo> streamInfos = null; try { streamInfos = VC.GetDirectoryInfo(dirSource, false); } catch (VcClientException) { // the directory doens't exist } if (streamInfos != null) { foreach (StreamInfo streamInfo in streamInfos) { string[] parts = streamInfo.StreamName.Split( new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); string lastPart = parts[parts.Length - 1]; string targetName = BuildUrlPath(dirTarget, lastPart); if (streamInfo.IsDirectory && recursive) { fileCount += MoveFolderFiles( streamInfo.StreamName, targetName, recursive); } else { RenameStream(streamInfo.StreamName, targetName); fileCount++; } } } return(fileCount); }
public static List <string> GetFiles(string cosmosDirectory, string pattern) { List <string> files = new List <string>(); if (string.IsNullOrEmpty(cosmosDirectory) || string.IsNullOrEmpty(pattern)) { throw new ArgumentException("Argument cosmosDirectory or pattern is null/empty"); } cosmosDirectory = cosmosDirectory.Trim(new char[] { '/' }); List <StreamInfo> streamInfos = null; try { streamInfos = VC.GetDirectoryInfo(cosmosDirectory, false); } catch (VcClientException) { // the directory doens't exist } if (streamInfos != null) { Regex regex = new Regex(pattern, RegexOptions.IgnoreCase); foreach (StreamInfo streamInfo in streamInfos) { string fileName = CosmosStream.GetFileName(streamInfo.StreamName); if (regex.IsMatch(fileName)) { files.Add(streamInfo.StreamName); } } } return(files); }