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


C# IFileSystem.Exists方法代码示例

本文整理汇总了C#中IFileSystem.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.Exists方法的具体用法?C# IFileSystem.Exists怎么用?C# IFileSystem.Exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFileSystem的用法示例。


在下文中一共展示了IFileSystem.Exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: builder

        public void builder()
        {
            _filesystem = Substitute.For<IFileSystem>();
            _filesystem.GetPlatformRoot().Returns(The.Root);

            _filesystem.Exists(null).ReturnsForAnyArgs(true);

            _modules = Substitute.For<IModules>();
            _modules.Paths.Returns(new[] { "group1/proj1", "group1/proj2", "group2/proj3" });
            _modules.Repos.Returns(new[] { "p1Repo", "p2Repo", "p3Repo" });
            _locks = new List<AutoResetEvent> { new AutoResetEvent(true), new AutoResetEvent(true), new AutoResetEvent(true) };
            _modules.CreateAndSetLocks().Returns(_locks);

            _patterns = new Patterns
            {
                DependencyPattern = "*.dll",
                DependencyPath = (FilePath)"lib",
                Masters = new FilePath[] { }
            };

            _git = Substitute.For<IGit>();
            _depMgr = Substitute.For<IDependencyManager>();
            _ruleFac = Substitute.For<IRuleFactory>();
            _ruleFac.GetModules().Returns(_modules);
            _ruleFac.GetRulePatterns().Returns(_patterns);

            _buildCmd = Substitute.For<IBuildCmd>();

            _subject = new Builder(_filesystem, _git, _depMgr, _ruleFac, _buildCmd);
            _subject.Prepare();
            _subject.GetDependenciesAndBuild();
        }
开发者ID:i-e-b,项目名称:PlatformBuild,代码行数:32,代码来源:Builder_BuildProjects.cs

示例2: ManageFolders

        internal override void ManageFolders(IFileSystem fileSystem)
        {
            if (Folders != null)
            {
                // helper list to be able to modify Folders property inside the loop
                var iterate = new List<FolderInfo>(Folders);

                foreach (var folder in iterate)
                {
                    if (fileSystem.Exists(this, folder))
                    {
                        var directoryInfos = fileSystem.GetFolders(this, folder);
                        foreach (var directoryInfo in directoryInfos.OrderByDescending(x => x.Name))
                        {
                            var newFolder = new FolderInfo
                            {
                                Absolute = folder.Absolute,
                                Filter = folder.Filter,
                                Levels = new List<LogLevel>(folder.Levels),
                                Name = $"{folder.Name}_{directoryInfo.Name}",
                                Path = fileSystem.CombinePath(folder.Path, directoryInfo.Name),
                                OpeningLinePattern = folder.OpeningLinePattern
                            };

                            Folders.Insert(Folders.IndexOf(folder) + 1, newFolder);
                        }
                    }
                    else
                    {
                        Folders.Remove(folder);
                    }
                }
            }
        }
开发者ID:andy250,项目名称:caselog,代码行数:34,代码来源:HostInfo.cs

示例3: AssemblyInfoFileUpdate

        public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
        {
            if (!args.UpdateAssemblyInfo) return;

            if (args.Output != OutputType.Json)
                Console.WriteLine("Updating assembly info files");

            var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem);

            foreach (var assemblyInfoFile in assemblyInfoFiles)
            {
                var backupAssemblyInfo = assemblyInfoFile + ".bak";
                var localAssemblyInfo = assemblyInfoFile;
                fileSystem.Copy(assemblyInfoFile, backupAssemblyInfo, true);
                restoreBackupTasks.Add(() =>
                {
                    if (fileSystem.Exists(localAssemblyInfo))
                        fileSystem.Delete(localAssemblyInfo);
                    fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
                });
                cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));

                var assemblyVersion = variables.AssemblySemVer;
                var assemblyInfoVersion = variables.InformationalVersion;
                var assemblyFileVersion = variables.MajorMinorPatch + ".0";
                var fileContents = fileSystem.ReadAllText(assemblyInfoFile)
                    .RegexReplace(@"AssemblyVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyVersion(\"{0}\")", assemblyVersion))
                    .RegexReplace(@"AssemblyInformationalVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion))
                    .RegexReplace(@"AssemblyFileVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion));

                fileSystem.WriteAllText(assemblyInfoFile, fileContents);
            }
        }
开发者ID:Wikell,项目名称:GitVersion,代码行数:33,代码来源:AssemblyInfoFileUpdate.cs

示例4: builder

        public void builder()
        {
            _filesystem = Substitute.For<IFileSystem>();
            _filesystem.GetPlatformRoot().Returns(The.Root);

            var dbpath = The.Root.Navigate((FilePath)"group1/proj2/DatabaseScripts");
            _filesystem.Exists(null).ReturnsForAnyArgs(c=> c.Args()[0] as FilePath == dbpath);
            _filesystem.SortedDescendants(null,null).ReturnsForAnyArgs(new [] {(FilePath)"one",(FilePath)"two"});

            _modules = Substitute.For<IModules>();
            _modules.Paths.Returns(new[] {"group1/proj1", "group1/proj2", "group2/proj3"});
            _modules.Repos.Returns(new[] {"p1Repo", "p2Repo", "p3Repo"});
            _locks = new List<AutoResetEvent> { new AutoResetEvent(true), new AutoResetEvent(true), new AutoResetEvent(true) };
            _modules.CreateAndSetLocks().Returns(_locks);

            _git = Substitute.For<IGit>();
            _depMgr = Substitute.For<IDependencyManager>();
            _ruleFac = Substitute.For<IRuleFactory>();
            _ruleFac.GetModules().Returns(_modules);

            _buildCmd = Substitute.For<IBuildCmd>();

            _subject = new Builder(_filesystem, _git, _depMgr, _ruleFac, _buildCmd);
            _subject.Prepare();
            _subject.RebuildDatabases();
        }
开发者ID:i-e-b,项目名称:PlatformBuild,代码行数:26,代码来源:Builder_Databases.cs

示例5: StaticFileRouteHandler

        public StaticFileRouteHandler(string basePath, IReadOnlyDictionary<string, string> extensionsToMimeTypes, IFileSystem fileSystem)
        {
            _basePath = basePath.GetAbsoluteBasePathUri();
            _fileSystem = fileSystem ?? new PhysicalFileSystem();
            _mimeTypeProvider = new MimeTypeProvider(extensionsToMimeTypes ?? MimeTypeProvider.DefaultMimeTypesByExtension);

            if (!_fileSystem.Exists(_basePath))
            {
                throw new Exception($"Path at {_basePath} could not be found.");
            }
        }
开发者ID:anondesigns,项目名称:restup,代码行数:11,代码来源:StaticFileRouteHandler.cs

示例6: Provide

        public static Config Provide(string gitDirectory, IFileSystem fileSystem)
        {
            var configFilePath = GetConfigFilePath(gitDirectory);

            if (fileSystem.Exists(configFilePath))
            {
                var readAllText = fileSystem.ReadAllText(configFilePath);
                LegacyConfigNotifier.Notify(new StringReader(readAllText));

                return ConfigSerialiser.Read(new StringReader(readAllText));
            }

            return new Config();
        }
开发者ID:Wikell,项目名称:GitVersion,代码行数:14,代码来源:ConfigurationProvider.cs

示例7: GetAssemblyInfoFiles

        static IEnumerable<string> GetAssemblyInfoFiles(string workingDirectory, Arguments args, IFileSystem fileSystem)
        {
            if (args.UpdateAssemblyInfoFileName != null)
            {
                var fullPath = Path.Combine(workingDirectory, args.UpdateAssemblyInfoFileName);

                if (fileSystem.Exists(fullPath))
                {
                    return new[] { fullPath };
                }
            }

            return fileSystem.DirectoryGetFiles(workingDirectory, "AssemblyInfo.cs", SearchOption.AllDirectories);
        }
开发者ID:Wikell,项目名称:GitVersion,代码行数:14,代码来源:AssemblyInfoFileUpdate.cs

示例8: AssemblyInfoFileUpdate

        public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
        {
            if (!args.UpdateAssemblyInfo) return;

            if (args.Output != OutputType.Json)
                Logger.WriteInfo("Updating assembly info files");

            var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem).ToList();
            Logger.WriteInfo(string.Format("Found {0} files", assemblyInfoFiles.Count));

            var assemblyVersion = variables.AssemblySemVer;
            var assemblyVersionRegex = new Regex(@"AssemblyVersion\s*\(\s*""[^""]*""\s*\)");
            var assemblyVersionString = !string.IsNullOrWhiteSpace(assemblyVersion) ? string.Format("AssemblyVersion(\"{0}\")", assemblyVersion) : null;
            var assemblyInfoVersion = variables.InformationalVersion;
            var assemblyInfoVersionRegex = new Regex(@"AssemblyInformationalVersion\s*\(\s*""[^""]*""\s*\)");
            var assemblyInfoVersionString = string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion);
            var assemblyFileVersion = variables.MajorMinorPatch + ".0";
            var assemblyFileVersionRegex = new Regex(@"AssemblyFileVersion\s*\(\s*""[^""]*""\s*\)");
            var assemblyFileVersionString = string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion);

            foreach (var assemblyInfoFile in assemblyInfoFiles)
            {
                var backupAssemblyInfo = assemblyInfoFile.FullName + ".bak";
                var localAssemblyInfo = assemblyInfoFile.FullName;
                fileSystem.Copy(assemblyInfoFile.FullName, backupAssemblyInfo, true);
                restoreBackupTasks.Add(() =>
                {
                    if (fileSystem.Exists(localAssemblyInfo))
                        fileSystem.Delete(localAssemblyInfo);
                    fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
                });
                cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));

                var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
                var appendedAttributes = false;
                if (!string.IsNullOrWhiteSpace(assemblyVersion))
                {
                    fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
                }
                fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
                fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension, ref appendedAttributes);

                if (appendedAttributes)
                {
                    // If we appended any attributes, put a new line after them
                    fileContents += Environment.NewLine;
                }
                fileSystem.WriteAllText(assemblyInfoFile.FullName, fileContents);
            }
        }
开发者ID:qetza,项目名称:GitVersion,代码行数:50,代码来源:AssemblyInfoFileUpdate.cs

示例9: GetAssemblyInfoFiles

        static IEnumerable<string> GetAssemblyInfoFiles(string workingDirectory, Arguments args, IFileSystem fileSystem)
        {
            if (args.UpdateAssemblyInfoFileName != null)
            {
                var fullPath = Path.Combine(workingDirectory, args.UpdateAssemblyInfoFileName);

                if (fileSystem.Exists(fullPath))
                {
                    return new[] { fullPath };
                }
            }

            return fileSystem.DirectoryGetFiles(workingDirectory, "AssemblyInfo.*", SearchOption.AllDirectories)
                .Where(f => f.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".vb", StringComparison.OrdinalIgnoreCase));
        }
开发者ID:pierrebakker,项目名称:GitVersion,代码行数:15,代码来源:AssemblyInfoFileUpdate.cs

示例10: WriteSample

        public static void WriteSample(string gitDirectory, IFileSystem fileSystem)
        {
            var configFilePath = GetConfigFilePath(gitDirectory);

            if (!fileSystem.Exists(configFilePath))
            {
                using (var stream = fileSystem.OpenWrite(configFilePath))
                using (var writer = new StreamWriter(stream))
                {
                    ConfigSerialiser.WriteSample(writer);
                }
            }
            else
            {
                Logger.WriteError("Cannot write sample, GitVersionConfig.yaml already exists");
            }
        }
开发者ID:Wikell,项目名称:GitVersion,代码行数:17,代码来源:ConfigurationProvider.cs

示例11: Provide

        public static Config Provide(string gitDirectory, IFileSystem fileSystem)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException("fileSystem");
            }

            var configFilePath = GetConfigFilePath(gitDirectory);

            if (fileSystem.Exists(configFilePath))
            {
                var readAllText = fileSystem.ReadAllText(configFilePath);

                return ConfigSerializer.Read(new StringReader(readAllText));
            }

            return new Config();
        }
开发者ID:gitter-badger,项目名称:GitReleaseManager,代码行数:18,代码来源:ConfigurationProvider.cs

示例12: builder

        public void builder()
        {
            _filesystem = Substitute.For<IFileSystem>();
            _filesystem.GetPlatformRoot().Returns(The.Root);
            _missingRepo = The.Root.Append((FilePath)"/group1/proj2");

            _filesystem.Exists(null).ReturnsForAnyArgs(c=> (c.Args()[0] as FilePath !=_missingRepo));

            _modules = Substitute.For<IModules>();
            _modules.Paths.Returns(new[] {"group1/proj1", "group1/proj2", "group2/proj3"});
            _modules.Repos.Returns(new[] {"p1Repo", "p2Repo", "p3Repo"});

            _git = Substitute.For<IGit>();
            _depMgr = Substitute.For<IDependencyManager>();
            _ruleFac = Substitute.For<IRuleFactory>();
            _ruleFac.GetModules().Returns(_modules);

            _subject = new Builder(_filesystem, _git, _depMgr, _ruleFac, null);
            _subject.Prepare();
        }
开发者ID:i-e-b,项目名称:PlatformBuild,代码行数:20,代码来源:Builder_WhenPreparing.cs

示例13: AssemblyInfoFileUpdate

        public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
        {
            if (!args.UpdateAssemblyInfo) return;

            if (args.Output != OutputType.Json)
                Logger.WriteInfo("Updating assembly info files");

            var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem);
            Logger.WriteInfo(string.Format("Found {0} files", assemblyInfoFiles.Count()));

            var assemblyVersion = variables.AssemblySemVer;
            var assemblyVersionRegex = new Regex(@"AssemblyVersion\(""[^""]*""\)");
            var assemblyVersionString = string.Format("AssemblyVersion(\"{0}\")", assemblyVersion);
            var assemblyInfoVersion = variables.InformationalVersion;
            var assemblyInfoVersionRegex = new Regex(@"AssemblyInformationalVersion\(""[^""]*""\)");
            var assemblyInfoVersionString = string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion);
            var assemblyFileVersion = variables.MajorMinorPatch + ".0";
            var assemblyFileVersionRegex = new Regex(@"AssemblyFileVersion\(""[^""]*""\)");
            var assemblyFileVersionString = string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion);

            foreach (var assemblyInfoFile in assemblyInfoFiles.Select(f => new FileInfo(f)))
            {
                var backupAssemblyInfo = assemblyInfoFile.FullName + ".bak";
                var localAssemblyInfo = assemblyInfoFile.FullName;
                fileSystem.Copy(assemblyInfoFile.FullName, backupAssemblyInfo, true);
                restoreBackupTasks.Add(() =>
                {
                    if (fileSystem.Exists(localAssemblyInfo))
                        fileSystem.Delete(localAssemblyInfo);
                    fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
                });
                cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));

                var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
                fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString);
                fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString);
                fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString);

                fileSystem.WriteAllText(assemblyInfoFile.FullName, fileContents);
            }
        }
开发者ID:Tungsten78,项目名称:GitVersion,代码行数:41,代码来源:AssemblyInfoFileUpdate.cs

示例14: WriteSample

        public static void WriteSample(string targetDirectory, IFileSystem fileSystem)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException("fileSystem");
            }

            var configFilePath = GetConfigFilePath(targetDirectory);

            if (!fileSystem.Exists(configFilePath))
            {
                using (var stream = fileSystem.OpenWrite(configFilePath))
                using (var writer = new StreamWriter(stream))
                {
                    ConfigSerializer.WriteSample(writer);
                }
            }
            else
            {
                Logger.WriteError("Cannot write sample, GitReleaseManager.yaml already exists");
            }
        }
开发者ID:gitter-badger,项目名称:GitReleaseManager,代码行数:22,代码来源:ConfigurationProvider.cs

示例15: builder

        public void builder()
        {
            _filesystem = Substitute.For<IFileSystem>();
            _filesystem.GetPlatformRoot().Returns(The.Root);

            _filesystem.Exists(null).ReturnsForAnyArgs(c=> (c.Args()[0] as FilePath != (FilePath)"group1/proj2"));

            _modules = Substitute.For<IModules>();
            _modules.Paths.Returns(new[] {"group1/proj1", "group1/proj2", "group2/proj3"});
            _modules.Repos.Returns(new[] {"p1Repo", "p2Repo", "p3Repo"});
            _locks = new List<AutoResetEvent> { new AutoResetEvent(false), new AutoResetEvent(false), new AutoResetEvent(false) };
            _modules.CreateAndSetLocks().Returns(_locks);

            _git = Substitute.For<IGit>();
            _depMgr = Substitute.For<IDependencyManager>();
            _ruleFac = Substitute.For<IRuleFactory>();
            _ruleFac.GetModules().Returns(_modules);

            _subject = new Builder(_filesystem, _git, _depMgr, _ruleFac, null);
            _subject.Prepare();
            _subject.PullRepos();
        }
开发者ID:i-e-b,项目名称:PlatformBuild,代码行数:22,代码来源:Builder_Pulling.cs


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