Example #1
0
        public List <string> GetAllCities(string country)
        {
            List <string> cityNames = new List <string>();

            // Creating object of WeatherService proxy class and calling GlobalWeatherSoap12 endpoint
            WeatherService.GlobalWeatherSoapClient client = new WeatherService.GlobalWeatherSoapClient("GlobalWeatherSoap12");
            // Invoke service method through service proxy
            var allCountryCities = client.GetCitiesByCountry(country);

            if (allCountryCities.ToString() == "Data Not Found")
            {
                return(null);
            }

            DataSet ds = new DataSet();

            //Creating a stringReader object with Xml Data
            StringReader stringReader = new StringReader(allCountryCities);

            // Xml Data is read and stored in the DataSet object
            ds.ReadXml(stringReader);

            //Adding all city names to the List objects
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                cityNames.Add(item["City"].ToString());
            }

            stringReader.Dispose();

            return(cityNames);
        }
Example #2
0
        public List<string> GetAllCities(string country)
        {
            List<string> cityNames = new List<string>();

            // Creating object of WeatherService proxy class and calling GlobalWeatherSoap12 endpoint
            WeatherService.GlobalWeatherSoapClient client = new WeatherService.GlobalWeatherSoapClient("GlobalWeatherSoap12");
            // Invoke service method through service proxy
            var allCountryCities = client.GetCitiesByCountry(country);

            if (allCountryCities.ToString() == "Data Not Found")
            {
                return null;
            }

            DataSet ds = new DataSet();

            //Creating a stringReader object with Xml Data
            StringReader stringReader = new StringReader(allCountryCities);

            // Xml Data is read and stored in the DataSet object
            ds.ReadXml(stringReader);

            //Adding all city names to the List objects
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                cityNames.Add(item["City"].ToString());
            }

            stringReader.Dispose();

            return cityNames;
        }
Example #3
0
        /*
         * WEATHER SERVICE - The Weather method calls a getWeather method that is from an external service reference
         * that was obtained from donkerhoekdata.co.za/IWSWebServices/weather.asmx?op=getWeather
         * The provider is an international weather provider & the method below has been customed to route to
         * South African cities only & gives current weather updates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         * A SOAP client establishes the connection to a client objection via the SOAP configuration in the
         * Web config file; when a city query is issued the results are captured in one "result" string and
         * string manipulation captures essentials which are passed to a ViewBag object to the Weather view
         */

        //[HttpPost]
        public ActionResult Weather(string CityName, string CountryName)
        {
            WeatherService.GlobalWeatherSoapClient client = new WeatherService.GlobalWeatherSoapClient("GlobalWeatherSoap");

            string location, time, wind, visibility, skyconditions, temperature, dewpoint, humidity, pressure, status;

            if (!String.IsNullOrEmpty(CityName))
            {
                string result = client.GetWeather(CityName, "South Africa");

                location      = getBetween(result, "<Location>", "</Location>");
                time          = getBetween(result, "<Time>", "</Time>");
                wind          = getBetween(result, "<Wind>", "</Wind>");
                visibility    = getBetween(result, "<Visibility>", "</Visibility");
                skyconditions = getBetween(result, "<SkyConditions>", "</SkyConditions");
                temperature   = getBetween(result, "<Temperature>", "</Temperature>");
                dewpoint      = getBetween(result, "<DewPoint>", "</DewPoint>");
                humidity      = getBetween(result, "<RelativeHumidity>", "</RelativeHumidity>");
                pressure      = getBetween(result, "<Pressure>", "</Pressure>");
                status        = getBetween(result, "<Status>", "</Status>");

                if (status == "Success")
                {
                    ViewBag.Error            = string.Empty;
                    ViewBag.Location         = location;
                    ViewBag.Time             = time;
                    ViewBag.Wind             = wind;
                    ViewBag.Visibility       = visibility;
                    ViewBag.SkyConditions    = skyconditions;
                    ViewBag.Temperature      = temperature;
                    ViewBag.Dewpoint         = dewpoint;
                    ViewBag.RelativeHumidity = humidity;
                    ViewBag.Pressure         = pressure;
                    ViewBag.Status           = status;
                }
                else
                {
                    ViewBag.Error            = "Sorry :( - Weather Retrival Failure - REFRESH & try again";
                    ViewBag.Location         = string.Empty;
                    ViewBag.Time             = string.Empty;
                    ViewBag.Wind             = string.Empty;
                    ViewBag.Visibility       = string.Empty;
                    ViewBag.SkyConditions    = string.Empty;
                    ViewBag.Temperature      = string.Empty;
                    ViewBag.Dewpoint         = string.Empty;
                    ViewBag.RelativeHumidity = string.Empty;
                    ViewBag.Pressure         = string.Empty;
                    ViewBag.Status           = status;
                }
            }
            else
            {
                ViewBag.Coordinates = "Specify your city query update please...";
            }

            return(View());
        }
Example #4
0
        public void GetLastUpdateStatus()
        {
            DownloadResult = SyncState.SyncResult.InActive;
            try
            {
                WeatherService.GlobalWeatherSoapClient client = new WeatherService.GlobalWeatherSoapClient();
                client.GetWeatherCompleted += new EventHandler <WeatherService.GetWeatherCompletedEventArgs>(WeatherService_GetSLastUpdate);
                client.GetWeatherAsync("Alexandroupoli", "Greece");
                DownloadServerResult = SyncState.ServerSyncResult.Downloading;
            }

            catch { MessageBox.Show("Σφάλμα ! Ο Server δεν Ανταποκρίθηκε έγκαιρα"); DownloadResult = SyncState.SyncResult.Failed; return; }
        }
Example #5
0
        public void GetSaveWeatherForAirport(string AirportName, string AirportCode)
        {
            this.AirportCode = AirportCode;
            DownloadResult   = SyncState.SyncResult.InActive;
            try
            {
                WeatherService.GlobalWeatherSoapClient client = new WeatherService.GlobalWeatherSoapClient();
                client.GetWeatherCompleted += new EventHandler <WeatherService.GetWeatherCompletedEventArgs>(WeatherService_GetSaveWeather);
                client.GetWeatherAsync(TranslationEngine.TranslatedCityName(AirportName), "Greece");
                DownloadResult = SyncState.SyncResult.Downloading;
            }

            catch { MessageBox.Show("Σφάλμα ! Ο Server δεν Ανταποκρίθηκε έγκαιρα"); DownloadResult = SyncState.SyncResult.Failed; return; }
        }
Example #6
0
        public ContentResult GetWeather()
        {
            var weather = new WeatherService.GlobalWeatherSoapClient("GlobalWeatherSoap");
            var temp = weather.GetWeather("Dublin", "Ireland");
            XmlDocument xd = new XmlDocument();
            xd.LoadXml(temp);

            XmlNodeList xnList = xd.SelectNodes("/CurrentWeather/Temperature");
            string x = "";
            foreach (XmlNode xn in xnList)
            {
                x = xn.InnerText;
            }
               // x = x.Substring(7, 1);

            return Content(x);
        }
Example #7
0
        public WeatherReport GetTheWeather(string city, string country)
        {
            // Creating object of WeatherService proxy class and calling GlobalWeatherSoap12 endpoint
            WeatherService.GlobalWeatherSoapClient clientObject = new WeatherService.GlobalWeatherSoapClient("GlobalWeatherSoap12");

            // Invoke service method through service proxy
            var weatherReportXmlObject = clientObject.GetWeather(city, country);

            if (weatherReportXmlObject.ToString() == "Data Not Found")
            {
                return null;
            }
            DataSet ds = new DataSet();

            //Creating a stringReader object with Xml Data
            StringReader stringReader = new StringReader(weatherReportXmlObject);

            // Xml Data is read and stored in the DataSet object
            ds.ReadXml(stringReader);

            // Assigning the data to an object of the model class and checking if the Dataset contains the perticular field.
            WeatherReport obj = new WeatherReport();

            if (ds.Tables[0].Columns.Contains("Location"))
            {
                obj.location = ds.Tables[0].Rows[0]["Location"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Time"))
            {
                obj.time = ds.Tables[0].Rows[0]["Time"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Wind"))
            {
                obj.wind = ds.Tables[0].Rows[0]["Wind"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Visibility"))
            {
                obj.visibility = ds.Tables[0].Rows[0]["Visibility"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("SkyConditions"))
            {
                obj.skyConditions = ds.Tables[0].Rows[0]["SkyConditions"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Temperature"))
            {
                obj.temperature = ds.Tables[0].Rows[0]["Temperature"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Dewpoint"))
            {
                obj.dewpoint = ds.Tables[0].Rows[0]["Dewpoint"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("RelativeHumidity"))
            {
                obj.relativeHumidity = ds.Tables[0].Rows[0]["RelativeHumidity"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Pressure"))
            {
                obj.pressure = ds.Tables[0].Rows[0]["Pressure"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Status"))
            {
                obj.status = ds.Tables[0].Rows[0]["Status"].ToString();
            }

            stringReader.Dispose();

            return obj;
        }
Example #8
0
        public WeatherReport GetTheWeather(string city, string country)
        {
            // Creating object of WeatherService proxy class and calling GlobalWeatherSoap12 endpoint
            WeatherService.GlobalWeatherSoapClient clientObject = new WeatherService.GlobalWeatherSoapClient("GlobalWeatherSoap12");

            // Invoke service method through service proxy
            var weatherReportXmlObject = clientObject.GetWeather(city, country);

            if (weatherReportXmlObject.ToString() == "Data Not Found")
            {
                return(null);
            }
            DataSet ds = new DataSet();

            //Creating a stringReader object with Xml Data
            StringReader stringReader = new StringReader(weatherReportXmlObject);

            // Xml Data is read and stored in the DataSet object
            ds.ReadXml(stringReader);

            // Assigning the data to an object of the model class and checking if the Dataset contains the perticular field.
            WeatherReport obj = new WeatherReport();

            if (ds.Tables[0].Columns.Contains("Location"))
            {
                obj.location = ds.Tables[0].Rows[0]["Location"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Time"))
            {
                obj.time = ds.Tables[0].Rows[0]["Time"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Wind"))
            {
                obj.wind = ds.Tables[0].Rows[0]["Wind"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Visibility"))
            {
                obj.visibility = ds.Tables[0].Rows[0]["Visibility"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("SkyConditions"))
            {
                obj.skyConditions = ds.Tables[0].Rows[0]["SkyConditions"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Temperature"))
            {
                obj.temperature = ds.Tables[0].Rows[0]["Temperature"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Dewpoint"))
            {
                obj.dewpoint = ds.Tables[0].Rows[0]["Dewpoint"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("RelativeHumidity"))
            {
                obj.relativeHumidity = ds.Tables[0].Rows[0]["RelativeHumidity"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Pressure"))
            {
                obj.pressure = ds.Tables[0].Rows[0]["Pressure"].ToString();
            }
            if (ds.Tables[0].Columns.Contains("Status"))
            {
                obj.status = ds.Tables[0].Rows[0]["Status"].ToString();
            }

            stringReader.Dispose();

            return(obj);
        }