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


C# TempFile.WriteAllText方法代码示例

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


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

示例1: Can_read_and_write_text

 public void Can_read_and_write_text()
 {
     using( var file = new TempFile() )
     {
         var text = TestStrings.Internationalisation;
         file.WriteAllText(text);
         Assert.AreEqual(text, file.ReadAllText());
     }
 }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:9,代码来源:TempFileFixture.cs

示例2: Execute

        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// <c>true</c> if the task successfully executed; otherwise, <c>false</c>.
        /// </returns>
        public override bool Execute()
        {
            // Get the version control arguments, which are in the form of a URI
            var uri = new Uri(VersionControlArguments);

            if( Symbols == null )
            {
                Log.LogWarning("No symbol files passed to index");
                return true;
            }

            var vaultExecutable = VcsExecutablePath;

            var args = VersionControlArgumentsConverter.FromUri(uri);

            foreach (var item in Symbols)
            {
                var path = item.GetMetadata("FullPath");

                Log.LogMessage("Indexing source in file: {0}", path);

                var srcTool = new SrcTool(path);

                // Obtain a list of source files to index
                var files = srcTool.GetSourceFiles();
                files.ForEach( file => Log.LogMessage(MessageImportance.Low, "Source file: {0}", file) );

                // We'll write the SrcSrv stream to a temporary file, and that
                // will be passed to write to the debug symbols.
                var sb = new StringBuilder();

                var provider = new VaultVersionControlProvider(vaultExecutable);

                var indexer = new SourceIndexer(provider, args);

                sb.Append(indexer.GetIniBlock());
                sb.Append(indexer.GetVariableBlock());

                sb.AppendLine("SRCSRV: source files ---------------------------------------");

                var indexedFiles = files.Select(indexer.GetVersionIndexForFile).Where(line => !line.IsNullOrEmpty());

                // If we didn't manage to index any files, then move on to the next file
                if( indexedFiles.Count() == 0)
                {
                    Log.LogMessage("No files found to map against version control");
                    continue;
                }

                // Write out any successfully indexed files
                foreach (var line in indexedFiles )
                {
                    sb.AppendLine(line);
                }

                // Done indexing source
                sb.AppendLine("SRCSRV: end ------------------------------------------------");

                var lines = sb.ToString().Trim();

                Log.LogMessage(MessageImportance.Low, lines);

                // Write the stream to a temp file, which we can pass
                // to PdbStr);
                using (var temp = new TempFile())
                {
                    temp.WriteAllText(lines);

                    // Write the stream to the debug symbols
                    using (var pdbStr = new PdbStr())
                    {
                        pdbStr.PdbFileName = path;
                        pdbStr.StreamFileName = temp.FileInfo.FullName;
                        pdbStr.StreamName = "srcsrv";
                        pdbStr.Operation = PdbStrOperation.Write;

                        if(!pdbStr.Start()) throw new FoundationException("Couldn't start PdbStr: {0}", pdbStr.StartInfo.FileName);

                        var result = new ProcessResult(pdbStr);

                        pdbStr.WaitForExit();

                        var output = result.StandardOutput;

                        if (output.ContainsCaseInsensitive("error"))
                        {
                            Log.LogError(output);
                        }
                        else
                        {
                            Log.LogMessage(output);
                        }

                    }
//.........这里部分代码省略.........
开发者ID:DavidMoore,项目名称:Foundation,代码行数:101,代码来源:IndexSymbolSources.cs

示例3: Execute

        public override bool Execute()
        {
            Log.LogMessage("Generating resource file: {0}", OutputPath.GetMetadata("FullPath"));

            // Define all the variables for the file version information.
            var sb = new StringBuilder();

            var fileVersionValue = new Version(FileVersion);
            var productVersionValue = new Version(ProductVersion);
            var fileType = FileType.IsNullOrEmpty() ? MSBuild.FileType.Dll : (FileType) Enum.Parse(typeof (FileType), FileType);

            sb.AppendFormat("#define ISDEBUG {0}", IsDebug ? 1 : 0).AppendLine()
            .AppendFormat("#define ISPRERELEASE {0}", IsPreRelease ? 1 : 0).AppendLine()
            .AppendFormat("#define ISSPECIALBUILD {0}", IsSpecialBuild ? 1 : 0).AppendLine()
            .AppendFormat("#define ISPRIVATEBUILD {0}", IsPrivateBuild ? 1 : 0).AppendLine()
            .AppendFormat("#define ISPATCHED {0}", IsPatched ? 1 : 0).AppendLine()
            .AppendFormat("#define FILEVERSIONBINARY {0},{1},{2},{3}", fileVersionValue.Major, fileVersionValue.Minor, fileVersionValue.Build, fileVersionValue.Revision).AppendLine()
            .AppendFormat("#define FILEVERSIONSTRING \"{0}\\0\"", fileVersionValue).AppendLine()
            .AppendFormat("#define PRODUCTVERSIONBINARY {0},{1},{2},{3}", productVersionValue.Major, productVersionValue.Minor, productVersionValue.Build, productVersionValue.Revision).AppendLine()
            .AppendFormat("#define PRODUCTVERSIONSTRING \"{0}\\0\"", ProductVersion).AppendLine()
            .AppendFormat("#define COMPANYNAMESTRING \"{0}\\0\"", Company).AppendLine()
            .AppendFormat("#define INTERNALNAMESTRING \"{0}\\0\"", InternalName).AppendLine()
            .AppendFormat("#define COPYRIGHTSTRING \"{0}\\0\"", Copyright).AppendLine()
            .AppendFormat("#define ORIGINALFILENAMESTRING \"{0}\\0\"", OriginalFileName).AppendLine()
            .AppendFormat("#define PRODUCTNAMESTRING \"{0}\\0\"", ProductName).AppendLine()
            .AppendFormat("#define FILEDESCRIPTIONSTRING \"{0}\\0\"", FileDescription).AppendLine()
            .AppendFormat("#define FILETYPEVALUE {0}", (int)fileType).AppendLine()
            .AppendFormat("#define SPECIALBUILDSTRING \"{0}\\0\"", SpecialBuildDescription).AppendLine()
            .AppendFormat("#define PRIVATEBUILDSTRING \"{0}\\0\"", PrivateBuildDescription).AppendLine();

            if (!ManifestFile.IsNullOrEmpty()) sb.AppendFormat("#define MANIFESTFILEPATH \"{0}\\0\"", CString(ManifestFile) ).AppendLine();
            if (IconFile != null && fileType == MSBuild.FileType.Application) sb.AppendFormat("#define ICONFILEPATH \"{0}\\0\"", CString(IconFile.GetMetadata("FullPath"))).AppendLine();

            if (!AssemblyVersion.IsNullOrEmpty()) sb.AppendFormat("#define ASSEMBLYVERSIONSTRING \"{0}\\0\"", AssemblyVersion).AppendLine();

            // Add the guts of the resource file script, which uses the variables we
            // just declared to define the file version information and embed the manifest if applicable.
            sb.AppendLine(Resources.FileVersionInfo);

            Log.LogMessage(MessageImportance.Low, sb.ToString());

            // Create temporary file for the resource script));
            using (var tempFile = new TempFile("FileVersionInfo-" + Guid.NewGuid() + ".rc"))
            {
                // Write out the resource script contents
                tempFile.WriteAllText(sb.ToString());

                // Any additional script?
                if (!string.IsNullOrWhiteSpace(AdditionalResourceScript))
                {
                    using (var writer = tempFile.FileInfo.AppendText())
                    {
                        writer.WriteLine();
                        writer.WriteLine(CString(AdditionalResourceScript));
                    }
                }

                var compilerLocation = GetResourceCompilerLocation();

                // Compile the resource file
                var processStartInfo = new ProcessStartInfo(Path.Combine(compilerLocation, resourceCompilerRelativePath))
                {
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    Arguments = string.Format("/D _UNICODE /D UNICODE /l\"0x0409\" /nologo /fo\"{0}\" \"{1}\"",
                    OutputPath.GetMetadata("FullPath"), tempFile.FileInfo.FullName),
                    WindowStyle = ProcessWindowStyle.Hidden,
                    CreateNoWindow = true
                };

                Log.LogMessage("Executing: {0} {1}", processStartInfo.FileName, processStartInfo.Arguments);

                using (var process = Process.Start(processStartInfo))
                {
                    process.WaitForExit();

                    string output = process.StandardOutput.ReadToEnd();
                    if (output.Length > 0) Log.LogMessage(MessageImportance.Normal, output);

                    string errorStream = process.StandardError.ReadToEnd();
                    if (errorStream.Length > 0) Log.LogError(errorStream);

                    if (process.ExitCode == 0) return true;

                    Log.LogError("Non-zero exit code from rc.exe: " + process.ExitCode);

                    return false;
                }
            }
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:91,代码来源:GenerateFileVersionInfo.cs


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