Exemple #1
0
 public DynamicMemberValue(DynamicMemberDescription description, object value)
 {
     Description = description;
     if (Description.IsArray)
     {
         Value = new DynamicContractValue[0];
     }
     else
     {
         Value = value;
     }
 }
Exemple #2
0
 private void CreateDefaultValues()
 {
     foreach (var item in _dynamicMessageDescription.Members)
     {
         var defaultValue = item.Value.Default;
         if (item.Value.IsContract)
         {
             defaultValue = new DynamicContractValue(item.Value.ContractDescription);
         }
         _data.Add(item.Key, new DynamicMemberValue(item.Value, defaultValue));
     }
 }
Exemple #3
0
        private DynamicContractValue DeserializeDynamicContractValue(JObject obj)
        {
            DynamicContractValue target = new DynamicContractValue();

            foreach (var child in obj.Children())
            {
                if (child.GetType() == typeof(JProperty))
                {
                    if (((JProperty)child).Value.Type == JTokenType.Object)
                    {
                        target[((JProperty)child).Name] = DeserializeDynamicContractValue(((JProperty)child).Value as JObject);
                    }
                    else if (((JProperty)child).Value.Type == JTokenType.Array)
                    {
                        var jarray = ((JArray)((JProperty)child).Value);
                        var temp   = new object[jarray.Count];
                        for (int i = 0; i < jarray.Count; i++)
                        {
                            if (jarray[i] is JObject)
                            {
                                temp[i] = DeserializeDynamicContractValue((JObject)jarray[i]);
                            }
                            else
                            {
                                temp[i] = ((JValue)jarray[i]).Value;
                            }
                        }
                        target[((JProperty)child).Name] = new DynamicMemberValue(null, temp);
                    }
                    else
                    {
                        target[((JProperty)child).Name] = new DynamicMemberValue(null, ((JValue)((JProperty)child).Value).Value);
                    }
                }
            }
            return(target);
        }
Exemple #4
0
 //todo:this should be deep copy
 public DynamicContractValue(DynamicContractValue from)
 {
     _dynamicMessageDescription = from._dynamicMessageDescription;
     _data = from._data;
 }
        public bool TryParseContract(Protocol.Buffer.IBitArray buffer, out IDynamicContractValue msg)
        {
            msg = new DynamicContractValue(this);
            foreach (var property in this.Members)
            {
                if (property.Value.IsConditional)
                {
                    if (!property.Value.Condition.Evaluate(msg.Data))
                    {
                        if (msg.Data.ContainsKey(property.Value.Name))
                        {
                            msg.Data.Remove(property.Value.Name);
                        }
                        continue;
                    }
                }

                if (property.Value.IsContract)
                {
                    if (property.Value.IsArray)
                    {
                        int length      = 0;
                        var arrayLength = property.Value.ArrayLength;
                        if (!Int32.TryParse(arrayLength, out length))
                        {
                            //is reference value
                            length = (int)msg.Data[arrayLength].Value;
                        }
                        object[] temp = new object[length];

                        IDynamicMemberValue propValue = new DynamicMemberValue(property.Value, null);

                        for (int i = 0; i < length; i++)
                        {
                            IDynamicContractValue value;

                            if (!property.Value.ContractDescription.TryParseContract(buffer, out value))
                            {
                                return(false);
                            }
                            temp[i] = value;
                        }
                        propValue.Value = temp;
                        msg.Data[property.Value.Name] = propValue;
                    }
                    else
                    {
                        IDynamicContractValue value;

                        if (!property.Value.ContractDescription.TryParseContract(buffer, out value))
                        {
                            return(false);
                        }

                        msg.Data[property.Value.Name] = value;
                    }
                }
                else
                {
                    IDynamicMemberValue value;
                    if (!property.Value.TryParseDynamicPropertyValue(buffer, msg, out value))
                    {
                        return(false);
                    }
                    msg.Data[value.Description.Name] = value;
                }
            }
            return(true);
        }