protected override void OnListen()
        {
            string listenHost = this.transportSettings.Host;

            Fx.Assert(listenHost != null, "Host cannot be null!");
            List <IPAddress> addresses = new List <IPAddress>();
            IPAddress        ipAddress;

            // TODO: Fix this code to listen on Any address for FQDN pointing to the local host machine.
            if (listenHost.Equals(string.Empty))
            {
                addresses.AddRange(Dns.GetHostAddressesAsync(listenHost).Result);
            }
            else if (listenHost.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
                     listenHost.Equals(Environment.GetEnvironmentVariable("COMPUTERNAME"), StringComparison.OrdinalIgnoreCase) ||
                     listenHost.Equals(Dns.GetHostEntryAsync(string.Empty).Result.HostName, StringComparison.OrdinalIgnoreCase))
            {
                if (Socket.OSSupportsIPv4)
                {
                    addresses.Add(IPAddress.Any);
                }

                if (Socket.OSSupportsIPv6)
                {
                    addresses.Add(IPAddress.IPv6Any);
                }
            }
            else if (IPAddress.TryParse(listenHost, out ipAddress))
            {
                addresses.Add(ipAddress);
            }
            else
            {
                addresses.AddRange(Dns.GetHostAddressesAsync(this.transportSettings.Host).Result);
            }

            if (addresses.Count == 0)
            {
                throw new InvalidOperationException(AmqpResources.GetString(AmqpResources.AmqpNoValidAddressForHost, this.transportSettings.Host));
            }

            this.listenSockets = new Socket[addresses.Count];
            for (int i = 0; i < addresses.Count; ++i)
            {
                this.listenSockets[i] = new Socket(addresses[i].AddressFamily, SocketType.Stream, ProtocolType.Tcp)
                {
                    NoDelay = true
                };
                this.listenSockets[i].Bind(new IPEndPoint(addresses[i], this.transportSettings.Port));
                this.listenSockets[i].Listen(this.transportSettings.TcpBacklog);

                for (int j = 0; j < this.transportSettings.ListenerAcceptorCount; ++j)
                {
                    SocketAsyncEventArgs listenEventArgs = new SocketAsyncEventArgs();
                    listenEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(this.OnAcceptComplete);
                    listenEventArgs.UserToken  = this.listenSockets[i];
                    ActionItem.Schedule(this.acceptTransportLoop, listenEventArgs);
                }
            }
        }
示例#2
0
            static void OnTimer(object state)
            {
                var thisPtr = (TimeoutTaskSource <T>)state;

                thisPtr.onTimeout(thisPtr.t);
                thisPtr.TrySetException(new TimeoutException(AmqpResources.GetString(AmqpResources.AmqpTimeout, thisPtr.timeout, typeof(T).Name)));
            }
示例#3
0
 internal override void EnsureRequired()
 {
     if (this.ContainerId == null)
     {
         throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpRequiredFieldNotSet, "container-id", Name));
     }
 }
示例#4
0
        public static void DecodeDescriptor(ByteBuffer buffer, out AmqpSymbol name, out ulong code)
        {
            name = default(AmqpSymbol);
            code = 0;

            FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer);

            if (formatCode == FormatCode.Described)
            {
                formatCode = AmqpEncoding.ReadFormatCode(buffer);
            }

            if (formatCode == FormatCode.Symbol8 ||
                formatCode == FormatCode.Symbol32)
            {
                name = SymbolEncoding.Decode(buffer, formatCode);
            }
            else if (formatCode == FormatCode.ULong ||
                     formatCode == FormatCode.ULong0 ||
                     formatCode == FormatCode.SmallULong)
            {
                code = ULongEncoding.Decode(buffer, formatCode).Value;
            }
            else
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
            }
        }
示例#5
0
 protected override void EnsureRequired()
 {
     if (!this.Handle.HasValue)
     {
         throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpRequiredFieldNotSet, "handle", Name));
     }
 }
示例#6
0
 static void Validate(int bufferSize, int dataSize)
 {
     if (bufferSize < dataSize)
     {
         throw new AmqpException(AmqpErrorCode.DecodeError, AmqpResources.GetString(AmqpResources.AmqpInsufficientBufferSize, dataSize, bufferSize));
     }
 }
示例#7
0
 protected override void EnsureRequired()
 {
     if (this.Condition.Value == null)
     {
         throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpRequiredFieldNotSet, "condition", Name));
     }
 }
示例#8
0
        public static string Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode == 0 && (formatCode = AmqpEncoding.ReadFormatCode(buffer)) == FormatCode.Null)
            {
                return(null);
            }

            int      count;
            Encoding encoding;

            if (formatCode == FormatCode.String8Utf8)
            {
                count    = (int)AmqpBitConverter.ReadUByte(buffer);
                encoding = Encoding.UTF8;
            }
            else if (formatCode == FormatCode.String32Utf8)
            {
                count    = (int)AmqpBitConverter.ReadUInt(buffer);
                encoding = Encoding.UTF8;
            }
            else
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
            }

            string value = encoding.GetString(buffer.Buffer, buffer.Offset, count);

            buffer.Complete(count);

            return(value);
        }
示例#9
0
        // This list should have non-SB related exceptions. The contract that handles SB exceptions
        // are in ExceptionHelper
        public static Error FromException(Exception exception)
        {
            AmqpException amqpException = exception as AmqpException;

            if (amqpException != null)
            {
                return(amqpException.Error);
            }

            Error error = new Error();

            error.Description = exception.Message;
            if (exception is UnauthorizedAccessException)
            {
                error.Condition = AmqpErrorCode.UnauthorizedAccess;
            }
            else if (exception is InvalidOperationException)
            {
                error.Condition = AmqpErrorCode.NotAllowed;
            }
#if NET45
            else if (exception is System.Transactions.TransactionAbortedException)
            {
                error.Condition = AmqpErrorCode.TransactionRollback;
            }
#endif
            else if (exception is NotImplementedException)
            {
                error.Condition = AmqpErrorCode.NotImplemented;
            }
            else
            {
                error.Condition   = AmqpErrorCode.InternalError;
                error.Description = AmqpResources.GetString(AmqpResources.AmqpErrorOccurred, AmqpErrorCode.InternalError);
            }

            // Set the error details if 'IncludeErrorDetails' is set explicitly
            if (IncludeErrorDetails)
            {
                error.Description = exception.Message;
            }

#if DEBUG
            error.Info = new Fields();

            // Limit the size of the exception string as it may exceed the conneciton max frame size
            string exceptionString = exception.ToString();
            if (exceptionString.Length > MaxSizeInInfoMap)
            {
                exceptionString = exceptionString.Substring(0, MaxSizeInInfoMap);
            }

            error.Info.Add("exception", exceptionString);
#endif

            return(error);
        }
示例#10
0
        protected override TransportBase OnCreateTransport(TransportBase innerTransport, bool isInitiator)
        {
            if (innerTransport.GetType() != typeof(TcpTransport))
            {
                throw new InvalidOperationException(AmqpResources.GetString(AmqpResources.AmqpTransportUpgradeNotAllowed,
                                                                            innerTransport.GetType().Name, typeof(TlsTransport).Name));
            }

            return(new TlsTransport(innerTransport, this.tlsSettings));
        }
示例#11
0
        public static object DecodeObject(ByteBuffer buffer, FormatCode formatCode)
        {
            EncodingBase encoding;

            if (encodingsByCode.TryGetValue(formatCode, out encoding))
            {
                return(encoding.DecodeObject(buffer, formatCode));
            }

            throw GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
        }
示例#12
0
        /// <summary>
        /// Server receives the client init that may contain the initial response message.
        /// </summary>
        void OnSaslInit(SaslInit init)
        {
            if (this.state != SaslState.WaitingForInit)
            {
                throw new AmqpException(AmqpErrorCode.IllegalState, AmqpResources.GetString(AmqpResources.AmqpIllegalOperationState, "R:SASL-INIT", this.state));
            }

            this.state       = SaslState.Negotiating;
            this.saslHandler = this.provider.GetHandler(init.Mechanism.Value, true);
            this.saslHandler.Start(this, init, false);
        }
示例#13
0
            protected override void Initialize(ByteBuffer buffer, FormatCode formatCode,
                                               out int size, out int count, out int encodeWidth, out Collection effectiveType)
            {
                if (formatCode != FormatCode.Map32 && formatCode != FormatCode.Map8)
                {
                    throw new AmqpException(AmqpErrorCode.InvalidField, AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
                }

                encodeWidth = formatCode == FormatCode.Map8 ? FixedWidth.UByte : FixedWidth.UInt;
                AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.Map8, FormatCode.Map32, out size, out count);
                effectiveType = this;
            }
示例#14
0
        static DescribedType Decode(ByteBuffer buffer, FormatCode formatCode)
        {
            if (formatCode != FormatCode.Described)
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
            }

            object descriptor = AmqpEncoding.DecodeObject(buffer);
            object value      = AmqpEncoding.DecodeObject(buffer);

            return(new DescribedType(descriptor, value));
        }
示例#15
0
        internal override void EnsureRequired()
        {
            if (!this.Role.HasValue)
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpRequiredFieldNotSet, "role", Name));
            }

            if (!this.First.HasValue)
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpRequiredFieldNotSet, "first", Name));
            }
        }
示例#16
0
        protected override TransportBase OnCreateTransport(TransportBase innerTransport, bool isInitiator)
        {
#if !PCL
            if (innerTransport.GetType() != typeof(TcpTransport))
            {
                throw new InvalidOperationException(AmqpResources.GetString(AmqpResources.AmqpTransportUpgradeNotAllowed,
                                                                            innerTransport.GetType().Name, typeof(TlsTransport).Name));
            }

            return(new TlsTransport(innerTransport, this.tlsSettings));
#else
            throw new NotImplementedException(Microsoft.Azure.Amqp.PCL.Resources.ReferenceAssemblyInvalidUse);
#endif
        }
示例#17
0
 public static void ReadCount(ByteBuffer buffer, FormatCode formatCode, FormatCode formatCode8, FormatCode formatCode32, out int count)
 {
     if (formatCode == formatCode8)
     {
         count = AmqpBitConverter.ReadUByte(buffer);
     }
     else if (formatCode == formatCode32)
     {
         count = (int)AmqpBitConverter.ReadUInt(buffer);
     }
     else
     {
         throw GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
     }
 }
示例#18
0
        void OnReadHeaderComplete(TransportAsyncCallbackArgs args)
        {
            if (args.Exception != null)
            {
                AmqpTrace.Provider.AmqpLogError(this, "ReadHeader", args.Exception.Message);
                this.Complete(args);
                return;
            }

            try
            {
                ProtocolHeader receivedHeader = new ProtocolHeader();
                receivedHeader.Decode(new ByteBuffer(args.Buffer, args.Offset, args.Count));
#if DEBUG
                receivedHeader.Trace(false);
                AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Receive, receivedHeader);
#endif

                if (!receivedHeader.Equals(this.sentHeader))
                {
                    // TODO: need to reconnect with the reply version if supported
                    throw new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.sentHeader, receivedHeader));
                }

                // upgrade transport
                TransportBase secureTransport = this.settings.TransportProviders[this.providerIndex].CreateTransport(args.Transport, true);
                AmqpTrace.Provider.AmqpUpgradeTransport(this, args.Transport, secureTransport);
                args.Transport = secureTransport;
                IAsyncResult result = args.Transport.BeginOpen(this.timeoutHelper.RemainingTime(), this.OnTransportOpenCompete, args);
                if (result.CompletedSynchronously)
                {
                    this.HandleTransportOpened(result);
                }
            }
            catch (Exception exp)
            {
                if (Fx.IsFatal(exp))
                {
                    throw;
                }

                AmqpTrace.Provider.AmqpLogError(this, "OnProtocolHeader", exp.Message);
                args.Exception = exp;
                this.Complete(args);
            }
        }
示例#19
0
        public void Decode(ByteBuffer buffer)
        {
            if (buffer.Length < this.EncodeSize)
            {
                throw new AmqpException(AmqpErrorCode.DecodeError, AmqpResources.GetString(AmqpResources.AmqpInsufficientBufferSize, this.EncodeSize, buffer.Length));
            }

            uint prefix = AmqpBitConverter.ReadUInt(buffer);

            if (prefix != ProtocolHeader.AmqpPrefix)
            {
                throw new AmqpException(AmqpErrorCode.DecodeError, "ProtocolName" + prefix.ToString("X8"));
            }

            this.protocolId = (ProtocolId)AmqpBitConverter.ReadUByte(buffer);

            this.version = new AmqpVersion(
                AmqpBitConverter.ReadUByte(buffer),
                AmqpBitConverter.ReadUByte(buffer),
                AmqpBitConverter.ReadUByte(buffer));
        }
示例#20
0
        internal override void EnsureRequired()
        {
            if (this.LinkName == null)
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpRequiredFieldNotSet, "name", Name));
            }

            if (!this.Handle.HasValue)
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpRequiredFieldNotSet, "handle", Name));
            }

            if (!this.Role.HasValue)
            {
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpRequiredFieldNotSet, "role", Name));
            }

            ////if (!this.Role.Value && this.InitialDeliveryCount == null)
            ////{
            ////    throw AmqpEncoding.GetEncodingException("attach.initial-delivery-count");
            ////}
        }
示例#21
0
        public static EncodingBase GetEncoding(Type type)
        {
            EncodingBase encoding = null;

            if (encodingsByType.TryGetValue(type, out encoding))
            {
                return(encoding);
            }
            else if (type.IsArray)
            {
                return(arrayEncoding);
            }
            else if (typeof(IList).IsAssignableFrom(type))
            {
                return(listEncoding);
            }
            else if (typeof(DescribedType).IsAssignableFrom(type))
            {
                return(describedTypeEncoding);
            }
            throw new NotSupportedException(AmqpResources.GetString(AmqpResources.AmqpInvalidType, type.ToString()));
        }
示例#22
0
        /// <summary>
        /// Client receives the announced server mechanisms.
        /// </summary>
        void OnSaslServerMechanisms(SaslMechanisms mechanisms)
        {
            if (this.state != SaslState.WaitingForServerMechanisms)
            {
                throw new AmqpException(AmqpErrorCode.IllegalState, AmqpResources.GetString(AmqpResources.AmqpIllegalOperationState, "R:SASL-MECH", this.state));
            }

            string mechanismToUse = null;

            foreach (string mechanism in this.provider.Mechanisms)
            {
                if (mechanisms.SaslServerMechanisms.Contains(new AmqpSymbol(mechanism)))
                {
                    mechanismToUse = mechanism;
                    break;
                }

                if (mechanismToUse != null)
                {
                    break;
                }
            }

            if (mechanismToUse == null)
            {
                throw new AmqpException(
                          AmqpErrorCode.NotFound,
                          AmqpResources.GetString(AmqpResources.AmqpNotSupportMechanism, mechanisms.SaslServerMechanisms.ToString(), string.Join(",", this.provider.Mechanisms)));
            }

            this.state       = SaslState.Negotiating;
            this.saslHandler = this.provider.GetHandler(mechanismToUse, true);
            SaslInit init = new SaslInit();

            init.Mechanism = mechanismToUse;
            this.saslHandler.Start(this, init, true);
        }
示例#23
0
        internal static decimal DecodeValue(ByteBuffer buffer, FormatCode formatCode)
        {
            decimal value = 0;

            switch (formatCode)
            {
            case FormatCode.Decimal32:
                value = DecimalEncoding.DecodeDecimal32(buffer);
                break;

            case FormatCode.Decimal64:
                value = DecimalEncoding.DecodeDecimal64(buffer);
                break;

            case FormatCode.Decimal128:
                value = DecimalEncoding.DecodeDecimal128(buffer);
                break;

            default:
                throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
            }

            return(value);
        }
示例#24
0
        public static EncodingBase GetEncoding(object value)
        {
            EncodingBase encoding = null;
            Type         type     = value.GetType();

            if (encodingsByType.TryGetValue(type, out encoding))
            {
                return(encoding);
            }
            else if (type.IsArray)
            {
                return(arrayEncoding);
            }
            else if (value is IList)
            {
                return(listEncoding);
            }
            else if (value is DescribedType)
            {
                return(describedTypeEncoding);
            }

            throw new NotSupportedException(AmqpResources.GetString(AmqpResources.AmqpInvalidType, type.ToString()));
        }
示例#25
0
            protected override void Initialize(ByteBuffer buffer, FormatCode formatCode,
                                               out int size, out int count, out int encodeWidth, out Collection effectiveType)
            {
                if (formatCode != FormatCode.Described)
                {
                    throw new AmqpException(AmqpErrorCode.InvalidField, AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, buffer.Offset));
                }

                effectiveType = null;
                formatCode    = AmqpEncoding.ReadFormatCode(buffer);
                ulong?     code   = null;
                AmqpSymbol symbol = default(AmqpSymbol);

                if (formatCode == FormatCode.ULong0)
                {
                    code = 0;
                }
                else if (formatCode == FormatCode.ULong || formatCode == FormatCode.SmallULong)
                {
                    code = ULongEncoding.Decode(buffer, formatCode);
                }
                else if (formatCode == FormatCode.Symbol8 || formatCode == FormatCode.Symbol32)
                {
                    symbol = SymbolEncoding.Decode(buffer, formatCode);
                }

                if (this.AreEqual(this.descriptorCode, this.descriptorName, code, symbol))
                {
                    effectiveType = this;
                }
                else if (this.knownTypes != null)
                {
                    for (int i = 0; i < this.knownTypes.Count; ++i)
                    {
                        Composite knownType = (Composite)this.serializer.GetType(this.knownTypes[i]);
                        if (this.AreEqual(knownType.descriptorCode, knownType.descriptorName, code, symbol))
                        {
                            effectiveType = knownType;
                            break;
                        }
                    }
                }

                if (effectiveType == null)
                {
                    throw new SerializationException(AmqpResources.GetString(AmqpResources.AmqpUnknownDescriptor, code ?? (object)symbol.Value, this.type.Name));
                }

                formatCode = AmqpEncoding.ReadFormatCode(buffer);
                if (this.Code == FormatCode.List32)
                {
                    if (formatCode == FormatCode.List0)
                    {
                        size = count = encodeWidth = 0;
                    }
                    else
                    {
                        encodeWidth = formatCode == FormatCode.List8 ? FixedWidth.UByte : FixedWidth.UInt;
                        AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.List8,
                                                      FormatCode.List32, out size, out count);
                    }
                }
                else
                {
                    encodeWidth = formatCode == FormatCode.Map8 ? FixedWidth.UByte : FixedWidth.UInt;
                    AmqpEncoding.ReadSizeAndCount(buffer, formatCode, FormatCode.Map8,
                                                  FormatCode.Map32, out size, out count);
                }
            }
示例#26
0
        SerializableType CompileType(Type type, bool describedOnly)
        {
            var typeAttributes = type.GetTypeInfo().GetCustomAttributes(typeof(AmqpContractAttribute), false);

            if (!typeAttributes.Any())
            {
                if (describedOnly)
                {
                    return(null);
                }
                else
                {
                    return(CompileNonContractTypes(type));
                }
            }

            AmqpContractAttribute contractAttribute = (AmqpContractAttribute)typeAttributes.First();
            SerializableType      baseType          = null;

            if (type.GetTypeInfo().BaseType != typeof(object))
            {
                baseType = this.CompileType(type.GetTypeInfo().BaseType, true);
                if (baseType != null)
                {
                    if (baseType.Encoding != contractAttribute.Encoding)
                    {
                        throw new SerializationException(AmqpResources.GetString(AmqpResources.AmqpEncodingTypeMismatch, type.Name, contractAttribute.Encoding, type.GetTypeInfo().BaseType.Name, baseType.Encoding));
                    }

                    this.customTypeCache.TryAdd(type.GetTypeInfo().BaseType, baseType);
                }
            }

            string descriptorName = contractAttribute.Name;
            ulong? descriptorCode = contractAttribute.InternalCode;

            if (descriptorName == null && descriptorCode == null)
            {
                descriptorName = type.FullName;
            }

            List <SerialiableMember> memberList = new List <SerialiableMember>();

            if (contractAttribute.Encoding == EncodingType.List && baseType != null)
            {
                memberList.AddRange(baseType.Members);
            }

            int lastOrder = memberList.Count + 1;

            MemberInfo[]   memberInfos    = type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            MethodAccessor onDeserialized = null;

            foreach (MemberInfo memberInfo in memberInfos)
            {
                if (memberInfo.DeclaringType != type)
                {
                    continue;
                }

                if (memberInfo is FieldInfo ||
                    memberInfo is PropertyInfo)
                {
                    var memberAttributes = memberInfo.GetCustomAttributes(typeof(AmqpMemberAttribute), true);
                    if (memberAttributes.Count() != 1)
                    {
                        continue;
                    }

                    AmqpMemberAttribute attribute = (AmqpMemberAttribute)memberAttributes.First();

                    SerialiableMember member = new SerialiableMember();
                    member.Name      = attribute.Name ?? memberInfo.Name;
                    member.Order     = attribute.InternalOrder ?? lastOrder++;
                    member.Mandatory = attribute.Mandatory;
                    member.Accessor  = MemberAccessor.Create(memberInfo, true);

                    // This will recursively resolve member types
                    Type memberType = memberInfo is FieldInfo ? ((FieldInfo)memberInfo).FieldType : ((PropertyInfo)memberInfo).PropertyType;
                    member.Type = GetType(memberType);

                    memberList.Add(member);
                }
                else if (memberInfo is MethodInfo)
                {
                    var memberAttributes = memberInfo.GetCustomAttributes(typeof(OnDeserializedAttribute), false);
                    if (memberAttributes.Count() == 1)
                    {
                        onDeserialized = MethodAccessor.Create((MethodInfo)memberInfo);
                    }
                }
            }

            if (contractAttribute.Encoding == EncodingType.List)
            {
                memberList.Sort(MemberOrderComparer.Instance);
                int order = -1;
                foreach (SerialiableMember member in memberList)
                {
                    if (order > 0 && member.Order == order)
                    {
                        throw new SerializationException(AmqpResources.GetString(AmqpResources.AmqpDuplicateMemberOrder, order, type.Name));
                    }

                    order = member.Order;
                }
            }

            SerialiableMember[] members = memberList.ToArray();

            Dictionary <Type, SerializableType> knownTypes = null;

            foreach (object o in type.GetTypeInfo().GetCustomAttributes(typeof(KnownTypeAttribute), false))
            {
                KnownTypeAttribute knownAttribute = (KnownTypeAttribute)o;
                if (knownAttribute.Type.GetTypeInfo().GetCustomAttributes(typeof(AmqpContractAttribute), false).Any())
                {
                    if (knownTypes == null)
                    {
                        knownTypes = new Dictionary <Type, SerializableType>();
                    }

                    // KnownType compilation is delayed and non-recursive to avoid circular references
                    knownTypes.Add(knownAttribute.Type, null);
                }
            }

            if (contractAttribute.Encoding == EncodingType.List)
            {
                return(SerializableType.CreateDescribedListType(this, type, baseType, descriptorName,
                                                                descriptorCode, members, knownTypes, onDeserialized));
            }
            else if (contractAttribute.Encoding == EncodingType.Map)
            {
                return(SerializableType.CreateDescribedMapType(this, type, baseType, descriptorName,
                                                               descriptorCode, members, knownTypes, onDeserialized));
            }
            else
            {
                throw new NotSupportedException(contractAttribute.Encoding.ToString());
            }
        }
示例#27
0
 static void ThrowInvalidFormatCodeException(FormatCode formatCode, int offset)
 {
     throw AmqpEncoding.GetEncodingException(AmqpResources.GetString(AmqpResources.AmqpInvalidFormatCode, formatCode, offset));
 }