Beispiel #1
0
 public static Property Deserialise(System.IO.Stream stream)
 {
     Property property = new Property();
     property.PropertyDefinitionID = IPCHelper.ReadGuid(stream);
     property.PropertyID = IPCHelper.ReadString(stream);
     byte nullItem = IPCHelper.ReadByte(stream);
     if (nullItem == 1)
     {
         property.Value = new PropertyValue() { Value = IPCHelper.ReadString(stream) };
     }
     int valueCount = IPCHelper.ReadInt32(stream);
     for (int valueIndex = 0; valueIndex < valueCount; valueIndex++)
     {
         PropertyValue value = new PropertyValue();
         value.PropertyValueID = IPCHelper.ReadString(stream);
         value.Value = IPCHelper.ReadString(stream);
         if (property.Values == null)
             property.Values = new List<PropertyValue>();
         property.Values.Add(value);
     }
     return property;
 }
Beispiel #2
0
        public static Property ParseProperty(ObjectDefinition objectDefinition, JsonReader reader)
        {
            Property result = new Property();
            string propertyValueID = null;
            while (reader.Read())
            {
                if (reader.State == TJsonReaderState.Member)
                {
                    if (string.Compare(reader.Text, "n") == 0)
                    {
                        if (reader.Read() && !string.IsNullOrEmpty(reader.Text))
                        {
                            string[] fields = reader.Text.Split('/');
                            PropertyDefinition property = objectDefinition.GetProperty(fields[0]);
                            if (property != null)
                            {
                                result.PropertyDefinitionID = property.PropertyDefinitionID;
                                result.PropertyID = property.PropertyID;
                                if (fields.Length > 1)
                                {
                                    propertyValueID = fields[1];
                                    result.Values = new List<PropertyValue>();
                                }
                            }
                        }
                    }
                    else if ((string.Compare(reader.Text, "v") == 0) || (string.Compare(reader.Text, "sv") == 0))
                    {
                        if (reader.Read() && !string.IsNullOrEmpty(reader.Text))
                        {
                            if (string.IsNullOrEmpty(propertyValueID))
                            {
                                result.Value = new PropertyValue(reader.Text);
                            }
                            else
                            {
                                PropertyValue value = new PropertyValue();
                                value.PropertyValueID = propertyValueID;
                                value.Value = reader.Text;
                                result.Values.Add(value);
                            }
                        }
                    }
                    else if (string.Compare(reader.Text, "bv") == 0)
                    {
                        if (reader.Read())
                        {
                            if (string.IsNullOrEmpty(propertyValueID))
                            {
                                result.Value = new PropertyValue(reader.AsBoolean.ToString());
                            }
                            else
                            {
                                PropertyValue value = new PropertyValue();
                                value.PropertyValueID = propertyValueID;
                                value.Value = reader.AsBoolean.ToString();
                                result.Values.Add(value);
                            }

                        }
                    }
                }
                if (reader.State == TJsonReaderState.EndObject)
                    break;
            }
            return result;
        }
Beispiel #3
0
 public static Property ParseProperty(PropertyDefinition propertyDefinition, JsonReader reader)
 {
     Property result = null;
     while (reader.Read())
     {
         if ((reader.State == TJsonReaderState.Member) && (string.Compare(reader.Text, "e") == 0))
         {
             if (result == null)
             {
                 result = new Property();
                 result.PropertyDefinitionID = propertyDefinition.PropertyDefinitionID;
                 result.PropertyID = propertyDefinition.PropertyID;
             }
             if (reader.Read())
             {
                 if (reader.State == TJsonReaderState.Array)
                 {
                     while (reader.Read())
                     {
                         if (reader.State == TJsonReaderState.Object)
                         {
                             string propertyValueID = null;
                             string value = null;
                             while (reader.Read())
                             {
                                 if (reader.State == TJsonReaderState.Member)
                                 {
                                     if (string.Compare(reader.Text, "n") == 0)
                                     {
                                         if (reader.Read() && !string.IsNullOrEmpty(reader.Text))
                                         {
                                             string[] fields = reader.Text.Split('/');
                                             if (fields.Length > 1)
                                             {
                                                 propertyValueID = fields[1];
                                                 result.Values = new List<PropertyValue>();
                                             }
                                         }
                                     }
                                     else if ((string.Compare(reader.Text, "v") == 0) || (string.Compare(reader.Text, "sv") == 0))
                                     {
                                         if (reader.Read() && !string.IsNullOrEmpty(reader.Text))
                                         {
                                             value = reader.Text;
                                         }
                                     }
                                     else if (string.Compare(reader.Text, "bv") == 0)
                                     {
                                         if (reader.Read())
                                         {
                                             value = reader.AsBoolean.ToString();
                                         }
                                     }
                                 }
                                 if (reader.State == TJsonReaderState.EndObject)
                                 {
                                     if (propertyDefinition.IsCollection)
                                     {
                                         PropertyValue propertyValue = new PropertyValue();
                                         propertyValue.PropertyValueID = propertyValueID;
                                         propertyValue.Value = value;
                                         result.Values.Add(propertyValue);
                                     }
                                     else
                                     {
                                         result.Value = new PropertyValue(value);
                                     }
                                     break;
                                 }
                             }
                         }
                         if (reader.State == TJsonReaderState.EndArray)
                             break;
                     }
                 }
             }
         }
     }
     return result;
 }
Beispiel #4
0
 public static Model.Object ParseObject(ObjectDefinition objectDefinition, TlvReader reader)
 {
     Model.Object result = null;
     while (reader.Read())
     {
         if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ObjectInstance)
         {
             TlvReader objectReader = new TlvReader(reader.TlvRecord.Value);
             result = ParseObject(objectDefinition, objectReader);
             if (result != null)
             {
                 result.InstanceID = reader.TlvRecord.Identifier.ToString();
             }
             break;
         }
         if ((reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.ObjectInstance) && (reader.TlvRecord.TypeIdentifier != TTlvTypeIdentifier.NotSet))
         {
             if (result == null)
             {
                 result = new Model.Object();
                 result.ObjectID = objectDefinition.ObjectID;
                 result.ObjectDefinitionID = objectDefinition.ObjectDefinitionID;
             }
             if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceWithValue)
             {
                 string propertyID = reader.TlvRecord.Identifier.ToString();
                 PropertyDefinition property = objectDefinition.GetProperty(propertyID);
                 if (property != null)
                 {
                     Property lwm2mProperty = new Property();
                     lwm2mProperty.PropertyDefinitionID = property.PropertyDefinitionID;
                     lwm2mProperty.PropertyID = property.PropertyID;
                     lwm2mProperty.Value = new PropertyValue(GetValue(reader, property));
                     result.Properties.Add(lwm2mProperty);
                 }
             }
             else if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources)
             {
                 string propertyID = reader.TlvRecord.Identifier.ToString();
                 PropertyDefinition property = objectDefinition.GetProperty(propertyID);
                 if (property != null)
                 {
                     Property lwm2mProperty = new Property();
                     lwm2mProperty.PropertyDefinitionID = property.PropertyDefinitionID;
                     lwm2mProperty.PropertyID = property.PropertyID;
                     result.Properties.Add(lwm2mProperty);
                     TlvReader arrayReader = new TlvReader(reader.TlvRecord.Value);
                     while (arrayReader.Read())
                     {
                         if (arrayReader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceInstance)
                         {
                             string value = GetValue(arrayReader, property);
                             if (value != null)
                             {
                                 if (lwm2mProperty.Values == null)
                                     lwm2mProperty.Values = new List<PropertyValue>();
                                 PropertyValue propertyValue = new PropertyValue();
                                 propertyValue.PropertyValueID = arrayReader.TlvRecord.Identifier.ToString();
                                 propertyValue.Value = value;
                                 lwm2mProperty.Values.Add(propertyValue);
                             }
                         }
                     }
                 }
             }
         }
     }
     return result;
 }