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); } }
public void UnsubscribeNetworkUpdates(NetworkListCallback cb) { _nwCb -= cb; }
public void SubscribeNetworkUpdates(NetworkListCallback cb) { _nwCb += cb; }