public void OpenConnection(Action <MessageContext> responseMessageHandler)
        {
            using (EneterTrace.Entering())
            {
                // If it shall listen to responses then check the responseMessageHandler.
                if (responseMessageHandler == null)
                {
                    throw new InvalidOperationException("responseMessageHandler is null.");
                }

                using (ThreadLock.Lock(myConnectionManipulatorLock))
                {
                    try
                    {
                        // Send open connection message to open the connection.
                        // When DuplexInputChannel receives the open connection message it creates
                        // shared memory for sending response messages.
                        mySender = new SharedMemorySender(myInputConnectorAddress, true, myConnectTimeout, mySendTimeout, myMaxMessageSize, mySecurity);
                        mySender.SendMessage(x => myProtocolFormatter.EncodeOpenConnectionMessage(myOutputConnectorAddress, x));

                        // The input connector has opened the shared memory for responses
                        // so we can start listening from it.
                        // (It will open existing memory mapped file.)
                        myResponseMessageHandler = responseMessageHandler;
                        myReceiver = new SharedMemoryReceiver(myOutputConnectorAddress, true, myConnectTimeout, myMaxMessageSize, mySecurity);
                        myReceiver.StartListening(HandleResponseMessage);
                    }
                    catch
                    {
                        CloseConnection();
                        throw;
                    }
                }
            }
        }
Beispiel #2
0
        public SharedMemoryInputConnector(string inputConnectorAddress, IProtocolFormatter protocolFormatter, TimeSpan sendResponseTimeout, int maxMessageSize, MemoryMappedFileSecurity memoryMappedFileSecurity)
        {
            using (EneterTrace.Entering())
            {
                myProtocolFormatter   = protocolFormatter;
                myMaxMessageSize      = maxMessageSize;
                mySendResponseTimeout = sendResponseTimeout;
                mySecurity            = memoryMappedFileSecurity;

                // Note: openTimeout is not used if SharedMemoryReceiver creates memory mapped file.
                TimeSpan aDummyOpenTimout = TimeSpan.Zero;
                myReceiver = new SharedMemoryReceiver(inputConnectorAddress, false, aDummyOpenTimout, myMaxMessageSize, mySecurity);
            }
        }