当前位置: 首页>>代码示例>>C#>>正文


C# HttpContext.GetFacebookMutualFriendsDic方法代码示例

本文整理汇总了C#中System.Web.HttpContext.GetFacebookMutualFriendsDic方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContext.GetFacebookMutualFriendsDic方法的具体用法?C# HttpContext.GetFacebookMutualFriendsDic怎么用?C# HttpContext.GetFacebookMutualFriendsDic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpContext的用法示例。


在下文中一共展示了HttpContext.GetFacebookMutualFriendsDic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddFriendsWithoutMutualFriends

        public static void AddFriendsWithoutMutualFriends(LoveHitchFacebookApp facebook, HttpContext context)
        {
            try
            {
                var mfDic = context.GetFacebookMutualFriendsDic();
                if (mfDic == null) return;
                var lstMutualFriends = (List<MutualFriendItem>)mfDic[facebook.UserId];
                if (lstMutualFriends == null) return;
                var user = FacebookHelper.LoadUserFromDbByFacebookId(facebook.UserId);

                var friendsIDsWithMutualFriends =
                    lstMutualFriends.Select(f => f.FriendID).Distinct().ToList();

                if (User.IsUsernameTaken(friendsIDsWithMutualFriends.Last().ToString()))
                {
                    FacebookHelper.AddFriends(user, 5000, context, facebook);
                }
            }
            catch (Exception ex)
            {
            }
        }
开发者ID:haimon74,项目名称:Easy-Fixup,代码行数:22,代码来源:LovehitchBackgroundWorker.cs

示例2: DoWork

        //protected override void OnDoWork(DoWorkEventArgs e)
        public new static void DoWork(LoveHitchFacebookApp facebook, HttpContext context)
        {
            //ReportProgress(0, "Working hard on this report...");
            //var msWait = 1000 * 120;

            //while (true)
            {
                //Thread.Sleep(msWait);

                //if (this.FacebookAppList.Count == 0)
                //{
                //    Thread.Sleep(msWait);
                //}
                //else
                {
                    //var facebook = FacebookAppList[0];
                    var user = FacebookHelper.LoadUserFromDbByFacebookId(facebook.UserId);
                    if (user == null) return;

                    //for (int i = 0; i < 2; i++)
                    {
                        DateTime[] time = new DateTime[10];
                        time[0] = DateTime.Now;

                        IList<FacebookHelper.FacebookFriendData> allFriendsData =
                            FacebookHelper.GetFriendsDataList(facebook, facebook.UserId);
                        var mfDic = context.GetFacebookMutualFriendsDic();// (Dictionary<long, List<MutualFriendItem>>)context.Application["FacebookMutualFriendsDic"];
                        var allMutualFriends = (List<MutualFriendItem>)mfDic[facebook.UserId];
                        if (allMutualFriends != null)
                        {
                            for (int i = 0; i < allFriendsData.Count; i++)
                            {
                                var fbFriendData = allFriendsData[i];
                                fbFriendData.MutualFriendsCount =
                                    allMutualFriends.Count(f => f.FriendID == fbFriendData.UserId);
                            }

                            allFriendsData = allFriendsData.OrderByDescending(f => f.MutualFriendsCount).ToList();
                        }
                        var lstFriendsIds = new List<long>();
                        try
                        {
                            using (var db = new ezFixUpDataContext())
                            {
                                var tmpList =
                                    CompiledQueries.FetchActiveFriendsForUsername(db, user.Username).
                                        ToList();
                                var tmpArray =
                                    tmpList.Where(
                                        f =>
                                        f.User1.u_logincount == 0 && f.User1.u_facebookid.HasValue &&
                                        !f.User1.u_face_control_approved)
                                        .OrderBy(f => f.User1.u_name).Select(f => f.User1.u_facebookid.Value).ToArray();

                                foreach (var friendData in allFriendsData)
                                {
                                    var un = friendData.UserId;

                                    if (!tmpArray.Contains(un)) continue;

                                    int imgId = Photo.GetPrimaryOrDefaultId(un.ToString());
                                    if (imgId < 0)
                                        lstFriendsIds.Add(un);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        if (lstFriendsIds.Count > 0)
                        {
                            try
                            {
                                var parameterizedThreadsList =
                                    new LoveHitchParallel.ParameterizedThreadsList<long>(
                                        lstFriendsIds,
                                        (new FacebookHelper.FetchAndSaveSaveFacebookFriendImageClass()).
                                            FetchAndSaveFacebookImageByFacebookId,
                                        null);
                                parameterizedThreadsList.RunAsBackgroundThreads = true;
                                parameterizedThreadsList.ExecuteParallelWork(1);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    //FacebookAppList.RemoveAt(0);
                }
            }
        }
开发者ID:haimon74,项目名称:Easy-Fixup,代码行数:92,代码来源:LovehitchBackgroundWorker.cs

示例3: FetchAndSaveFacebookMutualFriends

        private static void FetchAndSaveFacebookMutualFriends(LoveHitchFacebookApp facebook, HttpContext context)
        {
            DateTime[] time = new DateTime[5];
            time[0] = DateTime.Now;

            var user = FacebookHelper.LoadUserFromDbByFacebookId(facebook.UserId);
            var dic = context.GetFacebookFriendsDic();
            if (user == null || dic == null) return;

            var sessionFriendsData = (dic.ContainsKey(facebook.UserId)) ? dic[facebook.UserId] : null;
            if (sessionFriendsData == null) return;

            var mfDic = context.GetFacebookMutualFriendsDic();
            if (mfDic == null || mfDic[facebook.UserId] == null) return;

            var lstMutualFriends = (List<MutualFriendItem>)mfDic[facebook.UserId];
            if (lstMutualFriends == null) return;

            var totalFriendsCount = sessionFriendsData.Count;
            int limit = 40;
            var lstFriendsMutualCount = new List<MutualFriendItem>();

            for (int offset = 0; offset < totalFriendsCount; offset += limit)
            {
                var qry1 = "SELECT uid2 FROM friend WHERE uid1=me()";
                var qry2tmpl =
                    "select uid, mutual_friend_count from user where mutual_friend_count > 00 and mutual_friend_count <= 30 and uid in " +
                    "( SELECT uid2 FROM friend WHERE uid1=me() limit {0} offset {1})";
                var qry2 = String.Format(qry2tmpl, limit, offset);

                JsonArray res = FacebookHelper.GetFqlResult(facebook, qry2);
                lstFriendsMutualCount =
                    lstFriendsMutualCount.Union(
                                          res.Select(o => new MutualFriendItem
                                          {
                                              FriendID = long.Parse((string)((JsonObject)o)["uid"]),
                                              MutualFriendID = ((JsonObject)o)["mutual_friend_count"] == null ? 0 : long.Parse((string)((JsonObject)o)["mutual_friend_count"])
                                          })).ToList();
            }
            //var groups = lstFriendsMutualCount.GroupBy(o => o.FriendID);
            //int groupsCount = groups.Count();
            //long x = lstFriendsMutualCount.Sum(o => o.MutualFriendID);

            time[1] = DateTime.Now;

            var lstFacebookSessionMutualFriends = new List<MutualFriendItem>();
            //long counter = 0;
            const long limitCount = 20;
            //long skipCount = 0;
            int qryCount = 0;
            for (long i = 0; i < totalFriendsCount; i += limitCount)
            {
                //if (counter + lstFriendsMutualCount[i].MutualFriendID < 400 && limitCount < 80)
                //if (counter + lstFriendsMutualCount[i].MutualFriendID < 300 && limitCount < 30)
                //{
                //    limitCount++;
                //    counter += lstFriendsMutualCount[i].MutualFriendID;
                //}
                //else
                {
                    qryCount++;
                    //counter = lstFriendsMutualCount[i].MutualFriendID;
                    var qry1tmpl =
                        "select uid from user where mutual_friend_count > 30 and mutual_friend_count <= 200 and uid in (SELECT uid2 FROM friend WHERE uid1=me()  limit {0} offset {1}) ";
                    var qry1 = String.Format(qry1tmpl, limitCount, i);
                    //for (long j = 0; j < totalFriendsCount; j += 1260)
                    {
                        //var qry2tmpl = "SELECT uid2 FROM friend WHERE uid1=me() limit 1260 offset {0}";
                        //var qry2 = String.Format(qry2tmpl, j);
                        var qry2 = "SELECT uid2 FROM friend WHERE uid1=me()";
                        //limitCount = 1;
                        //skipCount = i-1;
                        var qry3tmpl = "select uid1,uid2 from friend where uid1 in ({0}) and uid2 in ({1})";
                        var qry3 = String.Format(qry3tmpl, qry1, qry2);
                        JsonArray res = FacebookHelper.GetFqlResult(facebook, qry3);
                        var res1 = res.Select(o => new MutualFriendItem
                        {
                            FriendID = long.Parse((string)((JsonObject)o)["uid1"]),
                            MutualFriendID =
                                long.Parse((string)((JsonObject)o)["uid2"])
                        });
                        var res2 = res1.Select(o => new MutualFriendItem
                        {
                            FriendID = o.MutualFriendID,
                            MutualFriendID = o.FriendID
                        });
                        lstFacebookSessionMutualFriends = lstFacebookSessionMutualFriends.Union(res1).Union(res2).ToList();
                    }
                }
            }
            time[2] = DateTime.Now;
            //time[2] = DateTime.Now;

            //var qryFriendsCountMF =
            //    //"SELECT uid FROM user ORDER BY mutual_friend_count DESC limit 5000";
            //    //"SELECT uid,mutual_friend_count FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) order by mutual_friend_count DESC limit 5000";
            //        "SELECT uid2 FROM friend WHERE uid1=me()";

            //JsonArray friendsByQuery = facebook.GetFqlResult(qryFriendsCountMF);

//.........这里部分代码省略.........
开发者ID:haimon74,项目名称:Easy-Fixup,代码行数:101,代码来源:LovehitchBackgroundWorker.cs


注:本文中的System.Web.HttpContext.GetFacebookMutualFriendsDic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。