Example #1
0
        public FBFriends GetFriends(FBUser User)
        {
            try
            {
                long userId = CheckFBUser(User);

                if (userId <= 0)
                {
                    throw new AppException(ErrorCode.INVALID_FB_USER);
                }

                List <long> friendsIds = GetFriendsIds(userId);

                List <FBFriend> friends = new List <FBFriend>();
                foreach (long fId in friendsIds)
                {
                    friends.Add(GetFriend(fId));
                }

                return(new FBFriends()
                {
                    Friends = friends
                });
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                throw new AppException(ErrorCode.SQL_GENERAL_ERROR);
            }
        }
Example #2
0
        public long CheckFBUser(FBUser User)
        {
            IDataReader reader = null;

            try
            {
                bool   isFBUser = !string.IsNullOrEmpty(User.id);
                string query    = string.Format(
                    isFBUser ? BaseQueries.CHECK_FB_USER : BaseQueries.CHECK_USER,
                    isFBUser ? User.id : User.Email);

                reader = ExecuteReader(query);

                using (reader)
                {
                    while (reader.Read())
                    {
                        return(Convert.ToInt64(reader["id"]));
                    }
                }
                return(0);
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                throw new AppException(ErrorCode.SQL_GENERAL_ERROR);
            }
        }
Example #3
0
        public void SetDefault()
        {
#if UNITY_IOS
            appVersion = 1f;
#endif
#if UNITY_ANDROID
            appVersion = 1f;
#endif
            myFBInfo = new FBUser();
#if PUSHNOTIFICATION
            pushToken = string.Empty;
#endif

            isSFX       = true;
            sfxVolume   = 1f;
            isMusic     = true;
            musicVolume = 1f;

            isNeverAskForReview = false;
            isAlreadyRated      = false;

            lastFBShare      = DateTime.Parse("1-Aug-2015 12:00:00");
            lastFBPage       = DateTime.Parse("1-Aug-2015 12:00:00");
            lastTwitterShare = DateTime.Parse("1-Aug-2015 12:00:00");
            lastOtherShare   = DateTime.Parse("1-Aug-2015 12:00:00");
            lastVideoReward  = DateTime.Parse("1-Aug-2015 12:00:00");

            gameLaunchCount = 0;
        }
Example #4
0
        public static void UpdateUserLocation(string id, string location)
        {
            MessageHandler.SenderId = id;
            string address;

            using (var client = new WebClient())
            {
                var json    = JObject.Parse(client.DownloadString(string.Format(MessageEndPoint, location)));
                var results = (JArray)json["results"];
                address = (string)results[0]["formatted_address"];
            }
            var user = db.GetUser(id);

            if (user == null)
            {
                var newUser = new FBUser
                {
                    SessionId      = id,
                    Location       = location,
                    LocationString = address,
                    Currency       = "USD",
                };
                db._db.FBUsers.InsertOnSubmit(newUser);

                db._db.SubmitChanges();
            }
            else
            {
                user.LocationString = address;
                user.Location       = location;
                db._db.SubmitChanges();
            }
            MessageHandler.SendTextMessage($"Location updated to {location}. Although, you may better know it as {address} :D");
        }
Example #5
0
        public override string ToString()
        {
            if (IsNull)// || (!IsLoaded()))
            {
                throw new System.ArgumentException("ToString failed, this is null or not loaded", "this");
            }
            else
            {
                string retStr = UniqueID.ToString();

                retStr += mDelim + FirstName;
                retStr += mDelim + LastName;
                retStr += mDelim + Email;
                retStr += mDelim + Phone;
                retStr += mDelim + FBUser.ToString();
                retStr += mDelim + LastFBSync.ToString();
                retStr += mDelim + ((int)Gender).ToString();
                retStr += mDelim + ((int)Title).ToString();
                retStr += mDelim + mLocation.ToString();

                retStr += mDelim + HoldingsInfo.Count.ToString();
                for (int i = 0; i < HoldingsInfo.Count; i++)
                {
                    retStr += mDelim + HoldingsInfo[i].UniqueID.ToString();
                }

                retStr += mDelim + Events.Count.ToString();
                for (int i = 0; i < Events.Count; i++)
                {
                    retStr += mDelim + Events[i].UniqueID.ToString();
                }

                return(retStr);
            }
        }
Example #6
0
        // Setup for sharing to facebook
        // Adapted from http://microsoft.github.io/winsdkfb/sample/
        private async void MainLogin_Click(object sender, RoutedEventArgs e)
        {
            FBSession sess = FBSession.ActiveSession;

            sess.FBAppId  = "<223139641423993>";
            sess.WinAppId = "<s-1-15-2-3097751537-2617460156-63370106-2036095025-3786947386-1211125068-2096569086>";
            List <String> permissionList = new List <String>();

            permissionList.Add("public_profile");
            permissionList.Add("user_friends");
            permissionList.Add("user_likes");
            permissionList.Add("user_location");
            permissionList.Add("user_photos");
            permissionList.Add("publish_actions");
            FBPermissions permissions = new FBPermissions(permissionList);

            // Login to Facebook
            FBResult result = await sess.LoginAsync(permissions);

            if (result.Succeeded)
            {
                FBUser user = sess.User;
                Debug.WriteLine(sess.User.Id);
                Debug.WriteLine(sess.User.Name);
            }
            else
            {
                //Login failed
            }
        }
Example #7
0
        public JsonResult PostStatus(string msg)
        {
            Session["postStatus"] = msg;


            Facebook facebook = auth.FacebookAuth();

            if (Session["facebookQueryStringValue"] == null)
            {
                string authLink = facebook.GetAuthorizationLink();
                return(Json(authLink));
            }

            if (Session["facebookQueryStringValue"] != null)
            {
                facebook.GetAccessToken(Session["facebookQueryStringValue"].ToString());
                FBUser    currentUser = facebook.GetLoggedInUserInfo();
                IFeedPost FBpost      = new FeedPost();
                if (Session["postStatus"].ToString() != "")
                {
                    FBpost.Message = Session["postStatus"].ToString();
                    facebook.PostToWall(currentUser.id.GetValueOrDefault(), FBpost);
                }
            }
            return(Json("No"));
        }
Example #8
0
 private IEnumerator SetFBStatus(FBUser user)
 {
     FacebookName = user.Name;
     PopulateFriends();
     FacebookImage = new Texture2D(128, 128, TextureFormat.DXT1, false);
     yield return(StartCoroutine(GetFBPicture(user.Id, FacebookImage)));
 }
Example #9
0
        public string SetCurrency(string id, string currency)
        {
            if (!Currency.currencies.ContainsKey(currency))
            {
                return(string.Empty);
            }

            var user = GetUser(id);

            if (user != null)
            {
                user.Currency = currency;
            }
            else
            {
                user = new FBUser()
                {
                    Currency = currency, SessionId = id
                };
                _db.FBUsers.InsertOnSubmit(user);
            }

            _db.SubmitChanges();
            return(user.Currency);
        }
Example #10
0
        void client_GetCompleted(object sender, FacebookApiEventArgs e)
        {
            if (e.Error != null)
            {
                Dispatcher.BeginInvoke(() => MessageBox.Show(e.Error.Message));
                return;
            }
            else
            {
                //SocialAccount account = new SocialAccount(
                //var result = (IDictionary<string, object>)e.GetResultData();
                //var id = (string)result["id"];
                FBUser userAccount = JsonConvert.DeserializeObject <FBUser>(e.GetResultData().ToString());

                SocialAccount socialAccount = new SocialAccount(userAccount.id, client.AccessToken, userAccount.username, null);
                SettingHelper.SetKeyValue <SocialAccount>("SocialAccount", socialAccount);

                Dispatcher.BeginInvoke(() =>
                {
                    FacebookWebBrowser.Visibility = System.Windows.Visibility.Collapsed;
                    StackPanelHeader.Visibility   = System.Windows.Visibility.Visible;
                    ContentPanel.Visibility       = System.Windows.Visibility.Visible;
                });
            }
        }
        private async void FacebookButton_Click(object sender, RoutedEventArgs e)
        {
            FBSession sess = FBSession.ActiveSession;

            sess.FBAppId = "1667835350097099";

            sess.WinAppId = "S-1-15-2-402772943-4257055698-2726507914-3453098009-221101651-2929789630-257638726";

            List <string> permissionList = new List <string>();

            permissionList.Add("public_profile");
            permissionList.Add("user_friends");
            permissionList.Add("user_photos");
            permissionList.Add("publish_actions");
            FBPermissions permissions = new FBPermissions(permissionList);

            FBResult result = await sess.LoginAsync(permissions);

            if (result.Succeeded)
            {
                FBUser user = sess.User;
                Debug.WriteLine("success");

                Debug.WriteLine(user.FirstName);
                Debug.WriteLine(user.LastName);
                Debug.WriteLine(user.Link);
                //  user.Id;
                // UserImage.Fill = Utils.ImageUtils.UrlToFillSource(user.Picture.Data.Url);
            }
            else
            {
                Debug.WriteLine("Fail");
            }
        }
Example #12
0
File: VizDAO.cs Project: radtek/vas
        public FBUser Register(FBUser user)
        {
            try
            {
                long userId = CheckFBUser(user);

                if (userId > 0)
                {
                    throw new AppException(ErrorCode.USER_ALREADY_EXISTS);
                }

                Dictionary <string, object> queryparams = new Dictionary <string, object>();
                queryparams.Add("@first_name", user.FirstName);
                queryparams.Add("@last_name", user.LastName);
                queryparams.Add("@email", user.Email);
                queryparams.Add("@password", user.Password);

                userId = ExecuteNonQueryWithOutputParam(VizQueries.REGISTER_USER, ConvertToDBParameters(queryparams));

                SaveDefaultSettings(userId);
                return(GetUser(userId));
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                throw new AppException(ErrorCode.SQL_GENERAL_ERROR);
            }
        }
Example #13
0
File: VizDAO.cs Project: radtek/vas
        private FBUser GetUser(long userId)
        {
            IDataReader reader = null;

            try
            {
                string query = string.Format(VizQueries.GET_USER, userId);

                reader = ExecuteReader(query);

                FBUser user = new FBUser();
                using (reader)
                {
                    while (reader.Read())
                    {
                        user.FirstName = Convert.ToString(reader["FIRST_NAME"]);
                        user.LastName  = Convert.ToString(reader["LAST_NAME"]);
                        user.Email     = Convert.ToString(reader["EMAIL"]);
                    }
                }
                return(user);
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                throw new AppException(ErrorCode.SQL_GENERAL_ERROR);
            }
        }
Example #14
0
        void AuthHelper_OnDownloadRequestCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
        {
            try
            {
                string result = e.Result;
                FBUser user   = JsonConvert.DeserializeObject <FBUser>(result);

                User userAccout = new User()
                {
                    id_user = Int32.Parse(user.id), name = user.name
                };

                App.CurrentUser = userAccout;

                SettingHelper.SetKeyValue <User>("User", userAccout);

                if (OnLoginCompleted != null)
                {
                    OnLoginCompleted(this, e);
                }
            }
            catch (Exception ex)
            {
                if (OnRegisterError != null)
                {
                    OnRegisterError(this, e);
                }
            }
        }
Example #15
0
    IEnumerator GrabScoreForUser(FBUser fbuser)
    {
        WWW www = new WWW(fbuser.id);

        yield return(www);

        fbuser.picture = www.texture;
    }
Example #16
0
        public bool SaveFBFriends(FBFriends fbFriends)
        {
            FBUser User = AppRequestContext.FBUser;

            long userId = CheckFBUser(User);

            return(SaveFBFriends(fbFriends, userId));
        }
Example #17
0
        private void ResetAppRequestContext(HttpSessionState session, string ipaddress)
        {
            FBUser User = (FBUser)session["authinfo"];

            AppRequestContext.FBUser    = User;
            AppRequestContext.SessionID = session.SessionID;
            AppRequestContext.IPAddress = ipaddress;
        }
Example #18
0
        public async void OnFBAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            try
            {
                await SecureStorage.SetAsync("oauth_token", e.Account.ToString());
            }
            catch (Exception ex)
            {
                // Possible that device doesn't support secure storage on device.
            }

            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnFBAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }

            FBUser user = null;

            if (e.IsAuthenticated)
            {
                FBAuth = true;
                Debug.WriteLine("Facebook Authenticated! ");

                var request = new OAuth2Request(
                    "GET",
                    new Uri("https://graph.facebook.com/me?fields=name,gender,birthday,age_range"),
                    null,
                    e.Account);

                var response = await request.GetResponseAsync();

                if (response != null)
                {
                    string userJson = await response.GetResponseTextAsync();

                    user = JsonConvert.DeserializeObject <FBUser>(userJson);

                    Debug.WriteLine("User Name: " + user.Name);
                    Debug.WriteLine("User Gender: " + user.Gender);
                    Debug.WriteLine("User Birthday: " + user.DoB);
                    Debug.WriteLine("Age Range: " + user.age_range.min);
                    Debug.WriteLine("Age Range: " + user.age_range.max);
                }


                if (account != null)
                {
                    //store.Delete(account, Constants.AppName);
                    Debug.WriteLine("Account isn't null");
                }

                await ExecuteSearchCommand(user);
            }
        }
Example #19
0
    IEnumerator LoadPicture(FBUser nearPlayer)
    {
        WWW www = new WWW(nearPlayer.pictureurl);

        yield return(www);

        nearPlayer.picture = www.texture;
        nearbyP.Add(nearPlayer);
    }
Example #20
0
        public async Task Login()
        {
            if (checkInternetConnection())
            {
                // Get active session
                sess = FBSession.ActiveSession;
                if (!sess.LoggedIn)
                {
                    sess.FBAppId = "438902522960732";
                    sess.WinAppId = "3779de4318934fee8f4d5d3a4411481a";

                    // Add permissions required by the app
                    List<String> permissionList = new List<String>();
                    permissionList.Add("public_profile");
                    permissionList.Add("user_friends");
                    permissionList.Add("user_likes");
                    //permissionList.Add("user_groups");
                    permissionList.Add("user_location");
                    //permissionList.Add("user_photos");
                    permissionList.Add("publish_actions");

                    FBPermissions permissions = new FBPermissions(permissionList);

                    // Login to Facebook
                    FBResult result = await sess.LoginAsync(permissions);

                    if (result.Succeeded)
                    {
                        fbUser = sess.User;

                        //Read the user information
                        string userName = fbUser.Name;
                        string userFirstname = fbUser.FirstName;
                        string userLastname = fbUser.LastName;

                        string userGender = fbUser.Gender;
                        int userTimezone = fbUser.Timezone;

                        FBProfilePictureData userPicture = fbUser.Picture;
                    }
                    else
                    {
                        fbUser = null;
                    }
                }
                else
                {
                    fbUser = sess.User;
                }
            }
            else
            {
                noInternet = true;
                fbUser = null;
            }
        }
Example #21
0
 public ProfileViewModel(INavService navService) : base(navService)
 {
     Debug.WriteLine("ProfileViewModel: Initialize");
     MessagingCenter.Subscribe <TabViewModel, FBUser>(this, "UserData", async(sender, arg) =>
     {
         Debug.WriteLine("ProfileViewModel: In Messaging Center");
         Debug.WriteLine("Name: " + arg.Name);
         FB_User = arg;
     });
 }
Example #22
0
    IEnumerator GrabPictureForUser(FBUser fbuser)
    {
        //WWW www=new WWW(fbuser.pictureurl);

        WWW www = new WWW("https://graph.facebook.com/" + fbuser.id + "/picture?width=60&height=60");

        yield return(www);

        fbuser.picture = www.texture;
    }
        public void AddFacebookCommentTest()
        {
            FacebookService   target  = new FacebookService();
            FBUser            fbUser  = new FBUser(12345, "a token", "theUsername", "f");
            string            comment = "this is a facebook comment";
            PublishedArticles article = new PublishedArticles();

            article.articleId = 1;
            target.AddFacebookComment(fbUser, comment, article);
        }
        public void OnCompleted(JSONObject jsonObject, GraphResponse response)
        {
            var id         = string.Empty;
            var first_name = string.Empty;
            var last_name  = string.Empty;
            var email      = string.Empty;
            var pictureUrl = string.Empty;

            if (jsonObject.Has("id"))
            {
                id = jsonObject.GetString("id");
            }

            if (jsonObject.Has("first_name"))
            {
                first_name = jsonObject.GetString("first_name");
            }

            if (jsonObject.Has("last_name"))
            {
                last_name = jsonObject.GetString("last_name");
            }

            if (jsonObject.Has("email"))
            {
                email = jsonObject.GetString("email");
            }

            if (jsonObject.Has("picture"))
            {
                var picture = jsonObject.GetJSONObject("picture");
                if (picture.Has("data"))
                {
                    var data = picture.GetJSONObject("data");
                    if (data.Has("url"))
                    {
                        pictureUrl = data.GetString("url");
                    }
                }
            }

            var fbUser = new FBUser()
            {
                Id        = id,
                Email     = email,
                FirstName = first_name,
                LastName  = last_name,
                PicUrl    = pictureUrl,
                Token     = AccessToken.CurrentAccessToken.Token
            };

            _onLoginComplete?.Invoke(fbUser, string.Empty);
        }
Example #25
0
        public Settings Login(Credentials creds)
        {
            IVizSecurityService service = ObjectFactory.Resolve <IVizSecurityService>();

            Settings settings = service.Login(creds);
            var      session  = HttpContext.Current.Session;

            session["authinfo"] = new FBUser {
                Email = creds.Email
            };
            return(settings);
        }
Example #26
0
    void GrabDataOnce(string friendslist)
    {
        try{
            Dictionary <string, object> dict = Json.Deserialize(friendsList) as Dictionary <string, object>;


            object        friendsH;
            List <object> friends = new List <object>();

            if (dict.TryGetValue("data", out friendsH))
            {
                friends = ((IEnumerable)friendsH).Cast <object>().ToList();
                //Debug.Log(friends.Count);


                for (int i = 0; i < friends.Count; i++)
                {
                    Dictionary <string, object> friendDict = ((Dictionary <string, object>)friends[i]);

                    Dictionary <string, object> friendDict2 = ((Dictionary <string, object>)friendDict["picture"]);


                    object urlc;
                    friendDict2.TryGetValue("data", out urlc);


                    List <object> imfo = new List <object>();
                    imfo = ((IEnumerable)urlc).Cast <object>().ToList();



                    string imageAddress = imfo[0].ToString().Trim();
                    string url;

                    url = imageAddress.Substring(6, imageAddress.Length - 7);

                    FBUser fbuser = new FBUser(url);
                    fbuser.id         = friendDict["id"].ToString();
                    fbuser.name       = friendDict["name"].ToString();
                    fbuser.pictureurl = url;
                    StartCoroutine("GrabPictureForUser", fbuser);
                    StartCoroutine("GetScoreAction", fbuser);
                    fbFriends.Add(fbuser);
                }
                //Debug.Log(mydata);
                AddSelf();
                dataReady = true;
            }
        }catch (Exception e) {
            Debug.Log("Exception came from function 'GrabDataOnce'");
        }
    }
Example #27
0
    void AddSelf()
    {
        ProcessMyData();

        FBUser me = new FBUser(PlayerFBPictureUrl);

        me.id         = FB.UserId;
        me.name       = PlayerFBname;
        me.pictureurl = PlayerFBPictureUrl;
        StartCoroutine("GrabPictureForUser", me);
        StartCoroutine("GetScoreAction", me);
        fbFriends.Add(me);
    }
 private void OnLoginComplete(FBUser facebookUser, string message)
 {
     if (facebookUser != null)
     {
         FacebookUser = facebookUser;
         IsLogin      = true;
         OnPropertyChanged("IsLogin");
         OnPropertyChanged("FacebookUser");
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("login failed, reason=" + message);
     }
 }
Example #29
0
        private long SaveFBUser(FBUser User)
        {
            try
            {
                long userId     = CheckFBUser(User);
                bool userExists = (userId > 0);

                string query = userExists ?
                               VizFBQueries.UPDATE_FB_USER_DETAILS : VizFBQueries.SAVE_FB_USER_DETAILS;
                Dictionary <string, object> queryparams = new Dictionary <string, object>();
                queryparams.Add("@fb_id", User.id);
                queryparams.Add("@first_name", User.FirstName);
                queryparams.Add("@username", User.UserName);
                queryparams.Add("@timezone", User.TimeZone);
                queryparams.Add("@verified", User.Verified);
                queryparams.Add("@locale", User.Locale);
                queryparams.Add("@link", User.Link);
                queryparams.Add("@name", User.Name);
                queryparams.Add("@last_name", User.LastName);
                queryparams.Add("@gender", User.Gender);
                int      str = User.UpdatedTime.Value.Year;
                DateTime date;
                if (str <= 1753)
                {
                    date = DateTime.Now;
                }
                else
                {
                    date = User.UpdatedTime.Value;
                }
                queryparams.Add("@updated_time", date);
                queryparams.Add("@profile_url", User.ProfileUrl);

                if (!userExists)
                {
                    return(ExecuteNonQueryWithOutputParam(query, ConvertToDBParameters(queryparams)));
                }
                else
                {
                    ExecuteNonQuery(query, ConvertToDBParameters(queryparams));
                    return(userId);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                throw new AppException(ErrorCode.SQL_GENERAL_ERROR);
            }
        }
Example #30
0
        public void InsertUser(string id)
        {
            var fbUser = new FBUser {
                SessionId = id
            };

            if (_db.FBUsers.FirstOrDefault(u => u.SessionId == id) != null)
            {
                return;
            }

            _db.FBUsers.InsertOnSubmit(fbUser);

            _db.SubmitChanges();
        }
Example #31
0
        public void TestPostCount()
        {
            FBUser u1 = new FBUser("abc");

            Post[] p =
            {
                new Message("2018-10-12", "I am doing final OOP revision"),
                new Message("2018-10-13", "I am in exam hall")
            };
            foreach (Post b in p)
            {
                u1.AddPost(b);
            }
            Assert.AreEqual(2, u1.PostCount);
        }
Example #32
0
 private FacebookHandler()
 {
     fbUser = null;
     sess = FBSession.ActiveSession;
 }
Example #33
0
 public async Task Logout()
 {
     FBSession sess = FBSession.ActiveSession;
     fbUser = null;
     await sess.LogoutAsync();
 }
 protected override ClaimsIdentity Retrieve(FBUser user)
 {
     return ClaimsIdentity;
 }
Example #35
0
        public void Insert(long Fbid,string FirstName,string LastName,string Fbemail,string Paypalemail,DateTime? CreatedDate,DateTime? LastChanged,string AccessToken)
        {
            FBUser item = new FBUser();

            item.Fbid = Fbid;

            item.FirstName = FirstName;

            item.LastName = LastName;

            item.Fbemail = Fbemail;

            item.Paypalemail = Paypalemail;

            item.CreatedDate = CreatedDate;

            item.LastChanged = LastChanged;

            item.AccessToken = AccessToken;

            item.Save(UserName);
        }
Example #36
0
	private void OnMeResults(FBResult p_results)
	{
		if(string.IsNullOrEmpty(p_results.Error))
		{
			JToken fbResultJToken = JsonTools.ConvertStringToJToken(p_results.Text);
			if(fbResultJToken != null)
			{
				// Create a new FBUser object inside a new GameObject
				GameObject newFBUserGameObject = new GameObject();
				newFBUserGameObject.transform.parent = this.transform;
				newFBUserGameObject.transform.localPosition = Vector3.zero;
				FBUser newFBUser = newFBUserGameObject.AddComponent<FBUser>();
				newFBUser.Init((JObject)fbResultJToken, FBUser.Type.SELF);

				this.me = newFBUser;
			}
		}
	}
Example #37
0
	// Initializes this object with a user's data
	public void Init(JObject p_jObject, FBUser.Type p_type)
	{
		// Fail safe
		if(p_jObject == null)
			return;

		this.jObjectData = p_jObject;
		this.type = p_type;

		this.Clear();

		JsonTools.PopulateJObjectToExistingObject(p_jObject, this);
		this.StartCoroutine(this.ReloadImage());
	}