private void ApplicationServiceConnect(ApportionDispatcher apportionDispatcher)
        {
            var appWorkerConnectionDispatcher = apportionDispatcher.CreateApplicationWorkerChannelDispatcher(_dispatchers, ConnectionWorkType.ApplicationServiceConnection);

            appWorkerConnectionDispatcher.ListByteBuffer.AddRange(apportionDispatcher.GetACKPacketData().BuilderHeadPacket());

            if (apportionDispatcher.ListByteBuffer.Count > 0)
            {
                var bufferData = apportionDispatcher.ListByteBuffer.ToArray();
                appWorkerConnectionDispatcher.ListByteBuffer.AddRange(bufferData);
            }

            this._dispatchers.Add(appWorkerConnectionDispatcher.DispatcherId, appWorkerConnectionDispatcher);
            this._appServiceChannels.Add(new Tuple <long, long>(apportionDispatcher.GetAccessId(), appWorkerConnectionDispatcher.DispatcherId));
            this.OnConnectedEventHandler?.Invoke(appWorkerConnectionDispatcher);
            //找到相应主控端连接
            TcpSessionChannelDispatcher dispatcher;

            if (_dispatchers.TryGetValue(apportionDispatcher.GetAccessId(), out dispatcher))
            {
                var data = MessageHelper.CopyMessageHeadTo(MessageHead.MID_APPWORK);
                dispatcher.SendTo(data);
            }
            else
            {
                appWorkerConnectionDispatcher.CloseSession();
                this.LogOutputEventHandler?.Invoke(LogOutLevelType.Debug, $"应用服务工作连接未找到相应的主控端!");
            }
        }
コード例 #2
0
        public static TcpSessionMainConnection CreateMainServiceChannelDispatcher(this ApportionDispatcher apportionDispatcher, IDictionary <long, TcpSessionChannelDispatcher> dispatchers)
        {
            var mainServiceChannelDispatcher = new TcpSessionMainConnection(dispatchers);

            mainServiceChannelDispatcher.ACKPacketData = apportionDispatcher.GetACKPacketData();
            mainServiceChannelDispatcher.SetSession(apportionDispatcher.CurrentSession);
            var bufferData = apportionDispatcher.ListByteBuffer.ToArray();

            if (bufferData.Length > 0)//如缓冲区有数据,则处理消息
            {
                mainServiceChannelDispatcher.ListByteBuffer.AddRange(bufferData);
                mainServiceChannelDispatcher.OnMessage();
            }
            return(mainServiceChannelDispatcher);
        }