示例#1
0
        public void WriteNode(ZigBeeNodeDao node)
        {
            var nodeFound = ReadNode(node.IeeeAddress);

            if (nodeFound != null)
            {
                _nodes.ReplaceOne(n => n.IeeeAddress == nodeFound.IeeeAddress, node);
            }
            else
            {
                _nodes.InsertOne(node);
            }
        }
示例#2
0
        public void SetDao(ZigBeeNodeDao dao)
        {
            IeeeAddress     = new IeeeAddress(dao.IeeeAddress);
            NetworkAddress  = dao.NetworkAddress;
            NodeDescriptor  = dao.NodeDescriptor;
            PowerDescriptor = dao.PowerDescriptor;
            if (dao.BindingTable != null)
            {
                BindingTable.AddRange(dao.BindingTable);
            }

            foreach (ZigBeeEndpointDao endpointDao in dao.Endpoints)
            {
                ZigBeeEndpoint endpoint = new ZigBeeEndpoint(this, endpointDao.EndpointId);
                endpoint.SetDao(endpointDao);
                Endpoints[endpoint.EndpointId] = endpoint;
            }
        }
        public ZigBeeNodeDao ReadNode(IeeeAddress address)
        {
            ZigBeeNodeDao node = null;

            try
            {
                string filename = GetFileName(address);

                if (File.Exists(filename))
                {
                    node = JsonConvert.DeserializeObject <ZigBeeNodeDao>(File.ReadAllText(filename));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(node);
        }
示例#4
0
        public void Serialize(ZigBeeNetworkManager networkManager)
        {
            List <ZigBeeNodeDao> nodes = new List <ZigBeeNodeDao>();

            foreach (var node in networkManager.Nodes)
            {
                ZigBeeNodeDao nodeDao = node.GetDao();
                nodes.Add(nodeDao);
            }

            var settings = new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };

            string json = JsonConvert.SerializeObject(nodes, Formatting.Indented, settings);

            File.WriteAllText(_filename, json);
        }
示例#5
0
        /// <summary>
        /// Gets a {@link ZigBeeNodeDao} representing the node
        ///
        /// @return the {@link ZigBeeNodeDao}
        /// </summary>
        public ZigBeeNodeDao GetDao()
        {
            ZigBeeNodeDao dao = new ZigBeeNodeDao();

            dao.IeeeAddress     = IeeeAddress.ToString();
            dao.NetworkAddress  = NetworkAddress;
            dao.NodeDescriptor  = NodeDescriptor;
            dao.PowerDescriptor = PowerDescriptor;
            dao.BindingTable    = BindingTable;

            List <ZigBeeEndpointDao> endpointDaoList = new List <ZigBeeEndpointDao>();

            foreach (ZigBeeEndpoint endpoint in Endpoints.Values)
            {
                endpointDaoList.Add(endpoint.GetDao());
            }
            dao.Endpoints = endpointDaoList;

            return(dao);
        }
        public void WriteNode(ZigBeeNodeDao node)
        {
            try
            {
                string filename = GetFileName(node.IeeeAddress);

                var settings = new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                };

                string json = JsonConvert.SerializeObject(node, Formatting.Indented, settings);

                File.WriteAllText(filename, json);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }