private static IEnumerable <KeyValuePair <String, String> > SelectPropertiesAsQueryStringParameters(this ModelMetadata modelMetadata, List <String> prefixChain) { if (modelMetadata.Model == null) { yield break; } if (modelMetadata.IsComplexType) { IEnumerable <KeyValuePair <String, String> > keyValuePairs; if (IEnumerableType.IsAssignableFrom(modelMetadata.ModelType)) { keyValuePairs = modelMetadata.GetItemMetadata().Select((mm, i) => new PrefixedModelMetadata( modelMetadata: mm, prefix: String.Format("{0}[{1}]", modelMetadata.PropertyName, i) ) ).SelectMany(prefixed => prefixed.ModelMetadata.SelectPropertiesAsQueryStringParameters( prefixChain.ToList().AddChainable(prefixed.Prefix, addOnlyIf: IsNeitherNullNorWhitespace) )); } else { keyValuePairs = modelMetadata.Properties.SelectMany(mm => mm.SelectPropertiesAsQueryStringParameters( prefixChain.ToList().AddChainable( modelMetadata.PropertyName, addOnlyIf: IsNeitherNullNorWhitespace ) ) ); } foreach (var keyValuePair in keyValuePairs) { yield return(keyValuePair); } } else { yield return(new KeyValuePair <String, String>( key: AntiXssEncoder.HtmlFormUrlEncode( String.Join(".", prefixChain.AddChainable( modelMetadata.PropertyName, addOnlyIf: IsNeitherNullNorWhitespace ) ) ), value: AntiXssEncoder.HtmlFormUrlEncode(modelMetadata.Model.ToString()))); } }
//[Route("Weather")] public HttpResponseMessage weatherApi() { CityWeather weather = new CityWeather(); var city = new CityWeather(); city.city = weather.city; // Initialize XML Serializer Class which hosts the Deserialize() function // typeof(query) - query is root node of XML XmlSerializer XMLdeserialize = new XmlSerializer(typeof(query)); // Initialize Web Client and set its encoding to UTF8 WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; // Form Actual URL - REST API call StringBuilder sbURL = new StringBuilder(); sbURL.Append(@"https://query.yahooapis.com/v1/public/yql?q="); // YQL is select * from geo.places where text='sfo' sbURL.Append(AntiXssEncoder.HtmlFormUrlEncode (@"select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + city.city + "')")); // Anti XSS encoder - // Prevent cross site scripting sbURL.Append("&format = json"); sbURL.Append(@"&diagnostics=true"); // Download string (XML data) from REST API response // Downloads the requested resource as a string. string XMLresult = wc.DownloadString(sbURL.ToString()); JObject jObject = JObject.Parse(XMLresult); JArray jArray = (JArray)jObject["query"]["results"]["Result"]; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "Created successfully"); return(response); }
protected void btn_formUrl_Click(object sender, EventArgs e) { String s = this.txt_1.Text; this.txt_2.Text = AntiXssEncoder.HtmlFormUrlEncode(s); }
//[Route("Weather")] public HttpResponseMessage weatherApi(CityWeather cityValue) { CityWeather weather = new CityWeather(); var city = new CityWeather(); city.city = cityValue.city; // Initialize XML Serializer Class which hosts the Deserialize() function // typeof(query) - query is root node of XML XmlSerializer XMLdeserialize = new XmlSerializer(typeof(query)); // Initialize Web Client and set its encoding to UTF8 WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; // Form Actual URL - REST API call StringBuilder sbURL = new StringBuilder(); sbURL.Append(@"https://query.yahooapis.com/v1/public/yql?q="); // YQL is select * from geo.places where text='sfo' sbURL.Append(AntiXssEncoder.HtmlFormUrlEncode (@"select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + city.city + "')")); // Anti XSS encoder - // Prevent cross site scripting //sbURL.Append("&format = json"); sbURL.Append(@"&diagnostics=true"); // Download string (XML data) from REST API response // Downloads the requested resource as a string. string XMLresult = wc.DownloadString(sbURL.ToString()); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(XMLresult); //using (var reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(XMLresult), XmlDictionaryReaderQuotas.Max)) //{ // XElement xml = XElement.Load(reader); // xmlDocument.LoadXml(xml.ToString()); //} XmlNode node = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(6); XmlNode week2 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(7); XmlNode week3 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(8); XmlNode week4 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(9); XmlNode week5 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(10); XmlNode week6 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(11); XmlNode week7 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(12); XmlNode week8 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(13); XmlNode week9 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(14); XmlNode week10 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(15); XmlNode node1 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(5); XmlNode pnode = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(9); XmlNode pnode1 = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(10); XmlNode wind = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(8); XmlNode country = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(7); XmlNode astronomy = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(10); CityWeather Temp = new CityWeather(); Temp.humidity = pnode.Attributes.Item(1).Value; Temp.pressure = pnode.Attributes.Item(2).Value; Temp.rising = pnode.Attributes.Item(3).Value; Temp.visibility = pnode.Attributes.Item(4).Value; Temp.country = country.Attributes.Item(2).Value; Temp.chill = int.Parse(wind.Attributes.Item(1).Value); Temp.direction = wind.Attributes.Item(2).Value; Temp.speed = wind.Attributes.Item(3).Value; Temp.sunrise = astronomy.Attributes.Item(1).Value; Temp.sunset = astronomy.Attributes.Item(2).Value; Temp.high = int.Parse(node.Attributes.Item(4).Value); int thigh = convertCelcius(Temp.high); Temp.low = int.Parse(node.Attributes.Item(5).Value); int tlow = convertCelcius(Temp.low); Temp.temperature = int.Parse(node1.Attributes.Item(3).Value); int temperature = convertCelcius(Temp.temperature); Temp.date = node1.Attributes.Item(2).Value; Temp.text = node1.Attributes.Item(4).Value; Temp.date1 = week2.Attributes.Item(2).Value; Temp.high1 = int.Parse(week2.Attributes.Item(4).Value); int thigh1 = convertCelcius(Temp.high1); Temp.low1 = int.Parse(week2.Attributes.Item(5).Value); int tlow1 = convertCelcius(Temp.low1); Temp.day1 = week2.Attributes.Item(3).Value; Temp.date2 = week3.Attributes.Item(2).Value; Temp.high2 = int.Parse(week3.Attributes.Item(4).Value); int thigh2 = convertCelcius(Temp.high2); Temp.low2 = int.Parse(week3.Attributes.Item(5).Value); int tlow2 = convertCelcius(Temp.low2); Temp.day2 = week3.Attributes.Item(3).Value; Temp.date3 = week4.Attributes.Item(2).Value; Temp.high3 = int.Parse(week4.Attributes.Item(4).Value); int thigh3 = convertCelcius(Temp.high3); Temp.low3 = int.Parse(week4.Attributes.Item(5).Value); int tlow3 = convertCelcius(Temp.low3); Temp.day3 = week4.Attributes.Item(3).Value; Temp.date4 = week5.Attributes.Item(2).Value; Temp.high4 = int.Parse(week5.Attributes.Item(4).Value); int thigh4 = convertCelcius(Temp.high4); Temp.low4 = int.Parse(week5.Attributes.Item(5).Value); int tlow4 = convertCelcius(Temp.low4); Temp.day4 = week5.Attributes.Item(3).Value; Temp.date5 = week6.Attributes.Item(2).Value; Temp.high5 = int.Parse(week6.Attributes.Item(4).Value); int thigh5 = convertCelcius(Temp.high5); Temp.low5 = int.Parse(week6.Attributes.Item(5).Value); int tlow5 = convertCelcius(Temp.low5); Temp.day5 = week6.Attributes.Item(3).Value; Temp.date6 = week7.Attributes.Item(2).Value; Temp.high6 = int.Parse(week7.Attributes.Item(4).Value); int thigh6 = convertCelcius(Temp.high6); Temp.low6 = int.Parse(week7.Attributes.Item(5).Value); int tlow6 = convertCelcius(Temp.low6); Temp.day6 = week7.Attributes.Item(3).Value; Temp.date7 = week8.Attributes.Item(2).Value; Temp.high7 = int.Parse(week8.Attributes.Item(4).Value); int thigh7 = convertCelcius(Temp.high7); Temp.low7 = int.Parse(week8.Attributes.Item(5).Value); int tlow7 = convertCelcius(Temp.low7); Temp.day7 = week8.Attributes.Item(3).Value; Temp.date8 = week9.Attributes.Item(2).Value; Temp.high8 = int.Parse(week9.Attributes.Item(4).Value); int thigh8 = convertCelcius(Temp.high8); Temp.low8 = int.Parse(week9.Attributes.Item(5).Value); int tlow8 = convertCelcius(Temp.low8); Temp.day8 = week9.Attributes.Item(3).Value; Temp.date9 = week10.Attributes.Item(2).Value; Temp.high9 = int.Parse(week10.Attributes.Item(4).Value); int thigh9 = convertCelcius(Temp.high9); Temp.low9 = int.Parse(week10.Attributes.Item(5).Value); int tlow9 = convertCelcius(Temp.low9); Temp.day9 = week10.Attributes.Item(3).Value; AddCity(cityValue.city, temperature, Temp.humidity, Temp.visibility); var result = new { cityValue.city, Temp.country, Temp.date, temperature, Temp.humidity, Temp.pressure, Temp.rising, Temp.visibility, Temp.chill, Temp.direction, Temp.speed, Temp.sunrise, Temp.sunset, thigh, tlow, Temp.text, Temp.date1, Temp.day1, thigh1, tlow1, Temp.date2, Temp.day2, thigh2, tlow2, Temp.date3, Temp.day3, thigh3, tlow3, Temp.date4, Temp.day4, thigh4, tlow4, Temp.date5, Temp.day5, tlow5, thigh5, Temp.date6, Temp.day6, thigh6, tlow6, Temp.date7, Temp.day7, thigh7, tlow7, Temp.date8, Temp.day8, thigh8, tlow8, Temp.date9, Temp.day9, thigh9, tlow9 }; HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.OK, result); //response.Content = new StringContent(xmlDocument.OuterXml, Encoding.UTF8, "application/xml"); return(response); }
public ActionResult weatherApi(string cityValue, string returnUrl) { var city = new CityWeather(); city.city = cityValue; // Initialize XML Serializer Class which hosts the Deserialize() function // typeof(query) - query is root node of XML XmlSerializer XMLdeserialize = new XmlSerializer(typeof(CityWeather)); // Initialize Web Client and set its encoding to UTF8 WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; // Form Actual URL - REST API call StringBuilder sbURL = new StringBuilder(); sbURL.Append(@"https://query.yahooapis.com/v1/public/yql?q="); // YQL is select * from geo.places where text='sfo' sbURL.Append(AntiXssEncoder.HtmlFormUrlEncode (@"select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + city.city + "')")); // Anti XSS encoder - // Prevent cross site scripting sbURL.Append(@"&diagnostics=true"); // Download string (XML data) from REST API response // Downloads the requested resource as a string. string XMLresult = wc.DownloadString(sbURL.ToString()); //diagnostics diagnostics = new diagnostics(); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(XMLresult); XmlNode node = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(6); //XmlNode node2 = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(9); XmlNode node3 = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(7); XmlNode node1 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(5); XmlNode pnode = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(9); var a = node.Attributes.Item(6).Value; CityWeather Temp = new CityWeather(); Temp.humidity = pnode.Attributes.Item(1).Value; Temp.high = int.Parse(node.Attributes.Item(4).Value); int thigh = convertCelcius(Temp.high); Temp.low = int.Parse(node.Attributes.Item(5).Value); int tlow = convertCelcius(Temp.low); Temp.city = node3.Attributes.Item(1).Value; Temp.temperature = int.Parse(node1.Attributes.Item(3).Value); int temperature = convertCelcius(Temp.temperature); TempData["Message"] = temperature; TempData["Message"] = thigh; TempData["Message1"] = tlow; TempData["Message2"] = node3.Attributes.Item(1).Value; TempData["temperature"] = temperature; TempData["Humidity"] = Temp.humidity; //Temp.precipitation = node.Attributes.Item(7).Value; //TempData["precipitation"] = Temp.precipitation; Temp.visibility = pnode.Attributes.Item(4).Value; TempData["visibility"] = Temp.visibility; var result = new { Temp.city, temperature, Temp.humidity, Temp.visibility }; AddCity(Temp.city, temperature, Temp.humidity, Temp.visibility); var listCity = cityList(); return(View(listCity)); //return Json(result,JsonRequestBehavior.AllowGet); }
public ActionResult fahrenheit(string cityFahrenValue, string returnUrl) { var cityName = new CityWeather(); cityName.city = cityFahrenValue; // Initialize XML Serializer Class which hosts the Deserialize() function // typeof(query) - query is root node of XML XmlSerializer XMLdeserialize = new XmlSerializer(typeof(query)); // Initialize Web Client and set its encoding to UTF8 WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; // Form Actual URL - REST API call StringBuilder sbURL = new StringBuilder(); sbURL.Append(@"https://query.yahooapis.com/v1/public/yql?q="); // YQL is select * from geo.places where text='sfo' sbURL.Append(AntiXssEncoder.HtmlFormUrlEncode (@"select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + cityName.city + "')")); // Anti XSS encoder - // Prevent cross site scripting sbURL.Append(@"&diagnostics=true"); // Download string (XML data) from REST API response string XMLresult = wc.DownloadString(sbURL.ToString()); //diagnostics diagnostics = new diagnostics(); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(XMLresult); XmlNode node1 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(5); CityWeather temp = new CityWeather(); temp.temperature = int.Parse(node1.Attributes.Item(3).Value); int temperature = temp.temperature; TempData["Message"] = temperature; XmlNode node3 = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(7); temp.city = node3.Attributes.Item(1).Value; TempData["Message2"] = node3.Attributes.Item(1).Value; XmlNode node = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(6); temp.text = node.Attributes.Item(6).Value; TempData["Message3"] = node.Attributes.Item(6).Value; //Tuesday XmlNode node4 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(7); temp.high = int.Parse(node4.Attributes.Item(4).Value); int thigh = temp.high; TempData["Message4"] = thigh; XmlNode node5 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(7); temp.low = int.Parse(node4.Attributes.Item(5).Value); int tlow = temp.low; TempData["Message5"] = tlow; //Wednesday XmlNode node6 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(8); temp.high1 = int.Parse(node6.Attributes.Item(4).Value); int thigh1 = temp.high1; TempData["Message6"] = thigh1; XmlNode node7 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(8); temp.low1 = int.Parse(node7.Attributes.Item(5).Value); int tlow1 = temp.low1; TempData["Message7"] = tlow1; //Thursday XmlNode node8 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(9); temp.high2 = int.Parse(node8.Attributes.Item(4).Value); int thigh2 = temp.high2; TempData["Message8"] = thigh2; XmlNode node9 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(9); temp.low2 = int.Parse(node9.Attributes.Item(5).Value); int tlow2 = temp.low2; TempData["Message9"] = tlow2; //Friday XmlNode node10 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(10); temp.high3 = int.Parse(node10.Attributes.Item(4).Value); int thigh3 = temp.high3; TempData["Message10"] = thigh3; XmlNode node11 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(10); temp.low3 = int.Parse(node11.Attributes.Item(5).Value); int tlow3 = temp.low3; TempData["Message11"] = tlow3; //Saturday XmlNode node12 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(11); temp.high4 = int.Parse(node12.Attributes.Item(4).Value); int thigh4 = temp.high4; TempData["Message12"] = thigh4; XmlNode node13 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(11); temp.low4 = int.Parse(node13.Attributes.Item(5).Value); int tlow4 = temp.low4; TempData["Message13"] = tlow4; //Sunday XmlNode node14 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(12); temp.high5 = int.Parse(node14.Attributes.Item(4).Value); int thigh5 = temp.high5; TempData["Message14"] = thigh5; XmlNode node15 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(12); temp.low5 = int.Parse(node15.Attributes.Item(5).Value); int tlow5 = temp.low5; TempData["Message15"] = tlow5; //Monday XmlNode node16 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(13); temp.high6 = int.Parse(node16.Attributes.Item(4).Value); int thigh6 = temp.high6; TempData["Message16"] = thigh6; XmlNode node17 = xmlDocument.SelectSingleNode("/query/results/channel/item").ChildNodes.Item(13); temp.low6 = int.Parse(node17.Attributes.Item(5).Value); int tlow6 = temp.low6; TempData["Message17"] = tlow6; XmlNode pnode = xmlDocument.SelectSingleNode("/query/results/channel").ChildNodes.Item(9); temp.humidity = pnode.Attributes.Item(1).Value; TempData["Humidity"] = temp.humidity; temp.visibility = pnode.Attributes.Item(4).Value; TempData["visibility"] = temp.visibility; return(View("fahrenheit")); }