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


C# MemoryStream.ReadToEnd方法代码示例

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


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

示例1: CreatePackageAddsVersionStampIfFrameworkAssembliesAreUsed

        public void CreatePackageAddsVersionStampIfFrameworkAssembliesAreUsed()
        {
            // Arrange
            PackageBuilder builder = new PackageBuilder() {
                Id = "A",
                Version = new Version("1.0"),
                Description = "Descriptions",
            };
            builder.Authors.Add("David");
            builder.FrameworkReferences.Add(new FrameworkAssemblyReference("System.Web"));
            var ms = new MemoryStream();

            // Act
            Manifest.Create(builder).Save(ms);
            ms.Seek(0, SeekOrigin.Begin);

            // Assert
            Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-8""?>
            <package xmlns=""http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"">
              <metadata schemaVersion=""2"">
            <id>A</id>
            <version>1.0</version>
            <authors>David</authors>
            <owners>David</owners>
            <requireLicenseAcceptance>false</requireLicenseAcceptance>
            <description>Descriptions</description>
            <frameworkAssemblies>
              <frameworkAssembly assemblyName=""System.Web"" targetFramework="""" />
            </frameworkAssemblies>
              </metadata>
            </package>", ms.ReadToEnd());
        }
开发者ID:jacksonh,项目名称:nuget,代码行数:32,代码来源:PackageBuilderTest.cs

示例2: OwnersFallsBackToAuthorsIfNoneSpecified

        public void OwnersFallsBackToAuthorsIfNoneSpecified()
        {
            // Arrange
            PackageBuilder builder = new PackageBuilder()
            {
                Id = "A",
                Version = new SemanticVersion("1.0"),
                Description = "Description"
            };
            builder.Authors.Add("JohnDoe");
            var ms = new MemoryStream();

            // Act
            Manifest.Create(builder).Save(ms);
            ms.Seek(0, SeekOrigin.Begin);

            // Assert
            Assert.Equal(@"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"">
  <metadata>
    <id>A</id>
    <version>1.0</version>
    <authors>JohnDoe</authors>
    <owners>JohnDoe</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
  </metadata>
</package>", ms.ReadToEnd());
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:29,代码来源:PackageBuilderTest.cs

示例3: ReleaseNotesAttributeIsRecognized

        public void ReleaseNotesAttributeIsRecognized()
        {
            // Arrange
            PackageBuilder builder = new PackageBuilder()
            {
                Id = "A",
                Version = new SemanticVersion("1.0"),
                Description = "Description",
                ReleaseNotes = "Release Notes"
            };
            builder.Authors.Add("David");
            var ms = new MemoryStream();

            // Act
            Manifest.Create(builder).Save(ms);
            ms.Seek(0, SeekOrigin.Begin);

            // Assert
            Assert.Equal(@"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"">
  <metadata>
    <id>A</id>
    <version>1.0</version>
    <authors>David</authors>
    <owners>David</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
    <releaseNotes>Release Notes</releaseNotes>
  </metadata>
</package>", ms.ReadToEnd());
        }
开发者ID:anurse,项目名称:NuGet,代码行数:31,代码来源:PackageBuilderTest.cs

示例4: ReadToEnd_should_return_all_bytes

        public void ReadToEnd_should_return_all_bytes()
        {
            var data = new byte[] { 0x1, 0x2, 0x3 };
            var stream = new MemoryStream(data);

            stream.ReadToEnd().Should().ContainInOrder(data);
        }
开发者ID:jasonreimer,项目名称:Praetorium,代码行数:7,代码来源:IOExtensionsSpecs.cs

示例5: AddingBindingRedirectToEmptyConfig

        public void AddingBindingRedirectToEmptyConfig()
        {
            // Arrange            
            var mockFileSystem = new Mock<IFileSystem>();
            mockFileSystem.Setup(m => m.FileExists("config")).Returns(true);
            mockFileSystem.Setup(m => m.OpenFile("config")).Returns(@"<configuration></configuration>".AsStream());
            var ms = new MemoryStream();
            mockFileSystem.Setup(m => m.AddFile("config", It.IsAny<Stream>())).Callback<string, Stream>((path, stream) =>
            {
                stream.CopyTo(ms);
                ms.Seek(0, SeekOrigin.Begin);
            });

            var bindingRedirectManager = new BindingRedirectManager(mockFileSystem.Object, "config");
            AssemblyBinding assemblyBinding = GetAssemblyBinding("AssemblyName", "token", "3.0.0.0");

            // Act
            bindingRedirectManager.AddBindingRedirects(new[] { assemblyBinding });

            // Assert
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <runtime>
    <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
      <dependentAssembly>
        <assemblyIdentity name=""AssemblyName"" publicKeyToken=""token"" culture=""neutral"" />
        <bindingRedirect oldVersion=""0.0.0.0-3.0.0.0"" newVersion=""3.0.0.0"" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>", ms.ReadToEnd());
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:32,代码来源:BindingRedirectManagerTest.cs

示例6: GetThumbnail

 public static byte[] GetThumbnail(this Stream stream, int width, int height)
 {
     Image image = new Bitmap(width, height);
     System.Drawing.Graphics.FromImage(image).DrawImage(Bitmap.FromStream(stream), 0, 0, width, height);
     Stream buffer = new MemoryStream();
     image.Save(buffer, ImageFormat.Jpeg);
     return buffer.ReadToEnd();
 }
开发者ID:koneta,项目名称:MangaPortal,代码行数:8,代码来源:Utility.cs

示例7: ReadStream

 private static string ReadStream(Action<Stream> write)
 {
     using (var stream = new MemoryStream())
     {
         write(stream);
         return stream.ReadToEnd();
     }
 }
开发者ID:carl-berg,项目名称:Bender,代码行数:8,代码来源:Extensions.cs

示例8: ToNuspecFileText

 private string ToNuspecFileText()
 {
     using (var stream = new MemoryStream())
     {
         _manifest.Save(stream, validate: false);
         stream.Seek(0, SeekOrigin.Begin);
         var content = stream.ReadToEnd();
         return RemoveSchemaNamespace(content);
     }
 }
开发者ID:modulexcite,项目名称:NuGet.Extensions,代码行数:10,代码来源:NuspecBuilder.cs

示例9: ToCSharp

        public static string ToCSharp(this CodeCompileUnit unit)
        {
            using (var stream = new MemoryStream())
            {
                var csharp = new CSharpCodeProvider();

                var writer = new IndentedTextWriter(new StreamWriter(stream));
                csharp.GenerateCodeFromCompileUnit(unit, writer, new CodeGeneratorOptions());
                writer.Flush();

                return stream.ReadToEnd();
            }
        }
开发者ID:ByteCarrot,项目名称:Masslog,代码行数:13,代码来源:CodeCompileUnitExtensions.cs

示例10: OnOpenFile


//.........这里部分代码省略.........
                                // Enumerate all shapes.
                                foreach (Shape shape in shapefile)
                                {
                                    // Shape basic information.
                                    //this.textBox.AppendText(string.Format("{0} {1} {2} ", shape.RecordNumber, shape.Type, shape.GetMetadata("name")));

                                    // Create a new shape.
                                    MapShape mapShape;
                                    switch (shape.Type)
                                    {
                                        case ShapeType.Point:
                                            ShapePoint shapePoint = shape as ShapePoint;
                                            mapShape = new MapShapePoint(new MapPoint(shapePoint.Point.X, shapePoint.Point.Y));
                                            break;
                                        case ShapeType.Polygon:
                                            ShapePolygon shapePolygon = shape as ShapePolygon;

                                            //this.textBox.AppendText(string.Format(": {0}", shapePolygon.Parts.Count));

                                            MapShapePolygon mapShapePolygon = new MapShapePolygon(new MapRectangle(
                                                shapePolygon.BoundingBox.Left,
                                                shapePolygon.BoundingBox.Top,
                                                shapePolygon.BoundingBox.Right,
                                                shapePolygon.BoundingBox.Bottom));
                                            foreach(PointD[] part in shapePolygon.Parts)
                                            {
                                                MapPart mapPart = new MapPart();
                                                foreach (PointD point in part)
                                                {
                                                    mapPart.Points.Add(point.X, point.Y);
                                                }
                                                mapShapePolygon.Parts.Add(mapPart);
                                            }
                                            mapShape = mapShapePolygon;
                                            break;
                                        default:
                                            throw new NotSupportedException(string.Format("Shape type {0} is not supported.", shape.Type));
                                    }
                                    // Add the shape metadata.
                                    foreach (string name in shape.GetMetadataNames())
                                    {
                                        mapShape.Metadata[name] = shape.GetMetadata(name);
                                    }
                                    // Add the shape to the map.
                                    map.Shapes.Add(mapShape);
                                    //this.textBox.AppendText(Environment.NewLine);
                                }

                                this.textBox.AppendText(Environment.NewLine);

                                // Create a memory stream.
                                using (MemoryStream memoryStream = new MemoryStream())
                                {
                                    // Serialize the map data.
                                    map.Write(memoryStream);
                                    // Display the XML.
                                    this.textBox.AppendText(Encoding.UTF8.GetString(memoryStream.ReadToEnd()));

                                    this.textBox.AppendText(Environment.NewLine);
                                    this.textBox.AppendText(Environment.NewLine);

                                    // Set the stream position to zero.
                                    memoryStream.Position = 0;
                                    // Display a dialog to save the file.
                                    if (this.saveFileDialog.ShowDialog(this) == DialogResult.OK)
                                    {
                                        // Create a file stream.
                                        using (FileStream fileOutStream = System.IO.File.Create(this.saveFileDialog.FileName))
                                        {
                                            // Compress the stream.
                                            //using (GZipStream zipStream = new GZipStream(fileOutStream, CompressionLevel.Optimal))
                                            //{
                                                this.textBox.AppendText("Uncompressed data is {0} bytes.{1}".FormatWith(memoryStream.Length, Environment.NewLine));
                                                memoryStream.CopyTo(fileOutStream);
                                                this.textBox.AppendText("Compressed data is {0} bytes.{1}".FormatWith(fileOutStream.Length, Environment.NewLine));
                                            //}
                                        }
                                    }
                                }
                                //this.textBox.AppendText(map.ToXml().ToString());
                                this.textBox.AppendText(Environment.NewLine);
                            }
                        }
                        finally
                        {
                            // Delete the temporary folder.
                            this.textBox.AppendText(Environment.NewLine);
                            System.IO.Directory.Delete(tempFolder, true);
                            this.textBox.AppendText(string.Format("Temporary folder \'{0}\' deleted.{1}", tempFolder, Environment.NewLine));
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                this.textBox.AppendText(string.Format("An exception occurred. {0}", exception.Message));
            }
            this.textBox.AppendText(Environment.NewLine);
            this.textBox.AppendText("Done.");
        }
开发者ID:alexbikfalvi,项目名称:DotNetApi,代码行数:101,代码来源:FormMain.cs

示例11: ExecuteCommand

        public override void ExecuteCommand()
        {
            var manifest = new Manifest();
            string projectFile = null;
            string fileName = null;

            if (!String.IsNullOrEmpty(AssemblyPath))
            {
                // Extract metadata from the assembly
                string path = Path.Combine(Directory.GetCurrentDirectory(), AssemblyPath);
                AssemblyMetadata metadata = AssemblyMetadataExtractor.GetMetadata(path);
                manifest.Metadata.Id = metadata.Name;
                manifest.Metadata.Version = metadata.Version.ToString();
                manifest.Metadata.Authors = metadata.Company;
                manifest.Metadata.Description = metadata.Description;
            }
            else
            {
                if (!ProjectHelper.TryGetProjectFile(out projectFile))
                {
                    manifest.Metadata.Id = Arguments.Any() ? Arguments[0] : "Package";
                    manifest.Metadata.Version = "1.0.0";
                }
                else
                {
                    fileName = Path.GetFileNameWithoutExtension(projectFile);
                    manifest.Metadata.Id = "$id$";
                    manifest.Metadata.Title = "$title$";
                    manifest.Metadata.Version = "$version$";
                    manifest.Metadata.Description = "$description$";
                    manifest.Metadata.Authors = "$author$";
                }
            }

            // Get the file name from the id or the project file
            fileName = fileName ?? manifest.Metadata.Id;

            // If we're using a project file then we want the a minimal nuspec
            if (String.IsNullOrEmpty(projectFile))
            {
                manifest.Metadata.Description = manifest.Metadata.Description ?? SampleDescription;
                if (String.IsNullOrEmpty(manifest.Metadata.Authors))
                {
                    manifest.Metadata.Authors = Environment.UserName;
                }
                manifest.Metadata.DependencySets = new List<ManifestDependencySet>();
                manifest.Metadata.DependencySets.Add(new ManifestDependencySet
                                                        {
                                                            Dependencies = new List<ManifestDependency> { SampleManifestDependency }
                                                        });
            }

            manifest.Metadata.ProjectUrl = SampleProjectUrl;
            manifest.Metadata.LicenseUrl = SampleLicenseUrl;
            manifest.Metadata.IconUrl = SampleIconUrl;
            manifest.Metadata.Tags = SampleTags;
            manifest.Metadata.Copyright = "Copyright " + DateTime.Now.Year;
            manifest.Metadata.ReleaseNotes = SampleReleaseNotes;
            string nuspecFile = fileName + Constants.ManifestExtension;

            // Skip the creation if the file exists and force wasn't specified
            if (File.Exists(nuspecFile) && !Force)
            {
                Console.WriteLine(NuGetResources.SpecCommandFileExists, nuspecFile);
            }
            else
            {
                try
                {
                    using (var stream = new MemoryStream())
                    {
                        manifest.Save(stream, validate: false);
                        stream.Seek(0, SeekOrigin.Begin);
                        string content = stream.ReadToEnd();
                        File.WriteAllText(nuspecFile, RemoveSchemaNamespace(content));
                    }

                    Console.WriteLine(NuGetResources.SpecCommandCreatedNuSpec, nuspecFile);
                }
                catch
                {
                    // Cleanup the file if it fails to save for some reason
                    File.Delete(nuspecFile);
                    throw;
                }
            }
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:87,代码来源:SpecCommand.cs

示例12: VersionFormatIsPreserved

        public void VersionFormatIsPreserved()
        {
            // Arrange
            PackageBuilder builder = new PackageBuilder()
            {
                Id = "A",
                Version = new SemanticVersion("1.0"),
                Description = "Descriptions",
                Summary = "Summary",
            };
            builder.Authors.Add("David");
            
            var dependencySet = new PackageDependencySet(null, new [] {
                new PackageDependency("B", new VersionSpec
                    {
                        MinVersion = new SemanticVersion("1.0"),
                        IsMinInclusive = true
                    }),
                new PackageDependency("C", new VersionSpec
                {
                    MinVersion = new SemanticVersion("1.0"),
                    MaxVersion = new SemanticVersion("5.0"),
                    IsMinInclusive = false
                })
            });

            builder.DependencySets.Add(dependencySet);

            var ms = new MemoryStream();

            // Act
            Manifest.Create(builder).Save(ms);
            ms.Seek(0, SeekOrigin.Begin);

            // Assert
            Assert.Equal(@"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"">
  <metadata>
    <id>A</id>
    <version>1.0</version>
    <authors>David</authors>
    <owners>David</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Descriptions</description>
    <summary>Summary</summary>
    <dependencies>
      <dependency id=""B"" version=""1.0"" />
      <dependency id=""C"" version=""(1.0, 5.0)"" />
    </dependencies>
  </metadata>
</package>", ms.ReadToEnd());
        }
开发者ID:anurse,项目名称:NuGet,代码行数:52,代码来源:PackageBuilderTest.cs

示例13: CreatePackageTrimsExtraWhitespace

        public void CreatePackageTrimsExtraWhitespace()
        {
            // Arrange
            PackageBuilder builder = new PackageBuilder()
            {
                Id = "                 A                 ",
                Version = new SemanticVersion("1.0"),
                Description = "Descriptions                                         ",
                Summary = "                            Summary",
                Language = "     en-us   ",
                Copyright = "            Copyright 2012                "
            };
            builder.Authors.Add("David");
            builder.Owners.Add("John");
            builder.Tags.Add("t1");
            builder.Tags.Add("t2");
            builder.Tags.Add("t3");
            var dependencies = new PackageDependency[] { 
                new PackageDependency("    X     ")
            };
            builder.DependencySets.Add(new PackageDependencySet(null, dependencies));
            var ms = new MemoryStream();

            // Act
            Manifest.Create(builder).Save(ms);
            ms.Seek(0, SeekOrigin.Begin);

            // Assert
            Assert.Equal(@"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"">
  <metadata>
    <id>A</id>
    <version>1.0</version>
    <authors>David</authors>
    <owners>John</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Descriptions</description>
    <summary>Summary</summary>
    <copyright>Copyright 2012</copyright>
    <language>en-us</language>
    <tags>t1 t2 t3</tags>
    <dependencies>
      <dependency id=""X"" />
    </dependencies>
  </metadata>
</package>", ms.ReadToEnd());
        }
开发者ID:anurse,项目名称:NuGet,代码行数:47,代码来源:PackageBuilderTest.cs

示例14: Decrypt

 private byte[] Decrypt(byte[] encrypteData)
 {
     // Extract the IV from the encryptedData
     using (var stream = new MemoryStream(encrypteData))
     {
         var ivLength = stream.ReadByte();
         var iv = stream.Read(ivLength);
         var data = stream.ReadToEnd();
         return CryptoUtils.AesDecrypt(data, encryptionKey, iv);
     }
 }
开发者ID:rsweeney21,项目名称:Timecraft,代码行数:11,代码来源:WebAuthenticationManager.cs

示例15: CreatePackageUsesV4SchemaNamespaceIfDependecyHasTargetFramework

        public void CreatePackageUsesV4SchemaNamespaceIfDependecyHasTargetFramework()
        {
            // Arrange
            PackageBuilder builder = new PackageBuilder()
            {
                Id = "A",
                Version = new SemanticVersion("1.0"),
                Description = "Descriptions",
            };
            builder.Authors.Add("Luan");

            var fx = new FrameworkName("Silverlight", new Version("4.0"));
            var dependencies = new PackageDependency[] { 
                new PackageDependency("B", null)
            };
            builder.DependencySets.Add(new PackageDependencySet(fx, dependencies));

            var ms = new MemoryStream();

            // Act
            Manifest.Create(builder).Save(ms);
            ms.Seek(0, SeekOrigin.Begin);

            // Assert
            Assert.Equal(@"<?xml version=""1.0""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"">
  <metadata>
    <id>A</id>
    <version>1.0</version>
    <authors>Luan</authors>
    <owners>Luan</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Descriptions</description>
    <dependencies>
      <group targetFramework=""Silverlight4.0"">
        <dependency id=""B"" />
      </group>
    </dependencies>
  </metadata>
</package>", ms.ReadToEnd());
        }
开发者ID:anurse,项目名称:NuGet,代码行数:41,代码来源:PackageBuilderTest.cs


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