Example #1
0
        public void Check(MessageSerializedPropertyInfo messageSerializedPropertyInfo, SerializationDefaults serializationDefaults, MessageClassAttribute classAttribute)
        {
            if (messageSerializedPropertyInfo.ElementType.FullName == typeof(DateTime).FullName)
            {
                var messagePropertyAttribute = messageSerializedPropertyInfo.MessagePropertyAttribute;
                if (!messagePropertyAttribute.IsIsBcdSpecified)
                {
                    messagePropertyAttribute.IsBcd = true;
                }

                if (!messagePropertyAttribute.IsFormatSpecified)
                {
                    messagePropertyAttribute.Format = "MMddyyyyHHmmss";
                }

                if (!messagePropertyAttribute.IsLengthSpecified)
                {
                    messagePropertyAttribute.Length = messagePropertyAttribute.Format.Length / 2; // BCD
                }
            }
        }
Example #2
0
        public void Check(MessageSerializedPropertyInfo messageSerializedPropertyInfo, SerializationDefaults serializationDefaults, MessageClassAttribute classAttribute)
        {
            var elementType = messageSerializedPropertyInfo.ElementType;
            var messagePropertyAttribute = messageSerializedPropertyInfo.MessagePropertyAttribute;

            if (!messagePropertyAttribute.IsLengthSpecified && NumericFunctions.IsIntegerType(elementType))
            {
                // If we are using BCD the max length isn't the number of bytes of the type,
                // it's however long the maximum number is.  Sort of.
                // As an example, the MaxUInt is 4294967295, which is 10 digits.
                // So really, it is 9 digits.  Of course that doesn't quite work
                // because that is 4 1/2 bytes so really we should support 5 bytes but limit
                // how many we fill in but for now we will just say it is the minimum number
                // of bytes that things can safely be fit in.
                // elementType.GetField("MaxValue").GetValue(null).ToString()
                // The call to GetField uses Reflection to the get static MaxValue field.
                // The call to GetValue(null) gets the value of the MaxValue field (the null is because it's static)
                // Then the ToString is to figure out the number of digits that can be used.
                Type lengthType = elementType.IsEnum ? Enum.GetUnderlyingType(elementType) : elementType;
                messagePropertyAttribute.Length = messagePropertyAttribute.IsBcd ? (lengthType.GetField("MaxValue").GetValue(null).ToString().Length + 1) / 2 : Marshal.SizeOf(lengthType);
            }

            if (!messagePropertyAttribute.IsLengthSpecified && messageSerializedPropertyInfo.ElementIsMessageSerializableObject)
            {
                MessageSerializedClassInfo classInfo = Serializer.Instance.GetClassInfo(elementType);
                messagePropertyAttribute.Length = classInfo.TotalLengthWithoutVariableData;
            }

            if (!messagePropertyAttribute.IsVariableLengthSpecified && messagePropertyAttribute.BlobType == BlobTypes.Data)
            {
                messagePropertyAttribute.VariableLength = true;
            }

            if (!messagePropertyAttribute.IsVariableLengthSpecified && messagePropertyAttribute.Length == 0 && elementType.FullName == typeof(string).FullName)
            {
                messagePropertyAttribute.VariableLength = true;
            }

            if (!messagePropertyAttribute.IsMinLengthSpecified)
            {
                messagePropertyAttribute.MinLength = 0;
            }

            if (!messagePropertyAttribute.IsMaxLengthSpecified)
            {
                messagePropertyAttribute.MaxLength = -1;
            }

            if (!messagePropertyAttribute.IsMinimizeVariableLengthSpecified)
            {
                messagePropertyAttribute.MinimizeVariableLength = false;
            }
        }
Example #3
0
 public ConfigClassInfo()
 {
     Properties            = new List <ConfigPropertyInfo>();
     MessageClassAttribute = new MessageClassAttribute();
 }
Example #4
0
 public void Check(MessageSerializedPropertyInfo messageSerializedPropertyInfo, SerializationDefaults serializationDefaults, MessageClassAttribute classAttribute)
 {
     if (!messageSerializedPropertyInfo.MessagePropertyAttribute.IsIsBcdSpecified && messageSerializedPropertyInfo.PropertyInfo.Name.StartsWith("Bcd", StringComparison.InvariantCultureIgnoreCase))
     {
         messageSerializedPropertyInfo.MessagePropertyAttribute.IsBcd = true;
     }
 }
Example #5
0
        public void Check(MessageSerializedPropertyInfo messageSerializedPropertyInfo, SerializationDefaults serializationDefaults, MessageClassAttribute classAttribute)
        {
            if (!messageSerializedPropertyInfo.ContainsAuthenticationAttribute &&
                messageSerializedPropertyInfo.PropertyInfo.Name.StartsWith("Crc", StringComparison.InvariantCultureIgnoreCase))
            {
                messageSerializedPropertyInfo.CalculatedFieldAttributes.Add(new CalculatedAuthenticationResultAttribute(typeof(CalculatorAuthenticationCrc16)));
            }

            // By default authentication fields are excluded from length calculations
            if (!messageSerializedPropertyInfo.ContainsLengthAttribute && messageSerializedPropertyInfo.PropertyInfo.Name.StartsWith("Crc", StringComparison.InvariantCultureIgnoreCase))
            {
                messageSerializedPropertyInfo.CalculatedFieldAttributes.Add(new CalculatedLengthAttribute()
                {
                    Exclude = true
                });
            }
        }
Example #6
0
        protected void CheckRules(MessagePropertyAttribute messagePropertyAttribute, PropertyInfo propertyInfo, Type elementType, bool isMessageSerializable, SerializationDefaults serializationDefaults, MessageClassAttribute classAttribute)
        {
            if (serializationDefaults is null)
            {
                return;
            }

            messagePropertyAttribute.ApplyingRules = true;
            foreach (IPropertyRule propertyRule in serializationDefaults.PropertyRules)
            {
                propertyRule.Check(this, serializationDefaults, classAttribute);
            }

            messagePropertyAttribute.ApplyingRules = false;
        }
Example #7
0
        public MessageSerializedPropertyInfo(int index, PropertyInfo propertyInfo, MessagePropertyAttribute messagePropertyAttribute, SerializationDefaults serializationDefaults, MessageClassAttribute classAttribute)
        {
            Index        = index;
            PropertyInfo = propertyInfo;
            SetElementType(propertyInfo.PropertyType);
            ElementIsMessageSerializableObject = TypeIsMessageSerializableObject(ElementType);
            MessagePropertyAttribute           = messagePropertyAttribute;
            CalculatedFieldAttributes          = GetCalculatedFieldAttributes(propertyInfo);

            //TODO: throw new Exception("Probably need to change this to be called after all the MessageSerializedPropertyInfos are created and then pass the list in to CheckRules.  Also, since it's a member, a bunch of the parameters don't need to be passed in anyways");
            CheckRules(messagePropertyAttribute, propertyInfo, ElementType, ElementIsMessageSerializableObject, serializationDefaults, classAttribute);
        }