async void btnAddFavourite_Click(object sender, System.EventArgs e)
        {
            try
            {
                WeatherTable weatherItem = new WeatherTable
                {
                    Title       = txtLocation.Text,
                    Temperature = txtTemperature.Text,
                    Wind        = txtWind.Text,
                    Humidity    = txtHumidity.Text,
                    Sunrise     = txtSunrise.Text,
                    Sunset      = txtSunset.Text,
                    Visibility  = "",
                    Longitute   = longitute,
                    Latitude    = latitude
                };



                int id = await App.Database.SaveItemAsync(weatherItem);

                if (id > 0)
                {
                    await DisplayAlert("Alert", "Favourite Added", "Ok");
                }
            }
            catch (Exception ex)
            {
                await  DisplayAlert("Error", ex.Message, "Ok");
            }
        }
        // http://www.nws.noaa.gov/forecasts/xml/
        public static DayWeatherData[] ParseWeatherXML(string xmlWeather)
        {
            try
            {
                DayWeatherData[] arrDayWeatherData;
                XmlDocument      xmlDoc = new XmlDocument();

                // load XML data into a tree
                xmlDoc.LoadXml(xmlWeather);

                // locate dwml/data/time-layout nodes. There should be three of them:
                //      - next week nighttime temperatures (lows)
                //      - next week daytime temperatures (highs)
                //      - next week cloud data

                // Find roots nodes for temperature and cloud data
                WeatherTable wtLowTemp  = new WeatherTable();
                WeatherTable wtHighTemp = new WeatherTable();
                WeatherTable wtClouds   = new WeatherTable();

                wtLowTemp.nodeData  = xmlDoc.SelectSingleNode("/dwml/data/parameters/temperature[@type='minimum']");
                wtHighTemp.nodeData = xmlDoc.SelectSingleNode("/dwml/data/parameters/temperature[@type='maximum']");
                wtClouds.nodeData   = xmlDoc.SelectSingleNode("/dwml/data/parameters/conditions-icon");

                // Find out corresponding time layout table for each top data node
                wtLowTemp.nodeTimeLayout  = FindLayoutTable(xmlDoc, wtLowTemp.nodeData);
                wtHighTemp.nodeTimeLayout = FindLayoutTable(xmlDoc, wtHighTemp.nodeData);
                wtClouds.nodeTimeLayout   = FindLayoutTable(xmlDoc, wtClouds.nodeData);

                // number of day data is min of low and high temperatures
                XmlNodeList listLowTimes  = wtLowTemp.nodeTimeLayout.SelectNodes("start-valid-time");
                XmlNodeList listHighTimes = wtHighTemp.nodeTimeLayout.SelectNodes("start-valid-time");

                int cTimes = Math.Min(listLowTimes.Count, listHighTimes.Count);

                arrDayWeatherData = new DayWeatherData[cTimes];
                for (int i = 0; i < cTimes; i++)
                {
                    arrDayWeatherData[i] = new DayWeatherData();
                }

                // Fill highs and lows
                FillLowTemperatures(wtLowTemp.nodeData, ref arrDayWeatherData);
                FillHighTemperatures(wtHighTemp.nodeData, ref arrDayWeatherData);

                FillDayNameAndTime(listLowTimes, listHighTimes, ref arrDayWeatherData);

                FillCloudData(wtClouds, ref arrDayWeatherData);

                return(arrDayWeatherData);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        void Start()
        {
            _dfUnity      = DaggerfallUnity.Instance;
            _weatherTable = WeatherTable.ParseJsonTable();

            if (DaggerfallUnity.Settings.MeshAndTextureReplacement)
            {
                AddWindZone();
            }
        }
Ejemplo n.º 4
0
        void Start()
        {
            _dfUnity      = DaggerfallUnity.Instance;
            _weatherTable = WeatherTable.ParseJsonTable();

            if (DaggerfallUnity.Settings.AssetInjection)
            {
                AddWindZone();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// update weather info by site
        /// </summary>
        /// <param name="site"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public void UpdateWeather(string site, string jsonInfo)
        {
            var weather     = Context.WeatherTable.Single(e => e.Site == site);
            var jo          = JObject.Parse(jsonInfo);
            var tmp_weather = new WeatherTable();

            tmp_weather.Site = (string)jo.SelectToken("site");
            var tmp_content = jo.SelectToken("content");

            if (tmp_content != null)
            {
                tmp_weather.Content = tmp_content.ToString();
            }
            tmp_weather.Province   = (string)jo.SelectToken("province");
            tmp_weather.Updatetime = DateTime.Parse((string)jo.SelectToken("updatetime") ?? DateTime.Now.ToString());
            tmp_weather.City       = (string)jo.SelectToken("city");
            weather.Update(ref tmp_weather);
        }
        void Start()
        {
            _dfUnity      = DaggerfallUnity.Instance;
            _weatherTable = WeatherTable.ParseJsonTable();

            postProcessLayer = Camera.main.GetComponent <PostProcessLayer>();
            if (postProcessLayer != null)
            {
                postProcessLayer.fog.excludeSkybox = true;
            }

            if (DaggerfallUnity.Settings.AssetInjection)
            {
                AddWindZone();
            }

            // initialize with clear overcast sky (so that initial fog settings like exponential fog mode are set)
            ClearOvercast();
        }
        private static void FillCloudData(WeatherTable wt, ref DayWeatherData[] arrDayWeatherData)
        {
            // Cloud data is typically much longer than day high/low data
            // We need to find times that match ones in high and low temp tables.
            XmlNodeList listTimes    = wt.nodeTimeLayout.SelectNodes("start-valid-time");
            XmlNodeList listIcons    = wt.nodeData.SelectNodes("icon-link");
            int         cWeatherData = 0;
            int         cNodes       = 0;
            int         hourDiff     = Int32.MaxValue;

            foreach (XmlNode node in listTimes)
            {
                DateTime dt = ParseDateTime(node.InnerText);

                if (dt.Date > arrDayWeatherData[cWeatherData].DateTime.Date)
                {
                    cWeatherData++;
                    if (cWeatherData >= arrDayWeatherData.Length)
                    {
                        break;
                    }

                    hourDiff = Int32.MaxValue;
                }

                if (dt.Date == arrDayWeatherData[cWeatherData].DateTime.Date)
                {
                    int diff = Math.Abs(dt.Hour - arrDayWeatherData[cWeatherData].DateTime.Hour);

                    if (diff < hourDiff)
                    {
                        hourDiff = diff;
                        arrDayWeatherData[cWeatherData].CloudIconURL = listIcons[cNodes].InnerText;
                    }
                }

                cNodes++;
            }
        }
Ejemplo n.º 8
0
        public void ORTest()
        {
            Weather one      = new Weather("Rainy", "Hot", "High", false, false);
            Weather two      = new Weather("Rainy", "Hot", "High", true, false);
            Weather three    = new Weather("Overcast", "Hot", "High", false, true);
            Weather four     = new Weather("Sunny", "Mild", "High", false, true);
            Weather five     = new Weather("Sunny", "Cool", "Normal", false, true);
            Weather six      = new Weather("Sunny", "Cool", "Normal", true, false);
            Weather seven    = new Weather("Overcast", "Cool", "Normal", true, true);
            Weather eight    = new Weather("Rainy", "Mild", "High", false, false);
            Weather nine     = new Weather("Rainy", "Cool", "Normal", false, true);
            Weather ten      = new Weather("Sunny", "Mild", "Normal", false, true);
            Weather eleven   = new Weather("Rainy", "Mild", "Normal", true, true);
            Weather twelve   = new Weather("Overcast", "Mild", "High", true, true);
            Weather thirteen = new Weather("Overcast", "Hot", "Normal", false, true);
            Weather fourteen = new Weather("Sunny", "Mild", "High", true, false);

            Weather[] weather = { one,  two, three,  four,   five,     six, seven, eight,
                                  nine, ten, eleven, twelve, thirteen, fourteen };

            WeatherTable wt = new WeatherTable(weather);

            string[] outLook  = wt.getOutlook();
            string[] temp     = wt.getTemp();
            string[] humidity = wt.getHumidity();
            string[] windy    = wt.getWindy();
            bool[]   playgolf = wt.getPlayGolf();

            object[] stuff = { outLook, temp, humidity, windy };

            //params passed by reference
            OneRule OR1 = new OneRule(ref outLook, ref playgolf, "outlook");
            OneRule OR2 = new OneRule(ref temp, ref playgolf, "temp");
            OneRule OR3 = new OneRule(ref humidity, ref playgolf, "humidity");
            OneRule OR4 = new OneRule(ref windy, ref playgolf, "windy");


            OR1.setClassCount();
            OR1.getClassCount();

            OR2.setClassCount();
            OR2.getClassCount();

            OR3.setClassCount();
            OR3.getClassCount();

            OR4.setClassCount();
            OR4.getClassCount();

            OneRule[] decide = { OR1, OR2, OR3, OR4 };

            OneRule prog   = new OneRule();
            OneRule chosen = prog.WhichClass(decide);


            Assert.Equal(chosen.getName(), "outlook");
            Assert.NotEqual(chosen.getName(), "windy");
            Assert.Equal(chosen.getClassError(), 4);


            //Console.WriteLine("Chosen: {0}, error is: {1}",chosen.getName(), chosen.getClassError());


            //Assert.Equal(e, 1.0);
        }
Ejemplo n.º 9
0
 void Start()
 {
     _dfUnity      = DaggerfallUnity.Instance;
     _weatherTable = WeatherTable.ParseJsonTable();
 }