示例#1
0
        private async Task GetStation()
        {
            //Load all data
            if (StaticData.MapVm.AllBus == null)
            {
                StaticData.MapVm.AllBus = await StorageHelper.Json2Object <ObservableCollection <BusTotal> >("data.json");
            }

            //Get bus id
            string html = await NetwordMethod.GetHttpAsString("http://mapbus.ebms.vn/routeoftrunk.aspx");

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);

            var nodes =
                doc.DocumentNode
                .Descendants("select").ToList()[0];

            Notify("Started get route id", true);

            for (int index = 1; index < nodes.ChildNodes.Count; index = index + 3)
            {
                HtmlNode htmlNode    = nodes.ChildNodes[index];
                int      id          = Convert.ToInt32(htmlNode.Attributes["value"].Value);
                string   routeNumber = nodes.ChildNodes[index + 1].InnerText.Split(']')[0].TrimStart('[');
                foreach (BusTotal busTotal in StaticData.MapVm.AllBus)
                {
                    if (busTotal.TextInfo.RouteNumber == routeNumber)
                    {
                        busTotal.RouteId = id;
                        Notify("Route: " + busTotal.TextInfo.RouteName);
                    }
                }
            }

            foreach (BusTotal busTotal in StaticData.MapVm.AllBus)
            {
                //Go direction

                busTotal.GoStationList = new ObservableCollection <BusStation>();

                html =
                    await
                    NetwordMethod.GetHttpAsString(
                        "http://mapbus.ebms.vn/ajax.aspx?action=listRouteStations&isgo=true&rid=" +
                        busTotal.RouteId);

                if (html == "null")
                {
                    continue;
                }

                JObject j = JObject.Parse(html);
                RawBusStationRootObject r = j.ToObject <RawBusStationRootObject>();

                foreach (ROW row in r.TABLE[0].ROW)
                {
                    BusStation b = new BusStation
                    {
                        StationId = Convert.ToInt32(row.COL[1].DATA),
                        MiniRoute = row.COL[3].DATA,
                        U1        = row.COL[4].DATA,
                        No        = Convert.ToInt32(row.COL[5].DATA),
                        U2        = row.COL[6].DATA,
                        Name      = row.COL[7].DATA,
                        Lon       = row.COL[8].DATA,
                        Lat       = row.COL[9].DATA,
                        Address   = row.COL[12].DATA,
                        CodeName  = row.COL[13].DATA
                    };

                    try
                    {
                        b.NextStationId = Convert.ToInt32(row.COL[2].DATA);
                    }
                    catch
                    {
                        // ignored
                    }

                    busTotal.GoStationList.Add(b);
                    Notify("New station added: Go: " + b.Name);
                }

                //Back direction
                busTotal.BackStationList = new ObservableCollection <BusStation>();
                html =
                    await
                    NetwordMethod.GetHttpAsString(
                        "http://mapbus.ebms.vn/ajax.aspx?action=listRouteStations&isgo=false&rid=" +
                        busTotal.RouteId);

                j = JObject.Parse(html);
                r = j.ToObject <RawBusStationRootObject>();

                foreach (ROW row in r.TABLE[0].ROW)
                {
                    BusStation b = new BusStation
                    {
                        StationId = Convert.ToInt32(row.COL[1].DATA),
                        MiniRoute = row.COL[3].DATA,
                        U1        = row.COL[4].DATA,
                        No        = Convert.ToInt32(row.COL[5].DATA),
                        U2        = row.COL[6].DATA,
                        Name      = row.COL[7].DATA,
                        Lon       = row.COL[8].DATA,
                        Lat       = row.COL[9].DATA,
                        Address   = row.COL[12].DATA,
                        CodeName  = row.COL[13].DATA
                    };

                    try
                    {
                        b.NextStationId = Convert.ToInt32(row.COL[2].DATA);
                    }
                    catch
                    {
                        // ignored
                    }

                    busTotal.BackStationList.Add(b);
                    Notify("New station added: Back: " + b.Name);
                }

                Notify("BUS: " + busTotal.TextInfo.RouteNumber + " COMPLETED: ALL STATION ADDED");
            }

            await StorageHelper.Object2Json(StaticData.MapVm.AllBus, "data.json");
        }
示例#2
0
        private async Task GetRoute()
        {
            //Load all data
            if (StaticData.MapVm.AllBus == null)
            {
                StaticData.MapVm.AllBus = await StorageHelper.Json2Object <ObservableCollection <BusTotal> >("data.json");
            }

            foreach (BusTotal busTotal in StaticData.MapVm.AllBus)
            {
                //Go Direction
                busTotal.GoRoute = new ObservableCollection <BasicGeoposition>();

                string html =
                    await
                    NetwordMethod.GetHttpAsString(
                        "http://mapbus.ebms.vn/ajax.aspx?action=GetFullRoute&isgo=true&rid=" + busTotal.RouteId);

                if (!string.IsNullOrEmpty(html))
                {
                    html = html.Trim();
                    string[] goRoute = html.Split(' ');
                    foreach (string s in goRoute)
                    {
                        if (string.IsNullOrEmpty(s) || string.IsNullOrWhiteSpace(s))
                        {
                            continue;
                        }
                        BasicGeoposition b = new BasicGeoposition
                        {
                            Latitude  = Convert.ToDouble(s.Split(',')[1]),
                            Longitude = Convert.ToDouble(s.Split(',')[0])
                        };
                        busTotal.GoRoute.Add(b);
                    }
                }

                //Back Direction
                busTotal.BackRoute = new ObservableCollection <BasicGeoposition>();

                html =
                    await
                    NetwordMethod.GetHttpAsString(
                        "http://mapbus.ebms.vn/ajax.aspx?action=GetFullRoute&isgo=false&rid=" + busTotal.RouteId);

                if (!string.IsNullOrEmpty(html))
                {
                    html = html.Trim();
                    string[] backRoute = html.Split(' ');
                    foreach (string s in backRoute)
                    {
                        if (string.IsNullOrEmpty(s) || string.IsNullOrWhiteSpace(s))
                        {
                            continue;
                        }
                        BasicGeoposition b = new BasicGeoposition
                        {
                            Latitude  = Convert.ToDouble(s.Split(',')[1]),
                            Longitude = Convert.ToDouble(s.Split(',')[0])
                        };
                        busTotal.BackRoute.Add(b);
                    }
                }

                Notify("New route added: " + busTotal.TextInfo.RouteNumber);
            }

            await StorageHelper.Object2Json(StaticData.MapVm.AllBus, "data.json");
        }
示例#3
0
        private async Task GetBusInfo()
        {
            string html = await NetwordMethod.GetHttpAsString("http://buyttphcm.com.vn/TTLT.aspx");

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);

            var nodes =
                doc.DocumentNode
                .Descendants("select")
                .First(d => d.Attributes.Contains("id") &&
                       d.Attributes["id"].Value == "ctl00_ContentPlaceHolder1_DropDownList1")
                .Descendants("option")
                .ToList();

            StaticData.MapVm.AllBus = new ObservableCollection <BusTotal>();

            for (int index = 1; index < nodes.Count; index++)
            {
                HtmlNode htmlNode = nodes[index];
                BusTotal b        = new BusTotal
                {
                    Id       = index,
                    TextInfo = new BusTextInfo {
                        RouteNumber = htmlNode.Attributes["value"].Value
                    }
                };

                string[] temp = WebUtility.HtmlDecode(htmlNode.NextSibling.InnerText).Split('-');
                string   r    = "";
                foreach (string s in temp)
                {
                    try
                    {
                        // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                        Convert.ToInt32(s.Trim());
                    }
                    catch (Exception)
                    {
                        r = r + "-" + s;
                    }
                }

                b.TextInfo.RouteName = r.TrimStart(' ', '-');
                StaticData.MapVm.AllBus.Add(b);

                Notify("New bus info added: " + b.TextInfo.RouteNumber + " " + b.TextInfo.RouteName);
            }

            foreach (BusTotal busTotal in StaticData.MapVm.AllBus)
            {
                Notify("Getting data for route: " + busTotal.TextInfo.RouteNumber + " - " + busTotal.TextInfo.RouteName);
                html = await
                       NetwordMethod.GetHttpAsString("http://www.buyttphcm.com.vn/Detail_TTLT.aspx?sl=" +
                                                     busTotal.TextInfo.RouteNumber);

                doc = new HtmlDocument();
                doc.LoadHtml(html);

                nodes =
                    doc.DocumentNode.Descendants("td")
                    .Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value == "conten").ToList();

                busTotal.TextInfo.GoDirection   = WebUtility.HtmlDecode(nodes[4].InnerText);
                busTotal.TextInfo.BackDirection = WebUtility.HtmlDecode(nodes[5].InnerText);
                busTotal.TextInfo.Details       = WebUtility.HtmlDecode(nodes[6].InnerText);
            }

            Notify("Save data");
            await StorageHelper.Object2Json(StaticData.MapVm.AllBus, "data.json");
        }