//------------------------------------------------------------------------------
 //
 // Method: Disconnect
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Disconnects from the configured IP address and port.
 /// </summary>
 public void Disconnect()
 {
     CheckNotDisposed();
     if (client.Connected == true)
     {
         client.Close();
         loggingUtilities.Log(this, LogLevel.Information, "Disconnected.");
     }
 }
Exemple #2
0
        //------------------------------------------------------------------------------
        //
        // Method: Connect
        //
        //------------------------------------------------------------------------------
        /// <summary>
        /// Connects to the message queue.
        /// </summary>
        public override void Connect()
        {
            base.Connect();
            try
            {
                if (testConstructor == false)
                {
                    consumer = session.CreateConsumer(destination, filterIdentifier + " = '" + messageFilter + "'");
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error creating message consumer.", e);
            }

            loggingUtilities.Log(this, LogLevel.Information, "Connected to URI: '" + connectUri + "', Queue: '" + queueName + "'.");
        }
        //------------------------------------------------------------------------------
        //
        // Method: Disconnect
        //
        //------------------------------------------------------------------------------
        /// <summary>
        /// Disconnects a connected client and stops listening on the configured TCP port.
        /// </summary>
        public void Disconnect()
        {
            CheckNotDisposed();
            try
            {
                client.Close();
                DisposeClient();
                listener.Stop();
                connected = false;
            }
            catch (Exception e)
            {
                throw new Exception("Failed to disconnect listener.", e);
            }

            loggingUtilities.Log(this, LogLevel.Information, "Disconnected.");
        }
        //------------------------------------------------------------------------------
        //
        // Method: Connect
        //
        //------------------------------------------------------------------------------
        /// <summary>
        /// Connects to the message queue.
        /// </summary>
        public override void Connect()
        {
            base.Connect();
            try
            {
                if (testConstructor == false)
                {
                    producer = session.CreateProducer(destination);
                }
                disposed = false;
            }
            catch (Exception e)
            {
                throw new Exception("Error creating message producer.", e);
            }

            loggingUtilities.Log(this, LogLevel.Information, "Connected to URI: '" + connectUriName + "', Queue: '" + queueName + "'.");
        }
Exemple #5
0
        /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:MethodInvocationRemoting.IRemoteReceiver.CancelReceive"]/*'/>
        public void CancelReceive()
        {
            cancelRequest = true;
            while (waitingForTimeout == true)
            {
                ;
            }

            loggingUtilities.Log(this, LogLevel.Information, "Receive operation cancelled.");
        }
Exemple #6
0
        /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:MethodInvocationRemoting.IRemoteReceiver.CancelReceive"]/*'/>
        public void CancelReceive()
        {
            remoteReceiver.CancelReceive();
            while (decompressing == true)
            {
                ;
            }

            loggingUtilities.Log(this, LogLevel.Information, "Receive operation cancelled.");
        }
        /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:MethodInvocationRemoting.IMethodInvocationRemoteReceiver.Receive"]/*'/>
        public void Receive()
        {
            cancelRequest = false;

            receiveLoopThread = new Thread(delegate()
            {
                while (cancelRequest == false)
                {
                    try
                    {
                        string serializedMethodInvocation = receiver.Receive();
                        if (serializedMethodInvocation != "")
                        {
                            metricsUtilities.Begin(new RemoteMethodReceiveTime());

                            IMethodInvocation receivedMethodInvocation;

                            try
                            {
                                receivedMethodInvocation = serializer.Deserialize(serializedMethodInvocation);
                                OnMethodInvocationReceived(new MethodInvocationReceivedEventArgs(receivedMethodInvocation));
                            }
                            catch (Exception e)
                            {
                                metricsUtilities.CancelBegin(new RemoteMethodReceiveTime());
                                throw;
                            }

                            loggingUtilities.Log(this, LogLevel.Information, "Received method invocation '" + receivedMethodInvocation.Name + "'.");
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Failed to invoke method.", e);
                    }
                }
            });
            receiveLoopThread.Name = "MethodInvocationRemoting.MethodInvocationRemoteReceiver message receive worker thread.";
            receiveLoopThread.Start();
        }
        /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:MethodInvocationRemoting.IMethodInvocationRemoteSender.InvokeMethod(MethodInvocationRemoting.IMethodInvocation)"]/*'/>
        public object InvokeMethod(IMethodInvocation inputMethodInvocation)
        {
            metricsUtilities.Begin(new RemoteMethodSendTime());

            object returnValue;

            try
            {
                // Check that inputted method invocation does not have a void return type.
                if (inputMethodInvocation.ReturnType == null)
                {
                    throw new ArgumentException("Method invocation cannot have a void return type.", "inputMethodInvocation");
                }

                string serializedReturnValue = SerializeAndSend(inputMethodInvocation);
                try
                {
                    returnValue = serializer.DeserializeReturnValue(serializedReturnValue);
                }
                catch (Exception e)
                {
                    throw new Exception("Failed to deserialize return value.", e);
                }
            }
            catch (Exception e)
            {
                metricsUtilities.CancelBegin(new RemoteMethodSendTime());
                throw;
            }

            metricsUtilities.End(new RemoteMethodSendTime());
            metricsUtilities.Increment(new RemoteMethodSent());
            loggingUtilities.Log(this, LogLevel.Information, "Invoked method '" + inputMethodInvocation.Name + "'.");

            return(returnValue);
        }
Exemple #9
0
        /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:MethodInvocationRemoting.IMethodInvocationSerializer.Deserialize(System.String)"]/*'/>
        public MethodInvocation Deserialize(string serializedMethodInvocation)
        {
            metricsUtilities.Begin(new MethodInvocationDeserializeTime());

            MethodInvocation returnMethodInvocation;

            try
            {
                returnMethodInvocation = (MethodInvocation)DeserializeObject(serializedMethodInvocation);
            }
            catch (Exception e)
            {
                metricsUtilities.CancelBegin(new MethodInvocationDeserializeTime());
                throw new DeserializationException("Failed to deserialize method invocation.", serializedMethodInvocation, e);
            }

            metricsUtilities.End(new MethodInvocationDeserializeTime());
            metricsUtilities.Increment(new MethodInvocationDeserialized());
            loggingUtilities.Log(this, LogLevel.Information, "Deserialized string to method invocation '" + returnMethodInvocation.Name + "'.");

            return(returnMethodInvocation);
        }
        /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:MethodInvocationRemoting.IRemoteSender.Send(System.String)"]/*'/>
        public void Send(string message)
        {
            metricsUtilities.Begin(new MessageSendTime());

            CheckNotDisposed();

            try
            {
                // Lock file is created before data is written to the message file
                //   The FileRemoteReceiver class checks for the absence of the lock file to prevent attempting to open the message file when it is partially written and causing an exception
                lockFile.WriteAll("");
                messageFile.WriteAll(message);
                fileSystem.DeleteFile(lockFilePath);
            }
            catch (Exception e)
            {
                metricsUtilities.CancelBegin(new MessageSendTime());
                throw new Exception("Error sending message.", e);
            }

            metricsUtilities.End(new MessageSendTime());
            metricsUtilities.Increment(new MessageSent());
            loggingUtilities.Log(this, LogLevel.Information, "Message sent.");
        }