public void PushForward(Route route, StopGroup stop) { lock (ctx) { var originalEntry = ctx.FavoriteEntries.Where(e => e.RouteID == route.ID && e.StopID == stop.ID).Single(); var nextEntry = ctx.FavoriteEntries.Where(e => e.Position > originalEntry.Position).MinBy(e => e.Position.Value); if (nextEntry != null) { int?nextPos = nextEntry.Position; nextEntry.Position = originalEntry.Position; originalEntry.Position = nextPos; ctx.Update(nextEntry); ctx.Update(originalEntry); } } }
public void SetRecentStopAtRoute(Route route, StopGroup stop) { lock (ctx) { var recentEntry = ctx.RecentEntries.SingleOrDefault(e => e.RouteID == route.ID); if (recentEntry != null) { ctx.RecentEntries.DeleteOnSubmit(recentEntry); } var entry = new RecentEntry { Route = route, Stop = stop }; ctx.RecentEntries.InsertOnSubmit(entry); ctx.SubmitChanges(); } }
public static RouteStopTile CreateTileBackgroundControl(StopGroup stop, Route route, Tuple <DateTime, Trip>[] timeTable, DateTime now) { var tileControl = new RouteStopTile { RouteShortName = route.RouteGroup.Name, RouteDirName = route.Name, StopName = stop.Name }; DateTime hourNow = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0); var hourGroups = timeTable.Where(x => x.Item1 >= hourNow).GroupBy(x => (int)(x.Item1 - hourNow).TotalHours).ToList(); int[] hours = hourGroups.Select(x => int.Parse(x.First().Item1.HourString())).ToArray(); int[][] minutes = hourGroups.Select(x => x.Select(y => y.Item1.Minute).ToArray()).ToArray(); tileControl.SetItemSource(hours, minutes); tileControl.FrameRoot.Background = new SolidColorBrush(Colors.Transparent); return(tileControl); }
private async void RecentList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (RecentList.SelectedItem != null) { await Task.Delay(100); RouteGroup selected = RecentList.SelectedItem as RouteGroup; Route route = UserEstimations.BestRoute(selected); StopGroup stop = UserEstimations.BestStop(route); if (RecentSelected != null) { RecentSelected(this, new TimetableParameter { Route = route, Stop = stop }); } RecentList.SelectedItem = null; } }
public WayModel(Way way, StopGroup source, StopGroup target, DateTime startDateTime) : base(way.Select(entry => new EntryModel(entry, startDateTime.Date))) { Way = way; EndStop = target; StartStop = source; StartDateTime = startDateTime; Colors = way.Select(e => e.Route.RouteGroup.BgColor).Distinct().ToArray(); if (way.TotalTransferCount >= 0) { RoutesText = String.Join(" " + (char)8594 + " ", Way.Select(x => x.Route.RouteGroup.Name)); } else { RoutesText = Services.Resources.LocalizedStringOf("PlanningWalk"); } }
public static async Task <bool> CreateTile(StopGroup stop, Route route, Grid temporaryContainer = null) { string tileName = "stoproute" + stop.ID + "-" + route.ID; string tileArg = String.Format("{0}-{1}", route.ID, stop.ID); var tiles = await SecondaryTile.FindAllAsync(); if (tiles.Any(t => t.Arguments == tileArg)) { return(false); } int tileId = 0; if (tiles.Any()) { tileId = tiles.Max(tile => int.Parse(tile.TileId)) + 1; } DateTime now = DateTime.Now; var timeTable = App.TB.Logic.GetTimetable(route, stop, now); var control = AppTileUpdater.CreateTileBackgroundControl(stop, route, timeTable, now); temporaryContainer.Children.Insert(0, control); StorageFile imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(tileName + ".png", Windows.Storage.CreationCollisionOption.ReplaceExisting); await AppTileUpdater.RenderTileImage(control, imageFile, control.FrameRoot.Width, control.FrameRoot.Height); temporaryContainer.Children.Remove(control); var secondaryTile = new SecondaryTile( tileId: tileId.ToString(), displayName: " ", arguments: tileArg, square150x150Logo: new Uri("ms-appdata:///local/" + tileName + ".png"), desiredSize: TileSize.Square150x150 ); bool isPinned = await secondaryTile.RequestCreateAsync(); return(isPinned); }
private void PlanBtn_Click(object sender, RoutedEventArgs e) { StopGroup source = null, dest = null; var sourceModel = (StopPicker.StopModel)SourceBox.Selected; if (sourceModel != null) { source = sourceModel.Value; } var destModel = (StopPicker.StopModel)DestBox.Selected; if (destModel != null) { dest = destModel.Value; } if (source == null) { new MessageDialog("A kiindulási megálló nem található. Kérem adja meg újra!").ShowAsync(); return; } if (dest == null) { new MessageDialog("A cél megálló nem található. Kérem adja meg újra!").ShowAsync(); return; } DateTime selectedTime = selectedDay + TimeSpan.FromHours((int)HourBox.SelectedItem) + TimeSpan.FromMinutes(int.Parse((string)MinuteBox.SelectedItem)); PlanningTimeType planningType = TypeBox.SelectedIndex == 0 ? PlanningTimeType.Departure : PlanningTimeType.Arrival; Frame.Navigate(typeof(PlanningPage), new PlanningParameter { SourceStop = source, DestStop = dest, DateTime = selectedTime, PlanningType = planningType }); }
public static async Task UpdateTile(Route route, StopGroup stop, Grid containerGrid = null, SecondaryTile tile = null, bool doFlush = false) { DateTime now = DateTime.Now; int routeId = route.ID, stopId = stop.ID; var timeTable = TransitBaseComponent.Current.Logic.GetTimetable(route, stop, now); var control = await CreateStaticTileBackgroundControl(stop, route, timeTable, now); if (doFlush) { route = null; stop = null; timeTable = null; TransitBaseComponent.Current.Flush(); } string imageFileName = "stoproute" + stopId + "-" + routeId + ".png"; StorageFile imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(imageFileName, Windows.Storage.CreationCollisionOption.ReplaceExisting); if (containerGrid != null) { containerGrid.Children.Insert(0, control); } await RenderTileImage(control, imageFile, control.Width, control.Height); if (containerGrid != null) { containerGrid.Children.Remove(control); } if (tile == null) { var tiles = await SecondaryTile.FindAllAsync(); string tileArg = String.Format("{0}-{1}", routeId, stopId); tile = tiles.First(t => t.Arguments == tileArg); } tile.VisualElements.Square150x150Logo = new Uri("ms-appdata:///local/" + imageFileName); await tile.UpdateAsync(); }
public async Task PlanAsync(StopGroup sourceStop, StopGroup targetStop, DateTime pickedDateTime, PlanningTimeType planningType) { if (planningInProgress) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningInProgress")); return; } if (!CommonComponent.Current.OfflinePlanningEnabled) { bool hasConnection = await CheckConnectionProcess.RunAsync(); if (!hasConnection) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningNoAccess")); return; } } planningInProgress = true; await planAsync(sourceStop, targetStop, pickedDateTime, planningType); planningInProgress = false; }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); token = (DialogToken)e.Parameter; this.routeGroup = token.OriginalRoute.RouteGroup; this.routes = routeGroup.Routes.ToList(); this.stop = token.OriginalStop; this.routeIndex = routes.IndexOf(token.OriginalRoute); if (stop == null) { this.stop = await UserEstimations.BestStopAsync(token.OriginalRoute); } DataContext = this; TextName.Text = routeGroup.Description.Replace(" / ", "\n"); setName(); setContent(); //Animations.FadeInFromBottomAfter(ContentListView, this, 25); }
private void ContentListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ContentListView.SelectedItem != null && ContentListView.SelectedItem is RouteModel) { RouteModel route = ContentListView.SelectedItem as RouteModel; StopGroup stop = route.Stop.Group; string uri = null; if (route.NextTripTime != null) { uri = "/TripPage.xaml?tripID=" + route.NextTrip.ID + "&routeID=" + route.NextTrip.Route.ID + "&stopID=" + stop.ID + "&nexttrips=true" + postQuery; } else { uri = "/TimetablePage.xaml?stopID=" + stop.ID + "&routeID=" + route.Route.ID; if (!ViewModel.CurrentTime) { uri += "&selectedTime=" + ViewModel.StartTime.ToString(); } } NavigationService.Navigate(new Uri(uri, UriKind.Relative)); ContentListView.SelectedItem = null; } }
public void Add(Route route, StopGroup stop) { lock (ctx) { if (Contains(route, stop)) { throw new DuplicateKeyException(null); } int position = 1; if (ctx.FavoriteEntries.FirstOrDefault() != null) { position = ctx.FavoriteEntries.Max(fav => fav.Position ?? 0) + 1; } FavoriteEntry entry = new FavoriteEntry { Route = route, Stop = stop, Position = position }; ctx.FavoriteEntries.InsertOnSubmit(entry); ctx.SubmitChanges(); } }
public void Add(Route route, StopGroup stop) { lock (ctx) { if (Contains(route, stop)) { throw new InvalidOperationException("Duplicate key at Favorites.Add"); } var table = ctx.FavoriteEntries; int position = 1; if (table.FirstOrDefault() != null) { position = table.Max(fav => fav.Position ?? 0) + 1; } FavoriteEntry entry = new FavoriteEntry { Route = route, Stop = stop, Position = position }; ctx.Insert(entry); } }
private void UpdateEditForm() { if (selectedStopId == null) { editForm.gameObject.SetActive(false); return; } StopGroup group = GetStopGroupById(selectedStopId); if (group == null) { selectedStopId = null; editForm.gameObject.SetActive(false); return; } group.stop.SetSelected(true); editForm.Populate(group.value, (T value) => { changeStopValueRequested?.Invoke(selectedStopId, value); }); editForm.gameObject.SetActive(true); }
public void AddPlanningHistory(StopGroup stop, bool isSource) { lock (ctx) { DateTime now = DateTime.Now; var q = from e in ctx.PlanningHistoryEntries where e.StopID == stop.ID && e.IsSource == isSource select e; PlanningHistoryEntry entry = q.SingleOrDefault(e => e.IsActive(now)); if (entry != null) { entry.RawCount = entry.RawCount + (1 << FloatingBits); ctx.Update(entry); } else { entry = new PlanningHistoryEntry(now) { Stop = stop, RawCount = 1 << FloatingBits, IsSource = isSource }; ctx.Insert(entry); } } }
public void AddStopHistory(StopGroup stop) { lock (ctx) { DateTime now = DateTime.Now; var q = from e in ctx.StopHistoryEntries where e.StopID == stop.ID select e; StopHistoryEntry entry = q.SingleOrDefault(e => e.IsActive(now)); if (entry != null) { entry.RawCount = entry.RawCount + (1 << FloatingBits); ctx.Update(entry); } else { entry = new StopHistoryEntry(now) { Stop = stop, RawCount = 1 << FloatingBits }; ctx.Insert(entry); } } }
public void AddTimetableHistory(Route route, StopGroup stop, int weight = 1) { lock (ctx) { DateTime now = DateTime.Now; var q = from e in ctx.HistoryEntries where e.RouteID == route.ID && e.StopID == stop.ID select e; HistoryEntry entry = q.SingleOrDefault(x => x.IsActive(now)); if (entry != null) { entry.RawCount = entry.RawCount + (weight << FloatingBits); ctx.Update(entry); } else { entry = new HistoryEntry(now) { Route = route, Stop = stop, RawCount = weight << FloatingBits }; ctx.Insert(entry); } } }
public override void Bind(IMapControl page, object parameter) { base.Bind(page, parameter); base.RegisterElementTypes(typeof(StopPopup), typeof(StopPushpin)); stopParam = (StopParameter)parameter; if (stopParam.StopGroup != null) { this.stopGroup = stopParam.StopGroup; this.mainStops = new HashSet <Stop>(stopGroup.Stops); this.mainPoints = mainStops.Select(s => s.Coordinate).ToArray(); } else { this.fromMainPage = true; if (StopTransfers.LastNearestStop != null) { this.mainPoints = StopTransfers.LastNearestStop.Stop.Group.Stops.Select(s => s.Coordinate).ToArray(); } } if (stopParam.Location != null) { //this.postQuery.Add("location", locationStr); if (!stopParam.Location.IsNear) { this.sourceStop = stopParam.Location.Stop; this.location = sourceStop.Coordinate; } else { this.location = CurrentLocation.Last; isNear = true; } } if (stopParam.DateTime != null) { //this.postQuery.Add("dateTime", dateTimeStr); this.dateTime = stopParam.DateTime.Value; isNow = false; } if (isNow) { timeUpdaterTask = new PeriodicTask(DoTimeUpdate); timeUpdaterTask.RunEveryMinute(); } if (isNear) { locationUpdaterTask = new PeriodicTask(10000, DoLocationUpdate); locationUpdaterTask.Run(delay: 1000); } //foreach (var transfer in transfers) //{ // Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline // { // StrokeColor = Colors.Gray, // StrokeDashed = true, // StrokeThickness = 8 // }; // line.Path.Add(transfer.Origin.Coordinate); // line.Path.AddRange(transfer.InnerPoints.Select(p => new GeoCoordinate(p.Latitude, p.Longitude))); // line.Path.Add(transfer.Target.Coordinate); // Map.MapElements.Add(line); //} this.EmptyMapTap += (sender, args) => clearSelection(); this.MapElementTap += (sender, element) => { if (element is StopPushpin) { tapActions[element].Invoke(); } }; var boundAddition = isNear ? new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation } : new GeoCoordinate[0]; var boundaries = calculateBoundaries(mainPoints.Concat(boundAddition)); SetBoundaries(page, boundaries, stopParam.StopGroup == null); }
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(); } } }
private void addStopLabels(MapPage page, List <IGrouping <GeoCoordinate, Stop> > mapPoints, double priorityLimit = double.MaxValue) { foreach (var position in mapPoints) { var stops = position.ToList(); bool isCurrent = this.mainStops.Intersect(stops).Count() > 0; var control = StopPushpin.Create(position.Key, isCurrent, stops, this.dateTime, this.location, this.sourceStop, !isCurrent); if (control != null && control.Priority <= priorityLimit) { this.addedPushpins.Add(control); this.markedStops.UnionWith(stops); control.StopClicked += (sender, stop) => { page.NavigationService.Navigate(new Uri("/StopPage.xaml?id=" + stop.Group.ID + getPostQuery((sender as StopPushpin).IsDistanceIgnored), UriKind.Relative)); }; control.TripClicked += (sender, route) => { StopGroup stop = route.Stop.Group; string uri = null; if (route.NextTripTime != null) { uri = String.Format("/TripPage.xaml?tripID={0}&routeID={1}&stopID={2}&nexttrips=true{3}", route.NextTrip.ID, route.NextTrip.Route.ID, stop.ID, getPostQuery((sender as StopPushpin).IsDistanceIgnored)); } else { uri = "/TimetablePage.xaml?stopID=" + stop.ID + "&routeID=" + route.Route.ID; if (dateTime != null) { uri += "&selectedTime=" + dateTime.ToString(); } } page.NavigationService.Navigate(new Uri(uri, UriKind.Relative)); }; //if (fromMainPage) //{ // control.Content.PlanningFromClicked += (sender, args) => // { // MainPage.Current.SetPlanningSource(stops.First().Group); // page.NavigationService.GoBack(); // }; // control.Content.PlanningToClicked += (sender, args) => // { // MainPage.Current.SetPlanningDestination(stops.First().Group); // page.NavigationService.GoBack(); // }; //} MapLayer mapLayer = new MapLayer(); mapLayer.Add(new MapOverlay() { GeoCoordinate = Convert(position.Key), PositionOrigin = new Point(0.5, 0.5), Content = control }); page.Map.Layers.Insert(0, mapLayer); Action currentTapAction = delegate() { if (!control.IsExpanded) { clearSelection(); control.ShowContent(); Selected = control; page.Map.Layers.Remove(mapLayer); page.Map.Layers.Add(mapLayer); } }; tapActions[control] = currentTapAction; //control.Tap += (sender, args) => //{ // currentTapAction(); //}; } } }
public override async void Bind(MapPage page) { base.Bind(page); base.RegisterElementTypes(typeof(StopPushpin)); int stopGroupId = int.Parse(page.NavigationContext.QueryString["stopGroupID"]); if (stopGroupId != 0) { this.stopGroup = App.Model.GetStopGroupByID(stopGroupId); this.mainStops = new HashSet <Stop>(stopGroup.Stops); this.mainPoints = mainStops.Select(s => s.Coordinate).ToArray(); } else { this.fromMainPage = true; if (StopTransfers.LastNearestStop != null) { this.mainPoints = StopTransfers.LastNearestStop.Stop.Group.Stops.Select(s => s.Coordinate).ToArray(); } } string locationStr = null, dateTimeStr = null; if (page.NavigationContext.QueryString.TryGetValue("location", out locationStr)) { this.postQuery.Add("location", locationStr); if (locationStr != "near") { this.sourceStop = App.Model.GetStopByID(int.Parse(locationStr)); this.location = sourceStop.Coordinate; } else { this.location = CurrentLocation.Last; isNear = true; } } if (page.NavigationContext.QueryString.TryGetValue("dateTime", out dateTimeStr)) { this.postQuery.Add("dateTime", dateTimeStr); this.dateTime = System.Convert.ToDateTime(dateTimeStr); isNow = false; } if (isNow) { timeUpdaterTask = new PeriodicTask(DoTimeUpdate); timeUpdaterTask.RunEveryMinute(); page.Tasks.Add(timeUpdaterTask); } if (isNear) { locationUpdaterTask = new PeriodicTask(10000, DoLocationUpdate); locationUpdaterTask.Run(delay: 1000); page.Tasks.Add(locationUpdaterTask); } //foreach (var transfer in transfers) //{ // Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline // { // StrokeColor = Colors.Gray, // StrokeDashed = true, // StrokeThickness = 8 // }; // line.Path.Add(transfer.Origin.Coordinate); // line.Path.AddRange(transfer.InnerPoints.Select(p => new GeoCoordinate(p.Latitude, p.Longitude))); // line.Path.Add(transfer.Target.Coordinate); // Map.MapElements.Add(line); //} this.EmptyMapTap += (sender, args) => clearSelection(); this.MapElementTap += (sender, element) => tapActions[element].Invoke(); var boundAddition = isNear ? new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation } : new GeoCoordinate[0]; var boundaries = calculateBoundaries(mainPoints.Concat(boundAddition)); //await Task.Delay(250); await initializeMapLabels(page); page.Map.SetView(boundaries, MapAnimationKind.None); while (page.Map.ZoomLevel < 15) { page.Map.SetView(boundaries, MapAnimationKind.None); await Task.Delay(100); } //while (page.IsMapEmpty) //{ // initializeMapLabels(page); // await Task.Delay(100); //} page.Map.CenterChanged += async(sender, args) => { await mapFillingLock.WaitAsync(); if (page.Map.ZoomLevel >= App.Config.LowStopsMapLevel) { var newLocation = page.Map.Center; await tryCreateStopLabelsAt(page, Convert(newLocation)); } else if (page.Map.ZoomLevel >= App.Config.HighStopsMapLevel) { var newLocation = page.Map.Center; await tryCreateHighStopLabelsAt(page, Convert(newLocation)); clearMap(page, 2.1); } else { clearMap(page); } mapFillingLock.Release(); }; if (isNear && stopGroupId == 0 && mainPoints.Length == 0) { var nearestResult = await StopTransfers.GetNearestStop(await CurrentLocation.Get()); if (nearestResult != null) { this.location = CurrentLocation.Last; this.mainPoints = nearestResult.Stop.Group.Stops.Select(s => s.Coordinate).ToArray(); boundAddition = new GeoCoordinate[] { CurrentLocation.Last ?? App.Config.CenterLocation }; boundaries = calculateBoundaries(mainPoints.Concat(boundAddition)); page.Map.SetView(boundaries, MapAnimationKind.None); await initializeMapLabels(page); } } }
private async Task planAsync(StopGroup source, StopGroup target, DateTime pickedDateTime, PlanningTimeType planningType) { if (source == null) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningSourceEmpty")); return; } if (target == null) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningTargetEmpty")); return; } //var source = SourceText.Selected; //var target = TargetText.Selected; //var pickedDateTime = DateTimePicker.Time; CommonComponent.Current.UB.History.AddPlanningHistory(source, true); CommonComponent.Current.UB.History.AddPlanningHistory(target, false); FoundRoutes.Clear(); ResultBorderHeight = 0; InProgress = true; await CommonComponent.Current.TB.UsingFiles; Stopwatch watch = Stopwatch.StartNew(); await Task.Run(() => { try { CommonComponent.Current.Planner.SetParams(new PlanningArgs { Type = planningType, EnabledTypes = Convert(new bool[] { PlanSettingsModel.TramAllowed, PlanSettingsModel.MetroAllowed, PlanSettingsModel.UrbanTrainAllowed, PlanSettingsModel.BusAllowed, true, true, true, true }), OnlyWheelchairAccessibleTrips = PlanSettingsModel.WheelchairAccessibleTrips, OnlyWheelchairAccessibleStops = PlanSettingsModel.WheelchairAccessibleStops, LatitudeDegreeDistance = CommonComponent.Current.Config.LatitudeDegreeDistance, LongitudeDegreeDistance = CommonComponent.Current.Config.LongitudeDegreeDistance, WalkSpeedRate = PlanSettingsModel.WalkingSpeed / 3.6 * 60 }); } catch (Exception e) { //Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Services.MessageBox.Show(Services.Localization.StringOf("PlanningError"))); } }); IEnumerable <PlanningAspect> aspects = new PlanningAspect[] { PlanningAspect.Time, PlanningAspect.TransferCount, PlanningAspect.WalkDistance }; //aspects = aspects.Take(CommonComponent.Current.Config.PlanningAspectsCount); //aspects = aspects.Take(1); await Task.WhenAll(aspects.Select(async aspect => { PlannerComponent.Interface.Way middleResult = await Task.Run(() => { try { return(CommonComponent.Current.Planner.CalculatePlanning(source, target, pickedDateTime, aspect)); } catch (Exception e) { //Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Services.MessageBox.Show(Services.Localization.StringOf("PlanningError"))); return(null); } }); if (middleResult != null) { //Services.MessageBox.Show(middleResult.Message); TransitBase.BusinessLogic.Way result = Convert(middleResult, PlanSettingsModel.WalkingSpeedInMps); if (FoundRoutes.All(x => !x.Way.Equals(result))) { int i = 0; while (i < FoundRoutes.Count && FoundRoutes[i].Way < result) { i++; } FoundRoutes.Insert(i, new WayModel(result, source, target, pickedDateTime)); ResultBorderHeight = double.NaN; } } })); InProgress = false; if (FoundRoutes.Count == 0) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningNoResult")); } else { //TimeText.Text = string.Format("{0} ({1:0.##} sec)", Services.Localization.StringOf("PlanningTimeLabel"), watch.ElapsedMilliseconds / 1000.0); //await Task.Delay(3000); //TimeText.Text = ""; } }
private void NearClose_Tap(object sender, System.Windows.Input.GestureEventArgs e) { NearStop = null; }
public override void Initialize(PlanningParameter initialData) { SourceStop = initialData.SourceStop; DestStop = initialData.DestStop; }
public StopGroupDistanceResult(IEnumerable <StopDistanceResult> stopEntries) : base(stopEntries) { AverageDistance = this.Average(e => e.DistanceInMeters); StopGroup = this.First().Stop.Group; }
private void NearClose_Tap(object sender, TappedRoutedEventArgs e) { NearStop = null; }
private async Task planning() { if (SourceText.Selected == null) { MessageBox.Show(AppResources.PlanningSourceEmpty); return; } if (TargetText.Selected == null) { MessageBox.Show(AppResources.PlanningTargetEmpty); return; } StopGroup source = SourceText.Selected; StopGroup target = TargetText.Selected; DateTime pickedDateTime = DateTimePicker.Time; App.UB.History.AddPlanningHistory(source, true); App.UB.History.AddPlanningHistory(target, false); ResultList.ItemsSource.Clear(); ResultBorder.Height = 0; ProgressBar.IsIndeterminate = true; await App.TB.UsingFiles; Stopwatch watch = Stopwatch.StartNew(); await Task.Run(() => { try { App.NativeComponent.SetParams(new PlanningArgs { Type = DateTimePicker.TimeType, EnabledTypes = Convert(new bool[] { PlanSettingsModel.TramAllowed, PlanSettingsModel.MetroAllowed, PlanSettingsModel.UrbanTrainAllowed, PlanSettingsModel.BusAllowed, true, true, true, true }), OnlyWheelchairAccessibleTrips = PlanSettingsModel.WheelchairAccessibleTrips, OnlyWheelchairAccessibleStops = PlanSettingsModel.WheelchairAccessibleStops, LatitudeDegreeDistance = App.Config.LatitudeDegreeDistance, LongitudeDegreeDistance = App.Config.LongitudeDegreeDistance, WalkSpeedRate = PlanSettingsModel.WalkingSpeed / 3.6 * 60 }); } catch (Exception e) { Dispatcher.BeginInvoke(() => MessageBox.Show(AppResources.PlanningError)); } }); IEnumerable <PlanningAspect> aspects = new PlanningAspect[] { PlanningAspect.Time, PlanningAspect.TransferCount, PlanningAspect.WalkDistance }; //aspects = aspects.Take(App.Config.PlanningAspectsCount); //aspects = aspects.Take(1); await Task.WhenAll(aspects.Select(async aspect => { var middleResult = await Task.Run(() => { try { return(App.NativeComponent.CalculatePlanning(source, target, pickedDateTime, aspect)); } catch (Exception e) { Dispatcher.BeginInvoke(() => MessageBox.Show(AppResources.PlanningError)); return(null); } }); if (middleResult != null) { //MessageBox.Show(middleResult.Message); TransitBase.BusinessLogic.Way result = Convert(middleResult, PlanSettingsModel.WalkingSpeedInMps); var resultList = ResultList.ItemsSource as ObservableCollection <WayModel>; if (resultList.All(x => !x.Way.Equals(result))) { int i = 0; while (i < resultList.Count && resultList[i].Way < result) { i++; } resultList.Insert(i, new WayModel(result, source, target, pickedDateTime)); ResultBorder.Height = double.NaN; } } })); ProgressBar.IsIndeterminate = false; if (ResultList.ItemsSource.Count == 0) { MessageBox.Show(AppResources.PlanningNoResult); } else { TimeText.Text = string.Format("{0} ({1:0.##} sec)", AppResources.PlanningTimeLabel, watch.ElapsedMilliseconds / 1000.0); await Task.Delay(3000); TimeText.Text = ""; } }
public Tuple <DateTime, Trip>[] GetCurrentTrips(DateTime currentTime, Route route, StopGroup stopGroup, int prevCount, int nextCount, TimeSpan?limit = null) { return(GetCurrentTrips(currentTime, route, stopGroup.Stops, prevCount, nextCount, limit)); }
public Tuple <DateTime, Trip>[] GetTimetable(Route route, StopGroup stopGroup, DateTime date_) { return(GetTimetable(route, stopGroup.Stops, date_)); }
private void addStopLabels(IMapControl page, IList <IGrouping <GeoCoordinate, Stop> > mapPoints, double priorityLimit = double.MaxValue) { foreach (var position in mapPoints.Reverse()) { var stops = position.ToList(); bool isCurrent = this.mainStops.Intersect(stops).Count() > 0; var control = StopPushpin.Create(page, position.Key, isCurrent, stops, this.dateTime, this.location, this.sourceStop, !isCurrent); if (control != null && control.Priority <= priorityLimit) { this.addedPushpins.Add(control); this.markedStops.UnionWith(stops); control.StopClicked += (sender, stop) => { if (StopGroupSelected != null) { StopGroupSelected(this, createStopGroupParam(stop.Group, (sender as StopPushpin).IsDistanceIgnored)); } }; control.TripClicked += (sender, route) => { StopGroup stop = route.Stop.Group; if (route.NextTripTime != null) { if (TripSelected != null) { TripSelected(this, createTripParam(route.NextTrip, route.Stop, (sender as StopPushpin).IsDistanceIgnored)); } } else { if (TimeTableSelected != null) { TimeTableSelected(this, new TimetableParameter { Stop = stop, Route = route.Route, SelectedTime = dateTime }); } } }; //if (fromMainPage) //{ // control.Content.PlanningFromClicked += (sender, args) => // { // MainPage.Current.SetPlanningSource(stops.First().Group); // page.NavigationService.GoBack(); // }; // control.Content.PlanningToClicked += (sender, args) => // { // MainPage.Current.SetPlanningDestination(stops.First().Group); // page.NavigationService.GoBack(); // }; //} //AddControlToMapAt(0, control, position.Key, new Point(0.5, 0.5)); AddControlToMap(control, position.Key, new Point(0.5, 0.5)); Action currentTappedAction = async delegate() { if (!control.IsExpanded) { clearSelection(); var popup = await control.ShowPopup(); AddControlToMap(popup, position.Key, new Point(0.5, 1)); Selected = control; //BringControlToForeground(control); } }; tapActions[control] = currentTappedAction; //control.Tapped += (sender, args) => //{ // currentTappedAction(); //}; } } }