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


C# IFileSystem.ReadAllText方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: GetTemplateOutput

        private static TemplateRenderingResult GetTemplateOutput(Project project, IFileSystem fileSystem, string template, string projectRelativeOutputPath, Hashtable model, bool force)
        {
            var templateFullPath = FindTemplateAssertExists(project, fileSystem, template);
            var templateContent = fileSystem.ReadAllText(templateFullPath);
            templateContent = PreprocessTemplateContent(templateContent);

            // Create the T4 host and engine
            using (var host = new DynamicTextTemplatingEngineHost { TemplateFile = templateFullPath }) {
                var t4Engine = GetT4Engine();

                // Make it possible to reference the same assemblies that your project references
                // using <@ Assembly @> directives.
                host.AddFindableAssembly(FindProjectAssemblyIfExists(project));
                foreach (dynamic reference in ((dynamic)project.Object).References) {
                    if ((!string.IsNullOrEmpty(reference.Path)) && (!reference.AutoReferenced))
                        host.AddFindableAssembly(reference.Path);
                }

                string projectRelativeOutputPathWithExtension = null;
                ProjectItem existingOutputProjectItem = null;
                if (!string.IsNullOrEmpty(projectRelativeOutputPath)) {
                    // Respect the <#@ Output Extension="..." #> directive
                    projectRelativeOutputPathWithExtension = projectRelativeOutputPath + GetOutputExtension(host, t4Engine, templateContent);

                    // Resolve the output path and ensure it doesn't already exist (unless "Force" is set)
                    var outputDiskPath = Path.Combine(project.GetFullPath(), projectRelativeOutputPathWithExtension);
                    existingOutputProjectItem = project.GetProjectItem(projectRelativeOutputPathWithExtension);
                    if (existingOutputProjectItem != null)
                        outputDiskPath = existingOutputProjectItem.GetFullPath();
                    if ((!force) && fileSystem.FileExists(outputDiskPath)) {
                        return new TemplateRenderingResult(projectRelativeOutputPathWithExtension) { SkipBecauseFileExists = true };
                    }
                }

                // Convert the incoming Hashtable to a dynamic object with properties for each of the Hashtable entries
                host.Model = DynamicViewModel.FromObject(model);

                // Run the text transformation
                var templateOutput = t4Engine.ProcessTemplate(templateContent, host);
                return new TemplateRenderingResult(projectRelativeOutputPathWithExtension) {
                    Content = templateOutput,
                    Errors = host.Errors,
                    ExistingProjectItemToOverwrite = existingOutputProjectItem,
                };
            }
        }
开发者ID:tikrimi,项目名称:MvcScaffolding4TwitterBootstrapMvc,代码行数:46,代码来源:InvokeScaffoldTemplateCmdlet.cs

示例7: IsFileEmpty

 public static bool IsFileEmpty(IFileSystem fileSystem, string fileName)
 {
     var fileContents = fileSystem.ReadAllText(fileName);
     return string.IsNullOrEmpty(fileContents);
 }
开发者ID:dchetwynd,项目名称:Mocking-with-Microsoft-Fakes,代码行数:5,代码来源:FileReader.cs

示例8: Load

 public void Load(IFileSystem fs)
 {
     Text = fs.ReadAllText(FileName);
     Dirty = false;
 }
开发者ID:alfar,项目名称:WordBuilder,代码行数:5,代码来源:Document.cs

示例9: GetConfigFileHash

        private static string GetConfigFileHash(IFileSystem fileSystem, GitPreparer gitPreparer)
        {
            // will return the same hash even when config file will be moved
            // from workingDirectory to rootProjectDirectory. It's OK. Config essentially is the same.
            var configFilePath = ConfigurationProvider.SelectConfigFilePath(gitPreparer, fileSystem);
            if (!fileSystem.Exists(configFilePath))
            {
                return string.Empty;
            }

            var configFileContent = fileSystem.ReadAllText(configFilePath);
            return GetHash(configFileContent);
        }
开发者ID:GitTools,项目名称:GitVersion,代码行数:13,代码来源:GitVersionCacheKeyFactory.cs


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