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 = ""; } }
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 async Task planning() { if (SourceText.Selected == null) { new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningSourceEmpty")).ShowAsync(); return; } if (TargetText.Selected == null) { new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningTargetEmpty")).ShowAsync(); return; } var source = SourceText.Selected; var target = TargetText.Selected; var 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.Planner.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.RunAsync(CoreDispatcherPriority.Normal, () => new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningError")).ShowAsync()); } }); 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 => { MiddleWay middleResult = await Task.Run(() => { try { return(App.Planner.CalculatePlanning(source.ID, target.ID, pickedDateTime.ToString(CultureInfo.InvariantCulture), aspect)); } catch (Exception e) { Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningError")).ShowAsync()); return(null); } }); if (middleResult != null) { //new MessageDialog(middleResult.Message).ShowAsync(); Way result = createWay(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) { new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningNoResult")).ShowAsync(); } else { TimeText.Text = string.Format("{0} ({1:0.##} sec)", App.Common.Services.Resources.LocalizedStringOf("PlanningTimeLabel"), watch.ElapsedMilliseconds / 1000.0); await Task.Delay(3000); TimeText.Text = ""; } }