Esempio n. 1
0
        // Reload air quality XML files.
        override public async Task <int> loadAq2Dict()
        {
            XDocument xd = new XDocument();

            try
            {
                var dataXml = await ApplicationData.Current.LocalFolder.GetFileAsync(Params.aqDbFile);

                using (var s = await dataXml.OpenStreamForReadAsync())
                {
                    // Reload to xd.
                    xd = XDocument.Load(s);
                }
            }
            catch
            {
                xd = XDocument.Load("Assets/" + Params.aqDbFile);
            }

            var dataX = from data in xd.Descendants("Data")
                        select data;
            var geoDataX = from data in siteGeoXd.Descendants("Data")
                           select data;

            sitesStrDict.Clear();
            sitesGeoDict.Clear();
            foreach (var d in dataX.OrderBy(x => x.Element("County").Value))
            {
                var siteName = d.Descendants("SiteName").First().Value;
                var geoD     = from gd in geoDataX
                               where gd.Descendants("SiteName").First().Value == siteName
                               select gd;

                var siteDict = d.Elements().ToDictionary(x => x.Name.LocalName, x => x.Value);
                var geoDict  = geoD.Elements().ToDictionary(x => x.Name.LocalName, x => x.Value);
                siteDict.Add("TWD97Lat", geoDict["TWD97Lat"]);
                siteDict.Add("TWD97Lon", geoDict["TWD97Lon"]);
                sitesGeoDict.Add(siteName, new GpsPoint
                {
                    twd97Lat = double.Parse(siteDict["TWD97Lat"]),
                    twd97Lon = double.Parse(siteDict["TWD97Lon"]),
                });
                // Shorten long status strings for map icons.
                siteDict.Add("ShortStatus", StaticTaqModel.getShortStatus(siteDict["Status"]));
                sitesStrDict.Add(siteName, siteDict);
            }
            return(0);
        }
Esempio n. 2
0
        // Reload air quality JSON files.
        override public async Task <int> loadAq2Dict()
        {
            JObject jTaqDb;

            try
            {
                var dataJson = await ApplicationData.Current.LocalFolder.GetFileAsync(Params.aqDbFile);

                jTaqDb = await readJObject(dataJson);
            }
            catch
            {
                var dataJson = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/" + Params.aqDbFile));

                jTaqDb = await readJObject(dataJson);
            }

            var data     = jTaqDb["result"]["records"];
            var geoDataX = from gdata in siteGeoXd.Descendants("Data")
                           select gdata;

            sitesStrDict.Clear();
            sitesGeoDict.Clear();
            foreach (var d in data)
            {
                var siteDict = d.ToObject <Dictionary <string, string> >();
                var siteName = siteDict["SiteName"];
                // Skip duplicate keys as possible.
                if (sitesStrDict.ContainsKey(siteName))
                {
                    continue;
                }

                var geoD = from gd in geoDataX
                           where gd.Descendants("SiteName").First().Value == siteName
                           select gd;

                var    geoDict = geoD.Elements().ToDictionary(x => x.Name.LocalName, x => x.Value);
                string latStr, lonStr;
                // No corresponding site geo info in SiteGeo.xml!!!
                if (geoDict.Count == 0)
                {
                    latStr = "0";
                    lonStr = "0";
                }
                else
                {
                    latStr = geoDict["TWD97Lat"];
                    lonStr = geoDict["TWD97Lon"];
                }
                siteDict.Add("TWD97Lat", latStr);
                siteDict.Add("TWD97Lon", lonStr);

                sitesGeoDict.Add(siteName, new GpsPoint
                {
                    twd97Lat = double.Parse(siteDict["TWD97Lat"]),
                    twd97Lon = double.Parse(siteDict["TWD97Lon"]),
                });
                // Shorten long status strings for map icons.
                siteDict.Add("ShortStatus", StaticTaqModel.getShortStatus(siteDict["Status"]));
                if (siteDict["ShortStatus"] == "維護")
                {
                    foreach (var f in aqHistNames)
                    {
                        siteDict[f] = "N/A";
                    }
                }
                sitesStrDict.Add(siteName, siteDict);
            }
            return(0);
        }