static void OnGetBufferComplete(IAsyncEventArgs state) { GetBufferEventResult result = ((GetBufferAsyncEventArgs)state).Result; InternalWriteBase64TextAsyncWriter thisPtr = (InternalWriteBase64TextAsyncWriter)state.AsyncState; XmlWriteBase64AsyncArguments writerArgs = thisPtr.writerState.Arguments; Exception completionException = null; bool completeSelf = false; try { if (state.Exception != null) { completionException = state.Exception; completeSelf = true; } else { byte[] chars = result.Buffer; int offset = result.Offset; Base64Encoding encoding = XmlConverter.Base64Encoding; int byteCount = Math.Min(bufferLength / 4 * 3, writerArgs.Count - writerArgs.Count % 3); int charCount = byteCount / 3 * 4; thisPtr.writer.Advance(encoding.GetChars( writerArgs.Buffer, writerArgs.Offset, byteCount, chars, offset)); if (byteCount >= 3) { writerArgs.Offset += byteCount; writerArgs.Count -= byteCount; } if (thisPtr.InternalWriteBase64TextAsync(thisPtr.writerState) == AsyncCompletionResult.Completed) { completeSelf = true; } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } completionException = exception; completeSelf = true; } if (completeSelf) { thisPtr.writerState.Complete(false, completionException); } }
static void OnWriteComplete(IAsyncEventArgs eventArgs) { InternalWriteBase64TextAsyncWriter thisPtr = (InternalWriteBase64TextAsyncWriter)eventArgs.AsyncState; AsyncEventArgs <XmlNodeWriterWriteBase64TextArgs> state = thisPtr.nodeState; thisPtr.nodeState = null; state.Complete(false, eventArgs.Exception); }
internal override AsyncCompletionResult WriteBase64TextAsync(AsyncEventArgs <XmlNodeWriterWriteBase64TextArgs> xmlNodeWriterState) { if (internalWriteBase64TextAsyncWriter == null) { internalWriteBase64TextAsyncWriter = new InternalWriteBase64TextAsyncWriter(this); } return(this.internalWriteBase64TextAsyncWriter.StartAsync(xmlNodeWriterState)); }
static private void OnTrailBytesComplete(IAsyncEventArgs eventArgs) { InternalWriteBase64TextAsyncWriter thisPtr = (InternalWriteBase64TextAsyncWriter)eventArgs.AsyncState; Exception completionException = null; bool completeSelf = false; try { if (eventArgs.Exception != null) { completionException = eventArgs.Exception; completeSelf = true; } else if (thisPtr.WriteBufferAsync() == AsyncCompletionResult.Completed) { completeSelf = true; } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } completionException = exception; completeSelf = true; } if (completeSelf) { AsyncEventArgs <XmlNodeWriterWriteBase64TextArgs> state = thisPtr.nodeState; thisPtr.nodeState = null; state.Complete(false, eventArgs.Exception); } }
internal override AsyncCompletionResult WriteBase64TextAsync(AsyncEventArgs<XmlNodeWriterWriteBase64TextArgs> xmlNodeWriterState) { if (internalWriteBase64TextAsyncWriter == null) { internalWriteBase64TextAsyncWriter = new InternalWriteBase64TextAsyncWriter(this); } return this.internalWriteBase64TextAsyncWriter.StartAsync(xmlNodeWriterState); }