TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Algady Khalefa
NA
18
775
filling RichtextBox from a list
Apr 28 2017 12:29 PM
Hi, I'm working on a project where I need to read weather data from openweathermap, for now I've managed to read data successfuly to my list but I'm not able to do any usefull steps with my data such as write it in a RichtextBox for example!
please note:
when I put a break point it line 70 and run it I can find that object w (line 68) has all data which read as expected.
my question is how can I read data from that list and write it for example to richtextbox?
please help and sorry for my english.
namespace
Weather_app
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
static
string
AppID =
"df2c579492931fb3df887b04edead343"
;
public
static
IEnumerable
> xEl {
get
;
private
set
; }
public
static
async Task
> GetWeather(
string
location)
{
string
url =
string
.Format
(
"http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&type=accurate&mode=xml&units=metric&cnt=5&appid={1}"
,
"Leeds"
, AppID);
using
(HttpClient client =
new
HttpClient())
{
try
{
string
response = await client.GetStringAsync(url);
if
(!(response.Contains(
"message"
) && response.Contains(
"cod"
)))
{
XElement xEl = XElement.Load(
new
System.IO.StringReader(response));
return
GetWeatherInfo(xEl);
}
else
{
return
new
List
();
}
}
catch
(HttpRequestException)
{
return
new
List
();
}
}
}
public
static
List
GetWeatherInfo(XElement xEl)
{
IEnumerable
w = xEl.Descendants(
"time"
).Select((el) =>
new
WeatherDetails
{
Humidity = el.Element(
"humidity"
).Attribute(
"value"
).Value +
"%"
,
MaxTemperature = el.Element(
"temperature"
).Attribute(
"max"
).Value +
"°"
,
MinTemperature = el.Element(
"temperature"
).Attribute(
"min"
).Value +
"°"
,
Temperature = el.Element(
"temperature"
).Attribute(
"day"
).Value +
"°"
,
Weather = el.Element(
"symbol"
).Attribute(
"name"
).Value,
WeatherDay = DayOfTheWeek(el),
WeatherIcon = WeatherIconPath(el),
WindDirection = el.Element(
"windDirection"
).Attribute(
"name"
).Value,
WindSpeed = el.Element(
"windSpeed"
).Attribute(
"mps"
).Value +
"mps"
});
return
w.ToList();
}
private
static
string
DayOfTheWeek(XElement el)
{
DayOfWeek dW = Convert.ToDateTime(el.Attribute(
"day"
).Value).DayOfWeek;
return
dW.ToString();
}
private
static
string
WeatherIconPath(XElement el)
{
string
symbolVar = el.Element(
"symbol"
).Attribute(
"var"
).Value;
string
symbolNumber = el.Element(
"symbol"
).Attribute(
"number"
).Value;
string
dayOrNight = symbolVar.ElementAt(2).ToString();
// d or n
return
String.Format(
"WeatherIcons/{0}{1}.png"
, symbolNumber, dayOrNight);
}
}
}
Reply
Answers (
2
)
Running SQLserver file from code
How to print in this pattern