public async Task <ICollection <MapDataDto> > GetAtmLocations(ICollection <ATM> atms) { var t = new ForwardGeocoder(); var atmData = new List <MapDataDto>(atms.Count); foreach (var atm in atms) { var request = new ForwardGeocodeRequest() { queryString = atm.Address, LimitResults = 1 }; var response = await t.Geocode(request); MapLocation location = null; if (response.Length > 0) { location = new MapLocation() { Latitude = response[0].Latitude, Longitude = response[0].Longitude }; } var tmp = new MapDataDto { Atm = atm, Location = location }; atmData.Add(tmp); } return(atmData); }
public List <MapDataDto> GetMapDataByRadioSignal(string radioSignal) { try { WebRequest request = WebRequest.Create("https://fangsdata-location-api.herokuapp.com/LastPosition/" + radioSignal); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); List <MapDataDto> mapData = new List <MapDataDto>(); using (Stream dataStream = response.GetResponseStream()) { try { StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); dynamic json = JObject.Parse(responseFromServer); MapDataDto item = new MapDataDto { Latitude = json.data.latitude, Longitude = json.data.longitude, }; mapData.Add(item); } catch (System.Exception e) { Console.WriteLine(e); Console.WriteLine("---- Could not parse map data"); } } response.Close(); return(mapData); } catch (System.Exception e) { Console.WriteLine(e); Console.WriteLine("---- Could not parse map data"); } return(null); }
public static string Serialize(GameField field) { // Clone the map and place rocks at the perimeter field = field.Clone(field.Radius + 1, field.SightRadius, GameField.Terrain.Rocks); var cells = new List <MapCellDto>(); MapCellDto GetCell((int cell, int row) pt) { var(x, y, z) = GameField.HexToCube(pt.cell, pt.row); var rv = new MapCellDto() { X = x, Y = y, Z = z, Type = (SurfaceTypeDto)((int)field[pt.cell, pt.row] - GameField.TerrainUtil.MinValidValue), VisibleCells = new List <LocationDto>() }; for (var c = -field.Radius; c <= field.Radius; c++) { for (var r = -field.Radius; r <= field.Radius; r++) { if (field.IsVisibleHex(pt, (c, r))) { rv.VisibleCells.Add(GetLocation((c, r))); } } } return(rv); } LocationDto GetLocation((int cell, int row) pt) { var(x, y, z) = GameField.HexToCube(pt.cell, pt.row); return(new LocationDto() { X = x, Y = y, Z = z, }); } for (var c = -field.Radius; c <= field.Radius; c++) { for (var r = -field.Radius; r <= field.Radius; r++) { if (field[c, r] != GameField.Terrain.Invalid) { cells.Add(GetCell((c, r))); } } } var dto = new MapDataDto() { Radius = field.Radius + 1, Cells = cells, Start = GetLocation(field.Start), Finish = GetLocation(field.Finish), SightRadius = field.SightRadius, }; return(JsonConvert.SerializeObject(dto)); }
private async Task <OffloadEntity> readOffload(DbDataReader reader) { using (reader) { OffloadEntity offload = null; bool hasInit = false; while (await reader.ReadAsync()) { string rowId = reader.GetString(38); string rowTown = reader.GetString(4); string rowState = reader.GetString(6); DateTime rowLandingDate = DateTime.Now; int totalWeight = 0; string rowBoatRadioSignal = reader.GetString(9); int rowBoatId = int.Parse(reader.GetString(7)); string rowRegistrationId = reader.GetString(8); string rowBoatName = reader.GetString(10); string rowBoatState = reader.GetString(6); string rowBoatNat = reader.GetString(13); double rowBoatLength = 0; string rowBoatFishingGear = reader.GetString(20); int rowFishId = int.Parse(reader.GetString(26)); string rowFishType = reader.GetString(27); string rowFishCondition = reader.GetString(29); string rowFishPackaging = reader.GetString(33); string rowFisQuality = reader.GetString(35); string rowFishPreservation = reader.GetString(31); string rowFishApplycation = reader.GetString(36); float rowFishWeight = 0; double rowLatitude = parseStrToDouble(reader.GetString(22)); double rowLongitude = parseStrToDouble(reader.GetString(21)); rowBoatLength = parseStrToDouble(reader.GetString(15)); if (rowBoatLength == 0) { rowBoatLength = parseStrToDouble(reader.GetString(14)); } try { rowFishWeight = float.Parse(reader.GetString(37)); } catch (System.Exception e) { Console.WriteLine(e); Console.WriteLine("--- Canot parse weight for" + reader.GetString(37)); } if (!hasInit) { hasInit = true; offload = new OffloadEntity { Id = rowId, Town = rowTown, State = rowState, LandingDate = rowLandingDate, TotalWeight = totalWeight, Fish = new List <FishDto>(), Boat = new BoatSimpleDto { Id = rowBoatId, Registration_id = rowRegistrationId, RadioSignalId = rowBoatRadioSignal, Name = rowBoatName, State = rowBoatState, Nationality = rowBoatNat, Length = rowBoatLength, FishingGear = rowBoatFishingGear, Image = string.Empty }, MapData = new List <MapDataDto>() }; var mapEntry = new MapDataDto { Longitude = rowLongitude, Latitude = rowLatitude, Time = rowLandingDate }; offload.MapData.Add(mapEntry); var fish = new FishDto { Id = rowFishId, Type = rowFishType, Condition = rowFishCondition, Preservation = rowFishPreservation, Packaging = rowFishPackaging, Quality = rowFisQuality, Application = rowFishApplycation, Weight = rowFishWeight }; offload.Fish.Add(fish); } else { var fish = new FishDto { Id = rowFishId, Type = rowFishType, Condition = rowFishCondition, Preservation = rowFishPreservation, Packaging = rowFishPackaging, Quality = rowFisQuality, Application = rowFishApplycation, Weight = rowFishWeight }; offload.Fish.Add(fish); } } float tempTotalWeight = 0f; for (int i = 0; i < offload.Fish.Count; i++) { tempTotalWeight += offload.Fish[i].Weight; } offload.TotalWeight = tempTotalWeight; return(offload); } throw new System.NotImplementedException(); }