Exemple #1
0
        private void OnReceiveSessionFrame(Frame frame)
        {
            AmqpSession  nullable = null;
            Performative command  = frame.Command;
            ushort       channel  = frame.Channel;

            if (command.DescriptorCode != Begin.Code)
            {
                if (!this.sessionsByRemoteHandle.TryGetObject(channel, out nullable))
                {
                    if (command.DescriptorCode != End.Code && command.DescriptorCode != Detach.Code && !base.Settings.IgnoreMissingSessions)
                    {
                        throw new AmqpException(AmqpError.NotFound, SRAmqp.AmqpChannelNotFound(channel, this));
                    }
                    return;
                }
                if (command.DescriptorCode == End.Code)
                {
                    this.sessionsByRemoteHandle.Remove(channel);
                    nullable.RemoteChannel = null;
                }
            }
            else
            {
                Begin begin = (Begin)command;
                if (!begin.RemoteChannel.HasValue)
                {
                    AmqpSessionSettings amqpSessionSetting = AmqpSessionSettings.Create(begin);
                    amqpSessionSetting.RemoteChannel = new ushort?(channel);
                    nullable = this.SessionFactory.CreateSession(this, amqpSessionSetting);
                    this.AddSession(nullable, new ushort?(channel));
                }
                else
                {
                    lock (base.ThisLock)
                    {
                        if (!this.sessionsByLocalHandle.TryGetObject(begin.RemoteChannel.Value, out nullable))
                        {
                            Error  notFound      = AmqpError.NotFound;
                            ushort?remoteChannel = begin.RemoteChannel;
                            throw new AmqpException(notFound, SRAmqp.AmqpChannelNotFound(remoteChannel.Value, this));
                        }
                        nullable.RemoteChannel = new ushort?(channel);
                        this.sessionsByRemoteHandle.Add(channel, nullable);
                    }
                }
            }
            nullable.ProcessFrame(frame);
        }