protected override bool Execute(T ruleContext) { var userIp = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(userIp)) { userIp = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } var location = ((ILocationRepository) new LocationRepository()) .GetLocationFromIp(userIp, GetLocationApi()); var request = new WeatherRequestModel() { AppId = DataSourceItem.Fields["AppId"].Value, BaseURL = DataSourceItem.Fields["AppWeatherBaseUrl"].Value, location = location, RelativeURL = DataSourceItem.Fields["SearchByDestinationRelativeUrl"].Value, Unit = GetValueFromTargetItem(DataSourceItem, "TemperatureUnit", "Name") }; IWeatherRepository weatherServiceRepository = new WeatherRepository(); var weatherInfoString = weatherServiceRepository.GetWeatherByCity(request); var weatherCurrent = Newtonsoft.Json.JsonConvert.DeserializeObject <WeatherCurrent>(weatherInfoString); switch (this.GetOperator()) { case ConditionOperator.Equal: return(SpecifiedValue == System.Convert.ToInt32(Math.Round(weatherCurrent.main.temp))); case ConditionOperator.GreaterThanOrEqual: return(SpecifiedValue >= System.Convert.ToInt32(Math.Round(weatherCurrent.main.temp))); case ConditionOperator.GreaterThan: return(SpecifiedValue > System.Convert.ToInt32(Math.Round(weatherCurrent.main.temp))); case ConditionOperator.LessThanOrEqual: return(SpecifiedValue <= System.Convert.ToInt32(Math.Round(weatherCurrent.main.temp))); case ConditionOperator.LessThan: return(SpecifiedValue < System.Convert.ToInt32(Math.Round(weatherCurrent.main.temp))); case ConditionOperator.NotEqual: return(SpecifiedValue != System.Convert.ToInt32(Math.Round(weatherCurrent.main.temp))); default: throw new ArgumentOutOfRangeException(); } }
public IActionResult Index() { WeatherRequestModel wrm = new WeatherRequestModel() { Params = new WeatherParam(true).Params, From = DateTime.Now, To = DateTime.Now.AddDays(-5), Temp = 1, Pressure = 1, Humidity = 1, Wind = 1 }; return(View(wrm)); }
string IWeatherRepository.GetWeatherForecastByCity(WeatherRequestModel request) { URL = request.BaseURL + request.RelativeURL; Dictionary <string, string> replacements = new Dictionary <string, string> { { "{{city}}", request.location }, { "{{appid}}", request.AppId }, { "{{metric}}", request.Unit } }; foreach (string to_replace in replacements.Keys) { URL = URL.Replace(to_replace, replacements[to_replace]); } return(GetCurrentWeatherJson(URL)); }
public ActionResult CityWeatherList() { var currentItem = GetDatasourceItem(); var weatherInfo = new WeatherCurrent(); if (currentItem == null) { return(View("WeatherWidget", weatherInfo)); } var locationApi = @"http://ip-api.com/json/";//currentItem.Fields["LocationApi"].Value; var location = GetGeoLocation(locationApi); var targetItem = ((LookupField)currentItem.Fields["ApiSource"]).TargetItem; var appId = targetItem.Fields["AppId"].Value; var baseUrl = targetItem.Fields["AppWeatherBaseUrl"].Value; var destinationUrl = targetItem.Fields["SearchByDestinationRelativeUrl"].Value; var temparatureUnit = targetItem.Fields["TemperatureUnit"].Value; var request = new WeatherRequestModel() { AppId = appId, BaseURL = baseUrl, location = location, RelativeURL = destinationUrl, Unit = temparatureUnit }; IWeatherRepository weatherServiceRepository = new WeatherRepository(); var weatherInfoString = weatherServiceRepository.GetWeatherByCity(request); weatherInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <WeatherCurrent>(weatherInfoString); return(View("WeatherWidget", weatherInfo)); }
public JsonResult Index(WeatherRequestModel wrm) { return(Json(wrm.Sdata)); }
protected override bool Execute(T ruleContext) { var userIp = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(userIp)) { userIp = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (string.IsNullOrWhiteSpace(userIp)) { userIp = "Hyderabad, India"; } var location = ((ILocationRepository) new LocationRepository()) .GetLocationFromIp(userIp, GetLocationApi()); var request = new WeatherRequestModel() { AppId = DataSourceItem.Fields["AppId"].Value, BaseURL = DataSourceItem.Fields["AppWeatherBaseUrl"].Value, location = location, RelativeURL = DataSourceItem.Fields["SearchByDestinationRelativeUrl"].Value, Unit = GetValueFromTargetItem(DataSourceItem, "TemperatureUnit", "Name") }; IWeatherRepository weatherServiceRepository = new WeatherRepository(); var weatherInfoString = weatherServiceRepository.GetWeatherByCity(request); var weatherCurrent = Newtonsoft.Json.JsonConvert.DeserializeObject <WeatherCurrent>(weatherInfoString); switch (this.GetOperator()) { case StringConditionOperator.Unknown: return(false); case StringConditionOperator.Equals: return(SpecifiedValue.Fields["Name"].Value .Equals(weatherCurrent.weather.description)); case StringConditionOperator.CaseInsensitivelyEquals: return(SpecifiedValue.Fields["Name"].Value.ToLowerInvariant() .Equals(weatherCurrent.weather.description.ToLowerInvariant())); case StringConditionOperator.NotEqual: return(!SpecifiedValue.Fields["Name"].Value .Equals(weatherCurrent.weather.description)); case StringConditionOperator.NotCaseInsensitivelyEquals: return(SpecifiedValue.Fields["Name"].Value .Equals(weatherCurrent.weather.description)); case StringConditionOperator.Contains: return(SpecifiedValue.Fields["Name"].Value .Contains(weatherCurrent.weather.description)); case StringConditionOperator.StartsWith: return(SpecifiedValue.Fields["Name"].Value .StartsWith(weatherCurrent.weather.description)); case StringConditionOperator.EndsWith: return(SpecifiedValue.Fields["Name"].Value .EndsWith(weatherCurrent.weather.description)); default: throw new ArgumentOutOfRangeException(); } }