Ejemplo n.º 1
0
        private void WriteValue(TlvWriter writer, TTlvTypeIdentifier typeIdentifier, TPropertyDataType dataType, string instanceID, string value)
        {
            ushort identifier;
            if (ushort.TryParse(instanceID, out identifier))
            {

                switch (dataType)
                {
                    case TPropertyDataType.NotSet:
                        break;
                    case TPropertyDataType.String:
                        writer.Write(typeIdentifier, identifier, value);
                        break;
                    case TPropertyDataType.Boolean:
                        bool boolValue;
                        if (bool.TryParse(value, out boolValue))
                            writer.Write(typeIdentifier, identifier, boolValue);
                        break;
                    case TPropertyDataType.Integer:
                        long longValue;
                        if (long.TryParse(value, out longValue))
                            writer.Write(typeIdentifier, identifier, longValue);
                        break;
                    case TPropertyDataType.Float:
                        double doubleValue;
                        if (double.TryParse(value, out doubleValue))
                            writer.Write(typeIdentifier, identifier, doubleValue);
                        break;
                    case TPropertyDataType.DateTime:
                        try
                        {
                            DateTime dateTimeValue = System.Xml.XmlConvert.ToDateTime(value, System.Xml.XmlDateTimeSerializationMode.Utc);
                            writer.Write(typeIdentifier, identifier, dateTimeValue);
                        }
                        catch
                        {

                        }
                        break;
                    case TPropertyDataType.Opaque:
                        byte[] buffer = Convert.FromBase64String(value);
                        writer.Write(typeIdentifier, identifier, buffer);
                        break;
                    case TPropertyDataType.Object:
                        break;
                    default:
                        break;
                }
            }
        }
Ejemplo n.º 2
0
        private void WriteValue(TlvWriter writer, TTlvTypeIdentifier typeIdentifier, TPropertyDataType dataType, string instanceID, string value)
        {
            ushort identifier;

            if (ushort.TryParse(instanceID, out identifier))
            {
                switch (dataType)
                {
                case TPropertyDataType.NotSet:
                    break;

                case TPropertyDataType.String:
                    writer.Write(typeIdentifier, identifier, value);
                    break;

                case TPropertyDataType.Boolean:
                    bool boolValue;
                    if (bool.TryParse(value, out boolValue))
                    {
                        writer.Write(typeIdentifier, identifier, boolValue);
                    }
                    break;

                case TPropertyDataType.Integer:
                    long longValue;
                    if (long.TryParse(value, out longValue))
                    {
                        writer.Write(typeIdentifier, identifier, longValue);
                    }
                    break;

                case TPropertyDataType.Float:
                    double doubleValue;
                    if (double.TryParse(value, out doubleValue))
                    {
                        writer.Write(typeIdentifier, identifier, doubleValue);
                    }
                    break;

                case TPropertyDataType.DateTime:
                    try
                    {
                        DateTime dateTimeValue = System.Xml.XmlConvert.ToDateTime(value, System.Xml.XmlDateTimeSerializationMode.Utc);
                        writer.Write(typeIdentifier, identifier, dateTimeValue);
                    }
                    catch
                    {
                    }
                    break;

                case TPropertyDataType.Opaque:
                    byte[] buffer = Convert.FromBase64String(value);
                    writer.Write(typeIdentifier, identifier, buffer);
                    break;

                case TPropertyDataType.Object:
                    break;

                default:
                    break;
                }
            }
        }