Exemple #1
0
        public void GetNetworks(NetworkListCallback cb)
        {
            var request = WebRequest.Create(url + "/network" + "?auth=" + authtoken) as HttpWebRequest;

            if (request == null)
            {
                cb(null);
            }

            request.Method      = "GET";
            request.ContentType = "application/json";
            request.Timeout     = 10000;

            try
            {
                var httpResponse = (HttpWebResponse)request.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var responseText = streamReader.ReadToEnd();

                    List <ZeroTierNetwork> networkList = null;
                    try
                    {
                        networkList = JsonConvert.DeserializeObject <List <ZeroTierNetwork> >(responseText);
                        foreach (ZeroTierNetwork n in networkList)
                        {
                            // all networks received via JSON are connected by definition
                            n.IsConnected = true;
                        }
                    }
                    catch (JsonReaderException e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                    cb(networkList);
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                cb(null);
            }
            catch (System.Net.WebException)
            {
                cb(null);
            }
        }
Exemple #2
0
 public void UnsubscribeNetworkUpdates(NetworkListCallback cb)
 {
     _nwCb -= cb;
 }
Exemple #3
0
 public void SubscribeNetworkUpdates(NetworkListCallback cb)
 {
     _nwCb += cb;
 }