示例#1
0
        private async Task <string> RefreshEstimatedTime(TransferBus bus)
        {
            var tempTimes = await PtxAPI.GetEstimatedTime(bus.Route.RouteName.Zh_tw);

            var tempArrivalTime = new List <string>();
            var allTime         = tempTimes.FindAll(t => t.RouteID == bus.Route.RouteID && t.EstimateTime.HasValue);

            allTime.FindAll(x => x.StopName.Zh_tw == bus.EndStop.Substring(3)).OrderBy(y => y.EstimateTime.Value).ToList().ForEach(
                x =>
            {
                var sec = TimeSpan.FromSeconds(Convert.ToDouble(x.EstimateTime.Value));
                if (sec.TotalSeconds < 10)
                {
                    tempArrivalTime.Add($"即將進站");
                }
                else
                {
                    tempArrivalTime.Add($"{sec.Minutes:D2}分{sec.Seconds:D2}秒");
                }
            });

            while (tempArrivalTime.Count < 2)
            {
                tempArrivalTime.Add("暫無資訊");
            }
            return($"第一班車:{tempArrivalTime[0]}\r\n第二班車:{tempArrivalTime[1]}");
        }
示例#2
0
        private async Task AddEstimatedTimeAndBus(int id, Route route, string startName, string stopName)
        {
            var tempTimes = await PtxAPI.GetEstimatedTime(@route.RouteName.Zh_tw);

            lock (new object())
            {
                var tempArrivalTime = new List <string>();
                var allTime         = tempTimes.FindAll(t => t.RouteID == route.RouteID && t.EstimateTime.HasValue);
                allTime.FindAll(x => x.StopName.Zh_tw == stopName).OrderBy(y => y.EstimateTime.Value).ToList().ForEach(
                    x =>
                {
                    var sec = TimeSpan.FromSeconds(Convert.ToDouble(x.EstimateTime.Value));
                    if (sec.TotalSeconds < 10)
                    {
                        tempArrivalTime.Add($"即將進站");
                    }
                    else
                    {
                        tempArrivalTime.Add($"{sec.Minutes:D2}分{sec.Seconds:D2}秒");
                    }
                });

                while (tempArrivalTime.Count < 2)
                {
                    tempArrivalTime.Add("暫無資訊");
                }

                AddBusToXaml(id, route, startName, stopName, tempArrivalTime);
            }
        }
示例#3
0
        private async void Init()
        {
            var localFolder = ApplicationData.Current.LocalFolder;

            try
            {
                StartTextBox.Visibility   = Visibility.Collapsed;
                EndTextBox.Visibility     = Visibility.Collapsed;
                SendButton.Visibility     = Visibility.Collapsed;
                LoadingIndicator.IsActive = true;

                if (await localFolder.TryGetItemAsync("stops.json") != null && await localFolder.TryGetItemAsync("routes.json") != null)
                {
                    var stopsFile = await localFolder.GetFileAsync("stops.json");

                    var content = await FileIO.ReadTextAsync(stopsFile);

                    App.Stops = JsonConvert.DeserializeObject <List <Stop> >(content);

                    var routesFile = await localFolder.GetFileAsync("routes.json");

                    content = await FileIO.ReadTextAsync(routesFile);

                    App.Routes = JsonConvert.DeserializeObject <List <Route> >(content);
                }
                else
                {
                    StorageFile stopsFile =
                        await localFolder.CreateFileAsync("stops.json", CreationCollisionOption.ReplaceExisting);

                    StorageFile routesFile =
                        await localFolder.CreateFileAsync("routes.json", CreationCollisionOption.ReplaceExisting);

                    App.Stops = await PtxAPI.GetStops();

                    App.Routes = await PtxAPI.GetRoutes();

                    var json = JsonConvert.SerializeObject(App.Stops);
                    await FileIO.WriteTextAsync(stopsFile, json);

                    json = JsonConvert.SerializeObject(App.Routes);
                    await FileIO.WriteTextAsync(routesFile, json);
                }
            }
            finally
            {
                LoadingIndicator.IsActive = false;
                StartTextBox.Visibility   = Visibility.Visible;
                EndTextBox.Visibility     = Visibility.Visible;
                SendButton.Visibility     = Visibility.Visible;
            }
        }