Exemple #1
0
 private static void Validate(int bufferSize, int dataSize)
 {
     if (bufferSize < dataSize)
     {
         throw new AmqpException(AmqpError.DecodeError, SRAmqp.AmqpInsufficientBufferSize(dataSize, bufferSize));
     }
 }
Exemple #2
0
        public static AmqpDescribed CreateAmqpDescribed(ByteBuffer buffer, Dictionary <string, Func <AmqpDescribed> > byName, Dictionary <ulong, Func <AmqpDescribed> > byCode)
        {
            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == 64)
            {
                return(null);
            }
            EncodingBase.VerifyFormatCode(formatCode, 0, buffer.Offset);
            Func <AmqpDescribed> func = null;

            formatCode = AmqpEncoding.ReadFormatCode(buffer);
            if (formatCode == 163 || formatCode == 179)
            {
                AmqpSymbol amqpSymbol = SymbolEncoding.Decode(buffer, formatCode);
                byName.TryGetValue(amqpSymbol.Value, out func);
            }
            else if (formatCode == 68 || formatCode == 128 || formatCode == 83)
            {
                ulong?nullable = ULongEncoding.Decode(buffer, formatCode);
                byCode.TryGetValue(nullable.Value, out func);
            }
            if (func == null)
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
            }
            return(func());
        }
Exemple #3
0
        protected override void OnProcessTransfer(Delivery delivery, Transfer transfer, Frame frame)
        {
            if (base.Settings.MaxMessageSize.HasValue)
            {
                ulong bytesTransfered = (ulong)(this.currentMessage.BytesTransfered + (long)frame.Payload.Count);
                if (bytesTransfered > base.Settings.MaxMessageSize.Value)
                {
                    if (!base.IsClosing())
                    {
                        Microsoft.ServiceBus.Messaging.Amqp.Framing.Error messageSizeExceeded = AmqpError.MessageSizeExceeded;
                        object value          = this.currentMessage.DeliveryId.Value;
                        object obj            = bytesTransfered;
                        ulong? maxMessageSize = base.Settings.MaxMessageSize;
                        throw new AmqpException(messageSizeExceeded, SRAmqp.AmqpMessageSizeExceeded(value, obj, maxMessageSize.Value));
                    }
                    return;
                }
            }
            ArraySegment <byte> payload = frame.Payload;

            frame.RawByteBuffer.AdjustPosition(payload.Offset, payload.Count);
            frame.RawByteBuffer.Clone();
            this.currentMessage.AddPayload(frame.RawByteBuffer, !transfer.More());
            if (!transfer.More())
            {
                AmqpMessage amqpMessage = this.currentMessage;
                this.currentMessage = null;
                Action <ReceivingAmqpLink, uint, int> action = (ReceivingAmqpLink source, uint id, int count) => {
                };
                SequenceNumber deliveryId = amqpMessage.DeliveryId;
                MessagingClientEtwProvider.TraceClient <ReceivingAmqpLink, uint, int>(action, this, deliveryId.Value, amqpMessage.RawByteBuffers.Count);
                this.OnReceiveMessage(amqpMessage);
            }
        }
            private static Exception ConvertToException(int statusCode, string statusDescription)
            {
                Exception messagingException;

                if (!Enum.IsDefined(typeof(HttpStatusCode), statusCode))
                {
                    messagingException = new MessagingException(SRAmqp.AmqpPutTokenFailed(statusCode, statusDescription));
                }
                else
                {
                    HttpStatusCode httpStatusCode = (HttpStatusCode)statusCode;
                    if (httpStatusCode == HttpStatusCode.BadRequest)
                    {
                        messagingException = new ArgumentException(SRAmqp.AmqpPutTokenFailed(statusCode, statusDescription));
                    }
                    else if (httpStatusCode == HttpStatusCode.NotFound)
                    {
                        messagingException = new MessagingEntityNotFoundException(SRAmqp.AmqpPutTokenFailed(statusCode, statusDescription));
                    }
                    else
                    {
                        messagingException = new MessagingException(SRAmqp.AmqpPutTokenFailed(statusCode, statusDescription));
                    }
                }
                return(messagingException);
            }
Exemple #5
0
 protected override void EnsureRequired()
 {
     if (!base.Handle.HasValue)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpRequiredFieldNotSet("handle", Transfer.Name));
     }
 }
        public static string Decode(ByteBuffer buffer, Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode)
        {
            int num;

            System.Text.Encoding uTF8;
            if (formatCode == 0)
            {
                Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode1 = AmqpEncoding.ReadFormatCode(buffer);
                formatCode = formatCode1;
                if (formatCode1 == 64)
                {
                    return(null);
                }
            }
            if (formatCode != 161)
            {
                if (formatCode != 177)
                {
                    throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
                }
                num  = (int)AmqpBitConverter.ReadUInt(buffer);
                uTF8 = System.Text.Encoding.UTF8;
            }
            else
            {
                num  = AmqpBitConverter.ReadUByte(buffer);
                uTF8 = System.Text.Encoding.UTF8;
            }
            string str = uTF8.GetString(buffer.Buffer, buffer.Offset, num);

            buffer.Complete(num);
            return(str);
        }
Exemple #7
0
 protected override void EnsureRequired()
 {
     if (this.ContainerId == null)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpRequiredFieldNotSet("container-id", Open.Name));
     }
 }
Exemple #8
0
        protected StateTransition TransitState(string operation, StateTransition[] states)
        {
            StateTransition stateTransition = null;

            lock (this.ThisLock)
            {
                StateTransition[] stateTransitionArray = states;
                int num = 0;
                while (num < (int)stateTransitionArray.Length)
                {
                    StateTransition stateTransition1 = stateTransitionArray[num];
                    if (stateTransition1.From != this.State)
                    {
                        num++;
                    }
                    else
                    {
                        this.State      = stateTransition1.To;
                        stateTransition = stateTransition1;
                        break;
                    }
                }
            }
            if (stateTransition == null)
            {
                throw new AmqpException(AmqpError.IllegalState, SRAmqp.AmqpIllegalOperationState(operation, this.State));
            }
            MessagingClientEtwProvider.TraceClient <AmqpObject, string, StateTransition>((AmqpObject source, string op, StateTransition st) => {
            }, this, operation, stateTransition);
            return(stateTransition);
        }
Exemple #9
0
 protected override void EnsureRequired()
 {
     if (this.Condition.Value == null)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpRequiredFieldNotSet("condition", Error.Name));
     }
 }
Exemple #10
0
        private void NotifyClosed()
        {
            if (this.pendingOpen != null)
            {
                object terminalException = this.TerminalException;
                if (terminalException == null)
                {
                    terminalException = new OperationCanceledException(SRAmqp.AmqpObjectAborted(this.name));
                }
                this.CompleteOpen(false, (Exception)terminalException);
            }
            if (this.pendingClose != null)
            {
                Exception operationCanceledException = this.TerminalException;
                if (operationCanceledException == null)
                {
                    operationCanceledException = new OperationCanceledException(SRAmqp.AmqpObjectAborted(this.name));
                }
                this.CompleteClose(false, operationCanceledException);
            }
            EventHandler eventHandler = Interlocked.Exchange <EventHandler>(ref this.Closed, null);

            if (eventHandler != null)
            {
                eventHandler(this, EventArgs.Empty);
            }
        }
Exemple #11
0
        public uint Add(T value)
        {
            for (int i = 0; i < (int)this.fastSegment.Length; i++)
            {
                if (this.fastSegment[i] == null)
                {
                    this.fastSegment[i] = value;
                    return((uint)i);
                }
            }
            if (this.slowSegment == null)
            {
                this.slowSegment = new Dictionary <uint, T>();
            }
            uint length = (uint)this.fastSegment.Length;

            while (length < this.maxHandle && this.slowSegment.ContainsKey(length))
            {
                length++;
            }
            if (length == this.maxHandle)
            {
                throw new AmqpException(AmqpError.ResourceLimitExceeded, SRAmqp.AmqpHandleExceeded(this.maxHandle));
            }
            this.slowSegment.Add(length, value);
            return(length);
        }
Exemple #12
0
        private void OnReceiveOpen(Open open)
        {
            StateTransition stateTransition = base.TransitState("R:OPEN", StateTransition.ReceiveOpen);

            this.Negotiate(open);
            base.NotifyOpening(open);
            uint num = open.IdleTimeOut();

            if (num < 60000)
            {
                base.CompleteOpen(false, new AmqpException(AmqpError.NotAllowed, SRAmqp.AmqpIdleTimeoutNotSupported(num, (uint)60000)));
                return;
            }
            if (stateTransition.To == AmqpObjectState.OpenReceived)
            {
                this.SendOpen();
            }
            if (this.isInitiator)
            {
                Error error = null;
                if (open.Properties != null && open.Properties.TryGetValue <Error>("com.microsoft:open-error", out error))
                {
                    base.CompleteOpen(stateTransition.From == AmqpObjectState.Start, new AmqpException(error));
                    return;
                }
            }
            if (num != -1)
            {
                this.heartBeatInterval = (int)(num * 7 / 8);
                this.heartBeatTimer    = new IOThreadTimer(new Action <object>(AmqpConnection.OnHeartBeatTimer), this, false);
                this.heartBeatTimer.Set(this.heartBeatInterval);
            }
            base.CompleteOpen(stateTransition.From == AmqpObjectState.Start, null);
        }
Exemple #13
0
 public static void VerifyFormatCode(Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode, Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode expected, int offset)
 {
     if (formatCode != expected)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, offset));
     }
 }
Exemple #14
0
        private void OnReceiveFlow(Flow flow)
        {
            this.outgoingChannel.OnFlow(flow);
            this.incomingChannel.OnFlow(flow);
            if (!flow.Handle.HasValue)
            {
                if (flow.Echo())
                {
                    this.SendFlow();
                }
                return;
            }
            AmqpLink amqpLink = null;

            if (this.linksByRemoteHandle.TryGetObject(flow.Handle.Value, out amqpLink))
            {
                amqpLink.OnFlow(flow);
                return;
            }
            if (this.Settings.IgnoreMissingLinks)
            {
                return;
            }
            Error unattachedHandle = AmqpError.UnattachedHandle;
            uint? handle           = flow.Handle;

            base.SafeClose(new AmqpException(unattachedHandle, SRAmqp.AmqpHandleNotFound(handle.Value, this)));
        }
            protected override IEnumerator <IteratorAsyncResult <AmqpMessageSender.SendAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                try
                {
                    this.amqpMessage = this.CreateAmqpMessage();
                }
                catch (Exception exception)
                {
                    base.Complete(exception);
                    goto Label0;
                }
                if (!this.parent.sendLink.TryGetOpenedObject(out this.amqpLink))
                {
                    AmqpMessageSender.SendAsyncResult sendAsyncResult = this;
                    IteratorAsyncResult <AmqpMessageSender.SendAsyncResult> .BeginCall beginCall = (AmqpMessageSender.SendAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.parent.sendLink.BeginGetInstance(t, c, s);
                    yield return(sendAsyncResult.CallAsync(beginCall, (AmqpMessageSender.SendAsyncResult thisPtr, IAsyncResult r) => thisPtr.amqpLink = thisPtr.parent.sendLink.EndGetInstance(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException == null)
                    {
                        goto Label1;
                    }
                    base.Complete(ExceptionHelper.GetClientException(base.LastAsyncStepException, this.parent.messagingFactory.RemoteContainerId));
                    goto Label0;
                }
Label1:
                if (this.amqpLink.Settings.MaxMessageSize.HasValue)
                {
                    ulong serializedMessageSize = (ulong)this.amqpMessage.SerializedMessageSize;
                    if (serializedMessageSize <= Convert.ToUInt64(this.amqpLink.Settings.MaxMessageSize))
                    {
                        goto Label2;
                    }
                    AmqpMessageSender.SendAsyncResult sendAsyncResult1 = this;
                    object value          = this.amqpMessage.DeliveryId.Value;
                    object obj            = serializedMessageSize;
                    ulong? maxMessageSize = this.amqpLink.Settings.MaxMessageSize;
                    sendAsyncResult1.Complete(new MessageSizeExceededException(SRAmqp.AmqpMessageSizeExceeded(value, obj, maxMessageSize.Value)));
                    goto Label0;
                }
Label2:
                AmqpMessageSender.SendAsyncResult sendAsyncResult2 = this;
                IteratorAsyncResult <AmqpMessageSender.SendAsyncResult> .BeginCall beginCall1 = (AmqpMessageSender.SendAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.amqpLink.BeginSendMessage(thisPtr.amqpMessage, thisPtr.parent.GetDeliveryTag(), AmqpConstants.NullBinary, t, c, s);
                yield return(sendAsyncResult2.CallAsync(beginCall1, (AmqpMessageSender.SendAsyncResult thisPtr, IAsyncResult r) => thisPtr.outcome = thisPtr.amqpLink.EndSendMessage(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                if (base.LastAsyncStepException != null)
                {
                    base.Complete(ExceptionHelper.GetClientException(base.LastAsyncStepException, this.amqpLink.GetTrackingId()));
                }
                else if (this.outcome.DescriptorCode == Rejected.Code)
                {
                    Rejected rejected = (Rejected)this.outcome;
                    base.Complete(ExceptionHelper.ToMessagingContract(rejected.Error));
                }
Label0:
                yield break;
            }
Exemple #16
0
 protected override void Initialize(ByteBuffer buffer, FormatCode formatCode, out int size, out int count, out int encodeWidth, out SerializableType.CollectionType effectiveType)
 {
     if (formatCode != 209 && formatCode != 193)
     {
         throw new AmqpException(AmqpError.InvalidField, SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
     }
     encodeWidth = (formatCode == 193 ? 1 : 4);
     AmqpEncoding.ReadSizeAndCount(buffer, formatCode, 193, 209, out size, out count);
     effectiveType = this;
 }
        public static int Compare(int x, int y)
        {
            int num = x - y;

            if (num == -2147483648)
            {
                throw new InvalidOperationException(SRAmqp.AmqpInvalidSequenceNumberComparison(x, y));
            }
            return(num);
        }
        public static object DecodeObject(ByteBuffer buffer, FormatCode formatCode)
        {
            EncodingBase encodingBase;

            if (!AmqpEncoding.encodingsByCode.TryGetValue(formatCode, out encodingBase))
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
            }
            return(encodingBase.DecodeObject(buffer, formatCode));
        }
Exemple #19
0
        private static DescribedType Decode(ByteBuffer buffer, Microsoft.ServiceBus.Messaging.Amqp.Encoding.FormatCode formatCode)
        {
            if (formatCode != 0)
            {
                throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
            }
            object obj = AmqpEncoding.DecodeObject(buffer);

            return(new DescribedType(obj, AmqpEncoding.DecodeObject(buffer)));
        }
 protected override void EnsureRequired()
 {
     if (!this.Role.HasValue)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpRequiredFieldNotSet("role", Disposition.Name));
     }
     if (!this.First.HasValue)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpRequiredFieldNotSet("first", Disposition.Name));
     }
 }
        protected override void OnListen()
        {
            IPAddress        pAddress;
            string           host       = this.transportSettings.Host;
            List <IPAddress> pAddresses = new List <IPAddress>();

            if (host.Equals(string.Empty))
            {
                pAddresses.AddRange(Dns.GetHostAddresses(host));
            }
            else if (host.Equals("localhost", StringComparison.OrdinalIgnoreCase) || host.Equals(Environment.MachineName, StringComparison.OrdinalIgnoreCase) || host.Equals(Dns.GetHostEntry(string.Empty).HostName, StringComparison.OrdinalIgnoreCase))
            {
                if (Socket.OSSupportsIPv4)
                {
                    pAddresses.Add(IPAddress.Any);
                }
                if (Socket.OSSupportsIPv6)
                {
                    pAddresses.Add(IPAddress.IPv6Any);
                }
            }
            else if (!IPAddress.TryParse(host, out pAddress))
            {
                pAddresses.AddRange(Dns.GetHostAddresses(this.transportSettings.Host));
            }
            else
            {
                pAddresses.Add(pAddress);
            }
            if (pAddresses.Count == 0)
            {
                throw new InvalidOperationException(SRAmqp.AmqpNoValidAddressForHost(this.transportSettings.Host));
            }
            this.listenSockets = new Socket[pAddresses.Count];
            for (int i = 0; i < pAddresses.Count; i++)
            {
                Socket[] socketArray = this.listenSockets;
                Socket   socket      = new Socket(pAddresses[i].AddressFamily, SocketType.Stream, ProtocolType.Tcp)
                {
                    NoDelay = true
                };
                socketArray[i] = socket;
                this.listenSockets[i].Bind(new IPEndPoint(pAddresses[i], this.transportSettings.Port));
                this.listenSockets[i].Listen(this.transportSettings.TcpBacklog);
                for (int j = 0; j < this.transportSettings.ListenerAcceptorCount; j++)
                {
                    SocketAsyncEventArgs socketAsyncEventArg = new SocketAsyncEventArgs();
                    socketAsyncEventArg.Completed += new EventHandler <SocketAsyncEventArgs>(this.OnAcceptComplete);
                    socketAsyncEventArg.UserToken  = this.listenSockets[i];
                    ActionItem.Schedule(this.acceptTransportLoop, socketAsyncEventArg);
                }
            }
        }
Exemple #22
0
        private void OnSaslInit(SaslInit init)
        {
            if (this.state != SaslNegotiator.SaslState.WaitingForInit)
            {
                throw new AmqpException(AmqpError.IllegalState, SRAmqp.AmqpIllegalOperationState("R:SASL-INIT", this.state));
            }
            this.state = SaslNegotiator.SaslState.Negotiating;
            SaslTransportProvider saslTransportProvider = this.provider;
            AmqpSymbol            mechanism             = init.Mechanism;

            this.saslHandler = saslTransportProvider.GetHandler(mechanism.Value, true);
            this.saslHandler.Start(this, init, false);
        }
 public void Decode(ByteBuffer buffer)
 {
     if (buffer.Length < this.EncodeSize)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInsufficientBufferSize(this.EncodeSize, buffer.Length));
     }
     if (AmqpBitConverter.ReadUInt(buffer) != 1095586128)
     {
         throw AmqpEncoding.GetEncodingException("ProtocolName");
     }
     this.protocolId = (Microsoft.ServiceBus.Messaging.Amqp.ProtocolId)AmqpBitConverter.ReadUByte(buffer);
     this.version    = new AmqpVersion(AmqpBitConverter.ReadUByte(buffer), AmqpBitConverter.ReadUByte(buffer), AmqpBitConverter.ReadUByte(buffer));
 }
 public static void ReadCount(ByteBuffer buffer, FormatCode formatCode, FormatCode formatCode8, FormatCode formatCode32, out int count)
 {
     if (formatCode == formatCode8)
     {
         count = AmqpBitConverter.ReadUByte(buffer);
         return;
     }
     if (formatCode != formatCode32)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInvalidFormatCode(formatCode, buffer.Offset));
     }
     count = (int)AmqpBitConverter.ReadUInt(buffer);
 }
Exemple #25
0
 public IAsyncResult BeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
 {
     lock (this.thisLock)
     {
         if (this.openCalled)
         {
             throw Fx.Exception.AsWarning(new InvalidOperationException(SRAmqp.AmqpInvalidReOpenOperation(this, this.State)), null);
         }
         this.openCalled = true;
     }
     MessagingClientEtwProvider.TraceClient <string>((string source) => {
     }, this.name);
     return(new AmqpObject.OpenAsyncResult(this, timeout, callback, state));
 }
Exemple #26
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);
        }
Exemple #27
0
 protected override void EnsureRequired()
 {
     if (this.LinkName == null)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpRequiredFieldNotSet("name", Attach.Name));
     }
     if (!base.Handle.HasValue)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpRequiredFieldNotSet("handle", Attach.Name));
     }
     if (!this.Role.HasValue)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpRequiredFieldNotSet("role", Attach.Name));
     }
 }
Exemple #28
0
 private void ThrowIfNotOpen()
 {
     if (this.webSocket.State != ServiceBusClientWebSocket.WebSocketState.Open)
     {
         if (this.webSocket.State != ServiceBusClientWebSocket.WebSocketState.Aborted)
         {
             if (this.webSocket.State != ServiceBusClientWebSocket.WebSocketState.Closed)
             {
                 throw Fx.Exception.AsWarning(new AmqpException(AmqpError.IllegalState, SRAmqp.AmqpUnopenObject), this.activity);
             }
             throw Fx.Exception.AsWarning(new ObjectDisposedException(SRAmqp.AmqpUnopenObject), this.activity);
         }
         throw Fx.Exception.AsWarning(new ObjectDisposedException(SRAmqp.AmqpObjectAborted(base.GetType().Name)), this.activity);
     }
 }
Exemple #29
0
 protected void ProcessTransfer(Transfer transfer, Frame rawFrame, Delivery delivery, bool newDelivery)
 {
     if (newDelivery)
     {
         bool flag = true;
         lock (this.syncRoot)
         {
             if (this.tempTotalCredit.HasValue && this.ApplyTempTotalLinkCredit())
             {
                 this.SendFlow(false, false, null);
             }
             if (this.linkCredit != 0 || this.bufferedCredit != 0)
             {
                 this.deliveryCount.Increment();
                 if (this.bufferedCredit > 0)
                 {
                     AmqpLink amqpLink = this;
                     amqpLink.bufferedCredit = amqpLink.bufferedCredit - 1;
                 }
                 else if (this.linkCredit < -1)
                 {
                     AmqpLink amqpLink1 = this;
                     amqpLink1.linkCredit = amqpLink1.linkCredit - 1;
                 }
             }
             else
             {
                 flag = false;
             }
         }
         if (!flag)
         {
             Error          transferLimitExceeded = AmqpError.TransferLimitExceeded;
             SequenceNumber deliveryId            = delivery.DeliveryId;
             throw new AmqpException(transferLimitExceeded, SRAmqp.AmqpTransferLimitExceeded(deliveryId.Value));
         }
         if (!delivery.Settled)
         {
             lock (this.syncRoot)
             {
                 this.unsettledMap.Add(delivery.DeliveryTag, delivery);
             }
         }
     }
     this.OnProcessTransfer(delivery, transfer, rawFrame);
 }
Exemple #30
0
        private void OnReceiveLinkFrame(Frame frame)
        {
            AmqpLink     handle  = null;
            Performative command = frame.Command;

            if (command.DescriptorCode != Attach.Code)
            {
                LinkPerformative linkPerformative = (LinkPerformative)command;
                if (!this.linksByRemoteHandle.TryGetObject(linkPerformative.Handle.Value, out handle))
                {
                    if (this.Settings.IgnoreMissingLinks)
                    {
                        return;
                    }
                    if (linkPerformative.DescriptorCode != Detach.Code)
                    {
                        Error unattachedHandle = AmqpError.UnattachedHandle;
                        uint? nullable         = linkPerformative.Handle;
                        base.SafeClose(new AmqpException(unattachedHandle, SRAmqp.AmqpHandleNotFound(nullable.Value, this)));
                    }
                    return;
                }
            }
            else
            {
                Attach attach = (Attach)command;
                lock (base.ThisLock)
                {
                    this.links.TryGetValue(attach.LinkName, out handle);
                }
                if (handle != null)
                {
                    lock (base.ThisLock)
                    {
                        handle.RemoteHandle = attach.Handle;
                        this.linksByRemoteHandle.Add(attach.Handle.Value, handle);
                    }
                }
                else if (!this.TryCreateRemoteLink(attach, out handle))
                {
                    return;
                }
            }
            handle.ProcessFrame(frame);
        }
 internal static string GetString(SRAmqp.StringResources id)
 {
     return ((string)(Microsoft.SPOT.ResourceUtility.GetObject(ResourceManager, id)));
 }