コード例 #1
0
            AsyncCompletionResult InternalWriteBase64TextAsync(AsyncEventArgs<XmlWriteBase64AsyncArguments> writerState)
            {
                GetBufferAsyncEventArgs bufferState = this.getBufferState;
                GetBufferArgs bufferArgs = this.getBufferArgs;
                XmlWriteBase64AsyncArguments writerArgs = writerState.Arguments;

                if (bufferState == null)
                {
                    // Need to initialize the cached getBufferState 
                    // used to call GetBufferAsync() multiple times.
                    bufferState = new GetBufferAsyncEventArgs();
                    bufferArgs = new GetBufferArgs();
                    this.getBufferState = bufferState;
                    this.getBufferArgs = bufferArgs;
                }

                Base64Encoding encoding = XmlConverter.Base64Encoding;

                while (writerArgs.Count >= 3)
                {
                    int byteCount = Math.Min(bufferLength / 4 * 3, writerArgs.Count - writerArgs.Count % 3);
                    int charCount = byteCount / 3 * 4;

                    bufferArgs.Count = charCount;
                    bufferState.Set(onGetBufferComplete, bufferArgs, this);
                    if (writer.GetBufferAsync(bufferState) == AsyncCompletionResult.Completed)
                    {
                        GetBufferEventResult getbufferResult = bufferState.Result;
                        bufferState.Complete(true);
                        writer.Advance(encoding.GetChars(
                            writerArgs.Buffer,
                            writerArgs.Offset,
                            byteCount,
                            getbufferResult.Buffer,
                            getbufferResult.Offset));
                        writerArgs.Offset += byteCount;
                        writerArgs.Count -= byteCount;
                    }
                    else
                    {
                        return AsyncCompletionResult.Queued;
                    }
                }

                if (writerArgs.Count > 0)
                {
                    bufferArgs.Count = 4;
                    bufferState.Set(onGetBufferComplete, bufferArgs, this);
                    if (writer.GetBufferAsync(bufferState) == AsyncCompletionResult.Completed)
                    {
                        GetBufferEventResult getbufferResult = bufferState.Result;
                        bufferState.Complete(true);
                        writer.Advance(encoding.GetChars(
                            writerArgs.Buffer,
                            writerArgs.Offset,
                            writerArgs.Count,
                            getbufferResult.Buffer,
                            getbufferResult.Offset));
                    }
                    else
                    {
                        return AsyncCompletionResult.Queued;
                    }
                }

                return AsyncCompletionResult.Completed;
            }
コード例 #2
0
            AsyncCompletionResult InternalWriteBase64TextAsync(AsyncEventArgs <XmlWriteBase64AsyncArguments> writerState)
            {
                GetBufferAsyncEventArgs      bufferState = this.getBufferState;
                GetBufferArgs                bufferArgs  = this.getBufferArgs;
                XmlWriteBase64AsyncArguments writerArgs  = writerState.Arguments;

                if (bufferState == null)
                {
                    // Need to initialize the cached getBufferState
                    // used to call GetBufferAsync() multiple times.
                    bufferState         = new GetBufferAsyncEventArgs();
                    bufferArgs          = new GetBufferArgs();
                    this.getBufferState = bufferState;
                    this.getBufferArgs  = bufferArgs;
                }

                Base64Encoding encoding = XmlConverter.Base64Encoding;

                while (writerArgs.Count >= 3)
                {
                    int byteCount = Math.Min(bufferLength / 4 * 3, writerArgs.Count - writerArgs.Count % 3);
                    int charCount = byteCount / 3 * 4;

                    bufferArgs.Count = charCount;
                    bufferState.Set(onGetBufferComplete, bufferArgs, this);
                    if (writer.GetBufferAsync(bufferState) == AsyncCompletionResult.Completed)
                    {
                        GetBufferEventResult getbufferResult = bufferState.Result;
                        bufferState.Complete(true);
                        writer.Advance(encoding.GetChars(
                                           writerArgs.Buffer,
                                           writerArgs.Offset,
                                           byteCount,
                                           getbufferResult.Buffer,
                                           getbufferResult.Offset));
                        writerArgs.Offset += byteCount;
                        writerArgs.Count  -= byteCount;
                    }
                    else
                    {
                        return(AsyncCompletionResult.Queued);
                    }
                }

                if (writerArgs.Count > 0)
                {
                    bufferArgs.Count = 4;
                    bufferState.Set(onGetBufferComplete, bufferArgs, this);
                    if (writer.GetBufferAsync(bufferState) == AsyncCompletionResult.Completed)
                    {
                        GetBufferEventResult getbufferResult = bufferState.Result;
                        bufferState.Complete(true);
                        writer.Advance(encoding.GetChars(
                                           writerArgs.Buffer,
                                           writerArgs.Offset,
                                           writerArgs.Count,
                                           getbufferResult.Buffer,
                                           getbufferResult.Offset));
                    }
                    else
                    {
                        return(AsyncCompletionResult.Queued);
                    }
                }

                return(AsyncCompletionResult.Completed);
            }