Esempio n. 1
0
 private void LoadNetworkFromJSON(string json)
 {
     if (json != null && json != "")
     {
         tree = JsonConvert.DeserializeObject <NetworkElement>(json);
     }
 }
Esempio n. 2
0
        public NetworkUtil()
        {
            HttpBaseProtocolFilter RootFilter = new HttpBaseProtocolFilter();

            RootFilter.CacheControl.ReadBehavior  = HttpCacheReadBehavior.NoCache;
            RootFilter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache;

            client = new HttpClient(RootFilter);

            tree = null;
        }
Esempio n. 3
0
        public static string ConvertTableToJSON()
        {
            NetworkElement tree = new NetworkElement();

            //filter out camera publisher as it is heckin big
            for (int i = 0; i < tree.Children.Count; i++)
            {
                if (tree.Children.ElementAt(i).Key == "CameraPublisher")
                {
                    tree.Children.RemoveAt(i);
                }
            }

            string myJson = JsonConvert.SerializeObject(tree);

            return(myJson);
        }
Esempio n. 4
0
        public object GetKey(string inputKey)
        {
            if (tree != null)
            {
                string[] tokens = inputKey.Split('/');

                NetworkElement myElement = tree;
                int            x         = 0;

                while (myElement.Key != tokens.Last())
                {
                    var matches = myElement.Children.Where(ntItem => ntItem.Key == tokens[x]);

                    try
                    {
                        if (matches.Count() > 0 && matches.First() != null)
                        {
                            myElement = matches.First();
                        }
                        else
                        {
                            throw new Exception($"Key {tokens[x]} Not Found!");
                        }
                    } catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }

                    x++;
                }

                return(myElement.Value);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 5
0
        public static object GetKey(string inputKey, NetworkElement tree)
        {
            string[] tokens = inputKey.Split('/');

            NetworkElement myElement = tree;
            int            x         = 0;

            while (myElement.Key != tokens.Last())
            {
                var matches = myElement.Children.Where(ntItem => ntItem.Key == tokens[x]);
                if (matches.Count() > 0 && matches.First() != null)
                {
                    myElement = matches.First();
                }
                else
                {
                    throw new Exception($"Key {tokens[x]} Not Found!");
                }

                x++;
            }

            return(myElement.Value);
        }
Esempio n. 6
0
        public IEnumerator UpdateNtTable()
        {
            UnityWebRequest www = UnityWebRequest.Get("http://infinitepc:4089/GetNetworkTablesJSON/");

            yield return(www.Send());

            if (www.isError)
            {
                Debug.Log(www.error);
            }
            else
            {
                // Show results as text
                //Debug.Log(www.downloadHandler.text);
                string json = www.downloadHandler.text;

                if (json != null && json != "")
                {
                    tree = JsonConvert.DeserializeObject <NetworkElement>(json);
                }

                OnRaiseNetworkUpdatedEvent(new NetworkUpdatedEvent(tree));
            }
        }
Esempio n. 7
0
 public NetworkUtil()
 {
     tree = null;
 }
Esempio n. 8
0
 public NetworkUpdatedEvent(NetworkElement tree)
 {
     this.tree = tree;
 }