예제 #1
0
        public async void mapItem_Friend(object param)
        {
            if ((App.Current as App).UserLocation != null)
            {
                //Locatie uit gekozen feestje halen.
                User.All item = param as User.All;

                //Tijdelijke locatie aanmaken
                try
                {
                    BasicGeoposition tempbasic = new BasicGeoposition();

                    //Feestlocatie opsplitsen (word opgeslagen als string)
                    Location location = (Location)item.Location;

                    //Locaties omzetten en in de tijdelijke posities opslaan.
                    tempbasic.Latitude  = location.Latitude;
                    tempbasic.Longitude = location.Longitude;

                    //Om de route aan te vragen, heb je een start en een eindpunt nodig. Die moeten er zo uit zien: "waypoint.1=47.610,-122.107".
                    //We gaan deze zelf aanmaken.

                    /*string startstring = "http://dev.virtualearth.net/REST/v1/Routes?wayPoint.1=";//Eerste deel van de url
                     * startstring += (App.Current as App).UserLocation.Coordinate.Point.Position.Latitude.ToString() + "," + (App.Current as App).UserLocation.Coordinate.Point.Position.Longitude.ToString();
                     * startstring += "&waypoint.2=";//Start van het eindpunt
                     * startstring += tempbasic.Latitude.ToString() + "," + tempbasic.Longitude.ToString();//Endpoint
                     * startstring += URL.URLBINGKEY + URL.BINGKEY;*/

                    Geopoint startpunt;
                    //Start en eindpunt ophalen en klaarzetten voor onderstaande vraag
                    if (VindRitFilterVM.SelectedDestination != null)
                    {
                        BasicGeoposition tempDest = new BasicGeoposition();
                        tempDest.Latitude  = ((Location)VindRitFilterVM.SelectedDestination.Location).Latitude;
                        tempDest.Longitude = ((Location)VindRitFilterVM.SelectedDestination.Location).Longitude;
                        startpunt          = new Geopoint(tempDest);
                    }
                    else
                    {
                        startpunt = (App.Current as App).UserLocation.Coordinate.Point;
                    }
                    Geopoint eindpunt = new Geopoint(tempbasic);
                    //De route tussen 2 punten opvragen
                    MapRouteFinderResult routeResult = await MapRouteFinder.GetDrivingRouteAsync(startpunt, eindpunt);

                    if (routeResult.Status == MapRouteFinderStatus.Success)//Het is gelukt, we hebben een antwoord gekregen.
                    {
                        MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
                        viewOfRoute.RouteColor = Color.FromArgb(255, 62, 94, 148);

                        if (item.RouteCommandText == "Toon route")
                        {
                            this.Map.Routes.Clear();
                        }

                        var items = this.Map.Routes;
                        if (items.Count() > 0)
                        {
                            item.RouteCommandText = "Toon route";
                            this.Map.Routes.Clear();
                        }
                        else
                        {
                            item.RouteCommandText = "Clear route";
                            this.Map.Routes.Add(viewOfRoute);
                        }

                        //MapRouteView toevoegen aan de Route Collectie


                        //Fit de mapcontrol op de route
                        await this.Map.TrySetViewBoundsAsync(routeResult.Route.BoundingBox, null, Windows.UI.Xaml.Controls.Maps.MapAnimationKind.Bow);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            UpdateMapOfType(typeof(List <User.All>));
        }
예제 #2
0
        private void StartSocket()
        {
            //to bob
            MainViewVM.socket.On("bob_ACCEPT", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    MainViewVM.LatestSocket = _socket;
                    VindRitBobVM.Request    = VindRitBobVM.Request + 1;

                    Bob_Accept(_socket.From, _socket.ID);
                }
            });

            MainViewVM.socket.On("disconnect", (msg) =>
            {
                LogOff();
            });
            //not implemented
            MainViewVM.socket.On("user_location_NEW", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    Messenger.Default.Send <NavigateTo>(new NavigateTo()
                    {
                        Name = "map_reload",
                    });
                }
            });
            //to bob
            MainViewVM.socket.On("trip_START", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                    Trip currentTrip  = JsonConvert.DeserializeObject <Trip>(_socket.Object.ToString());

                    TripSave(currentTrip);
                }
            });
            //to bob
            MainViewVM.socket.On("trip_DONE", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    if (fromUser != null)
                    {
                        if (fromUser.User.IsBob.Value == true && (bool)_socket.Object2 == true)
                        {
                            Messenger.Default.Send <NavigateTo>(new NavigateTo()
                            {
                                Name = "rating_dialog",
                                View = typeof(VindRit),
                                Data = _socket.Object
                            });
                        }
                        else
                        {
                            TripDone();
                        }
                    }
                    else
                    {
                        TripDone();
                    }
                }
            });
            //to bob and user
            MainViewVM.socket.On("friend_REQUEST", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    FriendRequest(fromUser);
                }
            });
            MainViewVM.socket.On("friend_ADDED", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    Messenger.Default.Send <Dialog>(new Dialog()
                    {
                        Message = fromUser.User.ToString() + " heeft u vriendschapsverzoek geaccepteerd",
                        ViewOk  = typeof(ZoekVrienden)
                    });
                }
            });



            MainViewVM.socket.On("status_UPDATE", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);

                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //from bob
                    if (VindRitVM.FindID == _socket.ID)
                    {
                        Messenger.Default.Send <NavigateTo>(new NavigateTo()
                        {
                            Name = "get_trip",
                            View = typeof(VindRit)
                        });
                    }
                }
            });

            //to user
            MainViewVM.socket.On("trip_MAKE", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);

                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //from bob
                    if (VindRitVM.FindID == _socket.ID)
                    {
                        User.All fromBob = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                        User.All user    = JsonConvert.DeserializeObject <User.All>(_socket.Object.ToString());
                        Trip newTrip     = (Trip)GetTripObject();

                        if (newTrip != null)
                        {
                            MakeTrip(newTrip, fromBob.Bob.ID.Value);
                        }
                    }
                }
            });
            //to bob and user
            MainViewVM.socket.On("chatroom_OPEN", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add

                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                    int bobsID        = JsonConvert.DeserializeObject <int>(_socket.Object.ToString());


                    OpenChatroom(bobsID);
                }
            });

            MainViewVM.socket.On("chatroom_COMMENT", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    Messenger.Default.Send <NavigateTo>(new NavigateTo()
                    {
                        Name = "newComment"
                    });


                    if ((bool)_socket.Object2 == true && fromUser != null)
                    {
                        Messenger.Default.Send <Dialog>(new Dialog()
                        {
                            Message        = fromUser.User.ToString() + " zegt: " + _socket.Object.ToString(),
                            Ok             = "Antwoord",
                            Nok            = "Negeer",
                            ViewOk         = typeof(VindRitChat),
                            ViewNok        = null,
                            ParamView      = false,
                            Cb             = null,
                            IsNotification = true
                        });
                    }
                }
            });
        }