コード例 #1
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

#if !DEBUG
            FlurryWP8SDK.Api.LogPageView();
#endif

            string tripId;

            if (NavigationContext.QueryString.TryGetValue("tripId", out tripId))
            {
                if (!String.IsNullOrEmpty(tripId))
                {
                    IUnitOfWork unitOfWork = SimpleIoc.Default.GetInstance<IUnitOfWork>();

                    Path pinnedPath = unitOfWork.PathRepository.GetPinned(Guid.Parse(tripId), unitOfWork.PublicTransportOperatorRepository.GetAll());
                    User user = unitOfWork.UserRepository.GetUser();

                    List<PathOption> pathOptions = new List<PathOption>();
                    pathOptions.Add(pinnedPath.PathOption);

                    PathResultsModel results = new PathResultsModel(new Address(pinnedPath.LocationText, pinnedPath.LocationText, pinnedPath.Location), new Address(pinnedPath.DestinationText, pinnedPath.DestinationText, pinnedPath.Destination), pathOptions, SimpleIoc.Default.GetInstance<IBumbleApiService>(), user);

                    SimpleIoc.Default.Unregister<PathResultsModel>();

                    SimpleIoc.Default.Register<PathResultsModel>(() =>
                    {
                        return results;
                    });

                    SimpleIoc.Default.Unregister<TripResultsModel>();

                    SimpleIoc.Default.Register<TripResultsModel>(() =>
                    {
                        return new TripResultsModel();
                    });
                }
            }
           
            NavigationContext.QueryString.Clear();
        }
コード例 #2
0
        private void ContinuePreviousTrip()
        {
            if (ContrinuePreviousTripImageOption == "/Images/64/W/TripKarmaWhite.png")
            {
                // Check if we must load last trip from the database first.
                if (!SimpleIoc.Default.ContainsCreated<PathResultsModel>())
                {
                    IEnumerable<Path> paths = UnitOfWork.PathRepository.GetAllCached(UnitOfWork.PublicTransportOperatorRepository.GetAll());

                    List<PathOption> pathOptions = paths.Select(x => x.PathOption).ToList();

                    Path firstPath = paths.First();

                    IEnumerable<TransportMode> modes = UnitOfWork.TransportModeRepository.GetAll();
                    // Attempt to add an uber option.
                    if (modes.Where(x => x.IsEnabled).Select(x => x.ApplicationTransportMode).Contains(ApplicationTransportMode.Taxi)
                        && base.InMemoryApplicationSettingModel.GetSetting(ApplicationSetting.UseUber).Value
                        && !UnitOfWork.UberTripRepository.ExistsCached())
                    {
                        double maxDurationInMinutes = (pathOptions.Where(x => !x.IsUber).SelectMany(x => x.Stages).Max(x => x.EndTime) - DateTime.Now).TotalMinutes;
                        pathOptions.Add(new PathOption(pathOptions.Count(), uberService, firstPath.Location, firstPath.Destination, maxDurationInMinutes, user.UberInfo.AccessToken));
                    }

                    PathResultsModel results = new PathResultsModel(new Address(firstPath.LocationText, firstPath.LocationText, firstPath.Location), new Address(firstPath.DestinationText, firstPath.DestinationText, firstPath.Destination), pathOptions, BumbleApiService, user);

                    if (SimpleIoc.Default.IsRegistered<PathResultsModel>())
                        SimpleIoc.Default.Unregister<PathResultsModel>();

                    SimpleIoc.Default.Register<PathResultsModel>(() =>
                    {
                        return results;
                    });

                    if (SimpleIoc.Default.IsRegistered<TripResultsModel>())
                        SimpleIoc.Default.Unregister<TripResultsModel>();

                    SimpleIoc.Default.Register<TripResultsModel>(() =>
                    {
                        return new TripResultsModel();
                    });
                }

                if (base.InMemoryApplicationSettingModel.GetSetting(ApplicationSetting.SkipTripSelection).Value)
                {
                    this.NavigationService.NavigateTo("/Views/TripDetails.xaml");
                }
                else
                {
                    this.NavigationService.NavigateTo("/Views/TripSelection.xaml");
                }
            }
            else
            {
                // Check if uber trip isn't already in memory
                if (!SimpleIoc.Default.ContainsCreated<UberTrip>())
                {
                    UberTrip uberTrip = UnitOfWork.UberTripRepository.GetAll().FirstOrDefault();

                    if (uberTrip != null)
                    {
                        if (SimpleIoc.Default.IsRegistered<UberTrip>())
                            SimpleIoc.Default.Unregister<UberTrip>();

                        SimpleIoc.Default.Register<UberTrip>(() =>
                        {
                            return uberTrip;
                        });

                        this.NavigationService.NavigateTo("/Views/UberTripDetails.xaml");
                    }
                }
                else
                {
                    this.NavigationService.NavigateTo("/Views/UberTripDetails.xaml");
                }
                
            }
        }
コード例 #3
0
        private void Drumble()
        {
            if (!this.LocationSearchBoxModel.IsValid())
            {
                base.ShowPopup(CustomPopupMessageType.Error, AppResources.WhereToLocationErrorPopupText, AppResources.CustomPopupGenericOkMessage, null);
            }
            else if (!this.DestinationSearchBoxModel.IsValid())
            {
                base.ShowPopup(CustomPopupMessageType.Error, AppResources.WhereToDestinationErrorPopupText, AppResources.CustomPopupGenericOkMessage, null);
            }
            else if (departureTimeCustom != null && departureTimeCustom < DateTime.Now.AddMinutes(-5))
            {
                base.ShowPopup(CustomPopupMessageType.Error, AppResources.WhereToCustomDateErrorPopupText, AppResources.CustomPopupGenericOkMessage, null);
            }
            else
            {
                IEnumerable<TransportMode> modes = UnitOfWork.TransportModeRepository.GetAll();

                if (!modes.Any(x => x.IsEnabled))
                {
                    base.ShowPopup(CustomPopupMessageType.Error, AppResources.WhereToNoModesErrorPopupText, AppResources.CustomPopupGenericOkMessage, null);
                    return;
                }

                IEnumerable<OperatorSetting> operatorSettings = UnitOfWork.OperatorSettingRepository.GetAll();

                if (!operatorSettings.Any(x => x.IsEnabled))
                {
                    base.ShowPopup(CustomPopupMessageType.Error, AppResources.WhereToNoModesErrorPopupText, AppResources.CustomPopupGenericOkMessage, null);
                    return;
                }

                DrumbleButtonIsEnabled = false;
                DrumbleCancelButtonVisibility = Visibility.Visible;
                ShowHeaderLoader();

                Action getPath = async () =>
                {
                    try
                    {
                        DateTime createdDate = DateTime.UtcNow;

                        // Try save a recent trip if user allows it.
                        if (base.InMemoryApplicationSettingModel.GetSetting(ApplicationSetting.StoreRecent).Value)
                        {
                            Recent recentTripLocation = new Recent(this.LocationSearchBoxModel.TripOptions.Location, this.LocationSearchBoxModel.TripOptions.Text, createdDate, createdDate);
                            UnitOfWork.RecentTripRepository.Insert(recentTripLocation);

                            Recent recentTripDestination = new Recent(this.DestinationSearchBoxModel.TripOptions.Location, this.DestinationSearchBoxModel.TripOptions.Text, createdDate, createdDate);
                            UnitOfWork.RecentTripRepository.Insert(recentTripDestination);

                            UnitOfWork.Save();
                        }

                        int? timeOffSetInMinutes = null;
                        DateTime? seletedDepartureDate = null;

                        if (selectedPredefinedDepartureTime != null)
                        {
                            timeOffSetInMinutes = selectedPredefinedDepartureTime.DepartureTimeInMinutes;
                        }
                        else if (departureTimeCustom != null)
                        {
                            seletedDepartureDate = departureTimeCustom.Value.ToUniversalTime();
                        }
                        else
                        {
                            timeOffSetInMinutes = 0;
                        }

                        List<string> excludedModes = modes.Where(x => x.IsEnabled == false).Select(x => x.ApplicationTransportMode.ToString()).ToList();
                        List<string> excludedOperators = operatorSettings.Where(x => x.IsEnabled == false).Select(x => x.OperatorName).ToList();

                        cancellationTokenSource = new CancellationTokenSource();

                        IEnumerable<PathOption> pathOptionResults = await BumbleApiService.Path(cancellationTokenSource.Token, UnitOfWork.UserRepository.GetUser(), this.LocationSearchBoxModel.TripOptions.Location, this.DestinationSearchBoxModel.TripOptions.Location, isDeparting, seletedDepartureDate, timeOffSetInMinutes, excludedModes, excludedOperators);

                        List<PathOption> pathOptions = pathOptionResults.ToList();

                        // Attempt to add an uber option.
                        if (modes.Where(x => x.IsEnabled).Select(x => x.ApplicationTransportMode).Contains(ApplicationTransportMode.Taxi)
                            && base.InMemoryApplicationSettingModel.GetSetting(ApplicationSetting.UseUber).Value
                            && !UnitOfWork.UberTripRepository.ExistsCached())
                        {
                            double maxDurationInMinutes = (!pathOptions.Any()) ? 0 : (pathOptions.Where(x => !x.IsUber).SelectMany(x => x.Stages).Max(x => x.EndTime) - DateTime.Now).TotalMinutes;
                            pathOptions.Add(new PathOption(pathOptions.Count(), uberService, LocationSearchBoxModel.TripOptions.Location, DestinationSearchBoxModel.TripOptions.Location, maxDurationInMinutes, (user.UberInfo == null) ? null : user.UberInfo.AccessToken));
                        }

                        if (!pathOptions.Any())
                        {
                            base.ShowPopup(CustomPopupMessageType.Information, AppResources.WhereToNoResultsFound, AppResources.CustomPopupGenericOkMessage, null);

                            HideHeaderLoader();
                            DrumbleButtonIsEnabled = true;
                            DrumbleCancelButtonVisibility = Visibility.Collapsed;
                            return;
                        }

                        DateTime startDate = DateTime.Now;
                        UnitOfWork.PathRepository.RemoveAll();
                        UnitOfWork.Save();

                        foreach (PathOption pathOption in pathOptions.Where(x => !x.IsUber))
                        {
                            if (pathOption.EndTime != null)
                                UnitOfWork.PathRepository.Insert(new Path(pathOption.TripId, startDate, pathOption.EndTime.Value, LocationSearchBoxModel.TripOptions.Text, DestinationSearchBoxModel.TripOptions.Text, LocationSearchBoxModel.TripOptions.Location, DestinationSearchBoxModel.TripOptions.Location, false, pathOption.JsonSerializedObject, pathOption.Order));
                        }

                        UnitOfWork.Save();

                        PathResultsModel results = new PathResultsModel(this.LocationSearchBoxModel.TripOptions.Address, this.DestinationSearchBoxModel.TripOptions.Address, pathOptions, BumbleApiService, user);

                        SimpleIoc.Default.Unregister<PathResultsModel>();

                        SimpleIoc.Default.Register<PathResultsModel>(() =>
                        {
                            return results;
                        });

                        SimpleIoc.Default.Unregister<TripResultsModel>();

                        SimpleIoc.Default.Register<TripResultsModel>(() =>
                        {
                            return new TripResultsModel();
                        });

                        if (base.InMemoryApplicationSettingModel.GetSetting(ApplicationSetting.SkipTripSelection).Value)
                        {
                            this.NavigationService.NavigateTo("/Views/TripDetails.xaml");
                        }
                        else
                        {
                            this.NavigationService.NavigateTo("/Views/TripSelection.xaml");
                        }
                    }
                    catch (Exception e)
                    {
                        if (e.Message != "Cancelled")
                            base.ShowPopup(CustomPopupMessageType.Error, e.Message, AppResources.CustomPopupGenericOkMessage, null);
                    }

                    HideHeaderLoader();
                    DrumbleButtonIsEnabled = true;
                    DrumbleCancelButtonVisibility = Visibility.Collapsed;
                };

                DispatcherHelper.CheckBeginInvokeOnUI(getPath);
            }
        }