public override void Disconnect(bool sendCloseMessage = true)
        {
            if (sendCloseMessage)
            {
                fPingTimer.Dispose();
                fStream.WriteMessage(new IPCMessage(StatusMessage.CloseConnection));
            }

            if (fStream != null)
            {
                fStream.Dispose();
                fStream = null;
            }

            base.Disconnect();
        }
Beispiel #2
0
        private bool ProcessMessage(IPCStream stream)
        {
            IPCMessage msg = stream.ReadMessage();

            // this was a close-connection notification
            if (msg.StatusMsg == StatusMessage.CloseConnection)
            {
                return(false);
            }
            else if (msg.StatusMsg == StatusMessage.Ping)
            {
                return(true);
            }

            bool   processedOk = false;
            string error       = "";
            object rv          = null;
            // find the service
            object instance;

            if (fServices.TryGetValue(msg.Service, out instance) && instance != null)
            {
                // get the method
                System.Reflection.MethodInfo method = instance.GetType().GetMethod(msg.Method);

                // double check method existence against type-list for security
                // typelist will contain interfaces instead of instances
                if (fTypes[msg.Service].GetMethod(msg.Method) != null && method != null)
                {
                    try {
                        // invoke method
                        rv          = method.Invoke(instance, msg.Parameters);
                        processedOk = true;
                    } catch (Exception e) {
                        error = e.ToString();
                    }
                }
                else
                {
                    error = "Could not find method";
                }
            }
            else
            {
                error = "Could not find service";
            }

            // return either return value or error message
            IPCMessage returnMsg;

            if (processedOk)
            {
                returnMsg = new IPCMessage()
                {
                    Return = rv
                }
            }
            ;
            else
            {
                returnMsg = new IPCMessage()
                {
                    Error = error
                }
            };

            stream.WriteMessage(returnMsg);

            // if there's more to come, keep reading a next message
            if (msg.StatusMsg == StatusMessage.KeepAlive)
            {
                return(true);
            }
            else // otherwise close the connection
            {
                return(false);
            }
        }