Esempio n. 1
0
        public BACnetNetwork(BACnetGlobalNetwork bgn, String ipAddr, InstanceHolder I) //, BACnetGlobalNetwork bgn)
        {
            this.IpAddress           = ipAddr;
            this.BacnetGlobalNetwork = bgn;
            Instance = I;
            //this.BacnetTreeNode = new TreeNode(this);

            //Discover();   //no, not until user clicks on node to get child devices.
        }
        //TODO: private methods for getting diff. objects....because we will need these



        private BACnetGlobalNetwork GetBacnetGlobalNetwork(NameValueCollection nodeData, Boolean refresh = false)     //any time this is called, shouldn't we refresh filters?  Maybe not.....
        {
            //always refresh if calling from data service, but if calling internally to create Homeseer object, no need to refresh everything


            if (bacnetGlobalNetwork == null || refresh)    //if they re-filtered
            {
                bacnetGlobalNetwork = new BACnetGlobalNetwork(
                    this.Instance,
                    Boolean.Parse(nodeData["filter_ip_address"] ?? "false"),
                    nodeData["selected_ip_address"],
                    Int32.Parse(nodeData["udp_port"] ?? "47808"),
                    Boolean.Parse(nodeData["filter_device_instance"] ?? "false"),
                    Int32.Parse(nodeData["device_instance_min"] ?? "0"),
                    Int32.Parse(nodeData["device_instance_max"] ?? "4194303"));
                bacnetGlobalNetwork.Discover();
            }

            return(bacnetGlobalNetwork);
        }
        //Each BACnet discovery should first produce a list of IPs (>= 1, depending if they select the filter.  Each IP should spawn off a BACnetNetwork, which initiates its own device discovery
        //based on the filter settings in the discovery window.



        public void Discover()

        {
            NetworksDiscovered = false;


            ipAddresses = BACnetGlobalNetwork.GetAvailableIps();    //This doesn't depend on user filters, so don't need to call this method per instance.

            BacnetNetworks = new Dictionary <string, BACnetNetwork>();

            foreach (String ipAddress in ipAddresses)
            {
                if (!FilterIpAddress || (ipAddress == SelectedIpAddress))
                {
                    BacnetNetworks.Add(ipAddress, new BACnetNetwork(this, ipAddress, Instance));
                }
            }


            NetworksDiscovered = true;
        }
 //Can call this before any filters set...good for getting initial tree data.
 public BACnetTreeNode GetTreeNode()
 {
     return(BACnetGlobalNetwork.RootNode());
 }
        //public BACnetObject GetBacnetProperty(NameValueCollection nodeData)
        //{

        //    var bacnetDevice = GetBacnetDevice(nodeData, refresh);

        //    BacnetObjectTypes objType = (BacnetObjectTypes)(Int32.Parse(nodeData["object_type"]));
        //    UInt32 objInstance = UInt32.Parse(nodeData["object_instance"]);
        //    var bacnetObjectId = new BacnetObjectId(objType, objInstance);

        //    var bacnetObject = bacnetDevice.GetBacnetObject(bacnetObjectId);
        //    return bacnetObject;

        //}



        //private String SerializedResult(List<BACnetTreeNode> nodes)
        //{
        //    return jss.Serialize(nodes);
        //}



        //not just tree data...


        //GetBacnetNode(string nodeData)             //GetNodeData(Bacnet node)


        //public void Get(String data, Boolean treeData = false)
        //{



        //}



        public string GetTreeData(String data)      //this is called from discover tree, but also
        {
            var jss         = new JavaScriptSerializer();
            var emptyResult = jss.Serialize(null);

            //TODO: if there are no keys supplied, just get all data.


            System.Collections.Specialized.NameValueCollection nodeData = null;
            nodeData = System.Web.HttpUtility.ParseQueryString(data);

            var dataType = nodeData["node_type"];

            //IBACnetTreeDataObject node;

            try
            {
                //switch (dataType)
                //{
                //    case "root":    //only happens for getNodeData - this is a construct used for treeview, has no underlying bacnet data structure
                //        return jss.Serialize(new List<BACnetTreeNode>() { BACnetGlobalNetwork.RootNode() });
                //        //node = BACnetGlobalNetwork.RootNode();
                //        //return jss.Serialize(new List<BACnetTreeNode>() { BACnetGlobalNetwork.RootNode() });
                //    //break;
                //    case "global_network":
                //        node = GetBacnetGlobalNetwork(nodeData, true);
                //        break;
                //        //return jss.Serialize(GetBacnetGlobalNetwork(nodeData, true).GetChildNodes());
                //    //break;
                //    case "network":
                //        node = GetBacnetNetwork(nodeData);
                //        break;
                //        //return jss.Serialize(GetBacnetNetwork(nodeData).GetChildNodes());
                //    //break;
                //    case "device":
                //        node = GetBacnetDevice(nodeData);
                //        break;
                //        //return jss.Serialize(GetBacnetDevice(nodeData).GetChildNodes());
                //    //break;
                //    case "object":
                //        node = GetBacnetObject(nodeData);
                //        return jss.Serialize(GetBacnetObject(nodeData).GetProperties());
                //    //break;
                //    //case "property":
                //    //    return jss.Serialize(GetBacnetProperty(nodeData, true));    //not node data, just list of id/value/names
                //    //    break;
                //    default:
                //        //return emptyResult;
                //        break;
                //}



                switch (dataType)
                {
                case "root":
                    return(jss.Serialize(new List <BACnetTreeNode>()
                    {
                        BACnetGlobalNetwork.RootNode()
                    }));

                //break;
                case "global_network":
                    return(jss.Serialize(GetBacnetGlobalNetwork(nodeData, true).GetChildNodes()));

                //break;
                case "network":
                    return(jss.Serialize(GetBacnetNetwork(nodeData).GetChildNodes()));

                //break;
                case "device":
                    return(jss.Serialize(GetBacnetDevice(nodeData).GetChildNodes()));

                //break;
                case "object":
                    return(jss.Serialize(GetBacnetObject(nodeData).GetProperties()));

                //break;
                //case "property":
                //    return jss.Serialize(GetBacnetProperty(nodeData, true));    //not node data, just list of id/value/names
                //    break;
                default:
                    //return emptyResult;
                    break;
                }
            }
            catch (Exception ex)
            {
                Instance.hspi.Log("BACnetDevice Exception in GetTreeData " + ex.Message, 2);
                Console.WriteLine("exception in GetPagePlugin");
                Console.WriteLine(ex.StackTrace);
                //return emptyResult;
            }

            return(emptyResult);
        }