public static async Task test()
        {
            Console.WriteLine("Start");

            var context     = new WienerLinienContext("O56IE8eH7Kf5R5aQ");
            var allStations = await Stations.GetAllStationsAsync();

            //initialize the RealtimeData object using the created context
            var rtd = new RealtimeData(context);

            var listRbls = new List <int>();

            foreach (var v in allStations)
            {
                if (v.Name.Equals("Pilgramgasse"))
                {
                    foreach (var v2 in v.Platforms)
                    {
                        if (v2.Name.Equals("12A"))
                        {
                            listRbls.Add(v2.RblNumber);
                        }
                    }
                    break;
                }
            }

            //Create a Parameters object to include the Rbls  and get Realtime Data for them
            var parameters = new Parameters.MonitorParameters()
            {
                Rbls = listRbls
            };

            //Get the monitor informatino asynchronous, and save them as MonitorData class
            var monitorInfo = await rtd.GetMonitorDataAsync(parameters);

            foreach (var v in monitorInfo.Data.Monitors)
            {
                foreach (var v2 in v.Lines)
                {
                    Console.WriteLine();
                    Console.WriteLine(v2.Name);
                    foreach (var v3 in v2.Departures.Departure)
                    {
                        Console.WriteLine(v3.DepartureTime.Countdown);
                    }
                    Console.WriteLine();
                }
            }

            //Get the planned arrival time for the first line and the next vehicle arriving (index at Departure)
            //var plannedTime = monitorInfo.Data.Monitors[0].Lines[0].Departures.Departure[0].DepartureTime.TimePlanned;


            Console.WriteLine("Finished");
            Console.ReadKey();
        }
Exemple #2
0
        public async Task GetMonitorData()
        {
            var wlc      = new WienerLinienContext("VgIHscNiquj8LYbV");
            var stations = await Stations.GetAllStationsAsync();

            var firstFive = stations.Take(4);
            var rtd       = new RealtimeData.RealtimeData(wlc);
            var listRbls  = firstFive.Select(item => item.Platforms[0].RblNumber).ToList();
            var mp        = new Parameters.MonitorParameters {
                Rbls = listRbls
            };
            var data = await rtd.GetMonitorDataAsync(mp);

            var a = data.Data.Monitors[0].Lines[0].Departures.Departure[0].DepartureTime.TimePlanned;

            Assert.IsFalse(data.Data.IsNull());
        }
        public static async Task <Dictionary <string, string> > GetDirections(string station, string line)
        {
            if (stations == null)
            {
                stations = await Stations.GetAllStationsAsync();
            }
            Console.WriteLine("Station=" + station + "&line=" + line + "&type=");
            var directions = (from v in stations
                              where v.Name == station
                              from p in v.Platforms
                              where p.Name == line
                              select p.RblNumber.ToString()).ToList();

            var rbls = directions.Select(int.Parse).ToList();

            var rtd = new RealtimeData.RealtimeData(Context);

            var parameters = new Parameters.MonitorParameters()
            {
                Rbls = rbls
            };
            var monitorInfo = await rtd.GetMonitorDataAsync(parameters);

            Data = monitorInfo;
            var strings = new  Dictionary <string, string>();
            var b       =
                monitorInfo.Data.Monitors.Where(i => i.Lines[0].Direction == "R" && i.Lines[0].Name == line).ToList();

            if (b.Count > 0)
            {
                strings.Add("R", ReplaceString(b.Select(i => i.Lines[0].Towards)
                                               .ToList()
                                               .First() + " "));
            }
            var c =
                monitorInfo.Data.Monitors.Where(i => i.Lines[0].Direction == "H" && i.Lines[0].Name == line).ToList();

            if (c.Count > 0)
            {
                strings.Add("H", ReplaceString(c.Select(i => i.Lines[0].Towards)
                                               .ToList()
                                               .First() + " "));
            }
            return(strings);
        }
        public async Task <MonitorData> GetMonitorDataAsync(Parameters.MonitorParameters parameters)
        {
            #region "Parameter check"
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            #endregion

            var url = parameters.GetStringFromParameters(MonitorApiLink, _apiKey);
            if (_client == null)
            {
                _client = new HttpClient();
            }

            var response = await _client.GetStringAsync(url).ConfigureAwait(false);

            var deserialized = JsonConvert.DeserializeObject <MonitorData>(response);
            if (deserialized.Message != null && !deserialized.Message.Value.Equals("OK"))
            {
                throw new RealtimeError(deserialized.Message.MessageCode);
            }
            return(response != null ? deserialized : null);
        }
        public static async Task test()
        {
            Console.WriteLine("Start");

            var context     = new WienerLinienContext("O56IE8eH7Kf5R5aQ");
            var allStations = await Stations.GetAllStationsAsync();

            //initialize the RealtimeData object using the created context
            var rtd = new RealtimeData(context);

            var listRbls = new List <int>();

            Console.WriteLine("Please enter the desired station (e.g. Pilgramgasse):");
            var station = Console.ReadLine();

            Console.WriteLine();

            // the desired station
            var SelectedStation = allStations.Find(x => station != null && x.Name.Contains(station));

            var listLines = new List <Station.Platform>();

            // gets every line once
            for (int i = 0; i < SelectedStation.Platforms.Count; i++)
            {
                if (i % 2 == 0)
                {
                    listLines.Add(SelectedStation.Platforms.ElementAt(i));
                }
            }

            // lists all possible lines
            listLines.ForEach(x => Console.WriteLine("- " + x.Name));

            Console.WriteLine("\nPlease enter the desired plattform (e.g. 14A):");
            var plattform = Console.ReadLine();;

            var StationLines = SelectedStation.Platforms.FindAll(x => x.Name.Equals(plattform));

            foreach (var x in StationLines)
            {
                listRbls.Add(x.RblNumber);
            }

            //Create a Parameters object to include the Rbls  and get Realtime Data for them
            var parameters = new Parameters.MonitorParameters()
            {
                Rbls = listRbls
            };

            //Get the monitor informatino asynchronous, and save them as MonitorData class
            var monitorInfo = await rtd.GetMonitorDataAsync(parameters);

            foreach (var m in monitorInfo.Data.Monitors)
            {
                foreach (var lineIterate in m.Lines)
                {
                    if (lineIterate.Name.Equals(plattform))
                    {
                        Console.WriteLine();
                        Console.WriteLine(lineIterate.Name + " " + lineIterate.Towards);
                        lineIterate.Departures.Departure.ForEach(x => Console.WriteLine(" " + x.DepartureTime.TimePlanned.Normalize().Substring(11, 5)));
                    }
                }
            }



            //Get the planned arrival time for the first line and the next vehicle arriving (index at Departure)
            //var plannedTime = monitorInfo.Data.Monitors[0].Lines[0].Departures.Departure[0].DepartureTime.TimePlanned;


            Console.WriteLine("Finished");
            Console.ReadKey();
        }