private async System.Threading.Tasks.Task Authenticate(string accessToken, string fbid) { ProfilePhoto.Background = new ImageBrush() { ImageSource = new BitmapImage(new Uri(String.Format("https://graph.facebook.com/me/picture?access_token={0}&height=100&width=100", accessToken))) }; FacebookSessionInfo sessionInfo = new FacebookSessionInfo(); sessionInfo.FacebookToken = accessToken; sessionInfo.FacebookID = fbid; Geolocator location = new Geolocator(); location.DesiredAccuracy = PositionAccuracy.Default; var usrLocation = await location.GetGeopositionAsync(); TinderSession activeSession = TinderSession.CreateNewSession(sessionInfo, new Position() { Latitude = usrLocation.Coordinate.Latitude, Longitude = usrLocation.Coordinate.Longitude }); if (await activeSession.Authenticate()) { (App.Current as App).RightSideBar.DataContext = activeSession.Matches; TopBarViewModel.ShowTopButtons = System.Windows.Visibility.Visible; NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); App.RootFrame.RemoveBackEntry(); } }
private TinderSession(FacebookSessionInfo fbSession, Position location) { _fbSessionInfo = fbSession; _location = location; }
public static TinderSession CreateNewSession(FacebookSessionInfo fbSession, Position location) { _currentSession = new TinderSession(fbSession, location); return _currentSession; }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <Message> Post([FromBody] Message message) { if (message.Type == "Message") { var reply = message.CreateReplyMessage(); if (message.BotUserData != null) { if (ReadyToTalk) { var keys = App.TinderSessions.Keys.ToList <string>(); if (keys.IndexOf(message.BotUserData.ToString()) >= 0) { TinderSession = App.TinderSessions[message.BotUserData.ToString()]; if (TinderSession.FbSessionInfo == null) { BotSessionSetup = 1; ReadyToTalk = false; } else { BotSessionSetup = 6; switch (message.Text.ToLower()) { case "list": reply = ListMatches(message); break; case "start": this.feedTimer = GetFeedTimer(message.BotUserData.ToString()); if (this.feedTimer != null) { this.feedTimer.Start(); reply.Text = "Hitch bot has started to talk with your matches"; } break; case "stop": this.feedTimer = GetFeedTimer(message.BotUserData.ToString()); if (this.feedTimer != null) { this.feedTimer.Stop(); reply.Text = "Hitch bot has stopped to talk with your matches"; } break; } } } else { reply.Text = MSG_ADD_BOT; BotSessionSetup = 0; ReadyToTalk = false; } } else { while (reply.Text == string.Empty && BotSessionSetup <= 4) { if (FacebookID == string.Empty) { if (BotSessionSetup == 0) { BotSessionSetup = 1; reply.Text = "Add your Facebook ID"; } else { FacebookID = message.Text; } } else if (FacebookToken == string.Empty) { if (BotSessionSetup == 1) { BotSessionSetup = 2; reply.Text = "Add your Facebook Token"; } else { FacebookToken = message.Text; } } else if (Latitude == 0) { if (BotSessionSetup == 2) { BotSessionSetup = 3; reply.Text = "Add your Latitude"; } else { try { Latitude = double.Parse(message.Text); if (Latitude < -85 || Latitude > 85) { reply.Text = "The latitude is out of range, please try enter it again number between -85 and 85"; } } catch { reply.Text = "An Error has occurred during the latitude parsing, please try enter it again"; } } } else { if (BotSessionSetup == 3) { BotSessionSetup = 4; reply.Text = "Add your Longitude"; } else { try { Longitude = double.Parse(message.Text); if (Longitude < -180 || Longitude > 180) { reply.Text = "The longitude is out of range, please try enter it again number between -180 and 180"; } else { BotSessionSetup = 5; } } catch { reply.Text = "An Error has occurred during the longitude parsing, please try enter it again"; } } } } if (BotSessionSetup == 5) { var fbsession = new FacebookSessionInfo(); fbsession.FacebookID = FacebookID; fbsession.FacebookToken = FacebookToken; Position location = new Position(); location.Latitude = Latitude; location.Longitude = Longitude; this.TinderSession = TinderSession.CreateNewSession(fbsession, location); try { //This method besides the authentication, sets the location, calls the update and checks for recommendations await this.TinderSession.Authenticate(); BotSessionSetup = 6; ReadyToTalk = true; reply.Text = $"Your Tinder account is connected to HitchBot! \r\n You have {this.TinderSession.Matches.Count} Matches"; //Update Match status and upload the data do AzureTable await ProcessMatches(); } catch (Exception ex) { reply.Text = $"Some error has occurred: { ex.Message }. Please try adding your facebook and location again"; BotSessionSetup = 1; FacebookID = string.Empty; FacebookToken = string.Empty; Longitude = 0; Latitude = 0; ReadyToTalk = false; } try { App.TinderSessions.Add(message.BotUserData.ToString(), this.TinderSession); } catch (ArgumentException) { //There is an element using the same key, so just update the object and you are okay to go App.TinderSessions[message.BotUserData.ToString()] = this.TinderSession; } } } } else { reply.Text = MessagesController.MSG_ADD_BOT; BotSessionSetup = 0; } return(reply); } else { return(HandleSystemMessage(message)); } }
public static TinderSession CreateNewSession(FacebookSessionInfo fbSession, Position location) { _currentSession = new TinderSession(fbSession, location); return(_currentSession); }