Example #1
0
 public void Complete()
 {
     NephosAssertionException.Assert(this.outStreamAccumulator != null, "The underlying AccumulatorStream must not be null!");
     NephosAssertionException.Assert(this.xmlWriter != null, "The underlying XML Writer must not be null!");
     this.xmlWriter.Close();
     this.outStreamAccumulator.Dispose();
     this.xmlWriter            = null;
     this.outStreamAccumulator = null;
 }
Example #2
0
        protected IEnumerator <IAsyncResult> EncodeListsToStreamImpl(Uri requestUrl, IList <ListType> results, IList <ListOperationContext> listOperationContexts, string rootElement, Stream outStream, TimeSpan timeout, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult innerStream;

            NephosAssertionException.Assert(results.Count == listOperationContexts.Count, "The number of lists did not match the number of list operation contexts.");
            Duration startingNow      = Duration.StartingNow;
            int      bytesAccumulated = 0;

            if (this.outStreamAccumulator != null)
            {
                NephosAssertionException.Assert(this.xmlWriter != null, "The underlying XML writer must not be null if the underlying AccumulatorStream is not null.");
            }
            else
            {
                NephosAssertionException.Assert(this.xmlWriter == null, "The underlying XML writer must be null if the underlying AccumulatorStream is null.");
                this.outStreamAccumulator = new AccumulatorStream(outStream, 262144, false);
                this.xmlWriter            = XmlWriter.Create(this.outStreamAccumulator, this.xmlWriterSettings);
            }
            bool flag = !string.IsNullOrEmpty(rootElement);

            if (!flag)
            {
                NephosAssertionException.Assert(results.Count == 1, "If there is no root element specified, only one list must be being encoded.");
            }
            else
            {
                this.xmlWriter.WriteStartElement(rootElement);
            }
            int num = 0;

            foreach (ListType listType in results)
            {
                ListOperationContext item = listOperationContexts[num];
                this.EncodeInitialElements(requestUrl, item, listType, this.xmlWriter);
                foreach (ListEntryType listEntryType in listType)
                {
                    XmlListEncoder <ListType, ListEntryType, ListOperationContext> totalCount = this;
                    totalCount.TotalCount = totalCount.TotalCount + 1;
                    this.EncodeEntry(requestUrl, item, listEntryType, this.xmlWriter);
                    if (!XmlListEncoder <ListType, ListEntryType, ListOperationContext> .AccumulatorStreamNeedsFlush(this.outStreamAccumulator, 262144))
                    {
                        continue;
                    }
                    bytesAccumulated += this.outStreamAccumulator.BytesAccumulated;
                    innerStream       = this.outStreamAccumulator.BeginFlushToInnerStream(startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("HttpRestProcessor.EncodeListsToStreamImpl"));
                    yield return(innerStream);

                    this.outStreamAccumulator.EndFlushToInnerStream(innerStream);
                }
                this.EncodeEndElements(this.xmlWriter, listType, item);
                num++;
            }
            if (flag)
            {
                this.xmlWriter.WriteEndElement();
            }
            this.xmlWriter.Flush();
            bytesAccumulated += this.outStreamAccumulator.BytesAccumulated;
            innerStream       = this.outStreamAccumulator.BeginFlushToInnerStream(startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("HttpRestProcessor.EncodeListsToStreamImpl"));
            yield return(innerStream);

            this.outStreamAccumulator.EndFlushToInnerStream(innerStream);
            IStringDataEventStream verbose = Logger <IRestProtocolHeadLogger> .Instance.Verbose;

            verbose.Log("Finished flushing the whole list data into the underlying stream. Total bytes: {0}", new object[] { bytesAccumulated });
            if (!this.isCompletingManually)
            {
                this.Complete();
            }
        }
Example #3
0
 private static bool AccumulatorStreamNeedsFlush(AccumulatorStream accStream, int bufferSize)
 {
     return((double)accStream.BytesAccumulated > (double)bufferSize * 0.9);
 }