示例#1
0
        public async Task <bool> AllowPendingNode(string MAC)
        {
            UnitOfWork repository = UnitOfWork.GetInstance();

            Home home = repository.HomeRespository.GetHome();

            Node node = repository.NodeRespository.GetByMacAddress(MAC);

            NetworkJoin joinMod = CommunicationManager.Instance.FindModule <NetworkJoin>();

            PendingNodeInfo info = joinMod.PendingNodes.FirstOrDefault(n => n.MacAddress == MAC);

            if (info != null)
            {
                if (node == null)
                {
                    node         = BusinessNode.CreateNode((BaseTypes)info.BaseType, (ShieldTypes)info.ShieldType);
                    node.Mac     = info.MacAddress;
                    node.Address = repository.NodeRespository.GetNewAddress();

                    node = repository.NodeRespository.Insert(node);
                }

                bool accepted = await joinMod.AcceptNode(MAC, (ushort)node.Address, home.Security);

                if (accepted)
                {
                    repository.Commit();
                }

                return(accepted);
            }

            return(false);
        }
示例#2
0
        private async void button2_Click(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedIndex >= 0)
            {
                ushort newAddress = Convert.ToUInt16(this.textBox1.Text, 16);

                var nodeInfo = (PendingNodeInfo)listBox1.SelectedItem;

                await joinMod.AcceptNode(nodeInfo.MacAddress, newAddress, new Security()
                {
                    SecurityKey = "TestSecurityKey0"
                });
            }
        }