Пример #1
0
 public void Appending()
 {
     var page = new SpoolPage();
     page.Append("hello");
     Assert.IsNull(page.Next);
     Assert.AreEqual(1, page.Count);
     Assert.AreEqual("hello", page.Buffer[0]);
 }
Пример #2
0
 public SpoolPage Append(SpoolPage pages)
 {
     _readonly = true;
     _next = new SpoolPage(pages);
     var scan = _next;
     while(scan._next != null)
         scan = scan._next;
     return scan;
 }
Пример #3
0
 public void AppendMultiple()
 {
     var page = new SpoolPage();
     page.Append("hello");
     page.Append("world");
     Assert.IsNull(page.Next);
     Assert.AreEqual(2, page.Count);
     Assert.AreEqual("hello", page.Buffer[0]);
     Assert.AreEqual("world", page.Buffer[1]);
 }
Пример #4
0
        private SpoolPage(SpoolPage original)
        {
            _buffer = original._buffer;
            _count = original._count;
            if (original._next != null)
                _next = new SpoolPage(original._next);

            _readonly = true;
            original._readonly = true;
            _nonreusable = true;
            original._nonreusable = true;
        }
Пример #5
0
        public SpoolPage Append(SpoolPage pages)
        {
            _readonly = true;
            _next     = new SpoolPage(pages);
            var scan = _next;

            while (scan._next != null)
            {
                scan = scan._next;
            }
            return(scan);
        }
Пример #6
0
 internal void SendToTextWriter(TextWriter target)
 {
     for (SpoolPage page = this._first; page != null; page = page.Next)
     {
         string[] buffer = page.Buffer;
         int      count  = page.Count;
         for (int i = 0; i != count; i++)
         {
             target.Write(buffer[i]);
         }
     }
 }
Пример #7
0
 IEnumerator <string> IEnumerable <string> .GetEnumerator()
 {
     for (SpoolPage iteratorVariable0 = this._first; iteratorVariable0 != null; iteratorVariable0 = iteratorVariable0.Next)
     {
         string[] buffer = iteratorVariable0.Buffer;
         int      count  = iteratorVariable0.Count;
         for (int i = 0; i != count; i++)
         {
             yield return(buffer[i]);
         }
     }
 }
        public SpoolPage Append(SpoolPage pages)
        {
            this._readonly = true;
            this._next     = new SpoolPage(pages);
            SpoolPage page = this._next;

            while (page._next != null)
            {
                page = page._next;
            }
            return(page);
        }
 private SpoolPage(SpoolPage original)
 {
     this._buffer = original._buffer;
     this._count  = original._count;
     if (original._next != null)
     {
         this._next = new SpoolPage(original._next);
     }
     this._readonly        = true;
     original._readonly    = true;
     this._nonreusable     = true;
     original._nonreusable = true;
 }
Пример #10
0
 public void AppendOverBoundary()
 {
     var page = new SpoolPage();
     var last = page;
     for (int index = 0; index != SpoolPage.BUFFER_SIZE + 30; ++index)
     {
         last = last.Append(index.ToString());
     }
     Assert.AreNotSame(page, last);
     Assert.AreEqual(SpoolPage.BUFFER_SIZE, page.Count);
     Assert.AreEqual(30, last.Count);
     Assert.AreEqual(SpoolPage.BUFFER_SIZE.ToString(), last.Buffer[0]);
 }
 public SpoolPage Append(string value)
 {
     if (this._readonly)
     {
         if (this._next == null)
         {
             this._next = new SpoolPage();
         }
         return(this._next.Append(value));
     }
     this._buffer[this._count++] = value;
     if (this._count == 250)
     {
         this._readonly = true;
     }
     return(this);
 }
Пример #12
0
        public SpoolPage Append(string value)
        {
            if (_readonly)
            {
                if (_next == null)
                {
                    _next = new SpoolPage();
                }
                return(_next.Append(value));
            }

            _buffer[_count++] = value;
            if (_count == BUFFER_SIZE)
            {
                _readonly = true;
            }
            return(this);
        }
 public void Release()
 {
     if (Monitor.TryEnter(_allocator._cache))
     {
         try
         {
             for (SpoolPage page = this; (page != null) && (_allocator._cache.Count < 200); page = page._next)
             {
                 if (!page._nonreusable && !page._released)
                 {
                     page._released = true;
                     Array.Clear(page._buffer, 0, page._count);
                     _allocator._cache.Push(page._buffer);
                 }
             }
         }
         finally
         {
             Monitor.Exit(_allocator._cache);
         }
     }
 }
Пример #14
0
        public void CallsReleaseOnNextOnlyIfIsNotReleasedAlready()
        {
            var first = new SpoolPage();
            var next = first;
            for (int index = 0; index != SpoolPage.BUFFER_SIZE + 30; ++index)
            {
                next = next.Append(index.ToString());
            }
            next.Release();

            var second = new SpoolPage();
            second.Append("1");
            second.Append("2");
            second.Append("3");

            first.Release();

            Assert.AreEqual(3, second.Count);
            Assert.AreEqual("1", second.Buffer[0]);
            Assert.AreEqual("2", second.Buffer[1]);
            Assert.AreEqual("3", second.Buffer[2]);
        }
Пример #15
0
 public override void Write(string value)
 {
     this._last = this._last.Append(value);
 }
Пример #16
0
 public SpoolWriter()
 {
     this._last = this._first;
 }
Пример #17
0
 public override void Write(string value)
 {
     _last = _last.Append(value);
 }
Пример #18
0
 public SpoolWriter()
 {
     _first = new SpoolPage();
     _last  = _first;
 }
Пример #19
0
        public SpoolPage Append(string value)
        {
            if (_readonly)
            {
                if (_next == null)
                    _next = new SpoolPage();
                return _next.Append(value);
            }

            _buffer[_count++] = value;
            if (_count == BUFFER_SIZE)
                _readonly = true;
            return this;
        }