Exemple #1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.NavigationMode == NavigationMode.New)
            {
                string stopID = "", tripID = "", routeID = "", dateStr = "", next = "", loc = "";
                //required parameters
                if (!NavigationContext.QueryString.TryGetValue("stopID", out stopID))
                {
                    throw new FormatException("TimeTable opened without parameter stopID");
                }
                if (!NavigationContext.QueryString.TryGetValue("tripID", out tripID))
                {
                    throw new FormatException("TimeTable opened without parameter tripID");
                }
                if (!NavigationContext.QueryString.TryGetValue("routeID", out routeID))
                {
                    throw new FormatException("TimeTable opened without parameter routeID");
                }

                bool      isTimeSet = false, near = false, hasLocation;
                DateTime? dateTime   = null;
                StopGroup stop       = null;
                Trip      trip       = null;
                Stop      sourceStop = null;
                TransitBase.GeoCoordinate location = null;

                //optional parameters
                if (isTimeSet = NavigationContext.QueryString.TryGetValue("dateTime", out dateStr))
                {
                    dateTime = Convert.ToDateTime(dateStr);
                }
                //else dateTime = DateTime.Now;
                if (hasLocation = NavigationContext.QueryString.TryGetValue("location", out loc))
                {
                    if (loc == "near")
                    {
                        near = true;
                        //location = CurrentLocation.Last;
                    }
                    else
                    {
                        sourceStop = App.Model.GetStopByID(int.Parse(loc));
                        location   = sourceStop.Coordinate;
                    }
                }
                //boolean parameters
                bool nextTripStrip = NavigationContext.QueryString.TryGetValue("nexttrips", out next);
                stop = App.Model.GetStopGroupByID(System.Convert.ToInt32(stopID));
                trip = App.Model.GetTripByID(System.Convert.ToInt32(tripID), System.Convert.ToInt32(routeID));


                ViewModel = new TripViewModel();
                ViewModel.ScrollIntoViewRequired += ViewModel_ScrollIntoViewRequired;
                ViewModel.Initialize(new TripParameter
                {
                    Trip      = trip,
                    NextTrips = nextTripStrip,
                    Stop      = stop,
                    DateTime  = dateTime,
                    Location  = !hasLocation ? null : new ParameterLocation
                    {
                        IsNear = near,
                        Stop   = sourceStop
                    }
                });
                this.DataContext = ViewModel;
                ViewModel.PostInizialize();
                if (ViewModel.TasksToSchedule.Any())
                {
                    contentSetterTask = new PeriodicTask(ViewModel.TasksToSchedule.Single());
                    contentSetterTask.RunEveryMinute(false);
                }
                if (ViewModel.IsTimeStripVisible)
                {
                    addContentToPivot();
                }
                setFavoriteIcon();
            }
            else
            {
                if (contentSetterTask != null)
                {
                    contentSetterTask.Resume();
                }
            }
        }
Exemple #2
0
 public static GeoCoordinate Convert(TransitBase.GeoCoordinate coordinate)
 {
     return(new GeoCoordinate(coordinate.Latitude, coordinate.Longitude));
 }