public async Task <List <Beacon> > GetData() { using (HttpClient client = new HttpClient()) { using (HttpResponseMessage response = await client.GetAsync($"http://{IP}:5000/scan")) { try { response.EnsureSuccessStatusCode(); String json = await response.Content.ReadAsStringAsync(); List <Beacon> list = new List <Beacon>(); List <RawBeacon> rawList = JsonConvert.DeserializeObject <List <RawBeacon> >(json); foreach (RawBeacon rawBeacon in rawList) { UInt16 major = Convert.ToUInt16(rawBeacon.Major, 16); UInt16 minor = Convert.ToUInt16(rawBeacon.Minor, 16); Int16 defRssi = Convert.ToInt16(rawBeacon.DefRSSI); Int32 rssi = Convert.ToInt32(rawBeacon.RSSI); Console.WriteLine(rawBeacon.Mac); try { Beacon dummyBeacon = new Beacon(Guid.Parse(rawBeacon.Mac).ToString("D").ToUpper(), major, minor, defRssi); if (list.Contains(dummyBeacon)) { Int32 index = list.IndexOf(dummyBeacon); list[index].AddData(rawBeacon.Time, rssi); } else { dummyBeacon.AddData(rawBeacon.Time, rssi); list.Add(dummyBeacon); } } catch (Exception) { } } return(list); } catch (HttpRequestException) { return(new List <Beacon>()); } } } }
protected bool Equals(Beacon other) { return(string.Equals(UUID, other.UUID, StringComparison.OrdinalIgnoreCase) && Major == other.Major && Minor == other.Minor); }