コード例 #1
0
        public byte[] ToByteArray(DynamicContractDescription dynamicMessageDescription)
        {
            DynamicMessageDescription = dynamicMessageDescription;

            Protocol.Buffer.BitArray buffer = new Protocol.Buffer.BitArray();
            PushContractData(Data, DynamicMessageDescription, buffer);
            return(buffer.ToByteArray());
        }
コード例 #2
0
 public static DynamicMemberDescription CreateDynamicMemberDescription(string name,
                                                                       DynamicContractDescription contractDescription)
 {
     return(new DynamicMemberDescription()
     {
         Name = name,
         ContractDescription = contractDescription,
         Condition = null
     });
 }
コード例 #3
0
 public static DynamicMemberDescription CreateDynamicMemberDescription(string name,
                                                                       DynamicContractDescription contractDescription,
                                                                       string arrayLength)
 {
     return(new DynamicMemberDescription()
     {
         Name = name,
         ContractDescription = contractDescription,
         ArrayLength = arrayLength
     });
 }
コード例 #4
0
 public static DynamicMemberDescription CreateDynamicMemberDescription(string name,
                                                                       int lengthInBits,
                                                                       TypeCode typeCode,
                                                                       object defaultValue,
                                                                       string arrayLength = null,
                                                                       DynamicMemberCondition condition = null,
                                                                       DynamicContractDescription contractDescription = null)
 {
     return(new DynamicMemberDescription()
     {
         Name = name,
         LengthInBits = lengthInBits,
         ArrayLength = arrayLength,
         TypeCode = typeCode,
         Default = defaultValue,
         Condition = condition,
         ContractDescription = contractDescription
     });
 }
コード例 #5
0
 public DynamicContractValue(DynamicContractDescription dynamicMessageDescription)
 {
     _dynamicMessageDescription = dynamicMessageDescription;
     CreateDefaultValues();
 }
コード例 #6
0
 //todo:this should be deep copy
 public DynamicContractValue(DynamicContractValue from)
 {
     _dynamicMessageDescription = from._dynamicMessageDescription;
     _data = from._data;
 }
コード例 #7
0
        public void PushContractData(Dictionary <string, IDynamicValue> data,
                                     DynamicContractDescription contractDescription,
                                     Protocol.Buffer.BitArray buffer)
        {
            foreach (var memberDescription in contractDescription.Members)
            {
                if (memberDescription.Value.IsConditional)
                {
                    if (!memberDescription.Value.Condition.Evaluate(data))
                    {
                        continue;
                    }
                }
                if (memberDescription.Value.IsContract)
                {
                    if (memberDescription.Value.IsArray)
                    {
                        var value = data[memberDescription.Value.Name] as IDynamicMemberValue;

                        var arrayValue = value.Value as System.Collections.IEnumerable;
                        int i          = 0;
                        foreach (var item in arrayValue)
                        {
                            i++;
                            //array of contract
                            PushContractData(((DynamicContractValue)item).Data, memberDescription.Value.ContractDescription, buffer);
                        }
                    }
                    else
                    {
                        //contract
                        PushContractData(((DynamicContractValue)data[memberDescription.Value.Name]).Data, memberDescription.Value.ContractDescription, buffer);
                    }
                }
                else
                {
                    var value = data[memberDescription.Value.Name] as IDynamicMemberValue;

                    value.Description = memberDescription.Value;
                    var val = value.ToByteArray(data);
                    if (memberDescription.Value.IsArray)
                    {
                        int length      = 0;
                        var arrayLength = value.Description.ArrayLength;
                        if (!Int32.TryParse(arrayLength, out length))
                        {
                            //is reference value
                            length = Convert.ToInt32(data[arrayLength].Value);
                        }

                        //array of simple type
                        buffer.Push(val, memberDescription.Value.LengthInBits * length);
                    }
                    else
                    {
                        //simple type
                        buffer.Push(val, memberDescription.Value.LengthInBits);
                    }
                }
            }
        }
コード例 #8
0
 public void AddProperty(DynamicContractDescription description)
 {
     _dynamicMessageDescriptions[description.Type] = description;
 }