Example #1
0
        private void xmppClient_OnIq(object sender, IqEventArgs e)
        {
            DisplayEvent("OnIq");

            if (e.Iq.Type == IqType.get &&
                e.Iq.Query is Weather)
            {
                var weather = e.Iq.Query as Weather;
                string zip = weather.Zip;
                // here you should lookup the weather information for the given zip code in a database or webservice
                // we just return some random numbers

                var temp = new Random().Next(-10, 40);
                var humidity = new Random().Next(10, 90);

                var wiq = new WeatherIq
                              {
                                  To = e.Iq.From,
                                  Type = IqType.result,
                                  Weather = new Weather {Temperature = temp, Humidity = humidity}
                              };
                // send the response
                xmppClient.Send(wiq);
            }
        }
Example #2
0
 private void RequestWeatherInfo(Jid from, string zip)
 {
     var wiq = new WeatherIq
                   {
                       Type = IqType.get,
                       To = from,
                       Weather = new Weather { Zip = zip }
                   };
     // we pass the zip code as state object to the IqFilter
     xmppClient.IqFilter.SendIq(wiq, WeatherInfoResponse, zip);
 }