Esempio n. 1
0
        private void OnProfile(IGraphResult response)
        {
            mAwaitingProfilesCount--;

            if (AssertResult(response))
            {
                SocialUserProfile rec = PrepareProfile(response.RawResult);
                mProfiles.Add(rec);

                // if all requested profiles are gotten
                if (mAwaitingProfilesCount <= 0)
                {
                    if (mRequestProfilesCallback != null)
                    {
                        mRequestProfilesCallback.Invoke(mProfiles);
                        mRequestProfilesCallback = null;
                    }
                    else
                    {
                        OnProfiles(mProfiles);
                    }
                }
            }

            if (mRequestProfilesQueue.Count > 0)
            {
                RequestProfilesQueueItem req = mRequestProfilesQueue.Dequeue();
                DoRequestProfiles(req.userids, req.callback);
            }
        }
        private void OnProfile(IGraphResult response)
        {
            mAwaitingProfilesCount--;

            if (AssertResult(response))
            {
                SocialUserProfile rec = PrepareProfile(response.RawResult);
                mProfiles.Add(rec);

                // если дождались ответов для всех запрошенных пользователей
                if (mAwaitingProfilesCount <= 0)
                {
                    if (mRequestProfilesCallback != null)
                    {
                        mRequestProfilesCallback.Invoke(mProfiles);
                        mRequestProfilesCallback = null;
                    }
                    else
                    {
                        OnProfiles(mProfiles);
                    }
                }
            }

            // если в очереди ожидают еще запросы, выполним их
            if (mRequestProfilesQueue.Count > 0)
            {
                RequestProfilesQueueItem req = mRequestProfilesQueue.Dequeue();
                DoRequestProfiles(req.userids, req.callback);
            }
        }
 protected void AddProfileToCache(SocialUserProfile profile)
 {
     if (profile != null &&
         !string.IsNullOrEmpty(profile.Id) &&
         !string.IsNullOrEmpty(profile.FirstName))
     {
         mProfilesCache[profile.CombinedUserID] = profile;
     }
 }
        public override bool Equals(object obj)
        {
            if (!(obj is SocialUserProfile))
            {
                return(false);
            }

            SocialUserProfile p = (obj as SocialUserProfile);

            return(this.Equals(p.Id, p.NetworkType));            //????
        }
        public static new SocialUserProfile FromObject(object raw_data)
        {
            var profile = SocialUserProfile.FromObject(raw_data);

            //if (string.IsNullOrEmpty(profile.PhotoSmallURL))
            profile.PhotoSmallURL = "https://graph.facebook.com/" + profile.Id + "/picture/?width=50&height=50";
            //if (string.IsNullOrEmpty(profile.PhotoMediumURL))
            profile.PhotoMediumURL = "https://graph.facebook.com/" + profile.Id + "/picture/?width=100&height=100";

            return(profile);
        }
        private SocialUserProfile PrepareProfile(IUserProfile data)
        {
            SocialUserProfile profile = new SocialUserProfile(data.id, SocialNetworkType.APPLE_GAME_CENTER);

            profile.Name           = data.userName;
            profile.PhotoSmallURL  = DUMMY_AVATAR_URL;
            profile.PhotoMediumURL = DUMMY_AVATAR_URL;

            // добавим в кэш
            //SetProfileData(profile);

            return(profile);
        }
        public SocialUserProfile Clone()
        {
            SocialUserProfile profile = new SocialUserProfile(this.Id, this.NetworkType);

            profile.FirstName      = this.FirstName;
            profile.LastName       = this.LastName;
            profile.PhotoSmallURL  = this.PhotoSmallURL;
            profile.PhotoMediumURL = this.PhotoMediumURL;
            profile.Link           = this.Link;
            profile.Gender         = this.Gender;
            profile.Online         = this.Online;
            profile.Invitable      = this.Invitable;
            return(profile);
        }
        public SocialUserProfile GetCachedProfile(string id, string nt = null)
        {
            if (string.IsNullOrEmpty(nt))
            {
                nt = this.NetworkType;
            }

            SocialUserProfile profile = null;

            if (mProfilesCache.TryGetValue(nt + id, out profile))
            {
                return(profile);
            }

            return(null);
        }
        private SocialUserProfile PrepareProfile(ExpandoObject data)
        {
            string            profile_id = data.ContainsKey("uid") ? data.SafeGetString("uid") : data.SafeGetString("id");
            SocialUserProfile profile    = new SocialUserProfile(profile_id, this.NetworkType);

            profile.FirstName      = data.SafeGetString("first_name");
            profile.LastName       = data.SafeGetString("last_name");
            profile.PhotoSmallURL  = "https://graph.facebook.com/" + profile.Id + "/picture/?width=50&height=50";
            profile.PhotoMediumURL = "https://graph.facebook.com/" + profile.Id + "/picture/?width=100&height=100";
            //profile.Link         = data.ContainsKey("link") ? Convert.ToString(data["link"]) : data.ContainsKey("profile_url") ? Convert.ToString(data["profile_url"]) : ("http://www.facebook.com/" + profile.Id);
            //profile.Gender       = (((string)(data.ContainsKey("sex") ? data["sex"] : data["gender"]) != "female")) ? 1 : 2;  // 1-мужской, 2-женский; приходит: "male"/"female"
            //profile.Online       = Convert.ToBoolean( data["online"] );

            // добавим в кэш
            AddProfileToCache(profile);
            Debug.Log("[FacebookProvider] PrepareProfile " + profile.ToJSONString());

            return(profile);
        }
        private SocialUserProfile PrepareProfile(IUserProfile data)
        {
            SocialUserProfile profile = new SocialUserProfile(data.id, SocialNetworkType.GOOGLE_PLAY);

            profile.Name           = data.userName;
            profile.PhotoSmallURL  = DUMMY_AVATAR_URL;
            profile.PhotoMediumURL = DUMMY_AVATAR_URL;

#if UNITY_ANDROID
            if (data.id == GooglePlayGames.PlayGamesPlatform.Instance.localUser.id)
            {
                string url = GooglePlayGames.PlayGamesPlatform.Instance.GetUserImageUrl();
                if (!string.IsNullOrEmpty(url))
                {
                    profile.PhotoSmallURL  = url;
                    profile.PhotoMediumURL = url;
                }
            }
#endif
            // добавим в кэш
            //SetProfileData(profile);

            return(profile);
        }
        public static SocialUserProfile FromObject(object raw_data)
        {
            if (raw_data is SocialUserProfile)
            {
                return((raw_data as SocialUserProfile).Clone());
            }

            if (!(raw_data is SnipeObject))
            {
                return(new SocialUserProfile());
            }

            SnipeObject data = (SnipeObject)raw_data;

            SocialUserProfile profile = new SocialUserProfile();

            if (data.ContainsKey("id"))
            {
                profile.Id = data.SafeGetString("id");
            }
            else if (data.ContainsKey("networkid"))                         // в таком формате данные могут прийти от игрового сервера
            {
                profile.Id = data.SafeGetString("networkid");
            }

            if (data.ContainsKey("network_type"))
            {
                profile.NetworkType = data.SafeGetString("network_type");
            }
            else if (data.ContainsKey("networktype"))                       // в таком формате данные могут прийти от игрового сервера
            {
                profile.NetworkType = data.SafeGetString("networktype");
            }
            else if (data.ContainsKey("nt"))                                // в таком формате данные могут прийти от игрового сервера
            {
                profile.NetworkType = data.SafeGetString("nt");
            }
            else if (data.ContainsKey("netid"))                             // в таком формате данные могут прийти от игрового сервера
            {
                profile.NetworkType = data.SafeGetString("netid");
            }

            if (data.ContainsKey("first_name"))
            {
                profile.FirstName = data.SafeGetString("first_name");
            }
            if (data.ContainsKey("last_name"))
            {
                profile.LastName = data.SafeGetString("last_name");
            }
            if (data.ContainsKey("photo_small"))
            {
                profile.PhotoSmallURL = data.SafeGetString("photo_small");
            }
            if (data.ContainsKey("photo_medium"))
            {
                profile.PhotoMediumURL = data.SafeGetString("photo_medium");
            }
            if (data.ContainsKey("link"))
            {
                profile.Link = data.SafeGetString("link");
            }
            if (data.ContainsKey("gender"))
            {
                profile.Gender = Convert.ToInt32(data["gender"]);
            }
            if (data.ContainsKey("online"))
            {
                profile.Online = Convert.ToBoolean(data["online"]);
            }

            if (data.ContainsKey("invitable"))
            {
                profile.Invitable = Convert.ToBoolean(data["invitable"]);
            }

            profile.UpdateCombinedID();

            return(profile);
        }