本文整理汇总了C#中System.IO.DirectoryInfo.GetAllFilesRecursively方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.GetAllFilesRecursively方法的具体用法?C# DirectoryInfo.GetAllFilesRecursively怎么用?C# DirectoryInfo.GetAllFilesRecursively使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.GetAllFilesRecursively方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDeltaPackage
public ReleasePackage CreateDeltaPackage(ReleasePackage basePackage, ReleasePackage newPackage, string outputFile)
{
Contract.Requires(basePackage != null);
Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));
if (basePackage.Version > newPackage.Version) {
var message = String.Format(
"You cannot create a delta package based on version {0} as it is a later version than {1}",
basePackage.Version,
newPackage.Version);
throw new InvalidOperationException(message);
}
if (basePackage.ReleasePackageFile == null) {
throw new ArgumentException("The base package's release file is null", "basePackage");
}
if (!File.Exists(basePackage.ReleasePackageFile)) {
throw new FileNotFoundException("The base package release does not exist", basePackage.ReleasePackageFile);
}
if (!File.Exists(newPackage.ReleasePackageFile)) {
throw new FileNotFoundException("The new package release does not exist", newPackage.ReleasePackageFile);
}
string baseTempPath = null;
string tempPath = null;
using (Utility.WithTempDirectory(out baseTempPath, null))
using (Utility.WithTempDirectory(out tempPath, null)) {
var baseTempInfo = new DirectoryInfo(baseTempPath);
var tempInfo = new DirectoryInfo(tempPath);
this.Log().Info("Extracting {0} and {1} into {2}",
basePackage.ReleasePackageFile, newPackage.ReleasePackageFile, tempPath);
var fz = new FastZip();
fz.ExtractZip(basePackage.ReleasePackageFile, baseTempInfo.FullName, null);
fz.ExtractZip(newPackage.ReleasePackageFile, tempInfo.FullName, null);
// Collect a list of relative paths under 'lib' and map them
// to their full name. We'll use this later to determine in
// the new version of the package whether the file exists or
// not.
var baseLibFiles = baseTempInfo.GetAllFilesRecursively()
.Where(x => x.FullName.ToLowerInvariant().Contains("lib" + Path.DirectorySeparatorChar))
.ToDictionary(k => k.FullName.Replace(baseTempInfo.FullName, ""), v => v.FullName);
var newLibDir = tempInfo.GetDirectories().First(x => x.Name.ToLowerInvariant() == "lib");
foreach (var libFile in newLibDir.GetAllFilesRecursively()) {
createDeltaForSingleFile(libFile, tempInfo, baseLibFiles);
}
ReleasePackage.addDeltaFilesToContentTypes(tempInfo.FullName);
fz.CreateZip(outputFile, tempInfo.FullName, true, null);
}
return new ReleasePackage(outputFile);
}
示例2: CreateDeltaPackage
public void CreateDeltaPackage(ReleasePackage baseFixture, string outputFile)
{
var baseTempPath = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
baseTempPath.Create();
var tempPath = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
tempPath.Create();
try {
var zf = new ZipFile(baseFixture.ReleasePackageFile);
zf.ExtractAll(baseTempPath.FullName);
zf = new ZipFile(ReleasePackageFile);
zf.ExtractAll(tempPath.FullName);
var baseLibFiles = baseTempPath.GetAllFilesRecursively()
.Where(x => x.FullName.ToLowerInvariant().Contains("lib" + Path.DirectorySeparatorChar))
.ToDictionary(k => k.FullName.Replace(baseTempPath.FullName, ""), v => v.FullName);
var libDir = tempPath.GetDirectories().First(x => x.Name.ToLowerInvariant() == "lib");
libDir.GetAllFilesRecursively().ForEach(libFile => {
var relativePath = libFile.FullName.Replace(tempPath.FullName, "");
if (!baseLibFiles.ContainsKey(relativePath)) {
this.Log().Info("{0} not found in base package, marking as new", relativePath);
return;
}
var oldData = File.ReadAllBytes(baseLibFiles[relativePath]);
var newData = File.ReadAllBytes(libFile.FullName);
if (bytesAreIdentical(oldData, newData)) {
this.Log().Info("{0} hasn't changed, writing dummy file", relativePath);
File.Create(libFile.FullName + ".diff").Dispose();
libFile.Delete();
return;
}
this.Log().Info("Delta patching {0} => {1}", baseLibFiles[relativePath], libFile.FullName);
using (var of = File.Create(libFile.FullName + ".diff")) {
BinaryPatchUtility.Create(oldData, newData, of);
libFile.Delete();
}
});
zf = new ZipFile(outputFile);
zf.AddDirectory(tempPath.FullName);
zf.Save();
} finally {
baseTempPath.Delete(true);
tempPath.Delete(true);
}
}
示例3: removeDeveloperDocumentation
void removeDeveloperDocumentation(DirectoryInfo expandedRepoPath)
{
expandedRepoPath.GetAllFilesRecursively()
.Where(x => x.Name.EndsWith(".dll", true, CultureInfo.InvariantCulture))
.Select(x => new FileInfo(x.FullName.ToLowerInvariant().Replace(".dll", ".xml")))
.Where(x => x.Exists)
.ForEach(x => x.Delete());
}
示例4: CreateDeltaPackage
public ReleasePackage CreateDeltaPackage(ReleasePackage baseFixture, string outputFile)
{
Contract.Requires(baseFixture != null && baseFixture.ReleasePackageFile != null);
Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));
string baseTempPath = null;
string tempPath = null;
using (Utility.WithTempDirectory(out baseTempPath))
using (Utility.WithTempDirectory(out tempPath)) {
var baseTempInfo = new DirectoryInfo(baseTempPath);
var tempInfo = new DirectoryInfo(tempPath);
using (var zf = new ZipFile(baseFixture.ReleasePackageFile)) {
zf.ExtractAll(baseTempInfo.FullName);
}
using (var zf = new ZipFile(ReleasePackageFile)) {
zf.ExtractAll(tempInfo.FullName);
}
// Collect a list of relative paths under 'lib' and map them
// to their full name. We'll use this later to determine in
// the new version of the package whether the file exists or
// not.
var baseLibFiles = baseTempInfo.GetAllFilesRecursively()
.Where(x => x.FullName.ToLowerInvariant().Contains("lib" + Path.DirectorySeparatorChar))
.ToDictionary(k => k.FullName.Replace(baseTempInfo.FullName, ""), v => v.FullName);
var newLibDir = tempInfo.GetDirectories().First(x => x.Name.ToLowerInvariant() == "lib");
// NB: There are three cases here that we'll handle:
//
// 1. Exists only in new => leave it alone, we'll use it directly.
// 2. Exists in both old and new => write a dummy file so we know
// to keep it.
// 3. Exists in old but changed in new => create a delta file
//
// The fourth case of "Exists only in old => delete it in new"
// is handled when we apply the delta package
newLibDir.GetAllFilesRecursively().ForEach(libFile => {
var relativePath = libFile.FullName.Replace(tempInfo.FullName, "");
if (!baseLibFiles.ContainsKey(relativePath)) {
this.Log().Info("{0} not found in base package, marking as new", relativePath);
return;
}
var oldData = File.ReadAllBytes(baseLibFiles[relativePath]);
var newData = File.ReadAllBytes(libFile.FullName);
if (bytesAreIdentical(oldData, newData)) {
this.Log().Info("{0} hasn't changed, writing dummy file", relativePath);
File.Create(libFile.FullName + ".diff").Dispose();
File.Create(libFile.FullName + ".shasum").Dispose();
libFile.Delete();
return;
}
this.Log().Info("Delta patching {0} => {1}", baseLibFiles[relativePath], libFile.FullName);
using (var of = File.Create(libFile.FullName + ".diff")) {
BinaryPatchUtility.Create(oldData, newData, of);
var rl = ReleaseEntry.GenerateFromFile(new MemoryStream(newData), libFile.Name + ".shasum");
File.WriteAllText(libFile.FullName + ".shasum", rl.EntryAsString, Encoding.UTF8);
libFile.Delete();
}
});
addDeltaFilesToContentTypes(tempInfo.FullName);
using (var zf = new ZipFile(outputFile)) {
zf.AddDirectory(tempInfo.FullName);
zf.Save();
}
}
return new ReleasePackage(outputFile);
}
示例5: CreateDeltaPackage
public ReleasePackage CreateDeltaPackage(ReleasePackage basePackage, ReleasePackage newPackage, string outputFile)
{
Contract.Requires(basePackage != null && basePackage.ReleasePackageFile != null);
Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));
string baseTempPath = null;
string tempPath = null;
using (Utility.WithTempDirectory(out baseTempPath))
using (Utility.WithTempDirectory(out tempPath)) {
var baseTempInfo = new DirectoryInfo(baseTempPath);
var tempInfo = new DirectoryInfo(tempPath);
using (var zf = new ZipFile(basePackage.ReleasePackageFile)) {
zf.ExtractAll(baseTempInfo.FullName);
}
using (var zf = new ZipFile(newPackage.ReleasePackageFile)) {
zf.ExtractAll(tempInfo.FullName);
}
// Collect a list of relative paths under 'lib' and map them
// to their full name. We'll use this later to determine in
// the new version of the package whether the file exists or
// not.
var baseLibFiles = baseTempInfo.GetAllFilesRecursively()
.Where(x => x.FullName.ToLowerInvariant().Contains("lib" + Path.DirectorySeparatorChar))
.ToDictionary(k => k.FullName.Replace(baseTempInfo.FullName, ""), v => v.FullName);
var newLibDir = tempInfo.GetDirectories().First(x => x.Name.ToLowerInvariant() == "lib");
newLibDir.GetAllFilesRecursively()
.ForEach(libFile => createDeltaForSingleFile(libFile, tempInfo, baseLibFiles));
ReleasePackage.addDeltaFilesToContentTypes(tempInfo.FullName);
using (var zf = new ZipFile(outputFile)) {
zf.AddDirectory(tempInfo.FullName);
zf.Save();
}
}
return new ReleasePackage(outputFile);
}