//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);
        }