private static void AsyncProcessFacebookPhotos(object data) { int curHour = DateTime.Now.Hour; if (_workerLock || curHour < 2 || curHour > 5) { return; } try { _workerLock = true; List<string> lstWithoutPhotosUsernames = null; List<long> lstWithoutPhotosFacebookIds = null; using (var db = new ezFixUpDataContext()) { try { //var lstWithPhotosUsernames = CompiledQueries.FetchUsernamesWithPhotos(db).ToList(); //var lstNewUsernames = CompiledQueries.FetchNew24HourFacebookFriendsUsernames(db).ToList(); //lstWithoutPhotosUsernames = lstNewUsernames.Except(lstWithPhotosUsernames).ToList(); lstWithoutPhotosUsernames = CompiledQueries.FetchFacebookUsernamesWithoutPhoto(db).ToList(); //foreach (var un in lstWithoutPhotosUsernames) //{ // int imgId = Photo.GetPrimaryOrDefaultId(un.ToString()); // if (imgId < 0) // lstFriendsIds.Add(un); //} } catch (Exception ex) { } if (lstWithoutPhotosUsernames != null && lstWithoutPhotosUsernames.Count > 0) { try { lstWithoutPhotosFacebookIds = lstWithoutPhotosUsernames.Select(un => long.Parse(un)).ToList(); var parameterizedThreadsList = new LoveHitchParallel.ParameterizedThreadsList<long>( lstWithoutPhotosFacebookIds, (new FacebookHelper.FetchAndSaveSaveFacebookFriendImageClass()). FetchAndSaveFacebookImageByFacebookId, null); parameterizedThreadsList.RunAsBackgroundThreads = true; parameterizedThreadsList.ExecuteParallelWork(1); } catch (Exception ex) { } } } } catch (Exception err) { Global.Logger.LogError("FacebookPhotosWorker", err); } finally { _workerLock = false; } }
//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); } } }