/// <summary> /// Get the list of users. /// </summary> /// <returns>The List of user or null on error.</returns> public CommandResult GetUserList() { Dictionary <string, Whitelist> list = new Dictionary <string, Whitelist>(); CommandResult bresult = new CommandResult { Success = false }; CommResult comres = Communication.SendRequest(new Uri(BridgeUrl + "/config"), WebRequestType.GET); switch (comres.status) { case WebExceptionStatus.Success: BridgeSettings brs = Serializer.DeserializeToObject <BridgeSettings>(comres.data); if (brs != null) { bresult.Success = true; bresult.resultobject = brs.whitelist; } else { lastMessages = new MessageCollection(Serializer.DeserializeToObject <List <Message> >(comres.data)); bresult.resultobject = lastMessages; } break; case WebExceptionStatus.Timeout: lastMessages = new MessageCollection { _bridgeNotResponding }; BridgeNotResponding?.Invoke(this, _e); bresult.resultobject = lastMessages; break; default: lastMessages = new MessageCollection { new UnkownError(comres) }; bresult.resultobject = lastMessages; break; } return(bresult); }
private static void _ipscanBgw_DoWork(object sender, DoWorkEventArgs e) { IPAddress ip = IPAddress.Parse(GetLocalIPAddress()); byte[] ipArray = ip.GetAddressBytes(); byte currentip = ipArray[3]; Dictionary <string, Bridge> newlist = new Dictionary <string, Bridge>(); BridgeSettings desc = new BridgeSettings(); for (byte x = 2; x <= 254; x++) { if (_ipscanBgw.CancellationPending) { break; } _ipscanBgw.ReportProgress(0, x); if (x == currentip) { continue; } ipArray[3] = x; Communication.Timeout = 50; if (_ipscanBgw.CancellationPending) { break; } CommResult comres = Communication.SendRequest(new Uri($@"http://{new IPAddress(ipArray)}/api/config"), WebRequestType.GET); switch (comres.status) { case WebExceptionStatus.Success: desc = Serializer.DeserializeToObject <BridgeSettings>(comres.data); // try to deserialize the received message. if (desc == null) { continue; // if the deserialisation didn't work it means this is not a bridge continue with next ip. } if (newlist.Count > 0) { if (!newlist.Any(y => Equals(y.Value.IpAddress, ipArray))) { newlist.Add(desc.mac, new Bridge() { IpAddress = new IPAddress(ipArray), ApiVersion = desc.apiversion, Mac = desc.mac }); } } else { newlist.Add(desc.mac, new Bridge() { IpAddress = new IPAddress(ipArray), ApiVersion = desc.apiversion, Mac = desc.mac }); } break; case WebExceptionStatus.Timeout: break; default: break; } } e.Result = newlist; }