Пример #1
0
        public static DeviceObject CreateFrom(DeviceObject parent, string name, JObject inputNode)
        {
            int?id      = inputNode.Value <int?>("id");
            var members = inputNode.Value <JArray>("members");

            return(CreateFrom(parent, id, name, members));
        }
Пример #2
0
        public static DeviceObject CreateFrom(DeviceObject parent, int?id, string name, JArray inputNodes)
        {
            var deviceObject = new DeviceObject
            {
                Parent = parent,
                ID     = id,
                Name   = name,
                Type   = DataType.Object
            };

            var memberList = new List <IDeviceMember>();

            foreach (dynamic node in inputNodes)
            {
                // Ignore the endpoint entry
                if (string.IsNullOrEmpty(node.Value <string>("name")) && node.Value <int>("id") == 0)
                {
                    continue;
                }

                // Ignore test entries
                if (node.Value <string>("name") == "test_function" || node.Value <string>("name") == "test_property")
                {
                    continue;
                }

                var deviceMember = DeviceSchemaParser.ParseMember(deviceObject, node);
                memberList.Add(deviceMember);
            }

            deviceObject.Members = memberList;

            return(deviceObject);
        }
Пример #3
0
        public static IDeviceMember ParseMember(DeviceObject parentObject, JObject inputNode)
        {
            switch (inputNode.Value <string>("type"))
            {
            case "object":
                return(DeviceObject.CreateFrom(parentObject, inputNode));

            case "function":
                return(DeviceFunction.CreateFrom(inputNode));

            default:
                return(DeviceProperty.CreateFrom(inputNode));
            }
        }
Пример #4
0
        public static DeviceObject Parse(string rootObjectName, string jsonInput)
        {
            dynamic nodes = JArray.Parse(jsonInput);

            return(DeviceObject.CreateFrom(null, null, rootObjectName, nodes));
        }
Пример #5
0
        public static DeviceObject CreateFrom(DeviceObject parent, JObject inputNode)
        {
            string name = inputNode.Value <string>("name");

            return(CreateFrom(parent, name, inputNode));
        }