Ejemplo n.º 1
0
        /// <summary>
        /// Called from NpgsqlState.ProcessBackendResponses upon CopyOutResponse.
        /// If CopyStream is already set, it is used to write data received from server, after which the copy ends.
        /// Otherwise CopyStream is set to a readable NpgsqlCopyOutStream that receives data from server.
        /// </summary>
        protected override void StartCopy(NpgsqlConnector context, NpgsqlCopyFormat copyFormat)
        {
            _copyFormat = copyFormat;
            Stream userFeed = context.Mediator.CopyStream;

            if (userFeed == null)
            {
                context.Mediator.CopyStream = new NpgsqlCopyOutStream(context);
            }
            else
            {
                byte[] buf;
                while ((buf = GetCopyData(context)) != null)
                {
                    userFeed.Write(buf, 0, buf.Length);
                }
                userFeed.Close();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called from NpgsqlState.ProcessBackendResponses upon CopyInResponse.
        /// If CopyStream is already set, it is used to read data to push to server, after which the copy is completed.
        /// Otherwise CopyStream is set to a writable NpgsqlCopyInStream that calls SendCopyData each time it is written to.
        /// </summary>
        protected override void StartCopy(NpgsqlConnector context, NpgsqlCopyFormat copyFormat)
        {
            _copyFormat = copyFormat;
            Stream userFeed = context.Mediator.CopyStream;

            if (userFeed == null)
            {
                context.Mediator.CopyStream = new NpgsqlCopyInStream(context);
            }
            else
            {
                // copy all of user feed to server at once
                int    bufsiz = context.Mediator.CopyBufferSize;
                byte[] buf    = new byte[bufsiz];
                int    len;
                while ((len = userFeed.Read(buf, 0, bufsiz)) > 0)
                {
                    SendCopyData(context, buf, 0, len);
                }
                SendCopyDone(context);
            }
        }
Ejemplo n.º 3
0
        // COPY methods

        protected virtual void StartCopy(NpgsqlConnector context, NpgsqlCopyFormat copyFormat)
        {
            throw new InvalidOperationException("Internal Error! " + this);
        }