当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.GetAllFilesRecursively方法代码示例

本文整理汇总了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);
        }
开发者ID:RxSmart,项目名称:Squirrel.Windows,代码行数:60,代码来源:DeltaPackage.cs

示例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);
            }
        }
开发者ID:larsw,项目名称:NSync,代码行数:53,代码来源:ReleasePackage.cs

示例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());
 }
开发者ID:iamnilay3,项目名称:Shimmer,代码行数:8,代码来源:ReleasePackage.cs

示例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);
        }
开发者ID:iamnilay3,项目名称:Shimmer,代码行数:80,代码来源:ReleasePackage.cs

示例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);
        }
开发者ID:christianlang,项目名称:Shimmer,代码行数:44,代码来源:DeltaPackage.cs


注:本文中的System.IO.DirectoryInfo.GetAllFilesRecursively方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。