Hi.
I need your help. I programming a private Speech Recognition in C#.
So far so good. Yesterday I took the weather function and put it into an own class. Before I've done this, it works fine. But now, I've the following Problem:
If I check the weather or temperature at the first time, after I start the program, the weather forecast works fine. But if I ask a second time, the function repeats and if I ask more than 2 times, it loops.
Here my code, I hope someone of you can help me!
[code]
//Questionhandle
else if (e.Result.Grammar.Name == "Weather")
{
switch (e.Result.Text)
{
case "Computer, wie ist das Wetter in Erpel?":
sage("Ich suche die aktuellen Wetterdaten!"); // say string
Wetter_heute.Get_Weather_today();
get_weather_now_pic_information();
sageAsync(Wetter_heute.weather_today_str.ToString());
show_weather_Tick();
break;
[...]
}
}
private void get_weather_now_pic_information()
{
if (Wetter_heute.weathercodenow == 113)
{
if (DateTime.Now.Hour < 7 && DateTime.Now.Hour > 18)
pictureBox1.ImageLocation = "Ico/_weather/sunny_night.png";
else
pictureBox1.ImageLocation = "Ico/_weather/sunny.png";
label7.Text = Wetter_heute.weathercode_lbl.ToString();
}
[...]
}
//Weather Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace WindowsFormsApplication10
{
class Weather
{
public string weathererpelchecktime_str;
public string weathererpelnowtemp_str;
public string weathererpelnowclouds_str;
public string weathererpelnowlufthum_str;
public string weathererpelnowluftspeed_str;
public string weathererpelnowluftdir_str;
public string weathererpelnowluftdeg_str;
public string weathererpelnowsight_str;
public string weathererpelcodenow_str;
[...]
public void Get_Weather()
{
//Hole Wetterdaten
XmlDocument WeatherErpelNowdoc = new XmlDocument();
WeatherErpelNowdoc.Load("http://free.worldweatheronline.com/feed/weather.ashx?
q=Erpel&format=xml&num_of_days=3&key=[xxx]");
XmlNode WeatherErpelPressure =
WeatherErpelNowdoc.SelectSingleNode("/data/current_condition/pressure");
XmlNode WeatherErpelNow =
WeatherErpelNowdoc.SelectSingleNode("/data/current_condition[1]");
XmlNode WeatherErpelTod =
WeatherErpelNowdoc.SelectSingleNode("/data/weather[1]");
XmlNode WeatherErpelTom =
WeatherErpelNowdoc.SelectSingleNode("/data/weather[2]");
XmlNode WeatherErpelTDAT =
WeatherErpelNowdoc.SelectSingleNode("/data/weather[3]");
weathererpelchecktime_str =
WeatherErpelNow["observation_time"].InnerText.ToString();
weathererpelnowtemp_str = WeatherErpelNow["temp_C"].InnerText.ToString();
weathererpelnowclouds_str = WeatherErpelNow["cloudcover"].InnerText.ToString();
weathererpelnowlufthum_str = WeatherErpelNow["humidity"].InnerText.ToString();
weathererpelnowluftspeed_str =
WeatherErpelNow["windspeedKmph"].InnerText.ToString();
weathererpelnowluftdir_str =
WeatherErpelNow["winddir16Point"].InnerText.ToString();
weathererpelnowluftdeg_str =
WeatherErpelNow["winddirDegree"].InnerText.ToString();
weathererpelcodenow_str = WeatherErpelNow["weatherCode"].InnerText.ToString();
weathererpelnowsight_str = WeatherErpelNow["visibility"].InnerText.ToString();
[...]
}
}
// Weather Class
class Weather_today
{
Weather weather_cs = new Weather();
Form1 Main = new Form1();
public string weathercode_lbl = "",
weathererpelnowtemp = "",
weathererpelnowclouds = "",
weathererpelchecktime = "";
public string weathererpelnowluftdir = "",
weathercodestr = "",
weathercodetodstr = "",
weather_today_str = "",
schwuelestr = "",
windstr = "";
public string weathererpelnowlufthum = "",
weathererpelcodetod = "",
weathererpelcodenow = "",
weathererpelnowsight = "";
public string weathererpelnowluftdeg = "", weathererpelnowluftspeed = "";
public double weathertempnow = 0,
weatherwolkendichtenow = 0,
weatherhumi = 0,
weatherwindspeednow = 0,
weatherluftdeg = 0,
weathercodenow = 0,
weathercodetod = 0,
weathersightnow = 0;
int tempnowint = 0, wolkendichte = 0, humidity = 0, windspeed = 0, luftdeg = 0, sight = 0, weathercodenowint = 0, weathercodetodint = 0;
bool schwuelecheckbool = false;
private string weather_result_str1 = "";
private string weather_result_str2 = "";
private string weather_result_str3 = "";
// Get_Weather_today Function
public void Get_Weather_today()
{
weather_cs.Get_Weather();
//Auslesen
weathererpelnowtemp = weather_cs.weathererpelnowtemp_str;
weathererpelnowclouds = weather_cs.weathererpelnowclouds_str;
weathererpelnowlufthum = weather_cs.weathererpelnowlufthum_str;
weathererpelnowluftspeed = weather_cs.weathererpelnowluftspeed_str;
weathererpelnowluftdir = weather_cs.weathererpelnowluftdir_str;
weathererpelnowluftdeg = weather_cs.weathererpelnowluftdeg_str;
weathererpelcodenow = weather_cs.weathererpelcodenow_str;
weathererpelcodetod = weather_cs.weathererpelcodetod_str;
weathererpelchecktime = weather_cs.weathererpelchecktime_str;
weathererpelnowsight = weather_cs.weathererpelnowsight_str;
set_Vars_Weather_today();
check_Weathercode_today();
check_Weathercode_today_forecast();
checkschwuele_today();
check_Wind_Situation();
set_today_str();
weather_today_str = weather_result_str3;
}
public void set_today_str()
{
if (weathererpelnowluftdir.Equals("E"))
{
weather_result_str1 =
(String.Format("{0} {1} Grad Celsius. Die Windgeschwindigkeit beträgt {2} Kilometer pro Stunde und weht aus {3} Grad, östlicher
Richtung. {4}.", weather_today_str, weathererpelnowtemp, weathererpelnowluftspeed, weathererpelnowluftdeg,
weather_result_str2));
}
else if (weathererpelnowluftdir.Equals("SE"))
{
weather_result_str1 = (String.Format("{0} {1} Grad Celsius. Die Windgeschwindigkeit beträgt {2} Kilometer pro Stunde und weht aus
{3} Grad, süd-östlicher Richtung. {4}.",weather_today_str, weathererpelnowtemp, weathererpelnowluftspeed,
weathererpelnowluftdeg, weather_result_str2));
}
[...]
if (weathererpelcodenow == weathererpelcodetod)
{ weather_result_str2 = "Im weiteren Verlauf des Tages bleibt es " + weathercodetodstr; }
else
{ weather_result_str2 = "Im weiteren Verlauf des Tages wird es" + weathercodetodstr; }
weather_result_str3 = "Zur Zeit " + weathercodestr + "." + schwuelestr + windstr + ", bei einer Temperatur von " + weather_result_str1 +
weather_result_str2;
}
private void check_Weathercode_today()
{
switch (weathercodenowint)
{
case 395:
weathercodestr = "ist mit mittleren bis starken Gewitterschauern zu rechnen ";
weathercode_lbl = "Mittlere-starke Gewitterschauer";
break;
[...]
}
}
private void check_Weathercode_today_forecast()
{
switch (weathercodetodint)
{
case 395:
weathercodetodstr = "mittlere bis starke, gewittrige Schneeschauer";
break;
[...]
}
}
private void checkschwuele_today()
{
//Werte für Schwüle gemäß Wikipedia
if (humidity >= 99 && tempnowint == 16) schwuelecheckbool = true;
if (humidity >= 93 && tempnowint == 17) schwuelecheckbool = true;
if (humidity >= 88 && tempnowint == 18) schwuelecheckbool = true;
if (humidity >= 83 && tempnowint == 19) schwuelecheckbool = true;
if (humidity >= 78 && tempnowint == 20) schwuelecheckbool = true;
if (humidity >= 74 && tempnowint == 21) schwuelecheckbool = true;
if (humidity >= 70 && tempnowint == 22) schwuelecheckbool = true;
if (humidity >= 66 && tempnowint == 23) schwuelecheckbool = true;
if (humidity >= 62 && tempnowint == 24) schwuelecheckbool = true;
if (humidity >= 60 && tempnowint == 25) schwuelecheckbool = true;
if (humidity >= 56 && tempnowint == 26) schwuelecheckbool = true;
if (humidity >= 53 && tempnowint == 27) schwuelecheckbool = true;
if (humidity >= 50 && tempnowint == 28) schwuelecheckbool = true;
if (humidity >= 47 && tempnowint == 29) schwuelecheckbool = true;
if (humidity >= 45 && tempnowint == 30) schwuelecheckbool = true;
if (humidity >= 43 && tempnowint == 31) schwuelecheckbool = true;
if (humidity >= 40 && tempnowint == 32) schwuelecheckbool = true;
if (humidity >= 38 && tempnowint == 33) schwuelecheckbool = true;
if (humidity >= 36 && tempnowint == 34) schwuelecheckbool = true;
if (humidity >= 34 && tempnowint == 35) schwuelecheckbool = true;
if (humidity >= 32 && tempnowint == 36) schwuelecheckbool = true;
if (humidity >= 30 && tempnowint == 37) schwuelecheckbool = true;
if (schwuelecheckbool == true) schwuelestr = "schwül";
else schwuelestr = "";
}
private void set_Vars_Weather_today()
{
weathertempnow = Convert.ToDouble(weathererpelnowtemp);
tempnowint = Convert.ToInt32(weathertempnow);
weatherwolkendichtenow = Convert.ToDouble(weathererpelnowclouds);
wolkendichte = Convert.ToInt32(weatherwolkendichtenow);
weatherhumi = Convert.ToDouble(weathererpelnowlufthum);
humidity = Convert.ToInt32(weatherhumi);
weatherwindspeednow = Convert.ToDouble(weathererpelnowluftspeed);
windspeed = Convert.ToInt32(weatherwindspeednow);
weatherluftdeg = Convert.ToDouble(weathererpelnowluftdeg);
luftdeg = Convert.ToInt32(weatherluftdeg);
weathersightnow = Convert.ToDouble(weathererpelnowsight);
sight = Convert.ToInt32(weathersightnow);
weathercodenow = Convert.ToDouble(weathererpelcodenow);
weathercodenowint = Convert.ToInt32(weathercodenow);
weathercodetod = Convert.ToDouble(weathererpelcodetod);
weathercodetodint = Convert.ToInt32(weathercodetod);
}
private void check_Wind_Situation()
{
if (schwuelecheckbool == true)
{
if (windspeed <= 1) windstr = "Es ist"+ schwuelestr + " und windstill";
else if (windspeed >= 2 && windspeed <= 19) windstr = "Es ist" + schwuelestr + " und leicht windig";
else if (windspeed >= 20 && windspeed <= 28) windstr = "Es ist" + schwuelestr + " und schwach windig";
else if (windspeed >= 29 && windspeed <= 46) windstr = "Es ist" + schwuelestr + " und mäßig bis frisch windig";
else if (windspeed >= 47 && windspeed <= 56) windstr = "Es ist" + schwuelestr + " und stark windig";
else if (windspeed >= 57 && windspeed <= 74) windstr = "Es ist" + schwuelestr + " und stürmisch";
else if (windspeed >= 75 && windspeed <= 83) windstr = "Es ist"+ schwuelestr + " und stürmt";
else if (windspeed >= 84 && windspeed <= 102) windstr = "Es ist" + schwuelestr + " und stark stürmisch";
else if (windspeed >= 103 && windspeed <= 120) windstr = "Es ist" + schwuelestr + " und stürmt orkanartik";
else if (windspeed >= 130 && windspeed <= 194) windstr = "Es ist" + schwuelestr + " und es tobt ein Orkan";
}
else
{
if (windspeed <= 1) windstr = "und es ist windstill";
else if (windspeed >= 2 && windspeed <= 19) windstr = "und es ist leicht windig";
else if (windspeed >= 20 && windspeed <= 28) windstr = "und es ist schwach windig";
else if (windspeed >= 29 && windspeed <= 46) windstr = "und es ist mäßig bis frisch windig";
else if (windspeed >= 47 && windspeed <= 56) windstr = "und es ist stark windig";
else if (windspeed >= 57 && windspeed <= 74) windstr = "und es ist stürmisch";
else if (windspeed >= 75 && windspeed <= 83) windstr = "und es stürmt";
else if (windspeed >= 84 && windspeed <= 102) windstr = "und es ist stark stürmisch";
else if (windspeed >= 103 && windspeed <= 120) windstr = "und es stürmt orkanartik";
else if (windspeed >= 130 && windspeed <= 194) windstr = "und es tobt ein Orkan";
}
}
}
[/code]