本文整理汇总了C#中IFileSystem.GetFiles方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.GetFiles方法的具体用法?C# IFileSystem.GetFiles怎么用?C# IFileSystem.GetFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.GetFiles方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindDifferences
public static IndexDifferences FindDifferences(
IFileSystem fileSystem,
IEnumerable<LucenePackage> indexedPackages,
CancellationToken cancellationToken,
Action<SynchronizationState> setState,
SynchronizationMode mode)
{
setState(SynchronizationState.ScanningFiles);
var fileSystemPackages = fileSystem.GetFiles(string.Empty, "*" + Constants.PackageExtension, true)
.WithCancellation(cancellationToken)
.Where(file => !fileSystem.IsTempFile(file))
.ToArray();
setState(SynchronizationState.ScanningIndex);
var indexedPackagesByPath = indexedPackages
.WithCancellation(cancellationToken)
.ToDictionary(pkg => pkg.Path, StringComparer.InvariantCultureIgnoreCase);
setState(SynchronizationState.Comparing);
var calc = new IndexDifferenceCalculator(fileSystem, fileSystemPackages, indexedPackagesByPath);
return calc.Calculate(mode);
}
示例2: DirectorySync
public DirectorySync(string directoryPath, ISyncFactory factory, IFileSystem fileSystem,
IDirectoryValidator validator, IProjectFactory projectFactory)
{
var files = fileSystem.GetFiles(directoryPath, "*.csproj", SearchOption.AllDirectories);
foreach (var file in files)
{
if (validator.IsDirectoryValid(file) && projectFactory.IsValidProject(file))
{
var project = factory.CreateProjectSynchronizer(file);
_projects.Add(project);
}
}
}
示例3: RepositoryGroupManager
/// <summary>
/// Initializes a new instance of the <see cref="RepositoryGroupManager"/> class. Provides nested operations over RepositoryManager instances.
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="fileSystem"> </param>
/// <example>Can be a direct path to a repository.config file</example>
///
/// <example>Can be a path to a directory, which will recursively locate all contained repository.config files</example>
public RepositoryGroupManager(string repository, IFileSystem fileSystem)
{
Contract.Requires(fileSystem != null);
this.fileSystem = fileSystem;
if (fileSystem.DirectoryExists(repository))
{
// we're dealing with a directory
//TODO Does this by default do a recursive???
RepositoryManagers = new ConcurrentBag<RepositoryManager>(fileSystem.GetFiles(repository, "repositories.config", SearchOption.AllDirectories).Select(file => new RepositoryManager(file, new RepositoryEnumerator(fileSystem), fileSystem)).ToList());
}
else if (fileSystem.FileExists(repository) && Path.GetFileName(repository) == "repositories.config")
RepositoryManagers = new ConcurrentBag<RepositoryManager>(new List<RepositoryManager> { new RepositoryManager(repository, new RepositoryEnumerator(fileSystem), fileSystem) });
else
throw new ArgumentOutOfRangeException("repository");
}
示例4: Compile
private static async Task<CompilationResult> Compile(IFileSystem fileSystem)
{
var compiler = new CSharpCompiler(
fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories)
.Select(each => new KeyValuePair<string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(),
ManagedAssets.FrameworkAssemblies.Concat(
AppDomain.CurrentDomain.GetAssemblies()
.Where(each => !each.IsDynamic && !string.IsNullOrEmpty(each.Location))
.Select(each => each.Location)
.Concat(new[]
{
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Microsoft.Rest.ClientRuntime.dll"),
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Microsoft.Rest.ClientRuntime.Azure.dll")
})
));
return await compiler.Compile(Microsoft.Rest.CSharp.Compiler.Compilation.OutputKind.DynamicallyLinkedLibrary);
}
示例5: GetLastTranscodingFile
private static FileSystemMetadata GetLastTranscodingFile(string playlist, string segmentExtension, IFileSystem fileSystem)
{
var folder = Path.GetDirectoryName(playlist);
var filePrefix = Path.GetFileNameWithoutExtension(playlist) ?? string.Empty;
try
{
return fileSystem.GetFiles(folder)
.Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase) && Path.GetFileNameWithoutExtension(i.Name).StartsWith(filePrefix, StringComparison.OrdinalIgnoreCase))
.OrderByDescending(fileSystem.GetLastWriteTimeUtc)
.FirstOrDefault();
}
catch (DirectoryNotFoundException)
{
return null;
}
}
示例6: LoadMachineWideSettings
/// <summary>
/// Loads the machine wide settings.
/// </summary>
/// <remarks>
/// For example, if <paramref name="paths"/> is {"IDE", "Version", "SKU" }, then
/// the files loaded are (in the order that they are loaded):
/// %programdata%\NuGet\Config\IDE\Version\SKU\*.config
/// %programdata%\NuGet\Config\IDE\Version\*.config
/// %programdata%\NuGet\Config\IDE\*.config
/// %programdata%\NuGet\Config\*.config
/// </remarks>
/// <param name="fileSystem">The file system in which the settings files are read.</param>
/// <param name="paths">The additional paths under which to look for settings files.</param>
/// <returns>The list of settings read.</returns>
public static IEnumerable<Settings> LoadMachineWideSettings(
IFileSystem fileSystem,
params string[] paths)
{
List<Settings> settingFiles = new List<Settings>();
string basePath = @"NuGet\Config";
string combinedPath = Path.Combine(paths);
while (true)
{
string directory = Path.Combine(basePath, combinedPath);
// load setting files in directory
foreach (var file in fileSystem.GetFiles(directory, "*.config", recursive: false))
{
var settings = ReadSettings(fileSystem, file, true);
if (settings != null)
{
settingFiles.Add(settings);
}
}
if (combinedPath.Length == 0)
{
break;
}
int index = combinedPath.LastIndexOf(Path.DirectorySeparatorChar);
if (index < 0)
{
index = 0;
}
combinedPath = combinedPath.Substring(0, index);
}
return settingFiles;
}
示例7: CopyNativeBinaries
private void CopyNativeBinaries(IProjectSystem projectSystem, IFileSystem packagesFileSystem, PackageName packageName)
{
const string nativeBinariesFolder = "NativeBinaries";
string nativeBinariesPath = Path.Combine(packageName.Name, nativeBinariesFolder);
if (packagesFileSystem.DirectoryExists(nativeBinariesPath))
{
IEnumerable<string> nativeFiles = packagesFileSystem.GetFiles(nativeBinariesPath, "*.*", recursive: true);
foreach (string file in nativeFiles)
{
string targetPath = Path.Combine(Constants.BinDirectory, file.Substring(nativeBinariesPath.Length + 1)); // skip over NativeBinaries/ word
using (Stream stream = packagesFileSystem.OpenFile(file))
{
projectSystem.AddFile(targetPath, stream);
}
}
}
}
示例8: SearchFilesWithinOneSubFolders
private IEnumerable<string> SearchFilesWithinOneSubFolders(IFileSystem fileSystem, string folder, string extension)
{
// get files directly under 'folder' or files under subfolders of 'folder'
return fileSystem.GetFiles(folder, extension)
.Concat(fileSystem.GetDirectories(folder).SelectMany(subFolder => fileSystem.GetFiles(subFolder, extension)));
}
示例9: Compile
protected async Task<CompilationResult> Compile(IFileSystem fileSystem)
{
var compiler = new CSharpCompiler(
fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories)
.Select(each => new KeyValuePair<string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(),
ManagedAssets.FrameworkAssemblies.Concat(
AppDomain.CurrentDomain.GetAssemblies()
.Where(each => !each.IsDynamic && !string.IsNullOrEmpty(each.Location) )
.Select(each => each.Location)
.Concat(new[]
{
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Microsoft.Rest.ClientRuntime.dll"),
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Microsoft.Rest.ClientRuntime.Azure.dll")
})
));
var result = await compiler.Compile(OutputKind.DynamicallyLinkedLibrary);
// if it failed compiling and we're in an interactive session
if (!result.Succeeded && System.Environment.OSVersion.Platform == PlatformID.Win32NT && System.Environment.UserInteractive)
{
var error = result.Messages.FirstOrDefault(each => each.Severity == DiagnosticSeverity.Error);
if (error != null)
{
// use this to dump the files to disk for examination
// open in Favorite Code Editor
InspectWithFavoriteCodeEditor(fileSystem.SaveFilesToTemp(GetType().Name), error.Location.GetMappedLineSpan());
}
}
return result;
}
示例10: GetLastTranscodingFiles
private static List<FileSystemMetadata> GetLastTranscodingFiles(string playlist, string segmentExtension, IFileSystem fileSystem, int count)
{
var folder = Path.GetDirectoryName(playlist);
try
{
return fileSystem.GetFiles(folder)
.Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase))
.OrderByDescending(fileSystem.GetLastWriteTimeUtc)
.Take(count)
.ToList();
}
catch (DirectoryNotFoundException)
{
return new List<FileSystemMetadata>();
}
}
示例11: FromFile
public static Project FromFile(string input, IFileSystem fileSystem)
{
var jObject = JsonConvert.DeserializeObject<Dictionary<string, JToken>>(input);
var project = new Project();
foreach (var entry in jObject)
{
var kindObj = entry.Key;
string[] list;
if (entry.Value is JArray)
list = entry.Value.ToObject<string[]>();
else
list = new[] {entry.Value.ToObject<string>()};
foreach (var item in list)
{
var info = fileSystem.GetFileInfo(PathInfo.Create(item));
if (info == null)
{
var globPattern = GlobPattern.Create(item);
if (!globPattern.IsWildcard)
throw new InvalidProjectFileException($"Could not find file {item}.");
var items = fileSystem.GetFiles(globPattern);
foreach (var file in items)
{
var fileItem = new FileProjectItem(kindObj, file, fileSystem);
ProjectItem existing;
if (!project.TryGetItemById(fileItem.Identifier, out existing))
project.AddItem(fileItem);
}
project.AddSubscription(fileSystem.Subscribe(globPattern, a =>
{
HandleChange(a, project, kindObj, fileSystem);
}));
}
else
{
AddFile(fileSystem, project, kindObj, info, item);
}
}
}
return project;
}