public Yard getYard(int thisYardID = 0) { if (thisYardID == 0) thisYardID = _YardID; String SQL = @"SELECT [AccountID], [YardName], [TopLeftLat], [TopLeftLon], [TopRightLat], [TopRightLon], [BottomLeftLat], [BottomLeftLon], [BottomRightLat], [BottomRightLon], [VechileOrientation], [VechileLength], [VechileWidth], [CreatedBy], [CreatedOn] FROM [PayLoadYard] WHERE YardID=" + thisYardID; var Row = Util.getDBRow(SQL); var theYard = new Yard(); if(Row["hasRows"].ToString() == "True") theYard = new Yard { YardID = thisYardID, AccountID = Util.toInt(Row["AccountID"]), YardName = Row["YardName"].ToString(), VechileOrientation = Row["VechileOrientation"].ToString(), VechileLength = Util.toInt(Row["VechileLength"]), VechileWidth = Util.toInt(Row["VechileWidth"]), Bounds = new GeoBox { TopLeft = new MapPoint { Latitude = Util.toDouble(Row["TopLeftLat"]), Longitude = Util.toDouble(Row["TopLeftLon"]) }, TopRight = new MapPoint { Latitude = Util.toDouble(Row["TopRightLat"]), Longitude = Util.toDouble(Row["TopRightLon"]) }, BottomRight = new MapPoint { Latitude = Util.toDouble(Row["BottomRightLat"]), Longitude = Util.toDouble(Row["BottomRightLon"]) }, BottomLeft = new MapPoint { Latitude = Util.toDouble(Row["BottomLeftLat"]), Longitude = Util.toDouble(Row["BottomLeftLon"]) } } }; return theYard; }
public static WeatherViewModel getLocalWeather(String UserIP) { String JSonContent = String.Empty; int DelayHours = 0; //If local server set it to dubai address MaxMind.GeoIP2.Responses.CityResponse city = new MaxMind.GeoIP2.Responses.CityResponse(); var WeatherView = new WeatherViewModel(); WeatherView.Forecast = new List <Forcast>(); String DatabaseLocation = HttpContext.Current.Server.MapPath("/GeoLiteCity/GeoLite2-City.mmdb"); using (var reader = new DatabaseReader(DatabaseLocation)) { // Replace "City" with the appropriate method for your database, e.g., // "Country". try { city = reader.City(UserIP); WeatherView.Country = city.Country.Name; // 'United States' WeatherView.City = city.City.Name; } catch { //do any error processing } }//using(var reader) if (String.IsNullOrEmpty(WeatherView.Country)) { WeatherView.Country = "United Arab Emirates"; } if (String.IsNullOrEmpty(WeatherView.City)) { WeatherView.City = "Dubai"; } do { String CacheFile = getWeatherFile(WeatherView.Country, WeatherView.City, DelayHours); if (!File.Exists(CacheFile)) { JSonContent = DownloadWeatherInfo(WeatherView.Country, WeatherView.City, CacheFile); } else { JSonContent = File.ReadAllText(CacheFile); } DelayHours = DelayHours - 4; } while (JSonContent.Length <= 10); dynamic WeatherInfo = System.Web.Helpers.Json.Decode(JSonContent); if (WeatherInfo != null) { var WeatherNow = WeatherInfo.data.current_condition[0]; WeatherView.ConditionText = WeatherNow.weatherDesc[0].value; WeatherView.ConditionCode = WeatherNow.weatherCode; WeatherView.Speed = WeatherNow.windspeedKmph; WeatherView.ConditionTemperature = Util.toDouble(WeatherNow.temp_C).ToString("0.0"); if (WeatherView.ConditionTemperature == "0.0") { Double Temp = (Util.toDouble(WeatherNow.temp_F) - 32) / 1.8; WeatherView.ConditionTemperature = Temp.ToString("0.0"); } WeatherView.TemperatureUnit = "°C"; WeatherView.Pressure = Util.toDouble(WeatherNow.pressure); WeatherView.Wind = WeatherNow.windspeedKmph; WeatherView.Direction = WeatherNow.winddirDegree; WeatherView.Visibility = Util.toDouble(WeatherNow.visibility); WeatherView.Humidity = WeatherNow.humidity; foreach (var ForcastDay in WeatherInfo.data.weather) { var thisForcast = new Forcast { Code = Util.toInt(ForcastDay.hourly[3].weatherCode), Date = (DateTime.Parse(ForcastDay.date)).ToString("dd MMM"), status = ForcastDay.hourly[3].weatherDesc[0].value, TempHigh = ForcastDay.maxtempC, TempLow = ForcastDay.mintempC }; WeatherView.Forecast.Add(thisForcast); } } //var intAddress = BitConverter.ToInt64(IPAddress.Parse(UserIP).GetAddressBytes(), 0); return(WeatherView); }