Exemplo n.º 1
0
        public async void PopulateStops(bool updateDb = false)
        {
            if (stops == null)
            {
                stops = db.GetStops();
            }
            if (updateDb)
            {
                stops.Clear();
                stops = db.GetStops();
            }

            // One task (thread) per each stop
            //var tasks = new List<Task<string>>();
            // Digitransit test
            var tasksDt = new List <Task <string> >();

            // Download XML files for each stop
            foreach (Stop stop in stops)
            {
                Connector connector = new Connector();

                // Reittiopas
                //connector.Url = RequestBuilder.getStopRequest(stop.Code);
                //tasks.Add(connector.GetXmlStringAsync());

                // Digitransit
                string query = QueryBuilder.MakeQuery(stop.GtfsId, QueryBuilder.QueryType.Departures);
                tasksDt.Add(connector.GetGraphQlAsync(query));
            }

            // Contains set of XML files from RO
            //List<string> resultXml = new List<string>(await Task.WhenAll(tasks));
            // Contains set of XML files from DT
            List <string> resultJson = new List <string>(await Task.WhenAll(tasksDt));

            DepartureFragmentEventArgs args = new DepartureFragmentEventArgs();

            if (resultJson.Count == 0)
            {
                args.NoData = true;
            }
            else
            {
                args.NoData = false;
            }

            Parser parser = new Parser();

            //stops = parser.ParseDepartureData(resultXml, stops);
            stops = parser.ParseDepartureDataJson(resultJson, stops);

            // Raise event that we're done here
            onTimeTableUpdated(args);
        }
Exemplo n.º 2
0
 protected void onTimeTableUpdated(DepartureFragmentEventArgs e)
 {
     TimeTableUpdated.Invoke(this, e);
 }