/// <summary>
        /// Starts the database manager. This will call the ZigBeeNetworkDataStore to retrieve the list of nodes, and
        /// then read all the nodes from the store, adding them to the ZigBeeNetworkManager.
        /// </summary>
        public void Startup()
        {
            if (DataStore == null)
            {
                Log.Debug("Data store: Undefined so network is not restored.");
                return;
            }

            ISet <IeeeAddress> nodes = DataStore.ReadNetworkNodes();

            foreach (IeeeAddress nodeAddress in nodes)
            {
                ZigBeeNode    node    = new ZigBeeNode(_networkManager, nodeAddress);
                ZigBeeNodeDao nodeDao = DataStore.ReadNode(nodeAddress);
                if (nodeDao == null)
                {
                    Log.Debug("{IeeeAddress}: Data store: Node was not found in database.", nodeAddress);
                    continue;
                }
                node.SetDao(nodeDao);
                Log.Debug("{IeeeAddress}: Data store: Node was restored.", nodeAddress);
                _networkManager.UpdateNode(node);
            }

            _nodesToSave = new BlockingCollection <ZigBeeNode>();

            //The consumer task that process the nodes produced by the elapsed timers
            //This ensure all write are done using a single thread.
            Task.Factory.StartNew(WriteNodeLoop, TaskCreationOptions.LongRunning);

            _networkManager.AddNetworkNodeListener(this);
        }
Exemplo n.º 2
0
        public void Deserialize(ZigBeeNetworkManager networkManager)
        {
            if (File.Exists(_filename) == false)
            {
                return;
            }

            List <ZigBeeNodeDao> nodes = JsonConvert.DeserializeObject <List <ZigBeeNodeDao> >(File.ReadAllText(_filename));

            if (nodes == null)
            {
                return;
            }

            foreach (var nodeDao in nodes)
            {
                ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress(nodeDao.IeeeAddress));
                node.SetDao(nodeDao);

                networkManager.AddNode(node);
            }
        }