GetResourceString() static private method

static private GetResourceString ( String key ) : String
key String
return String
示例#1
0
        public override void WriteByte(byte value)
        {
            if (this._bClosed)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }
            if (this._chunks == null)
            {
                this._chunks      = this.AllocateMemoryChunk();
                this._writeChunk  = this._chunks;
                this._writeOffset = 0;
            }
            byte[] buffer = this._writeChunk.Buffer;
            int    length = buffer.Length;

            if (this._writeOffset == length)
            {
                this._writeChunk.Next = this.AllocateMemoryChunk();
                this._writeChunk      = this._writeChunk.Next;
                this._writeOffset     = 0;
                buffer = this._writeChunk.Buffer;
                length = buffer.Length;
            }
            buffer[this._writeOffset++] = value;
        }
        private static void AsyncCopyStreamReadCallback(IAsyncResult iar)
        {
            AsyncCopyStreamResult asyncState = (AsyncCopyStreamResult)iar.AsyncState;

            try
            {
                int bytesRead = asyncState.Source.EndRead(iar);
                if (bytesRead == 0)
                {
                    asyncState.SetComplete(null, null);
                }
                else
                {
                    if (bytesRead < 0)
                    {
                        throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_UnknownReadError"));
                    }
                    AsyncCopyWriteHelper(asyncState, bytesRead);
                }
            }
            catch (Exception exception)
            {
                asyncState.SetComplete(null, exception);
            }
        }
示例#3
0
        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
        {
            IMethodCallMessage mcm = (IMethodCallMessage)msg;
            IMessage           retMsg;

            try
            {
                // serialize message
                ITransportHeaders headers;
                Stream            requestStream;
                SerializeMessage(mcm, out headers, out requestStream);

                // process message
                ClientChannelSinkStack sinkStack = new ClientChannelSinkStack(replySink);
                sinkStack.Push(this, mcm);
                _nextSink.AsyncProcessRequest(sinkStack, msg, headers, requestStream);
            }
            catch (Exception e)
            {
                retMsg = new ReturnMessage(e, mcm);
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(retMsg);
                }
            }
            catch {
                retMsg = new ReturnMessage(new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")), mcm);
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(retMsg);
                }
            }

            return(null);
        } // AsyncProcessMessage
 private static void AsyncCopyReadHelper(AsyncCopyStreamResult streamState)
 {
     if (streamState.AsyncRead)
     {
         byte[] buffer = streamState.Buffer;
         streamState.Source.BeginRead(buffer, 0, buffer.Length, _asyncCopyStreamReadCallback, streamState);
     }
     else
     {
         byte[] buffer2   = streamState.Buffer;
         int    bytesRead = streamState.Source.Read(buffer2, 0, buffer2.Length);
         if (bytesRead == 0)
         {
             streamState.SetComplete(null, null);
         }
         else
         {
             if (bytesRead < 0)
             {
                 throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_UnknownReadError"));
             }
             AsyncCopyWriteHelper(streamState, bytesRead);
         }
     }
 }
示例#5
0
        }         // BufferCopy

        internal static IAsyncResult BeginAsyncCopyStream(
            Stream source, Stream target,
            bool asyncRead, bool asyncWrite,
            bool closeSource, bool closeTarget,
            AsyncCallback callback, Object state)
        {
            AsyncCopyStreamResult streamState = new AsyncCopyStreamResult(callback, state);

            byte[] buffer = CoreChannel.BufferPool.GetBuffer();

            streamState.Source      = source;
            streamState.Target      = target;
            streamState.Buffer      = buffer;
            streamState.AsyncRead   = asyncRead;
            streamState.AsyncWrite  = asyncWrite;
            streamState.CloseSource = closeSource;
            streamState.CloseTarget = closeTarget;

            try
            {
                AsyncCopyReadHelper(streamState);
            }
            catch (Exception e)
            {
                streamState.SetComplete(null, e);
            }
            catch {
                streamState.SetComplete(null, new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")));
            }

            return(streamState);
        } // BeginAsyncCopyStream
示例#6
0
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMethodCallMessage mcm = (IMethodCallMessage)msg;
            IMessage           retMsg;

            try
            {
                // serialize message
                ITransportHeaders headers;
                Stream            requestStream;
                SerializeMessage(mcm, out headers, out requestStream);

                // process message
                Stream            returnStream;
                ITransportHeaders returnHeaders;
                _nextSink.ProcessMessage(msg, headers, requestStream,
                                         out returnHeaders, out returnStream);
                if (returnHeaders == null)
                {
                    throw new ArgumentNullException("returnHeaders");
                }

                // deserialize stream
                retMsg = DeserializeMessage(mcm, returnHeaders, returnStream);
            }
            catch (Exception e)
            {
                retMsg = new ReturnMessage(e, mcm);
            }
            catch {
                retMsg = new ReturnMessage(new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")), mcm);
            }

            return(retMsg);
        } // SyncProcessMessage
示例#7
0
        } // AsyncCopyWriteHelper

        private static void AsyncCopyStreamReadCallback(IAsyncResult iar)
        {
            AsyncCopyStreamResult state = (AsyncCopyStreamResult)iar.AsyncState;

            try
            {
                Stream source = state.Source;

                int bytesRead = source.EndRead(iar);
                if (bytesRead == 0)
                {
                    state.SetComplete(null, null);
                }
                else
                if (bytesRead < 0)
                {
                    throw new RemotingException(
                              CoreChannel.GetResourceString("Remoting_Stream_UnknownReadError"));
                }
                else
                {
                    AsyncCopyWriteHelper(state, bytesRead);
                }
            }
            catch (Exception e)
            {
                state.SetComplete(null, e);
            }
            catch {
                state.SetComplete(null, new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")));
            }
        } // AsyncCopyStreamReadCallback
        } // ToArray

        // write remainder of this stream to another stream
        public virtual void WriteTo(Stream stream)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (_readChunk == null)
            {
                if (_chunks == null)
                {
                    return;
                }

                _readChunk  = _chunks;
                _readOffset = 0;
            }

            byte[] chunkBuffer = _readChunk.Buffer;
            int    chunkSize   = chunkBuffer.Length;

            if (_readChunk.Next == null)
            {
                chunkSize = _writeOffset;
            }

            // following code mirrors Read() logic (_readChunk/_readOffset should
            //   point just past last byte of last chunk when done)

            for (;;) // loop until end of chunks is found
            {
                if (_readOffset == chunkSize)
                {
                    // exit if no more chunks are currently available
                    if (_readChunk.Next == null)
                    {
                        break;
                    }

                    _readChunk  = _readChunk.Next;
                    _readOffset = 0;
                    chunkBuffer = _readChunk.Buffer;
                    chunkSize   = chunkBuffer.Length;
                    if (_readChunk.Next == null)
                    {
                        chunkSize = _writeOffset;
                    }
                }

                int writeCount = chunkSize - _readOffset;
                stream.Write(chunkBuffer, _readOffset, writeCount);
                _readOffset = chunkSize;
            }
        } // WriteTo
示例#9
0
        } // EndAsyncCopyStream

        private static void AsyncCopyReadHelper(AsyncCopyStreamResult streamState)
        {
            // There is no try-catch here because the calling method always has a try-catch.

            if (streamState.AsyncRead)
            {
                byte[] buffer = streamState.Buffer;
                streamState.Source.BeginRead(buffer, 0, buffer.Length, _asyncCopyStreamReadCallback, streamState);
            }
            else
            {
                byte[] buffer    = streamState.Buffer;
                int    bytesRead = streamState.Source.Read(buffer, 0, buffer.Length);
                if (bytesRead == 0)
                {
                    streamState.SetComplete(null, null);
                }
                else
                if (bytesRead < 0)
                {
                    throw new RemotingException(
                              CoreChannel.GetResourceString("Remoting_Stream_UnknownReadError"));
                }
                else
                {
                    AsyncCopyWriteHelper(streamState, bytesRead);
                }
            }
        } // AsyncCopyReadHelper
示例#10
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (this._bClosed)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }
            if (this._chunks == null)
            {
                this._chunks      = this.AllocateMemoryChunk();
                this._writeChunk  = this._chunks;
                this._writeOffset = 0;
            }
            byte[] dst    = this._writeChunk.Buffer;
            int    length = dst.Length;

            while (count > 0)
            {
                if (this._writeOffset == length)
                {
                    this._writeChunk.Next = this.AllocateMemoryChunk();
                    this._writeChunk      = this._writeChunk.Next;
                    this._writeOffset     = 0;
                    dst    = this._writeChunk.Buffer;
                    length = dst.Length;
                }
                int num2 = Math.Min(count, length - this._writeOffset);
                Buffer.BlockCopy(buffer, offset, dst, this._writeOffset, num2);
                offset            += num2;
                count             -= num2;
                this._writeOffset += num2;
            }
        }
        } // Write

        public override void WriteByte(byte value)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            if (_chunks == null)
            {
                _chunks      = AllocateMemoryChunk();
                _writeChunk  = _chunks;
                _writeOffset = 0;
            }

            byte[] chunkBuffer = _writeChunk.Buffer;
            int    chunkSize   = chunkBuffer.Length;

            if (_writeOffset == chunkSize)
            {
                // allocate a new chunk if the current one is full
                _writeChunk.Next = AllocateMemoryChunk();
                _writeChunk      = _writeChunk.Next;
                _writeOffset     = 0;
                chunkBuffer      = _writeChunk.Buffer;
                chunkSize        = chunkBuffer.Length;
            }

            chunkBuffer[_writeOffset++] = value;
        } // WriteByte
        private Header[] GetChannelHeaders(ITransportHeaders requestHeaders, out string soapActionToVerify)
        {
            string str3;
            string str4;

            soapActionToVerify = null;
            string uRI = (string)requestHeaders["__RequestUri"];
            string uri = (string)requestHeaders["SOAPAction"];

            if (uri == null)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_SoapActionMissing"));
            }
            uri = HttpEncodingHelper.DecodeUri(uri);
            soapActionToVerify = uri;
            if (!SoapServices.GetTypeAndMethodNameFromSoapAction(uri, out str3, out str4))
            {
                Type serverTypeForUri = RemotingServices.GetServerTypeForUri(uRI);
                if (serverTypeForUri == null)
                {
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_TypeNotFoundFromUri"), new object[] { uRI }));
                }
                str3 = "clr:" + serverTypeForUri.FullName + ", " + serverTypeForUri.Assembly.GetName().Name;
            }
            else
            {
                str3 = "clr:" + str3;
            }
            int num = 2;

            Header[] headerArray = new Header[num];
            headerArray[0] = new Header("__Uri", uRI);
            headerArray[1] = new Header("__TypeName", str3);
            return(headerArray);
        }
        } // Position

        public override long Seek(long offset, SeekOrigin origin)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            switch (origin)
            {
            case SeekOrigin.Begin:
                Position = offset;
                break;

            case SeekOrigin.Current:
                Position = Position + offset;
                break;

            case SeekOrigin.End:
                Position = Length + offset;
                break;
            }

            return(Position);
        } // Seek
        } // Flush

        public override int Read(byte[] buffer, int offset, int count)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            if (_readChunk == null)
            {
                if (_chunks == null)
                {
                    return(0);
                }
                _readChunk  = _chunks;
                _readOffset = 0;
            }

            byte[] chunkBuffer = _readChunk.Buffer;
            int    chunkSize   = chunkBuffer.Length;

            if (_readChunk.Next == null)
            {
                chunkSize = _writeOffset;
            }

            int bytesRead = 0;

            while (count > 0)
            {
                if (_readOffset == chunkSize)
                {
                    // exit if no more chunks are currently available
                    if (_readChunk.Next == null)
                    {
                        break;
                    }

                    _readChunk  = _readChunk.Next;
                    _readOffset = 0;
                    chunkBuffer = _readChunk.Buffer;
                    chunkSize   = chunkBuffer.Length;
                    if (_readChunk.Next == null)
                    {
                        chunkSize = _writeOffset;
                    }
                }

                int readCount = Math.Min(count, chunkSize - _readOffset);
                Buffer.BlockCopy(chunkBuffer, _readOffset, buffer, offset, readCount);
                offset      += readCount;
                count       -= readCount;
                _readOffset += readCount;
                bytesRead   += readCount;
            }

            return(bytesRead);
        } // Read
        protected byte[] ReadToByte(byte b, ValidateByteDelegate validator)
        {
            byte[] dest = null;
            if (this._dataCount == 0)
            {
                this.BufferMoreData();
            }
            int  num       = this._dataOffset + this._dataCount;
            int  srcOffset = this._dataOffset;
            int  index     = srcOffset;
            bool flag      = false;

            while (!flag)
            {
                bool flag2 = index == num;
                flag = !flag2 && (this._dataBuffer[index] == b);
                if (((validator != null) && !flag2) && (!flag && !validator(this._dataBuffer[index])))
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_InvalidDataReceived"));
                }
                if (flag2 || flag)
                {
                    int count = index - srcOffset;
                    if (dest == null)
                    {
                        dest = new byte[count];
                        StreamHelper.BufferCopy(this._dataBuffer, srcOffset, dest, 0, count);
                    }
                    else
                    {
                        int    length  = dest.Length;
                        byte[] buffer2 = new byte[length + count];
                        StreamHelper.BufferCopy(dest, 0, buffer2, 0, length);
                        StreamHelper.BufferCopy(this._dataBuffer, srcOffset, buffer2, length, count);
                        dest = buffer2;
                    }
                    this._dataOffset += count;
                    this._dataCount  -= count;
                    if (flag2)
                    {
                        this.BufferMoreData();
                        num       = this._dataOffset + this._dataCount;
                        srcOffset = this._dataOffset;
                        index     = srcOffset;
                    }
                    else if (flag)
                    {
                        this._dataOffset++;
                        this._dataCount--;
                    }
                }
                else
                {
                    index++;
                }
            }
            return(dest);
        }
示例#16
0
        } // VerifyNoProviderData

        internal static void ReportUnknownProviderConfigProperty(String providerTypeName,
                                                                 String propertyName)
        {
            throw new RemotingException(
                      String.Format(
                          CoreChannel.GetResourceString(
                              "Remoting_Providers_Config_UnknownProperty"),
                          providerTypeName, propertyName));
        } // ReportUnknownProviderConfigProperty
        private int ReadFromSocket(byte[] buffer, int offset, int count)
        {
            int num = this.NetStream.Read(buffer, offset, count);

            if (num <= 0)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Socket_UnderlyingSocketClosed"));
            }
            return(num);
        }
示例#18
0
        } // CollectChannelDataFromServerSinkProviders

        // called by providers that aren't expecting custom provider data
        internal static void VerifyNoProviderData(String providerTypeName, ICollection providerData)
        {
            if ((providerData != null) && (providerData.Count > 0))
            {
                throw new RemotingException(
                          String.Format(
                              CoreChannel.GetResourceString(
                                  "Remoting_Providers_Config_NotExpectingProviderData"),
                              providerTypeName));
            }
        } // VerifyNoProviderData
示例#19
0
        } // Properties


        // Helper method for analyzing headers
        private Header[] GetChannelHeaders(ITransportHeaders requestHeaders,
                                           out String soapActionToVerify)
        {
            soapActionToVerify = null;

            // transport sink removes any channel specific information
            String objectURI = (String)requestHeaders[CommonTransportKeys.RequestUri];

            // see if a unique SOAPAction is present (if more than one SOAPAction is present some
            //   scenarios won't work, but one-many soap action to method base relationships are
            //   for interop scenarios only)
            String soapAction = (String)requestHeaders["SOAPAction"];

            if (soapAction == null)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_SoapActionMissing"));
            }
            soapAction = HttpEncodingHelper.DecodeUri(soapAction);

            soapActionToVerify = soapAction;

            String typeName, methodName;

            if (!SoapServices.GetTypeAndMethodNameFromSoapAction(soapAction, out typeName, out methodName))
            {
                // This means there are multiple methods for this soap action, so we will have to
                // settle for the type based off of the uri.
                Type type = RemotingServices.GetServerTypeForUri(objectURI);
                if (type == null)
                {
                    throw new RemotingException(
                              String.Format(
                                  CultureInfo.CurrentCulture, CoreChannel.GetResourceString(
                                      "Remoting_TypeNotFoundFromUri"), objectURI));
                }

                // @todo: This throws away the version, culture and public key token
                typeName = "clr:" + type.FullName + ", " + type.Assembly.GetName().Name;
            }
            else
            {
                typeName = "clr:" + typeName;
            }

            // Create a new header array and pass it back.
            int headerLen = 2;

            Header[] h = new Header[headerLen];
            h[0] = new Header("__Uri", objectURI);
            h[1] = new Header("__TypeName", typeName);

            return(h);
        } // GetChannelHeaders
示例#20
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (this._bClosed)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }
            if (this._readChunk == null)
            {
                if (this._chunks == null)
                {
                    return(0);
                }
                this._readChunk  = this._chunks;
                this._readOffset = 0;
            }
            byte[] src    = this._readChunk.Buffer;
            int    length = src.Length;

            if (this._readChunk.Next == null)
            {
                length = this._writeOffset;
            }
            int num2 = 0;

            while (count > 0)
            {
                if (this._readOffset == length)
                {
                    if (this._readChunk.Next == null)
                    {
                        return(num2);
                    }
                    this._readChunk  = this._readChunk.Next;
                    this._readOffset = 0;
                    src    = this._readChunk.Buffer;
                    length = src.Length;
                    if (this._readChunk.Next == null)
                    {
                        length = this._writeOffset;
                    }
                }
                int num3 = Math.Min(count, length - this._readOffset);
                Buffer.BlockCopy(src, this._readOffset, buffer, offset, num3);
                offset           += num3;
                count            -= num3;
                this._readOffset += num3;
                num2             += num3;
            }
            return(num2);
        }
示例#21
0
        } // DataArrivedCallbackState


        public void BeginReadMessage()
        {
            bool bProcessNow = false;

            try
            {
                if (_requestQueue != null)
                {
                    _requestQueue.ScheduleMoreWorkIfNeeded();
                }

                PrepareForNewMessage();

                if (_dataCount == 0)
                {
                    _beginReadAsyncResult =
                        NetStream.BeginRead(_dataBuffer, 0, _dataBufferSize,
                                            _beginReadCallback, null);
                }
                else
                {
                    // just queue the request if we already have some data
                    //   (note: we intentionally don't call the callback directly to avoid
                    //    overflowing the stack if we service a bunch of calls)
                    bProcessNow = true;
                }
            }
            catch (Exception e)
            {
                CloseOnFatalError(e);
            }
            catch {
                CloseOnFatalError(new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")));
            }

            if (bProcessNow)
            {
                if (_requestQueue != null)
                {
                    _requestQueue.ProcessNextRequest(this);
                }
                else
                {
                    ProcessRequestNow();
                }

                _beginReadAsyncResult = null;
            }
        } // BeginReadMessage
示例#22
0
        public virtual void WriteTo(Stream stream)
        {
            if (this._bClosed)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (this._readChunk == null)
            {
                if (this._chunks == null)
                {
                    return;
                }
                this._readChunk  = this._chunks;
                this._readOffset = 0;
            }
            byte[] buffer = this._readChunk.Buffer;
            int    length = buffer.Length;

            if (this._readChunk.Next == null)
            {
                length = this._writeOffset;
            }
            while (true)
            {
                if (this._readOffset == length)
                {
                    if (this._readChunk.Next == null)
                    {
                        return;
                    }
                    this._readChunk  = this._readChunk.Next;
                    this._readOffset = 0;
                    buffer           = this._readChunk.Buffer;
                    length           = buffer.Length;
                    if (this._readChunk.Next == null)
                    {
                        length = this._writeOffset;
                    }
                }
                int count = length - this._readOffset;
                stream.Write(buffer, this._readOffset, count);
                this._readOffset = length;
            }
        }
        } // Read

        public override int ReadByte()
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            if (_readChunk == null)
            {
                if (_chunks == null)
                {
                    return(0);
                }
                _readChunk  = _chunks;
                _readOffset = 0;
            }

            byte[] chunkBuffer = _readChunk.Buffer;
            int    chunkSize   = chunkBuffer.Length;

            if (_readChunk.Next == null)
            {
                chunkSize = _writeOffset;
            }

            if (_readOffset == chunkSize)
            {
                // exit if no more chunks are currently available
                if (_readChunk.Next == null)
                {
                    return(-1);
                }

                _readChunk  = _readChunk.Next;
                _readOffset = 0;
                chunkBuffer = _readChunk.Buffer;
                chunkSize   = chunkBuffer.Length;
                if (_readChunk.Next == null)
                {
                    chunkSize = _writeOffset;
                }
            }

            return(chunkBuffer[_readOffset++]);
        } // ReadByte
示例#24
0
        } // AsyncCopyStreamReadCallback

        private static void AsyncCopyStreamWriteCallback(IAsyncResult iar)
        {
            AsyncCopyStreamResult state = (AsyncCopyStreamResult)iar.AsyncState;

            try
            {
                state.Target.EndWrite(iar);

                AsyncCopyReadHelper(state);
            }
            catch (Exception e)
            {
                state.SetComplete(null, e);
            }
            catch {
                state.SetComplete(null, new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")));
            }
        } // AsyncCopyStreamWriteCallback
示例#25
0
        } // CloseOnFatalError

        // Called when the SocketHandler is pulled off the pending request queue.
        internal void ProcessRequestNow()
        {
            try
            {
                WaitCallback waitCallback = _dataArrivedCallback;
                if (waitCallback != null)
                {
                    waitCallback(this);
                }
            }
            catch (Exception e)
            {
                CloseOnFatalError(e);
            }
            catch
            {
                CloseOnFatalError(new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")));
            }
        } // ProcessRequestNow
示例#26
0
        } // BeginReadMessage

        public void BeginReadMessageCallback(IAsyncResult ar)
        {
            bool bProcessRequest = false;

            // data has been buffered; proceed to call provided callback
            try
            {
                _beginReadAsyncResult = null;

                _dataOffset = 0;
                _dataCount  = NetStream.EndRead(ar);
                if (_dataCount <= 0)
                {
                    // socket has been closed
                    Close();
                }
                else
                {
                    bProcessRequest = true;
                }
            }
            catch (Exception e)
            {
                CloseOnFatalError(e);
            }
            catch {
                CloseOnFatalError(new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException")));
            }

            if (bProcessRequest)
            {
                if (_requestQueue != null)
                {
                    _requestQueue.ProcessNextRequest(this);
                }
                else
                {
                    ProcessRequestNow();
                }
            }
        } // BeginReadMessageCallback
示例#27
0
        public override int ReadByte()
        {
            if (this._bClosed)
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }
            if (this._readChunk == null)
            {
                if (this._chunks == null)
                {
                    return(0);
                }
                this._readChunk  = this._chunks;
                this._readOffset = 0;
            }
            byte[] buffer = this._readChunk.Buffer;
            int    length = buffer.Length;

            if (this._readChunk.Next == null)
            {
                length = this._writeOffset;
            }
            if (this._readOffset == length)
            {
                if (this._readChunk.Next == null)
                {
                    return(-1);
                }
                this._readChunk  = this._readChunk.Next;
                this._readOffset = 0;
                buffer           = this._readChunk.Buffer;
                length           = buffer.Length;
                if (this._readChunk.Next == null)
                {
                    length = this._writeOffset;
                }
            }
            return(buffer[this._readOffset++]);
        }
示例#28
0
        internal void SetComplete(Object returnValue, Exception exception)
        {
            _returnValue = returnValue;
            _exception   = exception;

            CleanupOnComplete();

            _bIsComplete = true;

            try
            {
                if (_manualResetEvent != null)
                {
                    _manualResetEvent.Set();
                }
            }
            catch (Exception e)
            {
                if (_exception == null)
                {
                    _exception = e;
                }
            }
            catch {
                if (_exception == null)
                {
                    _exception = new Exception(CoreChannel.GetResourceString("Remoting_nonClsCompliantException"));
                }
            }


            // invoke the callback
            if (_asyncCallback != null)
            {
                _asyncCallback(this);
            }
        } // SetComplete
        } // ReadByte

        public override void Write(byte[] buffer, int offset, int count)
        {
            if (_bClosed)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Stream_StreamIsClosed"));
            }

            if (_chunks == null)
            {
                _chunks      = AllocateMemoryChunk();
                _writeChunk  = _chunks;
                _writeOffset = 0;
            }

            byte[] chunkBuffer = _writeChunk.Buffer;
            int    chunkSize   = chunkBuffer.Length;

            while (count > 0)
            {
                if (_writeOffset == chunkSize)
                {
                    // allocate a new chunk if the current one is full
                    _writeChunk.Next = AllocateMemoryChunk();
                    _writeChunk      = _writeChunk.Next;
                    _writeOffset     = 0;
                    chunkBuffer      = _writeChunk.Buffer;
                    chunkSize        = chunkBuffer.Length;
                }

                int copyCount = Math.Min(count, chunkSize - _writeOffset);
                Buffer.BlockCopy(buffer, offset, chunkBuffer, _writeOffset, copyCount);
                offset       += copyCount;
                count        -= copyCount;
                _writeOffset += copyCount;
            }
        } // Write
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack,
                                               IMessage requestMsg,
                                               ITransportHeaders requestHeaders, Stream requestStream,
                                               out IMessage responseMsg, out ITransportHeaders responseHeaders,
                                               out Stream responseStream)
        {
            if (requestMsg != null)
            {
                // The message has already been deserialized so delegate to the next sink.
                return(_nextSink.ProcessMessage(
                           sinkStack,
                           requestMsg, requestHeaders, requestStream,
                           out responseMsg, out responseHeaders, out responseStream));
            }

            if (requestHeaders == null)
            {
                throw new ArgumentNullException("requestHeaders");
            }

            BaseTransportHeaders wkRequestHeaders = requestHeaders as BaseTransportHeaders;

            ServerProcessing processing;

            responseHeaders = null;
            responseStream  = null;

            String verb        = null;
            String contentType = null;

            bool bCanServiceRequest = true;

            // determine the content type
            String contentTypeHeader = null;

            if (wkRequestHeaders != null)
            {
                contentTypeHeader = wkRequestHeaders.ContentType;
            }
            else
            {
                contentTypeHeader = requestHeaders["Content-Type"] as String;
            }
            if (contentTypeHeader != null)
            {
                String charsetValue;
                HttpChannelHelper.ParseContentType(contentTypeHeader,
                                                   out contentType, out charsetValue);
            }

            // check to see if Content-Type matches
            if ((contentType != null) &&
                (String.CompareOrdinal(contentType, CoreChannel.BinaryMimeType) != 0))
            {
                bCanServiceRequest = false;
            }

            // check for http specific verbs
            if (_protocol == Protocol.Http)
            {
                verb = (String)requestHeaders["__RequestVerb"];
                if (!verb.Equals("POST") && !verb.Equals("M-POST"))
                {
                    bCanServiceRequest = false;
                }
            }

            // either delegate or return an error message if we can't service the request
            if (!bCanServiceRequest)
            {
                // delegate to next sink if available
                if (_nextSink != null)
                {
                    return(_nextSink.ProcessMessage(sinkStack, null, requestHeaders, requestStream,
                                                    out responseMsg, out responseHeaders, out responseStream));
                }
                else
                {
                    // send back an error message
                    if (_protocol == Protocol.Http)
                    {
                        // return a client bad request error
                        responseHeaders = new TransportHeaders();
                        responseHeaders["__HttpStatusCode"]   = "400";
                        responseHeaders["__HttpReasonPhrase"] = "Bad Request";
                        responseStream = null;
                        responseMsg    = null;
                        return(ServerProcessing.Complete);
                    }
                    else
                    {
                        // The transport sink will catch this and do something here.
                        throw new RemotingException(
                                  CoreChannel.GetResourceString("Remoting_Channels_InvalidRequestFormat"));
                    }
                }
            }


            try
            {
                String objectUri = null;

                bool   bIsCustomErrorEnabled = true;
                object oIsCustomErrorEnabled = requestHeaders["__CustomErrorsEnabled"];
                if (oIsCustomErrorEnabled != null && oIsCustomErrorEnabled is bool)
                {
                    bIsCustomErrorEnabled = (bool)oIsCustomErrorEnabled;
                }
                CallContext.SetData("__CustomErrorsEnabled", bIsCustomErrorEnabled);

                if (wkRequestHeaders != null)
                {
                    objectUri = wkRequestHeaders.RequestUri;
                }
                else
                {
                    objectUri = (String)requestHeaders[CommonTransportKeys.RequestUri];
                }

                if (objectUri != lastUri && RemotingServices.GetServerTypeForUri(objectUri) == null)
                {
                    throw new RemotingException(
                              CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished"));
                }
                else
                {
                    lastUri = objectUri;
                }

                PermissionSet currentPermissionSet = null;
                if (this.TypeFilterLevel != TypeFilterLevel.Full)
                {
                    currentPermissionSet = new PermissionSet(PermissionState.None);
                    currentPermissionSet.SetPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));
                }

                try {
                    if (currentPermissionSet != null)
                    {
                        currentPermissionSet.PermitOnly();
                    }

                    // Deserialize Request - Stream to IMessage
                    requestMsg = CoreChannel.DeserializeBinaryRequestMessage(objectUri, requestStream, _strictBinding, this.TypeFilterLevel);
                }
                finally {
                    if (currentPermissionSet != null)
                    {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
                requestStream.Close();

                if (requestMsg == null)
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage"));
                }


                // Dispatch Call
                sinkStack.Push(this, null);
                processing =
                    _nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null,
                                             out responseMsg, out responseHeaders, out responseStream);
                // make sure that responseStream is null
                if (responseStream != null)
                {
                    throw new RemotingException(
                              CoreChannel.GetResourceString("Remoting_ChnlSink_WantNullResponseStream"));
                }

                switch (processing)
                {
                case ServerProcessing.Complete:
                {
                    if (responseMsg == null)
                    {
                        throw new RemotingException(CoreChannel.GetResourceString("Remoting_DispatchMessage"));
                    }

                    sinkStack.Pop(this);

                    SerializeResponse(sinkStack, responseMsg,
                                      ref responseHeaders, out responseStream);
                    break;
                } // case ServerProcessing.Complete

                case ServerProcessing.OneWay:
                {
                    sinkStack.Pop(this);
                    break;
                } // case ServerProcessing.OneWay:

                case ServerProcessing.Async:
                {
                    sinkStack.Store(this, null);
                    break;
                } // case ServerProcessing.Async
                } // switch (processing)
            }
            catch (Exception e)
            {
                processing  = ServerProcessing.Complete;
                responseMsg = new ReturnMessage(e, (IMethodCallMessage)(requestMsg == null?new ErrorMessage():requestMsg));
                //

                CallContext.SetData("__ClientIsClr", true);
                responseStream = (MemoryStream)CoreChannel.SerializeBinaryMessage(responseMsg, _includeVersioning);
                CallContext.FreeNamedDataSlot("__ClientIsClr");
                responseStream.Position = 0;
                responseHeaders         = new TransportHeaders();

                if (_protocol == Protocol.Http)
                {
                    responseHeaders["Content-Type"] = CoreChannel.BinaryMimeType;
                }
            }
            finally{
                CallContext.FreeNamedDataSlot("__CustomErrorsEnabled");
            }

            return(processing);
        } // ProcessMessage