void ILoadableContent.Load() { _object = ReplaysManager.Instance.GetById(_id); if (_object?.TrackId != null) { var trackObject = TracksManager.Instance.GetById(_object.TrackId); if (_object.TrackConfiguration != null) { _trackObject = trackObject?.GetLayoutByLayoutId(_object.TrackConfiguration) ?? trackObject; } else { _trackObject = trackObject; } } if (_object?.CarId != null) { _carObject = CarsManager.Instance.GetById(_object.CarId); _carSkinObject = _carObject == null ? null : (_object.CarSkinId != null ? _carObject.SkinsManager.GetById(_object.CarSkinId) : null) ?? _carObject.SelectedSkin; } if (_object?.WeatherId != null) { _weather = WeatherManager.Instance.GetById(_object.WeatherId); } }
async Task ILoadableContent.LoadAsync(CancellationToken cancellationToken) { _object = await ReplaysManager.Instance.GetByIdAsync(_id); if (_object?.TrackId != null) { var trackObject = await TracksManager.Instance.GetByIdAsync(_object.TrackId); if (_object.TrackConfiguration != null) { _trackObject = trackObject?.GetLayoutByLayoutId(_object.TrackConfiguration) ?? trackObject; } else { _trackObject = trackObject; } } if (_object?.CarId != null) { _carObject = await CarsManager.Instance.GetByIdAsync(_object.CarId); _carSkinObject = _carObject == null ? null : (_object.CarSkinId != null ? await _carObject.SkinsManager.GetByIdAsync(_object.CarSkinId) : null) ?? _carObject.SelectedSkin; } if (_object?.WeatherId != null) { _weather = await WeatherManager.Instance.GetByIdAsync(_object.WeatherId); } }
public void Setup() { _mockNavigationService = new Mock <INavigationService>(); _mockWeatherService = new Mock <IWeatherService>(); _weatherObject = new WeatherObject { Name = "Madrid", Clouds = new Clouds { All = 20 }, Main = new Main { Humidity = 20, Pressure = 12, Temp = 25, TempMax = 25, TempMin = 45 }, Coord = new Coord { Lat = 12, Lon = 25 }, Base = "Base", Cod = 45, Dt = 45, Id = 47, Sys = new Sys { Country = "Spain", Id = 15, Message = 25, Sunrise = 45, Sunset = 47, Type = 14 }, Visibility = 58, }; }
protected override bool SetOverride(WeatherObject weather, IniFile file) { var section = new IniFile(weather.IniFilename)["__CLOUDS_TEXTURES"]; Clouds.SourceList = section.ContainsKey(@"LIST") ? section.GetStrings("LIST") : null; return(Replacements.Aggregate(false, (current, replacement) => replacement.Apply(weather) || current)); }
public void AddWeatherObject(WeatherObject weatherObject, string weatherObjectId) { weatherObject.WeatherObjectId = weatherObjectId; _unitOfWork.WeatherRepository.Add(weatherObject); _unitOfWork.SaveWeatherChanges(); }
public void setCity(string city) { label1.Text = city; weather = proxy.weather(city); forecast = proxy.forecast(city); if (weather.main.temp < 20) { pictureBox1.Image = ExamenEnrique.Properties.Resources.Snowflake; } else if (weather.main.temp > 30) { pictureBox1.Image = ExamenEnrique.Properties.Resources.fire; } else { pictureBox1.Image = ExamenEnrique.Properties.Resources.medium; } label2.Text = weather.main.temp.ToString() + "°"; label3.Text = "Humidity"; label4.Text = weather.main.humidity.ToString() + "%"; label5.Text = "Wind"; label6.Text = weather.wind.speed.ToString() + "Km/H"; small_Forecast1.setWo(forecast, 0); small_Forecast2.setWo(forecast, 1); small_Forecast3.setWo(forecast, 2); small_Forecast4.setWo(forecast, 3); small_Forecast5.setWo(forecast, 4); }
/* * public string TestDay() * { * List<WeatherObject> lstWeather = GetDataWeather3days(); * WeatherObject datageted = new WeatherObject(); * datageted = lstWeather[0]; * string chuoiTest = lstWeather[0].Day.ToString() + lstWeather[0].Temp.ToString() + " - " + lstWeather[1].Day.ToString() + lstWeather[1].Temp.ToString() + " - " + lstWeather[2].Day.ToString() + lstWeather[2].Temp.ToString() + " - " + lstWeather[3].Day.ToString() + lstWeather[3].Temp.ToString() + " - " + lstWeather[4].Day.ToString() + lstWeather[4].Temp.ToString() + " - " + lstWeather[5].Day.ToString() + lstWeather[5].Temp.ToString() + " - " + lstWeather[6].Day.ToString() + lstWeather[6].Temp.ToString() + " - " + lstWeather[7].Day.ToString() + lstWeather[7].Temp.ToString() + " - " + lstWeather[8].Day.ToString() + lstWeather[8].Temp.ToString() + " - " + lstWeather[9].Day.ToString() + lstWeather[9].Temp.ToString() + " - " + lstWeather[10].Day.ToString() + lstWeather[10].Temp.ToString() + " - " + lstWeather[11].Day.ToString() + lstWeather[11].Temp.ToString() + " - " + lstWeather[12].Day.ToString() + lstWeather[12].Temp.ToString() + " - " + lstWeather[13].Day.ToString() + lstWeather[13].Temp.ToString() + " - " + lstWeather[14].Day.ToString() + lstWeather[14].Temp.ToString() + " - " + lstWeather[15].Day.ToString() + lstWeather[15].Temp.ToString(); + + return chuoiTest; + } */ public string GetTemperature(string dayRequest) { int temp_consume = 0; int temp_tb = 0; int counter = 0; List <WeatherObject> lstWeather = GetDataWeather3days(); WeatherObject datageted = new WeatherObject(); for (int i = 0; i < lstWeather.Count; i++) { datageted = lstWeather[i]; if (datageted.Day.Equals(dayRequest)) { int temp = (int)System.Convert.ToInt32(datageted.Temp); temp_consume = temp_consume + temp; counter++; } } temp_tb = (int)(temp_consume / counter); // Console.WriteLine("temp: " + counter); // datageted = lstWeather[0]; return("Nhiệt độ " + dayRequest + " là " + temp_tb.ToString() + " độ C"); }
public string GetStatusRain(string dayRequest) { string response = dayRequest + " trời không mưa"; List <WeatherObject> lstWeather = GetDataWeather3days(); //WeatherObject datageted = new WeatherObject(); for (int i = 0; i < lstWeather.Count; i++) { WeatherObject datageted = new WeatherObject(); datageted = lstWeather[i]; if (dayRequest.Equals(datageted.Day)) { if (datageted.Status.Contains("rain")) { response = dayRequest + " trời có thể sẽ mưa vào lúc " + GetHour(datageted.Time.ToString()); break; } } } //datageted = lstWeather[0]; return(response); }
public static void SaveWeather(WeatherObject wo, WeatherTranslation wt) { using (PokeEntities db = new PokeEntities()) { WeatherValue wv = new WeatherValue() { DateTime = wo.DateTime.ToUniversalTime(), WeatherIcon = wo.WeatherIcon, IconPhrase = wo.IconPhrase, IsDaylight = wo.IsDaylight, TempValue = wo.Temperature.Value, TempUnit = wo.Temperature.Unit, WindSpeed = wo.Wind.Speed.Value, WindUnit = wo.Wind.Speed.Unit, GustSpeed = wo.WindGust.Speed.Value, GustUnit = wo.WindGust.Speed.Unit, PrecipitationProbability = wo.PrecipitationProbability, RainProbability = wo.RainProbability, SnowProbability = wo.SnowProbability, IceProbability = wo.IceProbability, CloudCover = wo.CloudCover, RainAmt = wo.Rain.Value, SnowAmt = wo.Snow.Value, IceAmt = wo.Ice.Value, PgoIconId = wt.PgoWeather.Id, DateAdded = DateTime.Now.ToUniversalTime() }; db.WeatherValues.Add(wv); db.SaveChanges(); } }
public bool TryToGetWeather(WeatherType type, [CanBeNull] ref WeatherObject weather) { if (type == WeatherType.None) { return(true); } try { var candidates = WeatherManager.Instance.LoadedOnly.Where(x => x.Enabled && x.TemperatureDiapason?.DiapasonContains(_temperature) != false && x.TimeDiapason?.TimeDiapasonContains(_time) != false).ToList(); var closest = WeatherDescription.FindClosestWeather(from w in candidates select w.Type, type); if (closest == null) { return(false); } candidates = candidates.Where(x => x.Type == closest).ToList(); var footprint = candidates.Select(x => x.Id).JoinToString(';'); if (footprint != _weatherCandidatesFootprint || !candidates.Contains(weather)) { weather = candidates.RandomElementOrDefault(); _weatherCandidatesFootprint = footprint; } return(true); } catch (Exception e) { Logging.Error(e); return(false); } }
/* It includes methods related to SampleEntity */ #endregion #region Methods public static WeatherStatus GetCityWeatherStatus(string cityName) { try { HttpWebRequest myReq8 = DAT.DataService.CreateRequest(DAT.DataStatics.DomainForService, DAT.DataStatics.UserNameForService, DAT.DataStatics.PasswordForService, DAT.DataStatics.saportServiceURL(DAT.DataStatics.saportServiceGetCityWeatherStatus), false, true, "application/json; charset=UTF-8", "application/json; odata=verbose", "POST"); string parsedContent8 = "{\"CityName\":\"" + (string.IsNullOrEmpty(cityName) ? weatherDefaultCity : cityName) + "\"}"; UTF8Encoding encoding8 = new UTF8Encoding(); Byte[] bytes8 = encoding8.GetBytes(parsedContent8); myReq8.ContentLength = bytes8.Length; Stream newStream8 = myReq8.GetRequestStream(); newStream8.Write(bytes8, 0, bytes8.Length); newStream8.Close(); WebResponse response8 = myReq8.GetResponse(); string responseString8 = DAT.DataService.RestfulReader(response8); var serializer = new JavaScriptSerializer(); WeatherObject weatherObj = serializer.Deserialize <WeatherObject>(responseString8); WeatherStatus weatherStatus = weatherObj.Data; if (weatherStatus == null) { weatherStatus = GetDefaultWeatherStatus(); } return(weatherStatus); } catch (Exception ex) { EXP.RedirectToErrorPage(ex.Message); return(null); } }
public void Update(IObservable subject) { WeatherObject weatherObject = subject as WeatherObject; if (weatherObject != null) { float T = weatherObject.Temperature; float RH = weatherObject.RelativeHumidity; heatIndex = 16.923f + 1.85212f * T / 10f + 537.941f * RH - 10.0254f * T * RH + 9.41695f * T * T / 1000f + 72.8898f * RH * RH + 3.45372f * T * T * RH / 100f - 8.14971f * T * RH * RH + 1.02102f * T * T * RH * RH / 10f - 3.86460f * T * T * T / 100000f + 29.1583f * RH * RH * RH + 1.42721f * T * T * T * RH / 10000f + 1.97483f * T * RH * RH * RH / 10f - 2.18429f * T * T * T * RH * RH / 10000f + 8.43296f * T * T * RH * RH * RH / 10000f - 4.81975f * T * T * T * RH * RH * RH / 100000f; Display(); } }
public void Execute() { Object source; if (TestObject.Find(Source) != null) { source = TestObject.Find(Source); } else if (KodiObject.Find(Source) != null) { source = KodiObject.Find(Source); } else if (WeatherObject.Find(Source) != null) { source = WeatherObject.Find(Source); } else if (GenericInfoObject.Find(Source) != null) { source = GenericInfoObject.Find(Source); } else { Console.WriteLine("Source not found"); return; } if (Evaluate()) { source.GetType().GetMethod("A" + Action).Invoke(source, new string[] { Parameter }); } }
private async Task SendDataToAzureIOTSuite() { try { WeatherObject weather = await GetWeather(txtBoxCity.Text); string messageBody = DateTime.Now + " Temperature: " + Math.Round(weather.main.tempCelsius, 2) + ", Humidity: " + weather.main.humidity + "%" + ", External Temperature: " + Math.Round(weather.main.tempCelsius, 2); weatherLog.Add(messageBody); //We add rand value to see variation on graph Random rand = new Random(); double randHumidity = rand.Next(0, 5) * 0.1; double randTemperature = rand.Next(0, 5) * 0.1; RemoteMonitorTelemetryData monitorData = new RemoteMonitorTelemetryData() { DeviceId = deviceId, ExternalTemperature = Math.Round(weather.main.tempCelsius, 2) + randTemperature, Humidity = weather.main.humidity + randHumidity, Temperature = Math.Round(weather.main.tempCelsius, 2) + randTemperature }; var messageString = JsonConvert.SerializeObject(monitorData); var interactiveMessage = new Message(Encoding.ASCII.GetBytes(messageString)); interactiveMessage.Properties["messageType"] = "interactive"; interactiveMessage.MessageId = Guid.NewGuid().ToString(); await deviceClient.SendEventAsync(interactiveMessage); } catch (Exception) { } }
public WeatherObject forecastToWeather(Forecast f, int index) { WeatherObject weather = new WeatherObject { name = f.city.name, main = f.list[index].main }; return(weather); }
static void RulesCheck(WeatherObject currentWeather) { Console.WriteLine("Should I go outside - {0}, {1}", Enum.IsDefined(typeof(RainEnum), currentWeather.current.weather_code) ? "No" : "Yes", currentWeather.current.weather_descriptions.FirstOrDefault()); Console.WriteLine("Should I wear sunscreen? - {0}", currentWeather.current.uv_index > 3 ? "Yes" : "No"); Console.WriteLine("Can I fly kite? - {0}", !Enum.IsDefined(typeof(RainEnum), currentWeather.current.weather_code) && currentWeather.current.wind_speed > 15 ? "Yes" : "No"); }
// This is the main class that controls logic flow of the server (see comments below for process description) // It is sufficient to run this controller to start full-functional server static void Main(string[] args) { Console.WriteLine("Starting server initialization..."); // Initializes MEF loader class and triggers loading of dll files // All classes loaded with MEF are contained in the loader object, and are accessible from it Console.WriteLine("\tStarting MEF catalog..."); Loader loader = new Loader(); loader.LoadCatalog(); // Basically just re-writing loaded classes from dynamic loader object to static lists (see 00_DataObjects/Objects/) // Note: it was decided to keep 4 lists instead on one generic because of 2 reasons: // Resource shortage, due to several people dropped out from the program // To keep the code cleaner and to ensure type-safe behavior (however this has made the code larger and more redundant) Console.WriteLine("\tRegistering connectors..."); foreach (var i in loader.Test) { TestObject.Add(i); } foreach (var i in loader.Weather) { WeatherObject.Add(i); } foreach (var i in loader.Kodi) { KodiObject.Add(i); } foreach (var i in loader.GenericInfo) { GenericInfoObject.Add(i); } // This piece of code does 2 things: // Initializes DB connection and loads the rules from the database // Starts a daemon which executes business rules (once per minute) Console.WriteLine("\tLoading business rules..."); BusinessRules.BusinessRules.Initialize(); // This part goes through all loaded dll classes and collects their definition (methods exposed for administration, i.e. staring with A and AGet) // This information is then wrapped into the objects and is exposed to Admin section of a client Console.WriteLine("\tCollecting admin methods..."); BusinessRules.DataCollector.Collector.Collect(); // Just some hosting of web services // There is a separate web service exposed for each source (was done to reduce code complexity, provide type safety and comply to required architecture) // Note that web services are added to this project, since they are registered in static classes, which are not visible from other projects Console.WriteLine("\tHosting web services..."); new ServiceHost(typeof(TestService)).Open(); new ServiceHost(typeof(KodiService)).Open(); new ServiceHost(typeof(WeatherService)).Open(); new ServiceHost(typeof(GenericInfoService)).Open(); new ServiceHost(typeof(AdminService)).Open(); Console.WriteLine("Server initialization complete"); Console.WriteLine("------------------------------\n"); Console.ReadLine(); }
private static void ProcessScripts(WeatherObject weather, IniFile file, int?customTime = null) { if (customTime.HasValue) { file = file.Clone(); file["LIGHTING"].Set("SUN_ANGLE", Game.ConditionProperties.GetSunAngle(customTime.Value)); } WeatherProceduralContext context = null; WeatherProceduralContext GetContext() { return(context ?? (context = new WeatherProceduralContext(file, weather.Location))); } var destination = customTime.HasValue ? Path.Combine(weather.Location, @"__special", customTime.Value.ToString()) : null; ProcessFile(weather, GetContext, @"weather.ini", new[] { @"CLOUDS", @"FOG", @"CAR_LIGHTS", @"__CLOUDS_TEXTURES", @"__CUSTOM_LIGHTING" }, (table, ini) => { var customClouds = table[@"CLOUDS_TEXTURES"]; if (customClouds != null) { ini[@"__CLOUDS_TEXTURES"].Set("LIST", ToIniFileValue(customClouds)); } var extraParams = table[@"EXTRA_PARAMS"]; if (extraParams != null) { var s = new IniFileSection(null); MapOutputSection(extraParams, s); if (s.ContainsKey(@"TEMPERATURE_COEFF")) { ini[@"LAUNCHER"].Set("TEMPERATURE_COEFF", s.GetNonEmpty("TEMPERATURE_COEFF")); } if (s.ContainsKey(@"DISABLE_SHADOWS")) { ini[@"__LAUNCHER_CM"].Set("DISABLE_SHADOWS", s.GetNonEmpty("DISABLE_SHADOWS")); } if (s.ContainsKey(@"SKYBOX_REFLECTION_GAIN")) { ini[@"__LAUNCHER_CM"].Set("SKYBOX_REFLECTION_GAIN", s.GetNonEmpty("SKYBOX_REFLECTION_GAIN")); } } MapOutputSection(table[@"LAUNCHER"], ini[@"LAUNCHER"], "TEMPERATURE_COEFF"); MapOutputSection(table[@"__LAUNCHER_CM"], ini[@"__LAUNCHER_CM"], "DISABLE_SHADOWS", "SKYBOX_REFLECTION_GAIN"); MapOutputSection(table[@"CUSTOM_LIGHTING"], ini[@"__CUSTOM_LIGHTING"]); }, destination); ProcessFile(weather, GetContext, @"colorCurves.ini", new[] { @"HEADER", @"HORIZON", @"SKY", @"SUN", @"AMBIENT" }, null, destination); ProcessFile(weather, GetContext, @"filter.ini", new[] { @"YEBIS", @"OPTIMIZATIONS", @"VARIOUS", @"AUTO_EXPOSURE", @"GODRAYS", @"HEAT_SHIMMER", @"TONEMAPPING", @"DOF", @"CHROMATIC_ABERRATION", @"FEEDBACK", @"VIGNETTING", @"DIAPHRAGM", @"AIRYDISC", @"GLARE", @"LENSDISTORTION", @"ANTIALIAS", @"COLOR" }, null, destination); ProcessFile(weather, GetContext, @"tyre_smoke.ini", new[] { @"SETTINGS", @"TRIGGERS" }, null, destination); ProcessFile(weather, GetContext, @"tyre_smoke_grass.ini", new[] { @"SETTINGS" }, null, destination); ProcessFile(weather, GetContext, @"tyre_pieces_grass.ini", new[] { @"SETTINGS" }, null, destination); ProcessFile(weather, GetContext, @"track_state.ini", new[] { @"TRACK_STATE" }, null, destination); }
public static WeatherObject TryToGetWeather(WeatherType type, int time, double temperature) { var helper = new WeatherTypeHelper(); helper.SetParams(time, temperature); WeatherObject result = null; return(helper.TryToGetWeather(type, ref result) ? result : null); }
private void Set(WeatherObject CurrentWeather) { WeatherObj = CurrentWeather; WeatherInfo = WeatherObj.Weather.FirstOrDefault(); MainInfo = WeatherObj.Main; SysInfo = WeatherObj.Sys; Text = MainInfo.Humidity.ToString(); }
protected override bool SetOverride(WeatherObject weather, IniFile file) { var videoCfg = AcPaths.GetCfgVideoFilename(); if (!File.Exists(videoCfg)) { return(false); } var customFilter = false; if (SettingsHolder.Drive.WeatherSpecificPpFilter) { var replacement = Path.Combine(weather.Location, "filter.ini"); if (File.Exists(replacement)) { customFilter = true; _destination = Destination; if (File.Exists(_destination)) { File.Delete(_destination); } FileUtils.HardLinkOrCopy(replacement, _destination); } } var disableShadows = new IniFile(weather.IniFilename)["__LAUNCHER_CM"].GetBool("DISABLE_SHADOWS", false); if (!customFilter && !disableShadows) { return(false); } var ini = new IniFile(videoCfg); if (customFilter) { var section = ini["POST_PROCESS"]; section.Set("__CM_PREWEATHER_ORIGINAL_FILTER", section.GetNonEmpty("FILTER")); section.Set("FILTER", FilterId); } if (disableShadows) { var section = ini["VIDEO"]; section.Set("__CM_PREWEATHER_ORIGINAL_SHADOW_MAP_SIZE", section.GetNonEmpty("__CM_ORIGINAL_SHADOW_MAP_SIZE") ?? section.GetNonEmpty("SHADOW_MAP_SIZE")); section.Set("SHADOW_MAP_SIZE", -1); } ini.Save(); return(true); }
public ActionResult OnSearchCity(string searchTerm) { WeatherObject r = null; if (cities.Contains(searchTerm)) { IProxyMaster proxy = new Proxy(); proxy.IniciarApi(); r = proxy.weather(searchTerm); } return(View(r)); }
public void Update(IObservable subject) { WeatherObject weatherData = subject as WeatherObject; if (subject != null) { temperature = weatherData.Temperature; humidity = weatherData.RelativeHumidity; Display(); } }
public ActionResult ViewMore(WeatherObject w) { IProxyMaster prox = new Proxy(); prox.IniciarApi(); var k = prox.forecast(w.name); if (w.weather != null) { ViewBag.Image = "http://openweathermap.org/img/wn/" + k.list[0].weather[0].icon + "@2x.png"; } return(View(k)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string cityIp = WebToolsHelper.GetIp(); TerminalStatus terminal = TerminalOnlineMonitorThread.GetTerminal(cityIp); string cityCode = string.Empty; if (terminal != null) { cityCode = terminal.CityCode; } else { cityCode = "101010100"; } if (cityCode != null && cityCode.Length > 0) { WeatherObject weather = null; try { weather = WeatherHelper.GetCityWeather(cityCode); } catch { } if (weather != null) { this.lbCity.Text = weather.weatherinfo.city; this.lbDate.Text = System.DateTime.Now.ToString("M月d日"); this.lbTemp.Text = weather.weatherinfo.temp1; this.lbTrafficLimit.Text = this.GetTrafficLimitInfo(cityCode); this.lbWeek.Text = weather.weatherinfo.week; this.lbWind.Text = weather.weatherinfo.wind1; this.img1.Visible = true; this.img1.ImageUrl = weather.weatherinfo.img1; } else { this.lbCity.Text = "预报出错"; this.lbDate.Text = System.DateTime.Now.ToString("M月d日"); this.lbTemp.Text = string.Empty; this.lbTrafficLimit.Text = this.GetTrafficLimitInfo(cityCode); this.lbWeek.Text = DateTimeHelper.GetChineseXq(System.DateTime.Now); this.lbWind.Text = string.Empty; this.img1.Visible = false; // this.img1.ImageUrl = weather.weatherinfo.img1; } } } }
public ActionResult AddCity(WeatherObject w) { if (!UsuarioGen.citiesBD.Contains(w.name)) { UsuarioGen.caretaker.Backup(); UsuarioGen.citiesAdded.AddCity(w.name); _dataService.addCity(UsuarioGen.GetUsuarioGen().GetUserID(), w.name); UsuarioGen.updateCitiesBD(); } var q = UsuarioGen.citiesAdded; //q.GetImages(); return(View(q)); //return View(); }
protected override bool SetOverride(WeatherObject weather, IniFile raceIni) { var section = new IniFile(weather.IniFilename)["__CUSTOM_LIGHTING"]; if (section.ContainsKey(@"SUN_ANGLE")) { raceIni[@"LIGHTING"].Set(@"__CM_UNCLAMPED_SUN_ANGLE", raceIni[@"LIGHTING"].GetInt(@"SUN_ANGLE", 0)); raceIni[@"LIGHTING"].Set(@"SUN_ANGLE", section.GetPossiblyEmpty(@"SUN_ANGLE")); } var trackId = $@"{raceIni["RACE"].GetNonEmpty("TRACK")}/{raceIni["RACE"].GetNonEmpty("CONFIG_TRACK")}".TrimEnd('/'); var track = TracksManager.Instance.GetLayoutById(trackId); return(track != null && Process(Path.Combine(track.DataDirectory, "lighting.ini"), section)); }
public async Task Initialize() { _webHandler = IocContianer.IocContainer.Resolve <IWebserviceHandler>(); var result = await _webHandler.GetWeatherDetails(32.238413, 77.189310); _weatherObject = result as WeatherObject; CurrentTemparature = $"{_weatherObject.list[0].main.temp.ToString()} Kelvin"; MaxTemparature = $"{_weatherObject.list[0].main.temp_max.ToString()} Kelvin"; MinTemparature = $"{_weatherObject.list[0].main.temp_min.ToString()} Kelvin"; Location = $"{_weatherObject.city.name}, Currently Weather Is {_weatherObject.list[0].weather[0].description}"; tempDictionary = new Dictionary <string, double>(); tempDictionary.Add("Temp", _weatherObject.list[0].main.temp); tempDictionary.Add("Min_Temp", _weatherObject.list[0].main.temp); tempDictionary.Add("Max_Temp", _weatherObject.list[0].main.temp_min); }
public ActionResult Index(CountryWeather countryWeather) { var cities = _citiesService.GetCitiesByQuery(countryWeather.q); ViewBag.CityList = cities; ViewBag.CityListCount = cities.Count(); ViewBag.HideTable = false; if (ModelState.IsValid) { string apikey = WebConfigurationManager.AppSettings["WeatherAPIKey"].ToString(); string currentConditionsUrl = WebConfigurationManager.AppSettings["WeatherCurrentConditionsUrl"].ToString(); int CntVal = Convert.ToInt32(countryWeather.country.Trim()); //string url = string.Format("http://dataservice.accuweather.com/currentconditions/v1/{0}?apikey={1}&language=en-us&details=false", CntVal, apikey); string url = string.Format(currentConditionsUrl + "{0}?apikey={1}&language={2}&details={3}", CntVal, apikey, "en-us", false); using (WebClient client = new WebClient()) { string json = client.DownloadString(url); List <WeatherObject> objweatherInfo = (new JavaScriptSerializer()).Deserialize <List <WeatherObject> >(json); WeatherObject weatherInfo = objweatherInfo[0]; string weatherIconsUrl = WebConfigurationManager.AppSettings["WeatherIconsUrl"].ToString(); //ViewBag.lblLocalDateTime = DateTime.Parse(weatherInfo.LocalObservationDateTime); ViewBag.imgWeatherIcon = string.Format(weatherIconsUrl + "{0}.svg", weatherInfo.WeatherIcon.ToString().ToLower()); if (!String.IsNullOrEmpty(countryWeather.country)) { var selectedLocation = cities.Where(s => s.Value == countryWeather.country.Trim()).Select(x => x.Text); if (selectedLocation.Count() > 0) { ViewBag.lblCity_Country = selectedLocation.FirstOrDefault(); } else { ViewBag.HideTable = true; } } ViewBag.lblText = weatherInfo.WeatherText; ViewBag.lblMetric = string.Format("{0}°{1}", Math.Round(weatherInfo.Temperature.Metric.Value, 1), weatherInfo.Temperature.Metric.Unit); ViewBag.lblImperial = string.Format("{0}°{1}", Math.Round(weatherInfo.Temperature.Imperial.Value, 1), weatherInfo.Temperature.Imperial.Unit); ViewBag.lblMobileLink = weatherInfo.MobileLink; ViewBag.lblWebLink = weatherInfo.Link; } } return(View(countryWeather)); }
static void Main(string[] args) { WeatherObject weatherObject = new WeatherObject(); new CurrentConditionsDisplay(weatherObject); new StatisticsDisplay(weatherObject); new ForecastDisplay(weatherObject); new HeatIndexDisplay(weatherObject); weatherObject.SetMeasurements(80f, 0.65f, 30.4f); weatherObject.SetMeasurements(82f, 0.70f, 29.2f); weatherObject.SetMeasurements(78f, 0.90f, 29.2f); Console.WriteLine("Press any key to continue . . ."); Console.ReadKey(); }