internal AsyncCompletionResult StartAsync(AsyncEventArgs <XmlNodeWriterWriteBase64TextArgs> xmlNodeWriterState) { Fx.Assert(xmlNodeWriterState != null, "xmlNodeWriterState cannot be null."); Fx.Assert(this.nodeState == null, "nodeState is not null."); this.nodeState = xmlNodeWriterState; XmlNodeWriterWriteBase64TextArgs nodeWriterArgs = xmlNodeWriterState.Arguments; if (nodeWriterArgs.TrailCount > 0) { this.writerArgs.Buffer = nodeWriterArgs.TrailBuffer; this.writerArgs.Offset = 0; this.writerArgs.Count = nodeWriterArgs.TrailCount; this.writerState.Set(onTrailByteComplete, this.writerArgs, this); if (this.InternalWriteBase64TextAsync(this.writerState) != AsyncCompletionResult.Completed) { return(AsyncCompletionResult.Queued); } this.writerState.Complete(true); } if (this.WriteBufferAsync() == AsyncCompletionResult.Completed) { this.nodeState = null; return(AsyncCompletionResult.Completed); } return(AsyncCompletionResult.Queued); }
bool HandleWriteBase64Text(bool isAsyncCallback) { Fx.Assert(this.count > 0 && this.actualByteCount >= 3, "HandleWriteBase64Text cannot be invoked with less than 3 bytes."); if (!writer.isXmlnsAttribute) { if (!isAsyncCallback) { if (this.nodeWriterAsyncState == null) { this.nodeWriterAsyncState = new AsyncEventArgs<XmlNodeWriterWriteBase64TextArgs>(); this.nodeWriterArgs = new XmlNodeWriterWriteBase64TextArgs(); } if (onWriteComplete == null) { onWriteComplete = new AsyncEventArgsCallback(OnWriteComplete); } this.writer.StartContent(); this.nodeWriterArgs.TrailBuffer = this.writer.trailBytes; this.nodeWriterArgs.TrailCount = this.writer.trailByteCount; this.nodeWriterArgs.Buffer = this.buffer; this.nodeWriterArgs.Offset = this.offset; this.nodeWriterArgs.Count = this.actualByteCount - this.writer.trailByteCount; this.nodeWriterAsyncState.Set(onWriteComplete, this.nodeWriterArgs, this); if (this.writer.writer.WriteBase64TextAsync(this.nodeWriterAsyncState) != AsyncCompletionResult.Completed) { return false; } this.nodeWriterAsyncState.Complete(true); } this.writer.EndContent(); } this.writer.trailByteCount = (this.totalByteCount - this.actualByteCount); if (this.writer.trailByteCount > 0) { int trailOffset = offset + count - this.writer.trailByteCount; for (int i = 0; i < this.writer.trailByteCount; i++) this.writer.trailBytes[i] = this.buffer[trailOffset++]; } return true; }