예제 #1
0
        private void SubscribeIncomingMessage(string x)
        {
            {
                try
                {
                    var msg = x.JsonAs <WsMessageBase <object> >();

                    //_logger.WithTopic(msg.Name).Information("");

                    SystemReconnectionTimer.BeginInit();

                    switch (msg.Name)
                    {
                    case MessageType.Heartbeat:
                        SetHeartbeatTick((long)msg.Message);
                        break;

                    case MessageType.TimeSync:
                        SetServerTime((long)msg.Message);
                        break;

                    default:

                        // list of subs.
                        var methods = _subscribeMethodInfos.Where(m => m.Attribute.TopicName == msg.Name);

                        // invoke subscribers
                        if (methods.Any())
                        {
                            foreach (var method in _subscribeMethodInfos.Where(m =>
                                                                               m.Attribute.TopicName == msg.Name))
                            {
                                var args = msg.MessageAs(method.Attribute.ArgumentType);
                                method.TargetMethod.Invoke(this, new[] { args });
                                _logger
                                .WithTopic(msg.Name)
                                .Debug("Incoming socket message was handle by {Method}",
                                       method.TargetMethod.ToString());
                            }
                        }
                        else     // not support subscribers
                        {
                            _logger
                            .WithTopic(msg.Name)
                            .Debug(x);
                        }

                        break;
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.Message);
                }
            }
        }
        internal void SubscribeIncomingMessage(string x)
        {
            try
            {
                var msg = x.JsonAs <WsMessageBase <object> >();

                SystemReconnectionTimer.BeginInit();

                switch (msg.Name)
                {
                case MessageType.Heartbeat:
                    SetHeartbeatTick((long)msg.Message);
                    break;

                case MessageType.TimeSync:
                    SetServerTime((long)msg.Message);
                    break;

                default:

                    // list of subs.
                    var methods = _subscribeMethodInfos.Where(m => m.Attribute.TopicName == msg.Name);

                    // invoke subscribers
                    if (methods.Any())
                    {
                        foreach (var method in _subscribeMethodInfos.Where(m =>
                                                                           m.Attribute.TopicName == msg.Name))
                        {
                            var args = msg.MessageAs(method.Attribute.ArgumentType);
                            method.TargetMethod.Invoke(this, new[] { args });
                        }
                    }
                    else     // not support subscribers
                    {
                        _logger
                        .LogDebug("Not found handled method to support this kind of message topic '{0}'", msg.Name);
                    }


                    _logger.LogTrace("⬇ {0}", x);

                    break;
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
        }