Beispiel #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="typeId">Type ID.</param>
        /// <param name="typeName">Type name.</param>
        /// <param name="userType">User type flag.</param>
        /// <param name="nameMapper">Name converter.</param>
        /// <param name="idMapper">Mapper.</param>
        /// <param name="serializer">Serializer.</param>
        /// <param name="keepDeserialized">Whether to cache deserialized value in IBinaryObject</param>
        /// <param name="affKeyFieldName">Affinity field key name.</param>
        /// <param name="isEnum">Enum flag.</param>
        /// <param name="comparer">Equality comparer.</param>
        public BinaryFullTypeDescriptor(
            Type type,
            int typeId,
            string typeName,
            bool userType,
            IBinaryNameMapper nameMapper,
            IBinaryIdMapper idMapper,
            IBinarySerializerInternal serializer,
            bool keepDeserialized,
            string affKeyFieldName,
            bool isEnum,
            IEqualityComparer <IBinaryObject> comparer)
        {
            _type             = type;
            _typeId           = typeId;
            _typeName         = typeName;
            _userType         = userType;
            _nameMapper       = nameMapper;
            _idMapper         = idMapper;
            _serializer       = serializer;
            _keepDeserialized = keepDeserialized;
            _affKeyFieldName  = affKeyFieldName;
            _isEnum           = isEnum;

            _equalityComparer = comparer as IBinaryEqualityComparer;

            if (comparer != null && _equalityComparer == null)
            {
                throw new IgniteException(string.Format("Unsupported IEqualityComparer<IBinaryObject> " +
                                                        "implementation: {0}. Only predefined implementations " +
                                                        "are supported.", comparer.GetType()));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="typeId">Type ID.</param>
        /// <param name="typeName">Type name.</param>
        /// <param name="userType">User type flag.</param>
        /// <param name="nameMapper">Name converter.</param>
        /// <param name="idMapper">Mapper.</param>
        /// <param name="serializer">Serializer.</param>
        /// <param name="keepDeserialized">Whether to cache deserialized value in IBinaryObject</param>
        /// <param name="affKeyFieldName">Affinity field key name.</param>
        /// <param name="isEnum">Enum flag.</param>
        /// <param name="isRegistered">Registered flag.</param>
        public BinaryFullTypeDescriptor(
            Type type,
            int typeId,
            string typeName,
            bool userType,
            IBinaryNameMapper nameMapper,
            IBinaryIdMapper idMapper,
            IBinarySerializerInternal serializer,
            bool keepDeserialized,
            string affKeyFieldName,
            bool isEnum,
            bool isRegistered = true)
        {
            _type             = type;
            _typeId           = typeId;
            _typeName         = typeName;
            _userType         = userType;
            _nameMapper       = nameMapper;
            _idMapper         = idMapper;
            _serializer       = serializer;
            _keepDeserialized = keepDeserialized;
            _affKeyFieldName  = affKeyFieldName;
            _isEnum           = isEnum;

            _isRegistered = isRegistered;
            _schema       = new BinaryObjectSchema();
        }
Beispiel #3
0
        /// <summary>
        /// Adds a predefined system type.
        /// </summary>
        private void AddSystemType <T>(int typeId, Func <BinaryReader, T> ctor, string affKeyFldName = null,
                                       IBinarySerializerInternal serializer = null)
            where T : IBinaryWriteAware
        {
            var type = typeof(T);

            serializer = serializer ?? new BinarySystemTypeSerializer <T>(ctor);

            if (typeId == 0)
            {
                typeId = BinaryUtils.TypeId(type.Name, null, null);
            }

            AddType(type, typeId, BinaryUtils.GetTypeName(type), false, false, null, null, serializer, affKeyFldName,
                    false, null);
        }
Beispiel #4
0
        /// <summary>
        /// Adds a predefined system type.
        /// </summary>
        private void AddSystemType <T>(int typeId, Func <BinaryReader, T> ctor, string affKeyFldName = null,
                                       IBinarySerializerInternal serializer = null)
            where T : IBinaryWriteAware
        {
            var type = typeof(T);

            serializer = serializer ?? new BinarySystemTypeSerializer <T>(ctor);

            // System types always use simple name mapper.
            var typeName = type.Name;

            if (typeId == 0)
            {
                typeId = BinaryUtils.GetStringHashCodeLowerCase(typeName);
            }

            AddType(type, typeId, typeName, false, false, null, null, serializer, affKeyFldName, false);
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryFullTypeDescriptor"/> class,
        /// copying values from specified descriptor.
        /// </summary>
        /// <param name="desc">The descriptor to copy from.</param>
        /// <param name="type">Type.</param>
        /// <param name="serializer">Serializer.</param>
        /// <param name="isRegistered">Registered flag.</param>
        public BinaryFullTypeDescriptor(BinaryFullTypeDescriptor desc, Type type,
                                        IBinarySerializerInternal serializer, bool isRegistered)
        {
            _type             = type;
            _typeId           = desc._typeId;
            _typeName         = desc._typeName;
            _userType         = desc._userType;
            _nameMapper       = desc._nameMapper;
            _idMapper         = desc._idMapper;
            _serializer       = serializer;
            _keepDeserialized = desc._keepDeserialized;
            _affKeyFieldName  = desc._affKeyFieldName;
            _isEnum           = desc._isEnum;
            _isRegistered     = isRegistered;

            _schema              = desc._schema;
            _writerTypeStruct    = desc._writerTypeStruct;
            _readerTypeStructure = desc._readerTypeStructure;
        }
Beispiel #6
0
        /// <summary>
        /// Add type.
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="typeId">Type ID.</param>
        /// <param name="typeName">Type name.</param>
        /// <param name="userType">User type flag.</param>
        /// <param name="keepDeserialized">Whether to cache deserialized value in IBinaryObject</param>
        /// <param name="nameMapper">Name mapper.</param>
        /// <param name="idMapper">ID mapper.</param>
        /// <param name="serializer">Serializer.</param>
        /// <param name="affKeyFieldName">Affinity key field name.</param>
        /// <param name="isEnum">Enum flag.</param>
        /// <param name="comparer">Comparer.</param>
        private void AddType(Type type, int typeId, string typeName, bool userType,
                             bool keepDeserialized, IBinaryNameMapper nameMapper, IBinaryIdMapper idMapper,
                             IBinarySerializerInternal serializer, string affKeyFieldName, bool isEnum,
                             IEqualityComparer <IBinaryObject> comparer)
        {
            long typeKey = BinaryUtils.TypeKey(userType, typeId);

            IBinaryTypeDescriptor conflictingType;

            if (_idToDesc.TryGetValue(typeKey, out conflictingType))
            {
                var type1 = conflictingType.Type != null
                    ? conflictingType.Type.AssemblyQualifiedName
                    : conflictingType.TypeName;

                var type2 = type != null ? type.AssemblyQualifiedName : typeName;

                throw new BinaryObjectException(string.Format("Conflicting type IDs [type1='{0}', " +
                                                              "type2='{1}', typeId={2}]", type1, type2, typeId));
            }

            if (userType && _typeNameToDesc.ContainsKey(typeName))
            {
                throw new BinaryObjectException("Conflicting type name: " + typeName);
            }

            var descriptor = new BinaryFullTypeDescriptor(type, typeId, typeName, userType, nameMapper, idMapper,
                                                          serializer, keepDeserialized, affKeyFieldName, isEnum, comparer);

            if (type != null)
            {
                _typeToDesc[type] = descriptor;
            }

            if (userType)
            {
                _typeNameToDesc[typeName] = descriptor;
            }

            _idToDesc.GetOrAdd(typeKey, _ => descriptor);
        }
Beispiel #7
0
        /// <summary>
        /// Add type.
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="typeId">Type ID.</param>
        /// <param name="typeName">Type name.</param>
        /// <param name="userType">User type flag.</param>
        /// <param name="keepDeserialized">Whether to cache deserialized value in IBinaryObject</param>
        /// <param name="nameMapper">Name mapper.</param>
        /// <param name="idMapper">ID mapper.</param>
        /// <param name="serializer">Serializer.</param>
        /// <param name="affKeyFieldName">Affinity key field name.</param>
        /// <param name="isEnum">Enum flag.</param>
        private BinaryFullTypeDescriptor AddType(Type type, int typeId, string typeName, bool userType,
                                                 bool keepDeserialized, IBinaryNameMapper nameMapper, IBinaryIdMapper idMapper,
                                                 IBinarySerializerInternal serializer, string affKeyFieldName, bool isEnum)
        {
            long typeKey = BinaryUtils.TypeKey(userType, typeId);

            BinaryFullTypeDescriptor conflictingType;

            if (_idToDesc.TryGetValue(typeKey, out conflictingType))
            {
                var type1 = conflictingType.Type != null
                    ? conflictingType.Type.AssemblyQualifiedName
                    : conflictingType.TypeName;

                var type2 = type != null ? type.AssemblyQualifiedName : typeName;

                ThrowConflictingTypeError(type1, type2, typeId);
            }

            if (userType && _typeNameToDesc.ContainsKey(typeName))
            {
                throw new BinaryObjectException("Conflicting type name: " + typeName);
            }

            var descriptor = new BinaryFullTypeDescriptor(type, typeId, typeName, userType, nameMapper, idMapper,
                                                          serializer, keepDeserialized, affKeyFieldName, isEnum);

            if (type != null)
            {
                _typeToDesc.GetOrAdd(type, x => descriptor);
            }

            if (userType)
            {
                _typeNameToDesc.GetOrAdd(typeName, x => descriptor);
            }

            _idToDesc.GetOrAdd(typeKey, _ => descriptor);

            return(descriptor);
        }
Beispiel #8
0
        /// <summary>
        /// Add type.
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="typeId">Type ID.</param>
        /// <param name="typeName">Type name.</param>
        /// <param name="userType">User type flag.</param>
        /// <param name="keepDeserialized">Whether to cache deserialized value in IBinaryObject</param>
        /// <param name="nameMapper">Name mapper.</param>
        /// <param name="idMapper">ID mapper.</param>
        /// <param name="serializer">Serializer.</param>
        /// <param name="affKeyFieldName">Affinity key field name.</param>
        /// <param name="isEnum">Enum flag.</param>
        private BinaryFullTypeDescriptor AddType(Type type, int typeId, string typeName, bool userType,
                                                 bool keepDeserialized, IBinaryNameMapper nameMapper, IBinaryIdMapper idMapper,
                                                 IBinarySerializerInternal serializer, string affKeyFieldName, bool isEnum)
        {
            Debug.Assert(!string.IsNullOrEmpty(typeName));

            long typeKey = BinaryUtils.TypeKey(userType, typeId);

            BinaryFullTypeDescriptor conflictingType;

            if (_idToDesc.TryGetValue(typeKey, out conflictingType) && conflictingType.TypeName != typeName)
            {
                ThrowConflictingTypeError(typeName, conflictingType.TypeName, typeId);
            }

            var descriptor = new BinaryFullTypeDescriptor(type, typeId, typeName, userType, nameMapper, idMapper,
                                                          serializer, keepDeserialized, affKeyFieldName, isEnum);

            if (RegistrationDisabled)
            {
                return(descriptor);
            }

            if (type != null)
            {
                ValidateRegistration(type);
                _typeToDesc.Set(type, descriptor);
            }

            if (userType)
            {
                _typeNameToDesc.Set(typeName, descriptor);
            }

            _idToDesc.Set(typeKey, descriptor);

            return(descriptor);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="type">Type.</param>
 /// <param name="typeId">Type ID.</param>
 /// <param name="typeName">Type name.</param>
 /// <param name="userType">User type flag.</param>
 /// <param name="nameMapper">Name converter.</param>
 /// <param name="idMapper">Mapper.</param>
 /// <param name="serializer">Serializer.</param>
 /// <param name="keepDeserialized">Whether to cache deserialized value in IBinaryObject</param>
 /// <param name="affKeyFieldName">Affinity field key name.</param>
 /// <param name="isEnum">Enum flag.</param>
 public BinaryFullTypeDescriptor(
     Type type, 
     int typeId, 
     string typeName, 
     bool userType, 
     IBinaryNameMapper nameMapper, 
     IBinaryIdMapper idMapper,
     IBinarySerializerInternal serializer, 
     bool keepDeserialized, 
     string affKeyFieldName,
     bool isEnum)
 {
     _type = type;
     _typeId = typeId;
     _typeName = typeName;
     _userType = userType;
     _nameMapper = nameMapper;
     _idMapper = idMapper;
     _serializer = serializer;
     _keepDeserialized = keepDeserialized;
     _affKeyFieldName = affKeyFieldName;
     _isEnum = isEnum;
 }