Fixed errors when reading feeds and replaced some buffers
authorGerardo Hurtado Lozano <kanegerardo_@hotmail.com>
Mon, 12 Jun 2017 22:06:24 +0000 (15:06 -0700)
committerGerardo Hurtado Lozano <kanegerardo_@hotmail.com>
Mon, 12 Jun 2017 22:06:24 +0000 (15:06 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/398649d0317fadc6c7c59c476954c27fb91b6af7

13 files changed:
src/libraries/Microsoft.ServiceModel.Syndication.csproj
src/libraries/Resources/Resource.Designer.cs [new file with mode: 0644]
src/libraries/Resources/Resource.resx [new file with mode: 0644]
src/libraries/Resources/SR.cs
src/libraries/SyndicationFeedFormatter.cs
src/libraries/System/Runtime/BufferedOutputStream.cs
src/libraries/System/Runtime/InternalBufferManager.cs
src/libraries/System/ServiceModel/Channels/BufferManagerOutputStream.cs
src/libraries/System/ServiceModel/Diagnostics/ExceptionUtility.cs
src/libraries/System/ServiceModel/XmlBuffer.cs
src/libraries/TestingApp/Program.cs
src/libraries/TestingApp/TestingApp.csproj
src/libraries/tests/SampleTest.cs

index a9fb22c..ff48e71 100644 (file)
@@ -6,4 +6,17 @@
     <PackagingToolsInsufficientSDKVersion>false</PackagingToolsInsufficientSDKVersion>
   </PropertyGroup>
   <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <ItemGroup>
+    <Compile Update="Resources\Resource.Designer.cs">
+      <DesignTime>True</DesignTime>
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Resource.resx</DependentUpon>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Update="Resources\Resource.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resource.Designer.cs</LastGenOutput>
+    </EmbeddedResource>
+  </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/src/libraries/Resources/Resource.Designer.cs b/src/libraries/Resources/Resource.Designer.cs
new file mode 100644 (file)
index 0000000..e7b0dbb
--- /dev/null
@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.42000
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Microsoft.ServiceModel.Syndication.Resources {
+    using System;
+    
+    
+    /// <summary>
+    ///   A strongly-typed resource class, for looking up localized strings, etc.
+    /// </summary>
+    // This class was auto-generated by the StronglyTypedResourceBuilder
+    // class via a tool like ResGen or Visual Studio.
+    // To add or remove a member, edit your .ResX file then rerun ResGen
+    // with the /str option, or rebuild your VS project.
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    internal class Resource {
+        
+        private static global::System.Resources.ResourceManager resourceMan;
+        
+        private static global::System.Globalization.CultureInfo resourceCulture;
+        
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+        internal Resource() {
+        }
+        
+        /// <summary>
+        ///   Returns the cached ResourceManager instance used by this class.
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.ServiceModel.Syndication.Resources.Resource", typeof(Resource).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+        
+        /// <summary>
+        ///   Overrides the current thread's CurrentUICulture property for all
+        ///   resource lookups using this strongly typed resource class.
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
+                return resourceCulture;
+            }
+            set {
+                resourceCulture = value;
+            }
+        }
+    }
+}
diff --git a/src/libraries/Resources/Resource.resx b/src/libraries/Resources/Resource.resx
new file mode 100644 (file)
index 0000000..4fdb1b6
--- /dev/null
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+       <!-- 
+               Microsoft ResX Schema
+
+               Version 1.3
+
+               The primary goals of this format is to allow a simple XML format 
+               that is mostly human readable. The generation and parsing of the 
+               various data types are done through the TypeConverter classes 
+               associated with the data types.
+
+               Example:
+
+               ... ado.net/XML headers & schema ...
+               <resheader name="resmimetype">text/microsoft-resx</resheader>
+               <resheader name="version">1.3</resheader>
+               <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+               <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+               <data name="Name1">this is my long string</data>
+               <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+               <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+                       [base64 mime encoded serialized .NET Framework object]
+               </data>
+               <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+                       [base64 mime encoded string representing a byte array form of the .NET Framework object]
+               </data>
+
+               There are any number of "resheader" rows that contain simple 
+               name/value pairs.
+
+               Each data row contains a name, and value. The row also contains a 
+               type or mimetype. Type corresponds to a .NET class that support 
+               text/value conversion through the TypeConverter architecture. 
+               Classes that don't support this are serialized and stored with the 
+               mimetype set.
+
+               The mimetype is used for serialized objects, and tells the 
+               ResXResourceReader how to depersist the object. This is currently not 
+               extensible. For a given mimetype the value must be set accordingly:
+
+               Note - application/x-microsoft.net.object.binary.base64 is the format 
+               that the ResXResourceWriter will generate, however the reader can 
+               read any of the formats listed below.
+
+               mimetype: application/x-microsoft.net.object.binary.base64
+               value   : The object must be serialized with 
+                       : System.Serialization.Formatters.Binary.BinaryFormatter
+                       : and then encoded with base64 encoding.
+
+               mimetype: application/x-microsoft.net.object.soap.base64
+               value   : The object must be serialized with 
+                       : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+                       : and then encoded with base64 encoding.
+
+               mimetype: application/x-microsoft.net.object.bytearray.base64
+               value   : The object must be serialized into a byte array 
+                       : using a System.ComponentModel.TypeConverter
+                       : and then encoded with base64 encoding.
+       -->
+       
+       <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+               <xsd:element name="root" msdata:IsDataSet="true">
+                       <xsd:complexType>
+                               <xsd:choice maxOccurs="unbounded">
+                                       <xsd:element name="data">
+                                               <xsd:complexType>
+                                                       <xsd:sequence>
+                                                               <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                                                               <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+                                                       </xsd:sequence>
+                                                       <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+                                                       <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+                                                       <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+                                               </xsd:complexType>
+                                       </xsd:element>
+                                       <xsd:element name="resheader">
+                                               <xsd:complexType>
+                                                       <xsd:sequence>
+                                                               <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                                                       </xsd:sequence>
+                                                       <xsd:attribute name="name" type="xsd:string" use="required" />
+                                               </xsd:complexType>
+                                       </xsd:element>
+                               </xsd:choice>
+                       </xsd:complexType>
+               </xsd:element>
+       </xsd:schema>
+       <resheader name="resmimetype">
+               <value>text/microsoft-resx</value>
+       </resheader>
+       <resheader name="version">
+               <value>1.3</value>
+       </resheader>
+       <resheader name="reader">
+               <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+       </resheader>
+       <resheader name="writer">
+               <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+       </resheader>
+</root>
\ No newline at end of file
index c65168a..58f1617 100644 (file)
@@ -9,71 +9,71 @@ namespace Microsoft.ServiceModel
     {
         internal static object XmlBufferQuotaExceeded;
 
-        public static string InvalidObjectTypePassed { get { throw new NotImplementedException();  } internal set { } }
+        public static string InvalidObjectTypePassed = "resource";
 
-        public static string ErrorParsingDateTime { get { throw new NotImplementedException();  } internal set { } }
-        public static string ErrorParsingFeed { get { throw new NotImplementedException();  } internal set { } }
+        public static string ErrorParsingDateTime = "resource";
+        public static string ErrorParsingFeed = "resource";
 
-        public static string UnknownFeedXml { get { throw new NotImplementedException(); } internal set { } }
+        public static string UnknownFeedXml = "resource";
 
-        public static string Atom10SpecRequiresTextConstruct { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedHasNonContiguousItems { get { throw new NotImplementedException(); } internal set { } }
-        public static string ErrorParsingItem { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedFormatterDoesNotHaveFeed { get { throw new NotImplementedException(); } internal set { } }
-        public static string DocumentFormatterDoesNotHaveDocument { get { throw new NotImplementedException(); } internal set { } }
-        public static string UnknownDocumentXml { get { throw new NotImplementedException(); } internal set { } }
-        public static string ErrorParsingDocument { get { throw new NotImplementedException(); } internal set { } }
-        public static string UnsupportedRssVersion { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedAuthorsIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedContributorsIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedIdIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedLinksIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemAuthorsIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemLinksIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemLastUpdatedTimeIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemCopyrightIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemContentIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemContributorsIgnoredOnWrite { get { throw new NotImplementedException(); } internal set { } }
-        public static string ValueMustBeNonNegative { get { throw new NotImplementedException(); } internal set { } }
-        public static string UriGeneratorSchemeMustNotBeEmpty { get { throw new NotImplementedException(); } internal set { } }
+        public static string Atom10SpecRequiresTextConstruct = "resource";
+        public static string FeedHasNonContiguousItems = "resource";
+        public static string ErrorParsingItem = "resource";
+        public static string FeedFormatterDoesNotHaveFeed = "resource";
+        public static string DocumentFormatterDoesNotHaveDocument = "resource";
+        public static string UnknownDocumentXml = "resource";
+        public static string ErrorParsingDocument = "resource";
+        public static string UnsupportedRssVersion = "resource";
+        public static string FeedAuthorsIgnoredOnWrite = "resource";
+        public static string FeedContributorsIgnoredOnWrite = "resource";
+        public static string FeedIdIgnoredOnWrite = "resource";
+        public static string FeedLinksIgnoredOnWrite = "resource";
+        public static string ItemAuthorsIgnoredOnWrite = "resource";
+        public static string ItemLinksIgnoredOnWrite = "resource";
+        public static string ItemLastUpdatedTimeIgnoredOnWrite = "resource";
+        public static string ItemCopyrightIgnoredOnWrite = "resource";
+        public static string ItemContentIgnoredOnWrite = "resource";
+        public static string ItemContributorsIgnoredOnWrite = "resource";
+        public static string ValueMustBeNonNegative = "resource";
+        public static string UriGeneratorSchemeMustNotBeEmpty = "resource";
 
-        public static string XmlBufferInInvalidState { get { throw new NotImplementedException(); } internal set { } }
-        public static string UnknownItemXml { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemFormatterDoesNotHaveItem { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedCreatedNullCategory { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemCreatedNullCategory { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedCreatedNullItem { get { throw new NotImplementedException(); } internal set { } }
-        public static string FeedCreatedNullPerson { get { throw new NotImplementedException(); } internal set { } }
-        public static string ItemCreatedNullPerson { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationFeedReadBegin { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationFeedReadEnd { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationFeedWriteBegin { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationFeedWriteEnd { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationItemReadBegin { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationItemReadEnd { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationItemWriteBegin { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationItemWriteEnd { get { throw new NotImplementedException(); } internal set { } }
-        public static string TraceCodeSyndicationProtocolElementIgnoredOnRead { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlLineInfo { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlFoundEndOfFile { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlFoundElement { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlFoundEndElement { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlFoundText { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlFoundComment { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlFoundCData { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlFoundNodeType { get { throw new NotImplementedException(); } internal set { } }
-        public static string XmlStartElementExpected { get { throw new NotImplementedException(); } internal set { } }
+        public static string XmlBufferInInvalidState = "resource";
+        public static string UnknownItemXml = "resource";
+        public static string ItemFormatterDoesNotHaveItem = "resource";
+        public static string FeedCreatedNullCategory = "resource";
+        public static string ItemCreatedNullCategory = "resource";
+        public static string FeedCreatedNullItem = "resource";
+        public static string FeedCreatedNullPerson = "resource";
+        public static string ItemCreatedNullPerson = "resource";
+        public static string TraceCodeSyndicationFeedReadBegin = "resource";
+        public static string TraceCodeSyndicationFeedReadEnd = "resource";
+        public static string TraceCodeSyndicationFeedWriteBegin = "resource";
+        public static string TraceCodeSyndicationFeedWriteEnd = "resource";
+        public static string TraceCodeSyndicationItemReadBegin = "resource";
+        public static string TraceCodeSyndicationItemReadEnd = "resource";
+        public static string TraceCodeSyndicationItemWriteBegin = "resource";
+        public static string TraceCodeSyndicationItemWriteEnd = "resource";
+        public static string TraceCodeSyndicationProtocolElementIgnoredOnRead = "resource";
+        public static string XmlLineInfo = "resource";
+        public static string XmlFoundEndOfFile = "resource";
+        public static string XmlFoundElement = "resource";
+        public static string XmlFoundEndElement = "resource";
+        public static string XmlFoundText = "resource";
+        public static string XmlFoundComment = "resource";
+        public static string XmlFoundCData = "resource";
+        public static string XmlFoundNodeType = "resource";
+        public static string XmlStartElementExpected = "resource";
 
-        public static string OuterNameOfElementExtensionEmpty { get; internal set; }
-        public static string ErrorInLine { get; internal set; }
+        public static string OuterNameOfElementExtensionEmpty= "resource";
+        public static string ErrorInLine= "resource";
 
-        public static string OuterElementNameNotSpecified { get; internal set; }
-        public static string ExtensionNameNotSpecified { get; internal set; }
-        public static string UnbufferedItemsCannotBeCloned { get; internal set; }
+        public static string OuterElementNameNotSpecified= "resource";
+        public static string ExtensionNameNotSpecified= "resource";
+        public static string UnbufferedItemsCannotBeCloned= "resource";
 
         internal static string GetString(string nvalidObjectTypePassed, params object[] args)
         {
-            //throw new NotImplementedException();
+            //"resource"
             return nvalidObjectTypePassed;
         }
     }
index 4214d3e..f3cac14 100644 (file)
@@ -578,7 +578,7 @@ namespace Microsoft.ServiceModel.Syndication
         {
             if (value == null)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(errorMsg)));
+                //throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(errorMsg)));
             }
             return value;
         }
index 0f48584..fcd4066 100644 (file)
-//------------------------------------------------------------
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-//------------------------------------------------------------
-
-namespace System.Runtime
-{
-    using System;
-    using System.Globalization;
-    using System.IO;
-
-    class BufferedOutputStream : Stream
-    {
-        //[Fx.Tag.Cache(typeof(byte), Fx.Tag.CacheAttrition.None, Scope = Fx.Tag.Strings.ExternallyManaged,
-        //    SizeLimit = Fx.Tag.Strings.ExternallyManaged)]
-        InternalBufferManager bufferManager;
-
-        //[Fx.Tag.Queue(typeof(byte), SizeLimit = "BufferedOutputStream(maxSize)",
-        //    StaleElementsRemovedImmediately = true, EnqueueThrowsIfFull = true)]
-        byte[][] chunks;
-
-        int chunkCount;
-        byte[] currentChunk;
-        int currentChunkSize;
-        int maxSize;
-        int maxSizeQuota;
-        int totalSize;
-        bool callerReturnsBuffer;
-        bool bufferReturned;
-        bool initialized;
-
-        // requires an explicit call to Init() by the caller
-        public BufferedOutputStream()
-        {
-            this.chunks = new byte[4][];
-        }
-
-        public BufferedOutputStream(int initialSize, int maxSize, InternalBufferManager bufferManager)
-            : this()
-        {
-            Reinitialize(initialSize, maxSize, bufferManager);
-        }
-
-        public BufferedOutputStream(int maxSize)
-            : this(0, maxSize, InternalBufferManager.Create(0, int.MaxValue))
-        {
-        }
-
-        public override bool CanRead
-        {
-            get
-            {
-                return false;
-            }
-        }
-
-        public override bool CanSeek
-        {
-            get
-            {
-                return false;
-            }
-        }
-
-        public override bool CanWrite
-        {
-            get
-            {
-                return true;
-            }
-        }
-
-        public override long Length
-        {
-            get
-            {
-                return this.totalSize;
-            }
-        }
-
-        public override long Position
-        {
-            get
-            {
-                throw new NotSupportedException();// Fx.Exception.AsError(new NotSupportedException(InternalSR.SeekNotSupported));
-            }
-            set
-            {
-                throw new NotSupportedException();// Fx.Exception.AsError(new NotSupportedException(InternalSR.SeekNotSupported));
-            }
-        }
-
-        public void Reinitialize(int initialSize, int maxSizeQuota, InternalBufferManager bufferManager)
-        {
-            Reinitialize(initialSize, maxSizeQuota, maxSizeQuota, bufferManager);
-        }
-
-        public void Reinitialize(int initialSize, int maxSizeQuota, int effectiveMaxSize, InternalBufferManager bufferManager)
-        {
-            //Fx.Assert(!this.initialized, "Clear must be called before re-initializing stream");
-            this.maxSizeQuota = maxSizeQuota;
-            this.maxSize = effectiveMaxSize;
-            this.bufferManager = bufferManager;
-            this.currentChunk = bufferManager.TakeBuffer(initialSize);
-            this.currentChunkSize = 0;
-            this.totalSize = 0;
-            this.chunkCount = 1;
-            this.chunks[0] = this.currentChunk;
-            this.initialized = true;
-        }
-
-        void AllocNextChunk(int minimumChunkSize)
-        {
-            int newChunkSize;
-            if (this.currentChunk.Length > (int.MaxValue / 2))
-            {
-                newChunkSize = int.MaxValue;
-            }
-            else
-            {
-                newChunkSize = this.currentChunk.Length * 2;
-            }
-            if (minimumChunkSize > newChunkSize)
-            {
-                newChunkSize = minimumChunkSize;
-            }
-            byte[] newChunk = this.bufferManager.TakeBuffer(newChunkSize);
-            if (this.chunkCount == this.chunks.Length)
-            {
-                byte[][] newChunks = new byte[this.chunks.Length * 2][];
-                Array.Copy(this.chunks, newChunks, this.chunks.Length);
-                this.chunks = newChunks;
-            }
-            this.chunks[this.chunkCount++] = newChunk;
-            this.currentChunk = newChunk;
-            this.currentChunkSize = 0;
-        }
-
-        public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
-        {
-            throw new NotSupportedException();//   Fx.Exception.AsError(new NotSupportedException(InternalSR.ReadNotSupported));
-        }
-
-        public override int EndRead(IAsyncResult result)
-        {
-            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.ReadNotSupported));
-        }
-
-        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
-        {
-            Write(buffer, offset, size);
-            return new CompletedAsyncResult(callback, state);
-        }
-
-        public override void EndWrite(IAsyncResult result)
-        {
-            CompletedAsyncResult.End(result);
-        }
-
-        public void Clear()
-        {
-            if (!this.callerReturnsBuffer)
-            {
-                for (int i = 0; i < this.chunkCount; i++)
-                {
-                    this.bufferManager.ReturnBuffer(this.chunks[i]);
-                    this.chunks[i] = null;
-                }
-            }
-
-            this.callerReturnsBuffer = false;
-            this.initialized = false;
-            this.bufferReturned = false;
-            this.chunkCount = 0;
-            this.currentChunk = null;
-        }
-
-        public override void Close()
-        {
-        }
-
-        public override void Flush()
-        {
-        }
-
-        public override int Read(byte[] buffer, int offset, int size)
-        {
-            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.ReadNotSupported));
-        }
-
-        public override int ReadByte()
-        {
-            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.ReadNotSupported));
-        }
-
-        public override long Seek(long offset, SeekOrigin origin)
-        {
-            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.SeekNotSupported));
-        }
-
-        public override void SetLength(long value)
-        {
-            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.SeekNotSupported));
-        }
-
-        public MemoryStream ToMemoryStream()
-        {
-            int bufferSize;
-            byte[] buffer = ToArray(out bufferSize);
-            return new MemoryStream(buffer, 0, bufferSize);
-        }
-
-        public byte[] ToArray(out int bufferSize)
-        {
-            //Fx.Assert(this.initialized, "No data to return from uninitialized stream");
-            //Fx.Assert(!this.bufferReturned, "ToArray cannot be called more than once");
-
-            byte[] buffer;
-            if (this.chunkCount == 1)
-            {
-                buffer = this.currentChunk;
-                bufferSize = this.currentChunkSize;
-                this.callerReturnsBuffer = true;
-            }
-            else
-            {
-                buffer = this.bufferManager.TakeBuffer(this.totalSize);
-                int offset = 0;
-                int count = this.chunkCount - 1;
-                for (int i = 0; i < count; i++)
-                {
-                    byte[] chunk = this.chunks[i];
-                    Buffer.BlockCopy(chunk, 0, buffer, offset, chunk.Length);
-                    offset += chunk.Length;
-                }
-                Buffer.BlockCopy(this.currentChunk, 0, buffer, offset, this.currentChunkSize);
-                bufferSize = this.totalSize;
-            }
-
-            this.bufferReturned = true;
-            return buffer;
-        }
-
-        public void Skip(int size)
-        {
-            WriteCore(null, 0, size);
-        }
-
-        public override void Write(byte[] buffer, int offset, int size)
-        {
-            WriteCore(buffer, offset, size);
-        }
-
-        protected virtual Exception CreateQuotaExceededException(int maxSizeQuota)
-        {
-            return new InvalidOperationException();//new InvalidOperationException(InternalSR.BufferedOutputStreamQuotaExceeded(maxSizeQuota));
-        }
-
-        void WriteCore(byte[] buffer, int offset, int size)
-        {
-            //Fx.Assert(this.initialized, "Cannot write to uninitialized stream");
-            //Fx.Assert(!this.bufferReturned, "Cannot write to stream once ToArray has been called.");
-
-            if (size < 0)
-            {
-                throw new ArgumentOutOfRangeException();// Fx.Exception.ArgumentOutOfRange("size", size, InternalSR.ValueMustBeNonNegative);
-            }
-
-            if ((int.MaxValue - size) < this.totalSize)
-            {
-                throw new InvalidOperationException();//Fx.Exception.AsError(CreateQuotaExceededException(this.maxSizeQuota));
-            }
-
-            int newTotalSize = this.totalSize + size;
-            if (newTotalSize > this.maxSize)
-            {
-                throw new InvalidOperationException();//Fx.Exception.AsError(CreateQuotaExceededException(this.maxSizeQuota));
-            }
-
-            int remainingSizeInChunk = this.currentChunk.Length - this.currentChunkSize;
-            if (size > remainingSizeInChunk)
-            {
-                if (remainingSizeInChunk > 0)
-                {
-                    if (buffer != null)
-                    {
-                        Buffer.BlockCopy(buffer, offset, this.currentChunk, this.currentChunkSize, remainingSizeInChunk);
-                    }
-                    this.currentChunkSize = this.currentChunk.Length;
-                    offset += remainingSizeInChunk;
-                    size -= remainingSizeInChunk;
-                }
-                AllocNextChunk(size);
-            }
-
-            if (buffer != null)
-            {
-                Buffer.BlockCopy(buffer, offset, this.currentChunk, this.currentChunkSize, size);
-            }
-            this.totalSize = newTotalSize;
-            this.currentChunkSize += size;
-        }
-
-        public override void WriteByte(byte value)
-        {
-            //Fx.Assert(this.initialized, "Cannot write to uninitialized stream");
-            //Fx.Assert(!this.bufferReturned, "Cannot write to stream once ToArray has been called.");
-
-            if (this.totalSize == this.maxSize)
-            {
-                throw new InvalidOperationException();// Fx.Exception.AsError(CreateQuotaExceededException(this.maxSize));
-            }
-            if (this.currentChunkSize == this.currentChunk.Length)
-            {
-                AllocNextChunk(1);
-            }
-            this.currentChunk[this.currentChunkSize++] = value;
-        }
-    }
-}
\ No newline at end of file
+////------------------------------------------------------------
+//// Copyright (c) Microsoft Corporation.  All rights reserved.
+////------------------------------------------------------------
+
+//namespace System.Runtime
+//{
+//    using System;
+//    using System.Globalization;
+//    using System.IO;
+
+//    class BufferedOutputStream : Stream
+//    {
+//        //[Fx.Tag.Cache(typeof(byte), Fx.Tag.CacheAttrition.None, Scope = Fx.Tag.Strings.ExternallyManaged,
+//        //    SizeLimit = Fx.Tag.Strings.ExternallyManaged)]
+//        InternalBufferManager bufferManager;
+
+//        //[Fx.Tag.Queue(typeof(byte), SizeLimit = "BufferedOutputStream(maxSize)",
+//        //    StaleElementsRemovedImmediately = true, EnqueueThrowsIfFull = true)]
+//        byte[][] chunks;
+
+//        int chunkCount;
+//        byte[] currentChunk;
+//        int currentChunkSize;
+//        int maxSize;
+//        int maxSizeQuota;
+//        int totalSize;
+//        bool callerReturnsBuffer;
+//        bool bufferReturned;
+//        bool initialized;
+
+//        // requires an explicit call to Init() by the caller
+//        public BufferedOutputStream()
+//        {
+//            this.chunks = new byte[4][];
+//        }
+
+//        public BufferedOutputStream(int initialSize, int maxSize, InternalBufferManager bufferManager)
+//            : this()
+//        {
+//            Reinitialize(initialSize, maxSize, bufferManager);
+//        }
+
+//        public BufferedOutputStream(int maxSize)
+//            : this(0, maxSize, InternalBufferManager.Create(0, int.MaxValue))
+//        {
+//        }
+
+//        public override bool CanRead
+//        {
+//            get
+//            {
+//                return false;
+//            }
+//        }
+
+//        public override bool CanSeek
+//        {
+//            get
+//            {
+//                return false;
+//            }
+//        }
+
+//        public override bool CanWrite
+//        {
+//            get
+//            {
+//                return true;
+//            }
+//        }
+
+//        public override long Length
+//        {
+//            get
+//            {
+//                return this.totalSize;
+//            }
+//        }
+
+//        public override long Position
+//        {
+//            get
+//            {
+//                throw new NotSupportedException();// Fx.Exception.AsError(new NotSupportedException(InternalSR.SeekNotSupported));
+//            }
+//            set
+//            {
+//                throw new NotSupportedException();// Fx.Exception.AsError(new NotSupportedException(InternalSR.SeekNotSupported));
+//            }
+//        }
+
+//        public void Reinitialize(int initialSize, int maxSizeQuota, InternalBufferManager bufferManager)
+//        {
+//            Reinitialize(initialSize, maxSizeQuota, maxSizeQuota, bufferManager);
+//        }
+
+//        public void Reinitialize(int initialSize, int maxSizeQuota, int effectiveMaxSize, InternalBufferManager bufferManager)
+//        {
+//            //Fx.Assert(!this.initialized, "Clear must be called before re-initializing stream");
+//            this.maxSizeQuota = maxSizeQuota;
+//            this.maxSize = effectiveMaxSize;
+//            this.bufferManager = bufferManager;
+//            this.currentChunk = bufferManager.TakeBuffer(initialSize);
+//            this.currentChunkSize = 0;
+//            this.totalSize = 0;
+//            this.chunkCount = 1;
+//            this.chunks[0] = this.currentChunk;
+//            this.initialized = true;
+//        }
+
+//        void AllocNextChunk(int minimumChunkSize)
+//        {
+//            int newChunkSize;
+//            if (this.currentChunk.Length > (int.MaxValue / 2))
+//            {
+//                newChunkSize = int.MaxValue;
+//            }
+//            else
+//            {
+//                newChunkSize = this.currentChunk.Length * 2;
+//            }
+//            if (minimumChunkSize > newChunkSize)
+//            {
+//                newChunkSize = minimumChunkSize;
+//            }
+//            byte[] newChunk = this.bufferManager.TakeBuffer(newChunkSize);
+//            if (this.chunkCount == this.chunks.Length)
+//            {
+//                byte[][] newChunks = new byte[this.chunks.Length * 2][];
+//                Array.Copy(this.chunks, newChunks, this.chunks.Length);
+//                this.chunks = newChunks;
+//            }
+//            this.chunks[this.chunkCount++] = newChunk;
+//            this.currentChunk = newChunk;
+//            this.currentChunkSize = 0;
+//        }
+
+//        public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
+//        {
+//            throw new NotSupportedException();//   Fx.Exception.AsError(new NotSupportedException(InternalSR.ReadNotSupported));
+//        }
+
+//        public override int EndRead(IAsyncResult result)
+//        {
+//            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.ReadNotSupported));
+//        }
+
+//        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
+//        {
+//            Write(buffer, offset, size);
+//            return new CompletedAsyncResult(callback, state);
+//        }
+
+//        public override void EndWrite(IAsyncResult result)
+//        {
+//            CompletedAsyncResult.End(result);
+//        }
+
+//        public void Clear()
+//        {
+//            if (!this.callerReturnsBuffer)
+//            {
+//                for (int i = 0; i < this.chunkCount; i++)
+//                {
+//                    this.bufferManager.ReturnBuffer(this.chunks[i]);
+//                    this.chunks[i] = null;
+//                }
+//            }
+
+//            this.callerReturnsBuffer = false;
+//            this.initialized = false;
+//            this.bufferReturned = false;
+//            this.chunkCount = 0;
+//            this.currentChunk = null;
+//        }
+
+//        public override void Close()
+//        {
+//        }
+
+//        public override void Flush()
+//        {
+//        }
+
+//        public override int Read(byte[] buffer, int offset, int size)
+//        {
+//            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.ReadNotSupported));
+//        }
+
+//        public override int ReadByte()
+//        {
+//            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.ReadNotSupported));
+//        }
+
+//        public override long Seek(long offset, SeekOrigin origin)
+//        {
+//            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.SeekNotSupported));
+//        }
+
+//        public override void SetLength(long value)
+//        {
+//            throw new NotSupportedException();//Fx.Exception.AsError(new NotSupportedException(InternalSR.SeekNotSupported));
+//        }
+
+//        public MemoryStream ToMemoryStream()
+//        {
+//            int bufferSize;
+//            byte[] buffer = ToArray(out bufferSize);
+//            return new MemoryStream(buffer, 0, bufferSize);
+//        }
+
+//        public byte[] ToArray(out int bufferSize)
+//        {
+//            //Fx.Assert(this.initialized, "No data to return from uninitialized stream");
+//            //Fx.Assert(!this.bufferReturned, "ToArray cannot be called more than once");
+
+//            byte[] buffer;
+//            if (this.chunkCount == 1)
+//            {
+//                buffer = this.currentChunk;
+//                bufferSize = this.currentChunkSize;
+//                this.callerReturnsBuffer = true;
+//            }
+//            else
+//            {
+//                buffer = this.bufferManager.TakeBuffer(this.totalSize);
+//                int offset = 0;
+//                int count = this.chunkCount - 1;
+//                for (int i = 0; i < count; i++)
+//                {
+//                    byte[] chunk = this.chunks[i];
+//                    Buffer.BlockCopy(chunk, 0, buffer, offset, chunk.Length);
+//                    offset += chunk.Length;
+//                }
+//                Buffer.BlockCopy(this.currentChunk, 0, buffer, offset, this.currentChunkSize);
+//                bufferSize = this.totalSize;
+//            }
+
+//            this.bufferReturned = true;
+//            return buffer;
+//        }
+
+//        public void Skip(int size)
+//        {
+//            WriteCore(null, 0, size);
+//        }
+
+//        public override void Write(byte[] buffer, int offset, int size)
+//        {
+//            WriteCore(buffer, offset, size);
+//        }
+
+//        protected virtual Exception CreateQuotaExceededException(int maxSizeQuota)
+//        {
+//            return new InvalidOperationException();//new InvalidOperationException(InternalSR.BufferedOutputStreamQuotaExceeded(maxSizeQuota));
+//        }
+
+//        void WriteCore(byte[] buffer, int offset, int size)
+//        {
+//            //Fx.Assert(this.initialized, "Cannot write to uninitialized stream");
+//            //Fx.Assert(!this.bufferReturned, "Cannot write to stream once ToArray has been called.");
+
+//            if (size < 0)
+//            {
+//                //throw new ArgumentOutOfRangeException();// Fx.Exception.ArgumentOutOfRange("size", size, InternalSR.ValueMustBeNonNegative);
+//            }
+
+//            if ((int.MaxValue - size) < this.totalSize)
+//            {
+//                //throw new InvalidOperationException();//Fx.Exception.AsError(CreateQuotaExceededException(this.maxSizeQuota));
+//            }
+
+//            int newTotalSize = this.totalSize + size;
+//            if (newTotalSize > this.maxSize)
+//            {
+//                //throw new InvalidOperationException();//Fx.Exception.AsError(CreateQuotaExceededException(this.maxSizeQuota));
+//            }
+
+//            int remainingSizeInChunk = this.currentChunk.Length - this.currentChunkSize;
+//            if (size > remainingSizeInChunk)
+//            {
+//                if (remainingSizeInChunk > 0)
+//                {
+//                    if (buffer != null)
+//                    {
+//                        Buffer.BlockCopy(buffer, offset, this.currentChunk, this.currentChunkSize, remainingSizeInChunk);
+//                    }
+//                    this.currentChunkSize = this.currentChunk.Length;
+//                    offset += remainingSizeInChunk;
+//                    size -= remainingSizeInChunk;
+//                }
+//                AllocNextChunk(size);
+//            }
+
+//            if (buffer != null)
+//            {
+//                Buffer.BlockCopy(buffer, offset, this.currentChunk, this.currentChunkSize, size);
+//            }
+//            this.totalSize = newTotalSize;
+//            this.currentChunkSize += size;
+//        }
+
+//        public override void WriteByte(byte value)
+//        {
+//            //Fx.Assert(this.initialized, "Cannot write to uninitialized stream");
+//            //Fx.Assert(!this.bufferReturned, "Cannot write to stream once ToArray has been called.");
+
+//            if (this.totalSize == this.maxSize)
+//            {
+//               // throw new InvalidOperationException();// Fx.Exception.AsError(CreateQuotaExceededException(this.maxSize));
+//            }
+//            if (this.currentChunkSize == this.currentChunk.Length)
+//            {
+//                AllocNextChunk(1);
+//            }
+//            this.currentChunk[this.currentChunkSize++] = value;
+//        }
+//    }
+//}
\ No newline at end of file
index 451140b..78a63ca 100644 (file)
-//----------------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-//----------------------------------------------------------------------------
-namespace System.Runtime
-{
-    using System;
-    using System.Collections.Generic;
-    using System.Threading;
-
-
-#if DEBUG
-    using System.Collections.Concurrent;
-    using System.Diagnostics;
-    using System.Globalization;
-    using System.Security;
-    using System.Security.Permissions;
-#endif //DEBUG
-
-    abstract class InternalBufferManager
-    {
-        protected InternalBufferManager()
-        {
-        }
-
-        public abstract byte[] TakeBuffer(int bufferSize);
-        public abstract void ReturnBuffer(byte[] buffer);
-        public abstract void Clear();
-
-        public static InternalBufferManager Create(long maxBufferPoolSize, int maxBufferSize)
-        {
-            if (maxBufferPoolSize == 0)
-            {
-                return GCBufferManager.Value;
-            }
-            else
-            {
-                //Fx.Assert(maxBufferPoolSize > 0 && maxBufferSize >= 0, "bad params, caller should verify");
-                return new PooledBufferManager(maxBufferPoolSize, maxBufferSize);
-            }
-        }
-
-        class PooledBufferManager : InternalBufferManager
-        {
-            const int minBufferSize = 128;
-            const int maxMissesBeforeTuning = 8;
-            const int initialBufferCount = 1;
-            readonly object tuningLock;
-
-            int[] bufferSizes;
-            BufferPool[] bufferPools;
-            long memoryLimit;
-            long remainingMemory;
-            bool areQuotasBeingTuned;
-            int totalMisses;
-#if DEBUG
-            ConcurrentDictionary<int, string> buffersPooled = new ConcurrentDictionary<int, string>();
-#endif //DEBUG
-
-            public PooledBufferManager(long maxMemoryToPool, int maxBufferSize)
-            {
-                this.tuningLock = new object();
-                this.memoryLimit = maxMemoryToPool;
-                this.remainingMemory = maxMemoryToPool;
-                List<BufferPool> bufferPoolList = new List<BufferPool>();
-
-                for (int bufferSize = minBufferSize; ;)
-                {
-                    long bufferCountLong = this.remainingMemory / bufferSize;
-
-                    int bufferCount = bufferCountLong > int.MaxValue ? int.MaxValue : (int)bufferCountLong;
-
-                    if (bufferCount > initialBufferCount)
-                    {
-                        bufferCount = initialBufferCount;
-                    }
-
-                    bufferPoolList.Add(BufferPool.CreatePool(bufferSize, bufferCount));
-
-                    this.remainingMemory -= (long)bufferCount * bufferSize;
-
-                    if (bufferSize >= maxBufferSize)
-                    {
-                        break;
-                    }
-
-                    long newBufferSizeLong = (long)bufferSize * 2;
-
-                    if (newBufferSizeLong > (long)maxBufferSize)
-                    {
-                        bufferSize = maxBufferSize;
-                    }
-                    else
-                    {
-                        bufferSize = (int)newBufferSizeLong;
-                    }
-                }
-
-                this.bufferPools = bufferPoolList.ToArray();
-                this.bufferSizes = new int[bufferPools.Length];
-                for (int i = 0; i < bufferPools.Length; i++)
-                {
-                    this.bufferSizes[i] = bufferPools[i].BufferSize;
-                }
-            }
-
-            public override void Clear()
-            {
-#if DEBUG
-                this.buffersPooled.Clear();
-#endif //DEBUG
-
-                for (int i = 0; i < this.bufferPools.Length; i++)
-                {
-                    BufferPool bufferPool = this.bufferPools[i];
-                    bufferPool.Clear();
-                }
-            }
-
-            void ChangeQuota(ref BufferPool bufferPool, int delta)
-            {
-
-                //if (TraceCore.BufferPoolChangeQuotaIsEnabled(Fx.Trace))
-                //{
-                //    TraceCore.BufferPoolChangeQuota(Fx.Trace, bufferPool.BufferSize, delta);
-                //}
-
-                BufferPool oldBufferPool = bufferPool;
-                int newLimit = oldBufferPool.Limit + delta;
-                BufferPool newBufferPool = BufferPool.CreatePool(oldBufferPool.BufferSize, newLimit);
-                for (int i = 0; i < newLimit; i++)
-                {
-                    byte[] buffer = oldBufferPool.Take();
-                    if (buffer == null)
-                    {
-                        break;
-                    }
-                    newBufferPool.Return(buffer);
-                    newBufferPool.IncrementCount();
-                }
-                this.remainingMemory -= oldBufferPool.BufferSize * delta;
-                bufferPool = newBufferPool;
-            }
-
-            void DecreaseQuota(ref BufferPool bufferPool)
-            {
-                ChangeQuota(ref bufferPool, -1);
-            }
-
-            int FindMostExcessivePool()
-            {
-                long maxBytesInExcess = 0;
-                int index = -1;
-
-                for (int i = 0; i < this.bufferPools.Length; i++)
-                {
-                    BufferPool bufferPool = this.bufferPools[i];
-
-                    if (bufferPool.Peak < bufferPool.Limit)
-                    {
-                        long bytesInExcess = (bufferPool.Limit - bufferPool.Peak) * (long)bufferPool.BufferSize;
-
-                        if (bytesInExcess > maxBytesInExcess)
-                        {
-                            index = i;
-                            maxBytesInExcess = bytesInExcess;
-                        }
-                    }
-                }
-
-                return index;
-            }
-
-            int FindMostStarvedPool()
-            {
-                long maxBytesMissed = 0;
-                int index = -1;
-
-                for (int i = 0; i < this.bufferPools.Length; i++)
-                {
-                    BufferPool bufferPool = this.bufferPools[i];
-
-                    if (bufferPool.Peak == bufferPool.Limit)
-                    {
-                        long bytesMissed = bufferPool.Misses * (long)bufferPool.BufferSize;
-
-                        if (bytesMissed > maxBytesMissed)
-                        {
-                            index = i;
-                            maxBytesMissed = bytesMissed;
-                        }
-                    }
-                }
-
-                return index;
-            }
-
-            BufferPool FindPool(int desiredBufferSize)
-            {
-                for (int i = 0; i < this.bufferSizes.Length; i++)
-                {
-                    if (desiredBufferSize <= this.bufferSizes[i])
-                    {
-                        return this.bufferPools[i];
-                    }
-                }
-
-                return null;
-            }
-
-            void IncreaseQuota(ref BufferPool bufferPool)
-            {
-                ChangeQuota(ref bufferPool, 1);
-            }
-
-            public override void ReturnBuffer(byte[] buffer)
-            {
-                //Fx.Assert(buffer != null, "caller must verify");
-
-#if DEBUG
-                //int hash = buffer.GetHashCode();
-                //if (!this.buffersPooled.TryAdd(hash, CaptureStackTrace()))
-                //{
-                //    string originalStack;
-                //    if (!this.buffersPooled.TryGetValue(hash, out originalStack))
-                //    {
-                //        originalStack = "NULL";
-                //    }
-
-                //    //Fx.Assert(
-                //        //string.Format(
-                //        //    CultureInfo.InvariantCulture,
-                //        //    "Buffer '{0}' has already been returned to the bufferManager before. Previous CallStack: {1} Current CallStack: {2}",
-                //        //    hash,
-                //        //    originalStack,
-                //        //    CaptureStackTrace()));
-
-                //}
-#endif //DEBUG
-
-                BufferPool bufferPool = FindPool(buffer.Length);
-                if (bufferPool != null)
-                {
-                    if (buffer.Length != bufferPool.BufferSize)
-                    {
-                        throw new ArgumentException(); //Fx.Exception.Argument("buffer", InternalSR.BufferIsNotRightSizeForBufferManager);
-                    }
-
-                    if (bufferPool.Return(buffer))
-                    {
-                        bufferPool.IncrementCount();
-                    }
-                }
-            }
-
-            public override byte[] TakeBuffer(int bufferSize)
-            {
-                //Fx.Assert(bufferSize >= 0, "caller must ensure a non-negative argument");
-
-                BufferPool bufferPool = FindPool(bufferSize);
-                byte[] returnValue;
-                if (bufferPool != null)
-                {
-                    byte[] buffer = bufferPool.Take();
-                    if (buffer != null)
-                    {
-                        bufferPool.DecrementCount();
-                        returnValue = buffer;
-                    }
-                    else
-                    {
-                        if (bufferPool.Peak == bufferPool.Limit)
-                        {
-                            bufferPool.Misses++;
-                            if (++totalMisses >= maxMissesBeforeTuning)
-                            {
-                                TuneQuotas();
-                            }
-                        }
-
-                        //if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
-                        //{
-                        //    TraceCore.BufferPoolAllocation(Fx.Trace, bufferPool.BufferSize);
-                        //}
-
-                        returnValue = new Byte[bufferSize]; //Fx.AllocateByteArray(bufferPool.BufferSize);
-                    }
-                }
-                else
-                {
-                    //if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
-                    //{
-                    //    TraceCore.BufferPoolAllocation(Fx.Trace, bufferSize);
-                    //}
-
-                    returnValue = new Byte[bufferSize]; //Fx.AllocateByteArray(bufferSize);
-                }
-
-#if DEBUG
-                string dummy;
-                this.buffersPooled.TryRemove(returnValue.GetHashCode(), out dummy);
-#endif //DEBUG
-
-                return returnValue;
-            }
-
-#if DEBUG
-            //[SecuritySafeCritical]
-            //[PermissionSet(SecurityAction.Assert, Unrestricted = true)]
-            //private static string CaptureStackTrace()
-            //{
-            //    return new StackTrace(true).ToString();
-            //}
-#endif //DEBUG
-
-            void TuneQuotas()
-            {
-                if (this.areQuotasBeingTuned)
-                {
-                    return;
-                }
-
-                bool lockHeld = false;
-                try
-                {
-                    Monitor.TryEnter(this.tuningLock, ref lockHeld);
-
-                    // Don't bother if another thread already has the lock
-                    if (!lockHeld || this.areQuotasBeingTuned)
-                    {
-                        return;
-                    }
-
-                    this.areQuotasBeingTuned = true;
-                }
-                finally
-                {
-                    if (lockHeld)
-                    {
-                        Monitor.Exit(this.tuningLock);
-                    }
-                }
-
-                // find the "poorest" pool
-                int starvedIndex = FindMostStarvedPool();
-                if (starvedIndex >= 0)
-                {
-                    BufferPool starvedBufferPool = this.bufferPools[starvedIndex];
-
-                    if (this.remainingMemory < starvedBufferPool.BufferSize)
-                    {
-                        // find the "richest" pool
-                        int excessiveIndex = FindMostExcessivePool();
-                        if (excessiveIndex >= 0)
-                        {
-                            // steal from the richest
-                            DecreaseQuota(ref this.bufferPools[excessiveIndex]);
-                        }
-                    }
-
-                    if (this.remainingMemory >= starvedBufferPool.BufferSize)
-                    {
-                        // give to the poorest
-                        IncreaseQuota(ref this.bufferPools[starvedIndex]);
-                    }
-                }
-
-                // reset statistics
-                for (int i = 0; i < this.bufferPools.Length; i++)
-                {
-                    BufferPool bufferPool = this.bufferPools[i];
-                    bufferPool.Misses = 0;
-                }
-
-                this.totalMisses = 0;
-                this.areQuotasBeingTuned = false;
-            }
-
-            abstract class BufferPool
-            {
-                int bufferSize;
-                int count;
-                int limit;
-                int misses;
-                int peak;
-
-                public BufferPool(int bufferSize, int limit)
-                {
-                    this.bufferSize = bufferSize;
-                    this.limit = limit;
-                }
-
-                public int BufferSize
-                {
-                    get { return this.bufferSize; }
-                }
-
-                public int Limit
-                {
-                    get { return this.limit; }
-                }
-
-                public int Misses
-                {
-                    get { return this.misses; }
-                    set { this.misses = value; }
-                }
-
-                public int Peak
-                {
-                    get { return this.peak; }
-                }
-
-                public void Clear()
-                {
-                    this.OnClear();
-                    this.count = 0;
-                }
-
-                public void DecrementCount()
-                {
-                    int newValue = this.count - 1;
-                    if (newValue >= 0)
-                    {
-                        this.count = newValue;
-                    }
-                }
-
-                public void IncrementCount()
-                {
-                    int newValue = this.count + 1;
-                    if (newValue <= this.limit)
-                    {
-                        this.count = newValue;
-                        if (newValue > this.peak)
-                        {
-                            this.peak = newValue;
-                        }
-                    }
-                }
-
-                internal abstract byte[] Take();
-                internal abstract bool Return(byte[] buffer);
-                internal abstract void OnClear();
-
-                internal static BufferPool CreatePool(int bufferSize, int limit)
-                {
-                    // To avoid many buffer drops during training of large objects which
-                    // get allocated on the LOH, we use the LargeBufferPool and for 
-                    // bufferSize < 85000, the SynchronizedPool. However if bufferSize < 85000
-                    // and (bufferSize + array-overhead) > 85000, this would still use 
-                    // the SynchronizedPool even though it is allocated on the LOH.
-                    if (bufferSize < 85000)
-                    {
-                        return new SynchronizedBufferPool(bufferSize, limit);
-                    }
-                    else
-                    {
-                        return new LargeBufferPool(bufferSize, limit);
-                    }
-                }
-
-                class SynchronizedBufferPool : BufferPool
-                {
-                    SynchronizedPool<byte[]> innerPool;
-
-                    internal SynchronizedBufferPool(int bufferSize, int limit)
-                        : base(bufferSize, limit)
-                    {
-                        this.innerPool = new SynchronizedPool<byte[]>(limit);
-                    }
-
-                    internal override void OnClear()
-                    {
-                        this.innerPool.Clear();
-                    }
-
-                    internal override byte[] Take()
-                    {
-                        return this.innerPool.Take();
-                    }
-
-                    internal override bool Return(byte[] buffer)
-                    {
-                        return this.innerPool.Return(buffer);
-                    }
-                }
-
-                class LargeBufferPool : BufferPool
-                {
-                    Stack<byte[]> items;
-
-                    internal LargeBufferPool(int bufferSize, int limit)
-                        : base(bufferSize, limit)
-                    {
-                        this.items = new Stack<byte[]>(limit);
-                    }
-
-                    object ThisLock
-                    {
-                        get
-                        {
-                            return this.items;
-                        }
-                    }
-
-                    internal override void OnClear()
-                    {
-                        lock (ThisLock)
-                        {
-                            this.items.Clear();
-                        }
-                    }
-
-                    internal override byte[] Take()
-                    {
-                        lock (ThisLock)
-                        {
-                            if (this.items.Count > 0)
-                            {
-                                return this.items.Pop();
-                            }
-                        }
-
-                        return null;
-                    }
-
-                    internal override bool Return(byte[] buffer)
-                    {
-                        lock (ThisLock)
-                        {
-                            if (this.items.Count < this.Limit)
-                            {
-                                this.items.Push(buffer);
-                                return true;
-                            }
-                        }
-
-                        return false;
-                    }
-                }
-            }
-        }
-
-        class GCBufferManager : InternalBufferManager
-        {
-            static GCBufferManager value = new GCBufferManager();
-
-            GCBufferManager()
-            {
-            }
-
-            public static GCBufferManager Value
-            {
-                get { return value; }
-            }
-
-            public override void Clear()
-            {
-            }
-
-            public override byte[] TakeBuffer(int bufferSize)
-            {
-                return new Byte[bufferSize];// Fx.AllocateByteArray(bufferSize);
-            }
-
-            public override void ReturnBuffer(byte[] buffer)
-            {
-                // do nothing, GC will reclaim this buffer
-            }
-        }
-    }
-}
+////----------------------------------------------------------------------------
+//// Copyright (c) Microsoft Corporation.  All rights reserved.
+////----------------------------------------------------------------------------
+//namespace System.Runtime
+//{
+//    using System;
+//    using System.Collections.Generic;
+//    using System.Threading;
+
+
+//#if DEBUG
+//    using System.Collections.Concurrent;
+//    using System.Diagnostics;
+//    using System.Globalization;
+//    using System.Security;
+//    using System.Security.Permissions;
+//#endif //DEBUG
+
+//    abstract class InternalBufferManager
+//    {
+//        protected InternalBufferManager()
+//        {
+//        }
+
+//        public abstract byte[] TakeBuffer(int bufferSize);
+//        public abstract void ReturnBuffer(byte[] buffer);
+//        public abstract void Clear();
+
+//        public static InternalBufferManager Create(long maxBufferPoolSize, int maxBufferSize)
+//        {
+//            if (maxBufferPoolSize == 0)
+//            {
+//                return GCBufferManager.Value;
+//            }
+//            else
+//            {
+//                //Fx.Assert(maxBufferPoolSize > 0 && maxBufferSize >= 0, "bad params, caller should verify");
+//                return new PooledBufferManager(maxBufferPoolSize, maxBufferSize);
+//            }
+//        }
+
+//        class PooledBufferManager : InternalBufferManager
+//        {
+//            const int minBufferSize = 128;
+//            const int maxMissesBeforeTuning = 8;
+//            const int initialBufferCount = 1;
+//            readonly object tuningLock;
+
+//            int[] bufferSizes;
+//            BufferPool[] bufferPools;
+//            long memoryLimit;
+//            long remainingMemory;
+//            bool areQuotasBeingTuned;
+//            int totalMisses;
+//#if DEBUG
+//            ConcurrentDictionary<int, string> buffersPooled = new ConcurrentDictionary<int, string>();
+//#endif //DEBUG
+
+//            public PooledBufferManager(long maxMemoryToPool, int maxBufferSize)
+//            {
+//                this.tuningLock = new object();
+//                this.memoryLimit = maxMemoryToPool;
+//                this.remainingMemory = maxMemoryToPool;
+//                List<BufferPool> bufferPoolList = new List<BufferPool>();
+
+//                for (int bufferSize = minBufferSize; ;)
+//                {
+//                    long bufferCountLong = this.remainingMemory / bufferSize;
+
+//                    int bufferCount = bufferCountLong > int.MaxValue ? int.MaxValue : (int)bufferCountLong;
+
+//                    if (bufferCount > initialBufferCount)
+//                    {
+//                        bufferCount = initialBufferCount;
+//                    }
+
+//                    bufferPoolList.Add(BufferPool.CreatePool(bufferSize, bufferCount));
+
+//                    this.remainingMemory -= (long)bufferCount * bufferSize;
+
+//                    if (bufferSize >= maxBufferSize)
+//                    {
+//                        break;
+//                    }
+
+//                    long newBufferSizeLong = (long)bufferSize * 2;
+
+//                    if (newBufferSizeLong > (long)maxBufferSize)
+//                    {
+//                        bufferSize = maxBufferSize;
+//                    }
+//                    else
+//                    {
+//                        bufferSize = (int)newBufferSizeLong;
+//                    }
+//                }
+
+//                this.bufferPools = bufferPoolList.ToArray();
+//                this.bufferSizes = new int[bufferPools.Length];
+//                for (int i = 0; i < bufferPools.Length; i++)
+//                {
+//                    this.bufferSizes[i] = bufferPools[i].BufferSize;
+//                }
+//            }
+
+//            public override void Clear()
+//            {
+//#if DEBUG
+//                this.buffersPooled.Clear();
+//#endif //DEBUG
+
+//                for (int i = 0; i < this.bufferPools.Length; i++)
+//                {
+//                    BufferPool bufferPool = this.bufferPools[i];
+//                    bufferPool.Clear();
+//                }
+//            }
+
+//            void ChangeQuota(ref BufferPool bufferPool, int delta)
+//            {
+
+//                //if (TraceCore.BufferPoolChangeQuotaIsEnabled(Fx.Trace))
+//                //{
+//                //    TraceCore.BufferPoolChangeQuota(Fx.Trace, bufferPool.BufferSize, delta);
+//                //}
+
+//                BufferPool oldBufferPool = bufferPool;
+//                int newLimit = oldBufferPool.Limit + delta;
+//                BufferPool newBufferPool = BufferPool.CreatePool(oldBufferPool.BufferSize, newLimit);
+//                for (int i = 0; i < newLimit; i++)
+//                {
+//                    byte[] buffer = oldBufferPool.Take();
+//                    if (buffer == null)
+//                    {
+//                        break;
+//                    }
+//                    newBufferPool.Return(buffer);
+//                    newBufferPool.IncrementCount();
+//                }
+//                this.remainingMemory -= oldBufferPool.BufferSize * delta;
+//                bufferPool = newBufferPool;
+//            }
+
+//            void DecreaseQuota(ref BufferPool bufferPool)
+//            {
+//                ChangeQuota(ref bufferPool, -1);
+//            }
+
+//            int FindMostExcessivePool()
+//            {
+//                long maxBytesInExcess = 0;
+//                int index = -1;
+
+//                for (int i = 0; i < this.bufferPools.Length; i++)
+//                {
+//                    BufferPool bufferPool = this.bufferPools[i];
+
+//                    if (bufferPool.Peak < bufferPool.Limit)
+//                    {
+//                        long bytesInExcess = (bufferPool.Limit - bufferPool.Peak) * (long)bufferPool.BufferSize;
+
+//                        if (bytesInExcess > maxBytesInExcess)
+//                        {
+//                            index = i;
+//                            maxBytesInExcess = bytesInExcess;
+//                        }
+//                    }
+//                }
+
+//                return index;
+//            }
+
+//            int FindMostStarvedPool()
+//            {
+//                long maxBytesMissed = 0;
+//                int index = -1;
+
+//                for (int i = 0; i < this.bufferPools.Length; i++)
+//                {
+//                    BufferPool bufferPool = this.bufferPools[i];
+
+//                    if (bufferPool.Peak == bufferPool.Limit)
+//                    {
+//                        long bytesMissed = bufferPool.Misses * (long)bufferPool.BufferSize;
+
+//                        if (bytesMissed > maxBytesMissed)
+//                        {
+//                            index = i;
+//                            maxBytesMissed = bytesMissed;
+//                        }
+//                    }
+//                }
+
+//                return index;
+//            }
+
+//            BufferPool FindPool(int desiredBufferSize)
+//            {
+//                for (int i = 0; i < this.bufferSizes.Length; i++)
+//                {
+//                    if (desiredBufferSize <= this.bufferSizes[i])
+//                    {
+//                        return this.bufferPools[i];
+//                    }
+//                }
+
+//                return null;
+//            }
+
+//            void IncreaseQuota(ref BufferPool bufferPool)
+//            {
+//                ChangeQuota(ref bufferPool, 1);
+//            }
+
+//            public override void ReturnBuffer(byte[] buffer)
+//            {
+//                //Fx.Assert(buffer != null, "caller must verify");
+
+//#if DEBUG
+//                //int hash = buffer.GetHashCode();
+//                //if (!this.buffersPooled.TryAdd(hash, CaptureStackTrace()))
+//                //{
+//                //    string originalStack;
+//                //    if (!this.buffersPooled.TryGetValue(hash, out originalStack))
+//                //    {
+//                //        originalStack = "NULL";
+//                //    }
+
+//                //    //Fx.Assert(
+//                //        //string.Format(
+//                //        //    CultureInfo.InvariantCulture,
+//                //        //    "Buffer '{0}' has already been returned to the bufferManager before. Previous CallStack: {1} Current CallStack: {2}",
+//                //        //    hash,
+//                //        //    originalStack,
+//                //        //    CaptureStackTrace()));
+
+//                //}
+//#endif //DEBUG
+
+//                BufferPool bufferPool = FindPool(buffer.Length);
+//                if (bufferPool != null)
+//                {
+//                    if (buffer.Length != bufferPool.BufferSize)
+//                    {
+//                        throw new ArgumentException(); //Fx.Exception.Argument("buffer", InternalSR.BufferIsNotRightSizeForBufferManager);
+//                    }
+
+//                    if (bufferPool.Return(buffer))
+//                    {
+//                        bufferPool.IncrementCount();
+//                    }
+//                }
+//            }
+
+//            public override byte[] TakeBuffer(int bufferSize)
+//            {
+//                //Fx.Assert(bufferSize >= 0, "caller must ensure a non-negative argument");
+
+//                BufferPool bufferPool = FindPool(bufferSize);
+//                byte[] returnValue;
+//                if (bufferPool != null)
+//                {
+//                    byte[] buffer = bufferPool.Take();
+//                    if (buffer != null)
+//                    {
+//                        bufferPool.DecrementCount();
+//                        returnValue = buffer;
+//                    }
+//                    else
+//                    {
+//                        if (bufferPool.Peak == bufferPool.Limit)
+//                        {
+//                            bufferPool.Misses++;
+//                            if (++totalMisses >= maxMissesBeforeTuning)
+//                            {
+//                                TuneQuotas();
+//                            }
+//                        }
+
+//                        //if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
+//                        //{
+//                        //    TraceCore.BufferPoolAllocation(Fx.Trace, bufferPool.BufferSize);
+//                        //}
+
+//                        returnValue = new Byte[bufferSize]; //Fx.AllocateByteArray(bufferPool.BufferSize);
+//                    }
+//                }
+//                else
+//                {
+//                    //if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
+//                    //{
+//                    //    TraceCore.BufferPoolAllocation(Fx.Trace, bufferSize);
+//                    //}
+
+//                    returnValue = new Byte[bufferSize]; //Fx.AllocateByteArray(bufferSize);
+//                }
+
+//#if DEBUG
+//                string dummy;
+//                this.buffersPooled.TryRemove(returnValue.GetHashCode(), out dummy);
+//#endif //DEBUG
+
+//                return returnValue;
+//            }
+
+//#if DEBUG
+//            //[SecuritySafeCritical]
+//            //[PermissionSet(SecurityAction.Assert, Unrestricted = true)]
+//            //private static string CaptureStackTrace()
+//            //{
+//            //    return new StackTrace(true).ToString();
+//            //}
+//#endif //DEBUG
+
+//            void TuneQuotas()
+//            {
+//                if (this.areQuotasBeingTuned)
+//                {
+//                    return;
+//                }
+
+//                bool lockHeld = false;
+//                try
+//                {
+//                    Monitor.TryEnter(this.tuningLock, ref lockHeld);
+
+//                    // Don't bother if another thread already has the lock
+//                    if (!lockHeld || this.areQuotasBeingTuned)
+//                    {
+//                        return;
+//                    }
+
+//                    this.areQuotasBeingTuned = true;
+//                }
+//                finally
+//                {
+//                    if (lockHeld)
+//                    {
+//                        Monitor.Exit(this.tuningLock);
+//                    }
+//                }
+
+//                // find the "poorest" pool
+//                int starvedIndex = FindMostStarvedPool();
+//                if (starvedIndex >= 0)
+//                {
+//                    BufferPool starvedBufferPool = this.bufferPools[starvedIndex];
+
+//                    if (this.remainingMemory < starvedBufferPool.BufferSize)
+//                    {
+//                        // find the "richest" pool
+//                        int excessiveIndex = FindMostExcessivePool();
+//                        if (excessiveIndex >= 0)
+//                        {
+//                            // steal from the richest
+//                            DecreaseQuota(ref this.bufferPools[excessiveIndex]);
+//                        }
+//                    }
+
+//                    if (this.remainingMemory >= starvedBufferPool.BufferSize)
+//                    {
+//                        // give to the poorest
+//                        IncreaseQuota(ref this.bufferPools[starvedIndex]);
+//                    }
+//                }
+
+//                // reset statistics
+//                for (int i = 0; i < this.bufferPools.Length; i++)
+//                {
+//                    BufferPool bufferPool = this.bufferPools[i];
+//                    bufferPool.Misses = 0;
+//                }
+
+//                this.totalMisses = 0;
+//                this.areQuotasBeingTuned = false;
+//            }
+
+//            abstract class BufferPool
+//            {
+//                int bufferSize;
+//                int count;
+//                int limit;
+//                int misses;
+//                int peak;
+
+//                public BufferPool(int bufferSize, int limit)
+//                {
+//                    this.bufferSize = bufferSize;
+//                    this.limit = limit;
+//                }
+
+//                public int BufferSize
+//                {
+//                    get { return this.bufferSize; }
+//                }
+
+//                public int Limit
+//                {
+//                    get { return this.limit; }
+//                }
+
+//                public int Misses
+//                {
+//                    get { return this.misses; }
+//                    set { this.misses = value; }
+//                }
+
+//                public int Peak
+//                {
+//                    get { return this.peak; }
+//                }
+
+//                public void Clear()
+//                {
+//                    this.OnClear();
+//                    this.count = 0;
+//                }
+
+//                public void DecrementCount()
+//                {
+//                    int newValue = this.count - 1;
+//                    if (newValue >= 0)
+//                    {
+//                        this.count = newValue;
+//                    }
+//                }
+
+//                public void IncrementCount()
+//                {
+//                    int newValue = this.count + 1;
+//                    if (newValue <= this.limit)
+//                    {
+//                        this.count = newValue;
+//                        if (newValue > this.peak)
+//                        {
+//                            this.peak = newValue;
+//                        }
+//                    }
+//                }
+
+//                internal abstract byte[] Take();
+//                internal abstract bool Return(byte[] buffer);
+//                internal abstract void OnClear();
+
+//                internal static BufferPool CreatePool(int bufferSize, int limit)
+//                {
+//                    // To avoid many buffer drops during training of large objects which
+//                    // get allocated on the LOH, we use the LargeBufferPool and for 
+//                    // bufferSize < 85000, the SynchronizedPool. However if bufferSize < 85000
+//                    // and (bufferSize + array-overhead) > 85000, this would still use 
+//                    // the SynchronizedPool even though it is allocated on the LOH.
+//                    if (bufferSize < 85000)
+//                    {
+//                        return new SynchronizedBufferPool(bufferSize, limit);
+//                    }
+//                    else
+//                    {
+//                        return new LargeBufferPool(bufferSize, limit);
+//                    }
+//                }
+
+//                class SynchronizedBufferPool : BufferPool
+//                {
+//                    SynchronizedPool<byte[]> innerPool;
+
+//                    internal SynchronizedBufferPool(int bufferSize, int limit)
+//                        : base(bufferSize, limit)
+//                    {
+//                        this.innerPool = new SynchronizedPool<byte[]>(limit);
+//                    }
+
+//                    internal override void OnClear()
+//                    {
+//                        this.innerPool.Clear();
+//                    }
+
+//                    internal override byte[] Take()
+//                    {
+//                        return this.innerPool.Take();
+//                    }
+
+//                    internal override bool Return(byte[] buffer)
+//                    {
+//                        return this.innerPool.Return(buffer);
+//                    }
+//                }
+
+//                class LargeBufferPool : BufferPool
+//                {
+//                    Stack<byte[]> items;
+
+//                    internal LargeBufferPool(int bufferSize, int limit)
+//                        : base(bufferSize, limit)
+//                    {
+//                        this.items = new Stack<byte[]>(limit);
+//                    }
+
+//                    object ThisLock
+//                    {
+//                        get
+//                        {
+//                            return this.items;
+//                        }
+//                    }
+
+//                    internal override void OnClear()
+//                    {
+//                        lock (ThisLock)
+//                        {
+//                            this.items.Clear();
+//                        }
+//                    }
+
+//                    internal override byte[] Take()
+//                    {
+//                        lock (ThisLock)
+//                        {
+//                            if (this.items.Count > 0)
+//                            {
+//                                return this.items.Pop();
+//                            }
+//                        }
+
+//                        return null;
+//                    }
+
+//                    internal override bool Return(byte[] buffer)
+//                    {
+//                        lock (ThisLock)
+//                        {
+//                            if (this.items.Count < this.Limit)
+//                            {
+//                                this.items.Push(buffer);
+//                                return true;
+//                            }
+//                        }
+
+//                        return false;
+//                    }
+//                }
+//            }
+//        }
+
+//        class GCBufferManager : InternalBufferManager
+//        {
+//            static GCBufferManager value = new GCBufferManager();
+
+//            GCBufferManager()
+//            {
+//            }
+
+//            public static GCBufferManager Value
+//            {
+//                get { return value; }
+//            }
+
+//            public override void Clear()
+//            {
+//            }
+
+//            public override byte[] TakeBuffer(int bufferSize)
+//            {
+//                return new Byte[bufferSize];// Fx.AllocateByteArray(bufferSize);
+//            }
+
+//            public override void ReturnBuffer(byte[] buffer)
+//            {
+//                // do nothing, GC will reclaim this buffer
+//            }
+//        }
+//    }
+//}
index 059707e..d31571d 100644 (file)
@@ -1,67 +1,67 @@
-//------------------------------------------------------------
-// Copyright (c) Microsoft Corporation.  All rights reserved.
-//------------------------------------------------------------
+////------------------------------------------------------------
+//// Copyright (c) Microsoft Corporation.  All rights reserved.
+////------------------------------------------------------------
 
-namespace System.ServiceModel.Channels
-{
-    using System;
-    using System.Runtime;
-    using Microsoft.ServiceModel; // for QuotaExceededException
-    //using System.ServiceModel.Channels;
-    //using System.ServiceModel.Diagnostics.Application;
+//namespace System.ServiceModel.Channels
+//{
+//    using System;
+//    using System.Runtime;
+//    using Microsoft.ServiceModel; // for QuotaExceededException
+//    //using System.ServiceModel.Channels;
+//    //using System.ServiceModel.Diagnostics.Application;
 
-    class BufferManagerOutputStream : BufferedOutputStream
-    {
-        string quotaExceededString;
-        private object xmlBufferQuotaExceeded;
-        private int initialBufferSize;
-        private int maxBufferSize;
-        private InternalBufferManager bufferManager;
+//    class BufferManagerOutputStream : BufferedOutputStream
+//    {
+//        string quotaExceededString;
+//        private object xmlBufferQuotaExceeded;
+//        private int initialBufferSize;
+//        private int maxBufferSize;
+//        private InternalBufferManager bufferManager;
 
-        public BufferManagerOutputStream(string quotaExceededString)
-            : base()
-        {
-            this.quotaExceededString = quotaExceededString;
-        }
+//        public BufferManagerOutputStream(string quotaExceededString)
+//            : base()
+//        {
+//            this.quotaExceededString = quotaExceededString;
+//        }
 
-        public BufferManagerOutputStream(string quotaExceededString, int maxSize)
-            : base(maxSize)
-        {
-            this.quotaExceededString = quotaExceededString;
-        }
+//        public BufferManagerOutputStream(string quotaExceededString, int maxSize)
+//            : base(maxSize)
+//        {
+//            this.quotaExceededString = quotaExceededString;
+//        }
 
-        //public BufferManagerOutputStream(string quotaExceededString, int initialSize, int maxSize, BufferManager bufferManager)
-        //    : base(initialSize, maxSize, BufferManager.GetInternalBufferManager(bufferManager))
-        //{
-        //    this.quotaExceededString = quotaExceededString;
-        //}
+//        //public BufferManagerOutputStream(string quotaExceededString, int initialSize, int maxSize, BufferManager bufferManager)
+//        //    : base(initialSize, maxSize, BufferManager.GetInternalBufferManager(bufferManager))
+//        //{
+//        //    this.quotaExceededString = quotaExceededString;
+//        //}
 
-        public BufferManagerOutputStream(object xmlBufferQuotaExceeded, int initialBufferSize, int maxBufferSize, InternalBufferManager bufferManager)
-        {
-            this.xmlBufferQuotaExceeded = xmlBufferQuotaExceeded;
-            this.initialBufferSize = initialBufferSize;
-            this.maxBufferSize = maxBufferSize;
-            this.bufferManager = bufferManager;
-        }
+//        public BufferManagerOutputStream(object xmlBufferQuotaExceeded, int initialBufferSize, int maxBufferSize, InternalBufferManager bufferManager)
+//        {
+//            this.xmlBufferQuotaExceeded = xmlBufferQuotaExceeded;
+//            this.initialBufferSize = initialBufferSize;
+//            this.maxBufferSize = maxBufferSize;
+//            this.bufferManager = bufferManager;
+//        }
 
-        public void Init(int initialSize, int maxSizeQuota, InternalBufferManager bufferManager)
-        {
-            Init(initialSize, maxSizeQuota, maxSizeQuota, bufferManager);
-        }
+//        public void Init(int initialSize, int maxSizeQuota, InternalBufferManager bufferManager)
+//        {
+//            Init(initialSize, maxSizeQuota, maxSizeQuota, bufferManager);
+//        }
 
-        public void Init(int initialSize, int maxSizeQuota, int effectiveMaxSize, InternalBufferManager bufferManager)
-        {
-            base.Reinitialize(initialSize, maxSizeQuota, effectiveMaxSize, null/*BufferManager.GetInternalBufferManager(bufferManager)*/);
-        }
+//        public void Init(int initialSize, int maxSizeQuota, int effectiveMaxSize, InternalBufferManager bufferManager)
+//        {
+//            base.Reinitialize(initialSize, maxSizeQuota, effectiveMaxSize, null/*BufferManager.GetInternalBufferManager(bufferManager)*/);
+//        }
 
-        protected override Exception CreateQuotaExceededException(int maxSizeQuota)
-        {
-            string excMsg = SR.GetString(this.quotaExceededString, maxSizeQuota);
-            //if (TD.MaxSentMessageSizeExceededIsEnabled())
-            //{
-            //    TD.MaxSentMessageSizeExceeded(excMsg);
-            //}
-            return new NotSupportedException();// QuotaExceededException(excMsg);
-        }
-    }
-}
+//        protected override Exception CreateQuotaExceededException(int maxSizeQuota)
+//        {
+//            string excMsg = SR.GetString(this.quotaExceededString, maxSizeQuota);
+//            //if (TD.MaxSentMessageSizeExceededIsEnabled())
+//            //{
+//            //    TD.MaxSentMessageSizeExceeded(excMsg);
+//            //}
+//            return new NotSupportedException();// QuotaExceededException(excMsg);
+//        }
+//    }
+//}
index 8579633..b34fc2d 100644 (file)
@@ -9,32 +9,33 @@ namespace System.ServiceModel.Diagnostics
     {
         internal Exception ThrowHelperError(ArgumentOutOfRangeException argumentOutOfRangeException)
         {
-            throw new NotImplementedException();
+            return new NotImplementedException();
         }
 
         internal Exception ThrowHelperError(Exception exception)
         {
-            throw new NotImplementedException();
+            return new NotImplementedException();
+            return new NotImplementedException();
         }
 
         internal Exception ThrowHelperArgumentNull(string v)
         {
-            throw new NotImplementedException();
+            return new NotImplementedException();
         }
 
         internal Exception ThrowHelperArgument(string v1, string v2)
         {
-            throw new NotImplementedException();
+            return new NotImplementedException();
         }
 
         internal Exception ThrowHelperWarning(InvalidOperationException invalidOperationException)
         {
-            throw new NotImplementedException();
+            return new NotImplementedException();
         }
 
         internal Exception ThrowHelperArgument(string v)
         {
-            throw new NotImplementedException();
+            return new NotImplementedException();
         }
     }
 }
\ No newline at end of file
index 7395f75..7b8a01c 100644 (file)
 namespace Microsoft.ServiceModel {
     using System;
     using System.Collections.Generic;
-    using System.Runtime;
-    using System.ServiceModel.Channels;
     using System.Xml;
     using System.IO; // added to use buffered stream
-                     //using System.ServiceModel;
+    using System.Runtime;
+    using System.ServiceModel.Channels;
 
 
 
@@ -24,7 +23,7 @@ namespace Microsoft.ServiceModel {
         List<Section> sections;
         byte[] buffer;
         int offset;
-        BufferedOutputStream stream; //BufferedStream - Original: BufferedOutputStream
+        BufferedStream stream; //BufferedStream - Original: BufferedOutputStream
         BufferState bufferState;
         XmlDictionaryWriter writer;
         XmlDictionaryReaderQuotas quotas;
@@ -73,11 +72,12 @@ namespace Microsoft.ServiceModel {
 
             int initialBufferSize = Math.Min(512, maxBufferSize);
 
-           
-            stream = new BufferManagerOutputStream(SR.XmlBufferQuotaExceeded, initialBufferSize, maxBufferSize,
-                InternalBufferManager.Create(0, int.MaxValue));
-                     
 
+            //stream = new BufferManagerOutputStream(SR.XmlBufferQuotaExceeded, initialBufferSize, maxBufferSize,
+            //    InternalBufferManager.Create(0, int.MaxValue));
+
+            stream = new BufferedStream(new MemoryStream(), initialBufferSize);
+            //stream = new MemoryStream(initialBufferSize);
             //stream = new BufferedStream(, maxBufferSize); // replacing code above
 
             sections = new List<Section>(1);
@@ -110,8 +110,8 @@ namespace Microsoft.ServiceModel {
             //if (this.writer == null)
             //{
 
-            //this.writer = XmlDictionaryWriter.CreateBinaryWriter(stream, XD.Dictionary, null, true);
-            this.writer = XmlDictionaryWriter.CreateBinaryWriter(stream); // this code replaces above
+            this.writer = XmlDictionaryWriter.CreateBinaryWriter(stream, null, null, false);
+            //this.writer = XmlDictionaryWriter.CreateBinaryWriter(stream); // this code replaces above
 
             //}
             //else
@@ -125,9 +125,11 @@ namespace Microsoft.ServiceModel {
         {
             if (bufferState != BufferState.Writing)
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidStateException());
-            this.writer.Close();
+            this.writer.Close(); // move
             bufferState = BufferState.Created;
+            //stream.Length
             int size = (int)stream.Length - offset;
+            //int size = stream.BufferSize;
             sections.Add(new Section(offset, size, this.quotas));
             offset += size;
         }
@@ -139,11 +141,15 @@ namespace Microsoft.ServiceModel {
             bufferState = BufferState.Reading;
             //int bufferSize = 0;
             //buffer = stream.ToArray(out bufferSize); NOT SUPPORTED
-            
+
             //Implementation to do the same that the line above
-            MemoryStream ms = new MemoryStream();
-            stream.CopyTo(ms);
-            buffer = ms.ToArray();
+
+            buffer = new byte[stream.Length];
+            stream.Position = 0;
+            stream.Read(buffer, 0, buffer.Length);
+            //MemoryStream ms = new MemoryStream(stream.Length);
+            //stream.CopyTo(ms);
+            //buffer = ms.ToArray();
             //-----
             writer = null;
             stream = null;
@@ -154,14 +160,17 @@ namespace Microsoft.ServiceModel {
             return new InvalidOperationException(SR.GetString(SR.XmlBufferInInvalidState));
         }
 
-
+        
 
         public XmlDictionaryReader GetReader(int sectionIndex)
         {
             if (bufferState != BufferState.Reading)
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidStateException());
             Section section = sections[sectionIndex];
-            XmlDictionaryReader reader = null;// XmlDictionaryReader.CreateBinaryReader(buffer, section.Offset, section.Size, XD.Dictionary, section.Quotas, null, null);
+            XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(buffer, section.Offset, section.Size, null, section.Quotas, null, null);
+            //reader = XmlDictionaryReader.CreateBinaryReader(buffer,section.Offset);
+            //XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(buffer, section.Quotas);
+            //reader = XmlDictionaryReader.CreateBinaryReader(buffer``)
             reader.MoveToContent();
             return reader;
         }
index f808644..782a5c7 100644 (file)
@@ -1,5 +1,4 @@
 using System;
-using Microsoft.ServiceModel.Syndication;
 
 namespace TestingApp
 {
@@ -7,13 +6,7 @@ namespace TestingApp
     {
         static void Main(string[] args)
         {
-            SyndicationFeed sf = new SyndicationFeed("First feed on .net core ever!!", "This is the first feed on .net core ever!", new Uri("https://microsoft.com"));
-
-            //xml writter
-            XmlWriter xmlw = XmlWriter.Create("FirstFeedEver.xml");
-            Rss20FeedFormatter rssf = new Rss20FeedFormatter(sf);
-            rssf.WriteTo(xmlw);
-            xmlw.Close();
+            Console.WriteLine("Peo");
         }
     }
 }
\ No newline at end of file
index 67608fb..731ef4a 100644 (file)
@@ -2,11 +2,7 @@
 
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <TargetFramework>netcoreapp1.1</TargetFramework>
+    <TargetFramework>netcoreapp2.0</TargetFramework>
   </PropertyGroup>
 
-  <ItemGroup>
-    <ProjectReference Include="..\src\Microsoft.ServiceModel.Syndication.csproj" />
-  </ItemGroup>
-
 </Project>
\ No newline at end of file
index 509de2e..e8a1921 100644 (file)
@@ -12,6 +12,12 @@ namespace Microsoft.ServiceModel.Syndication.Tests
         [Fact]
         public static void PassingTest()
         {
+           
+        }
+        
+        [Fact]
+        public static void crear()
+        {
             SyndicationFeed sf = new SyndicationFeed("First feed on .net core ever!!", "This is the first feed on .net core ever!", new Uri("https://microsoft.com"));
 
             //xml writter
@@ -19,11 +25,27 @@ namespace Microsoft.ServiceModel.Syndication.Tests
             Rss20FeedFormatter rssf = new Rss20FeedFormatter(sf);
             rssf.WriteTo(xmlw);
             xmlw.Close();
-            Assert.True(sf != null);
+            Assert.True(true);
+        }
 
-            example3();
+        [Fact]
+        public static void read()
+        {
+            XmlReader xmlr = XmlReader.Create("feedatom.xml");
+            SyndicationFeed sf = SyndicationFeed.Load(xmlr);
+            //Console.WriteLine(sf.Title.ToString());
+
+            Console.WriteLine(sf.Title.ToString());
+            //Console.ReadLine();
+
+            //wite the one that was read
+            XmlWriter xmlw = XmlWriter.Create("leido.xml");
+            Atom10FeedFormatter rs = new Atom10FeedFormatter(sf);
+            rs.WriteTo(xmlw);
+            xmlw.Close();
         }
         
+        [Fact]
         public static void example3()
         {
             //Test example to syndicate the release of SyndicationFeed to .net core
@@ -59,6 +81,7 @@ namespace Microsoft.ServiceModel.Syndication.Tests
             Atom10FeedFormatter atomf = new Atom10FeedFormatter(feed);
             atomf.WriteTo(xmlw);
             xmlw.Close();
+            Assert.True(true);
         }
 
         [Fact]