C# Stream.ToString的代码示例
通过代码示例来学习C# Stream.ToString方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
Stream.ToString是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Stream.ToString() 已经帮大家高亮显示了,大家可以重点学习Stream.ToString() 方法的写法,从而快速掌握该方法的应用。
Stream.ToString的代码示例1 - TryCopyBlobContentStream()
using System.IO; public virtual bool TryCopyBlobContentStream( string sha, CancellationToken cancellationToken, RequestSource requestSource, Action
writeAction) { RetryWrapper retrier = new RetryWrapper (this.GitObjectRequestor.RetryConfig.MaxAttempts, cancellationToken); retrier.OnFailure += errorArgs => { EventMetadata metadata = new EventMetadata(); metadata.Add("sha", sha); metadata.Add("AttemptNumber", errorArgs.TryCount); metadata.Add("WillRetry", errorArgs.WillRetry); if (errorArgs.Error != null) { metadata.Add("Exception", errorArgs.Error.ToString()); } string message = "TryCopyBlobContentStream: Failed to provide blob contents"; if (errorArgs.WillRetry) { this.Tracer.RelatedWarning(metadata, message, Keywords.Telemetry); } else { this.Tracer.RelatedError(metadata, message); } }; RetryWrapper .InvocationResult invokeResult = retrier.Invoke( tryCount => { bool success = this.Context.Repository.TryCopyBlobContentStream(sha, writeAction); if (success) { return new RetryWrapper .CallbackResult(true); } else { // Pass in false for retryOnFailure because the retrier in this method manages multiple attempts if (this.TryDownloadAndSaveObject(sha, cancellationToken, requestSource, retryOnFailure: false) == DownloadAndSaveObjectResult.Success) { if (this.Context.Repository.TryCopyBlobContentStream(sha, writeAction)) { return new RetryWrapper .CallbackResult(true); } } return new RetryWrapper .CallbackResult(error: null, shouldRetry: true); } }); return invokeResult.Result; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:58,代码来源:GVFSGitObjects.cs
在TryCopyBlobContentStream()方法中,Stream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.ToString的代码示例2 - WriteAllEntries()
using System.IO; private void WriteAllEntries(uint version, bool isFinal) { try { using (Stream indexStream = new FileStream(this.indexLockPath, FileMode.Create, FileAccess.Write, FileShare.None)) using (BinaryWriter writer = new BinaryWriter(indexStream)) { writer.Write(IndexHeader); writer.Write(EndianHelper.Swap(version)); writer.Write((uint)0); // Number of entries placeholder uint lastStringLength = 0; LsTreeEntry entry; while (this.entryQueue.TryTake(out entry, Timeout.Infinite)) { this.WriteEntry(writer, version, entry.Sha, entry.Filename, ref lastStringLength); } // Update entry count writer.BaseStream.Position = EntryCountOffset; writer.Write(EndianHelper.Swap(this.entryCount)); writer.Flush(); } this.AppendIndexSha(); if (isFinal) { this.ReplaceExistingIndex(); } } catch (Exception e) { this.tracer.RelatedError("Failed to generate index: {0}", e.ToString()); this.HasFailures = true; } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:38,代码来源:GitIndexGenerator.cs
在WriteAllEntries()方法中,Stream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.ToString的代码示例3 - GetLooseBlobStateAtPath()
using System.IO; private LooseBlobState GetLooseBlobStateAtPath(string blobPath, Action
writeAction, out long size) { bool corruptLooseObject = false; try { if (this.fileSystem.FileExists(blobPath)) { using (Stream file = this.fileSystem.OpenFileStream(blobPath, FileMode.Open, FileAccess.Read, FileShare.Read, callFlushFileBuffers: false)) { // The DeflateStream header starts 2 bytes into the gzip header, but they are otherwise compatible file.Position = 2; using (DeflateStream deflate = new DeflateStream(file, CompressionMode.Decompress)) { if (!ReadLooseObjectHeader(deflate, out size)) { corruptLooseObject = true; return LooseBlobState.Corrupt; } writeAction?.Invoke(deflate, size); return LooseBlobState.Exists; } } } size = -1; return LooseBlobState.Missing; } catch (InvalidDataException ex) { corruptLooseObject = true; EventMetadata metadata = new EventMetadata(); metadata.Add("blobPath", blobPath); metadata.Add("Exception", ex.ToString()); this.tracer.RelatedWarning(metadata, nameof(this.GetLooseBlobStateAtPath) + ": Failed to stream blob (InvalidDataException)", Keywords.Telemetry); size = -1; return LooseBlobState.Corrupt; } catch (IOException ex) { EventMetadata metadata = new EventMetadata(); metadata.Add("blobPath", blobPath); metadata.Add("Exception", ex.ToString()); this.tracer.RelatedWarning(metadata, nameof(this.GetLooseBlobStateAtPath) + ": Failed to stream blob from disk", Keywords.Telemetry); size = -1; return LooseBlobState.Unknown; } finally { if (corruptLooseObject) { string corruptBlobsFolderPath = Path.Combine(this.enlistment.EnlistmentRoot, GVFSPlatform.Instance.Constants.DotGVFSRoot, GVFSConstants.DotGVFS.CorruptObjectsName); string corruptBlobPath = Path.Combine(corruptBlobsFolderPath, Path.GetRandomFileName()); EventMetadata metadata = new EventMetadata(); metadata.Add("blobPath", blobPath); metadata.Add("corruptBlobPath", corruptBlobPath); metadata.Add(TracingConstants.MessageKey.InfoMessage, nameof(this.GetLooseBlobStateAtPath) + ": Renaming corrupt loose object"); this.tracer.RelatedEvent(EventLevel.Informational, nameof(this.GetLooseBlobStateAtPath) + "_RenameCorruptObject", metadata); try { this.fileSystem.CreateDirectory(corruptBlobsFolderPath); this.fileSystem.MoveFile(blobPath, corruptBlobPath); } catch (Exception e) { metadata = new EventMetadata(); metadata.Add("blobPath", blobPath); metadata.Add("blobBackupPath", corruptBlobPath); metadata.Add("Exception", e.ToString()); metadata.Add(TracingConstants.MessageKey.WarningMessage, nameof(this.GetLooseBlobStateAtPath) + ": Failed to rename corrupt loose object"); this.tracer.RelatedEvent(EventLevel.Warning, nameof(this.GetLooseBlobStateAtPath) + "_RenameCorruptObjectFailed", metadata, Keywords.Telemetry); } } } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:82,代码来源:GitRepo.cs
在GetLooseBlobStateAtPath()方法中,Stream的代码示例类中的ToString的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.ToString的代码示例4 - Run()
using System.IO; public static ProcessResult Run(ProcessStartInfo processInfo, string errorMsgDelimeter = "\r\n", object executionLock = null, Stream inputStream = null) { using (Process executingProcess = new Process()) { string output = string.Empty; string errors = string.Empty; // From https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx // To avoid deadlocks, use asynchronous read operations on at least one of the streams. // Do not perform a synchronous read to the end of both redirected streams. executingProcess.StartInfo = processInfo; executingProcess.ErrorDataReceived += (sender, args) => { if (args.Data != null) { errors = errors + args.Data + errorMsgDelimeter; } }; if (executionLock != null) { lock (executionLock) { output = StartProcess(executingProcess, inputStream); } } else { output = StartProcess(executingProcess, inputStream); } return new ProcessResult(output.ToString(), errors.ToString(), executingProcess.ExitCode); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:36,代码来源:ProcessHelper.cs
在Run()方法中,Stream的代码示例类中的ToString的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.ToString的代码示例5 - ReadRegistry()
using System.IO; public Dictionary
ReadRegistry() { Dictionary allRepos = new Dictionary (GVFSPlatform.Instance.Constants.PathComparer); using (Stream stream = this.fileSystem.OpenFileStream( Path.Combine(this.registryParentFolderPath, RegistryName), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read, callFlushFileBuffers: false)) { using (StreamReader reader = new StreamReader(stream)) { string versionString = reader.ReadLine(); int version; if (!int.TryParse(versionString, out version) || version > RegistryVersion) { if (versionString != null) { EventMetadata metadata = new EventMetadata(); metadata.Add("Area", EtwArea); metadata.Add("OnDiskVersion", versionString); metadata.Add("ExpectedVersion", versionString); this.tracer.RelatedError(metadata, "ReadRegistry: Unsupported version"); } return allRepos; } while (!reader.EndOfStream) { string entry = reader.ReadLine(); if (entry.Length > 0) { try { RepoRegistration registration = RepoRegistration.FromJson(entry); string errorMessage; string normalizedEnlistmentRootPath = registration.EnlistmentRoot; if (this.fileSystem.TryGetNormalizedPath(registration.EnlistmentRoot, out normalizedEnlistmentRootPath, out errorMessage)) { if (!normalizedEnlistmentRootPath.Equals(registration.EnlistmentRoot, GVFSPlatform.Instance.Constants.PathComparison)) { EventMetadata metadata = new EventMetadata(); metadata.Add("registration.EnlistmentRoot", registration.EnlistmentRoot); metadata.Add(nameof(normalizedEnlistmentRootPath), normalizedEnlistmentRootPath); metadata.Add(TracingConstants.MessageKey.InfoMessage, $"{nameof(this.ReadRegistry)}: Mapping registered enlistment root to final path"); this.tracer.RelatedEvent(EventLevel.Informational, $"{nameof(this.ReadRegistry)}_NormalizedPathMapping", metadata); } } else { EventMetadata metadata = new EventMetadata(); metadata.Add("registration.EnlistmentRoot", registration.EnlistmentRoot); metadata.Add("NormalizedEnlistmentRootPath", normalizedEnlistmentRootPath); metadata.Add("ErrorMessage", errorMessage); this.tracer.RelatedWarning(metadata, $"{nameof(this.ReadRegistry)}: Failed to get normalized path name for registed enlistment root"); } if (normalizedEnlistmentRootPath != null) { allRepos[normalizedEnlistmentRootPath] = registration; } } catch (Exception e) { EventMetadata metadata = new EventMetadata(); metadata.Add("Area", EtwArea); metadata.Add("entry", entry); metadata.Add("Exception", e.ToString()); this.tracer.RelatedError(metadata, "ReadRegistry: Failed to read entry"); } } } } } return allRepos; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:83,代码来源:RepoRegistry.cs
在ReadRegistry()方法中,Stream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.ToString的代码示例6 - Load()
using System.IO; public void Load(System.IO.Stream stream) { Text = FileName; Renderer = new GenericModelRenderer(); ModelData = new CMDL(stream); TreeNode meshFolder = new TreeNode("Meshes"); Nodes.Add(meshFolder); Nodes.Add(texFolder); Nodes.Add(skeletonFolder); Nodes.Add(shaderFolder); Model = ToGeneric(); foreach (var mat in ModelData.Materials) shaderFolder.Nodes.Add(new TreeNode(mat.Name + "_" + mat.ID.ToString())); foreach (GenericRenderedObject mesh in Model.Objects) { Renderer.Meshes.Add(mesh); meshFolder.Nodes.Add(mesh); } foreach (var tex in TextureList) { Renderer.Textures.Add(tex); texFolder.Nodes.Add(tex); } Renderer.Skeleton = Model.GenericSkeleton; DrawableContainer = new DrawableContainer(); DrawableContainer.Name = FileName; DrawableContainer.Drawables.Add(Renderer); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:38,代码来源:CModel.cs
在Load()方法中,Stream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.ToString的代码示例7 - Load()
public void Load(System.IO.Stream stream) { try { header = new Header(); header.Read(new FileReader(stream)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } this.Text = FileName; foreach (var bone in header.Nodes) header.AnimGroups.Add(bone); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:18,代码来源:CSAB.cs
在Load()方法中,Stream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.ToString的代码示例8 - SaveFileForCompression()
using System.IO; private void SaveFileForCompression(bool Compress, string[] fileNames, ICompressionFormat compressionFormat) { if (fileNames.Length == 0) return; string ext = Compress ? ".comp" : ""; if (compressionFormat.Extension.Length > 0 && Compress) ext = compressionFormat.Extension[0].Replace("*", string.Empty); List
failedFiles = new List (); if (fileNames.Length > 1) { FolderSelectDialog ofd = new FolderSelectDialog(); if (ofd.ShowDialog() == DialogResult.OK) { foreach (var file in fileNames) { string name = Path.GetFileName(file); name = name.Count(c => c == '.') > 1 && !Compress ? name.Remove(name.LastIndexOf('.')) : name; using (var data = new FileStream(file, FileMode.Open, FileAccess.Read)) { try { Stream stream; if (Compress) stream = compressionFormat.Compress(data); else { compressionFormat.Identify(data, file); stream = compressionFormat.Decompress(data); } if (stream != null) { stream.ExportToFile($"{ofd.SelectedPath}/{name}{ext}"); stream.Flush(); stream.Close(); } } catch (Exception ex) { failedFiles.Add($"{file} \n\n {ex} \n\n"); } } } if (failedFiles.Count > 0) { string action = Compress ? "compress" : "decompress"; STErrorDialog.Show($"Some files failed to {action}! See detail list of failed files.", "Switch Toolbox", string.Join("\n", failedFiles.ToArray())); } else MessageBox.Show("Files batched successfully!"); } } else { SaveFileDialog sfd = new SaveFileDialog(); string name = Path.GetFileName(fileNames[0]); sfd.FileName = name + ext; sfd.Filter = "All files(*.*)|*.*"; Cursor.Current = Cursors.Default; if (sfd.ShowDialog() == DialogResult.OK) { try { using (var data = new FileStream(fileNames[0], FileMode.Open, FileAccess.Read)) { Stream stream; if (Compress) stream = compressionFormat.Compress(data); else { compressionFormat.Identify(data, fileNames[0]); stream = compressionFormat.Decompress(data); } if (stream != null) { stream.ExportToFile(sfd.FileName); stream.Flush(); stream.Close(); MessageBox.Show($"File has been saved to {sfd.FileName}", "Save Notification"); } } } catch (Exception ex) { string action = Compress ? "compress" : "decompress"; STErrorDialog.Show($"Failed to {action}! See details for info.", "Switch Toolbox", ex.ToString()); } } } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:99,代码来源:CompressionMenus.cs
在SaveFileForCompression()方法中,Stream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的Stream.ToString方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。