Пример #1
0
        public static object Route(string endpointName, NetCoreEventArgs e)
        {
            try
            {
                var endpoint = getEndpoint(endpointName);
                if (endpoint == null)
                {
                    var defaultEndpoint = getEndpoint("DEFAULT");
                    if (defaultEndpoint != null)
                    {
                        e.message.Type = endpointName + "|" + e.message.Type;
                        return(defaultEndpoint.OnMessageReceived(null, e));
                    }
                }
                return(endpoint.OnMessageReceived(null, e));
            }
            catch (Exception ex)
            {
                if (CloudDebug.ShowErrorDialog(ex) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }

                return(null);
            }
        }
Пример #2
0
        public static object Route(string endpointName, string messageType, object objectValue, bool synced)
        {
            NetCoreEventArgs ncea = new NetCoreEventArgs(messageType, objectValue);

            (ncea.message as NetCoreAdvancedMessage).requestGuid = (synced ? (Guid?)Guid.NewGuid() : null);
            return(Route(endpointName, ncea));
        }
Пример #3
0
        public static object Route(string endpointName, NetCoreEventArgs e)
        {
            try
            {
                var endpoint = getEndpoint(endpointName);
                if (endpoint == null)
                {
                    var defaultEndpoint = getEndpoint("DEFAULT");
                    if (defaultEndpoint != null)
                    {
                        e.message.Type = endpointName + "|" + e.message.Type;
                        return(defaultEndpoint.OnMessageReceived(null, e));
                    }
                }
                return(endpoint.OnMessageReceived(null, e));
            }
            catch (Exception ex)
            {
                string additionalInfo = "Error trapped from LocalRouter\n\n";

                var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace);

                if (CloudDebug.ShowErrorDialog(ex2) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }

                return(null);
            }
        }
Пример #4
0
        private void CheckMessages(object sender, System.Timers.ElapsedEventArgs e)
        {
            while (true) //checks all messages
            {
                NetCoreMessage message;

                lock (MessagePoolLock)
                {
                    if (MessagePool.Count == 0) //Stop checking messages once the pool is empty
                    {
                        return;
                    }

                    message = MessagePool.First.Value;
                    MessagePool.RemoveFirst();
                }

                if (message is NetCoreAdvancedMessage || (message.Type.Length > 0 && message.Type[0] == '{'))
                {
                    if (spec.Connector.tcp == null || spec.Connector.tcp.ProcessAdvancedMessage(message))
                    {
                        continue;   //If this message was processed internally, don't send further
                    }
                }
                var args = new NetCoreEventArgs();
                args.message = message;

                try
                {
                    spec.OnMessageReceived(args); //Send message to Client Implementation
                }
                catch (Exception ex)
                {
                    //We don't want to leave the scope here because if the code after the OnMessageReceive() call isn't
                    //executed, the other side could be left hanging forever if it's waiting for synced message response.

                    ConsoleEx.WriteLine(ex.ToString());
                }

                if (message is NetCoreAdvancedMessage)
                {
                    // Create return Message if a synced request was issued but no Return Advanced Message was set
                    if (args._returnMessage == null && (message as NetCoreAdvancedMessage).requestGuid != null)
                    {
                        args._returnMessage = new NetCoreAdvancedMessage("{RETURNVALUE}");
                    }

                    //send command back or return value if from bizhawk to bizhawk
                    if (args._returnMessage != null)
                    {
                        (args._returnMessage as NetCoreAdvancedMessage).ReturnedFrom = message.Type;
                        (args._returnMessage as NetCoreAdvancedMessage).requestGuid  = (message as NetCoreAdvancedMessage).requestGuid;
                        SendMessage(args._returnMessage);
                    }

                    //returnAdvancedMessage = null;
                }
            }
        }
Пример #5
0
 public virtual void OnMessageReceived(NetCoreEventArgs e)
 {
     if (MessageReceived == null)
     {
         throw new Exception("No registered handler for MessageReceived!");
     }
     MessageReceived.Invoke(this, e);
 }
Пример #6
0
 public object OnMessageReceived(object sender, NetCoreEventArgs e)
 {
     if ((e.message as NetCoreAdvancedMessage)?.requestGuid != null)
     {
         return(SendMessage(e.message, true));
     }
     else
     {
         SendMessage(e.message);
         return(null);
     }
 }
Пример #7
0
        public static object Route(string endpointName, object sender, NetCoreEventArgs e)
        {
            var endpoint = getEndpoint(endpointName);

            if (endpoint == null)
            {
                ConsoleEx.WriteLine($"Error in NetCore Local Router, could not route message to endpoint {endpointName}");
                return(null);
            }

            return(endpoint.OnMessageReceived(sender, e));
        }
Пример #8
0
        public virtual void OnConsoleWritten(NetCoreEventArgs e)
        {
            if (syncObject != null)
            {
                if (syncObject.InvokeRequired)
                {
                    syncObject.Invoke(new MethodInvoker(() => { OnConsoleWritten(e); }), null);
                    return;
                }
            }

            ConsoleWritten?.Invoke(this, e);
        }
Пример #9
0
        public static T QueryRoute <T>(string endpointName, string messageType, object objectValue, bool synced = true)
        {
            NetCoreEventArgs ncea = new NetCoreEventArgs(messageType, objectValue);

            (ncea.message as NetCoreAdvancedMessage).requestGuid = (synced ? (Guid?)Guid.NewGuid() : null);
            var returnValue = Route(endpointName, ncea);

            if (returnValue is NetCoreAdvancedMessage ncam)
            {
                return((T)ncam.objectValue);
            }
            if (returnValue == null)
            {
                return(default(T));
            }
            return((T)returnValue);
        }
Пример #10
0
 public virtual void OnMessageReceived(NetCoreEventArgs e) => MessageReceived?.Invoke(this, e);