private void SynchronizeFriends() { List <WeChatFriend> allFriends = new List <WeChatFriend>(); var allAccounts = AccountInfoAdapter.Instance.LoadAll(); foreach (var account in allAccounts) { WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password); Thread.Sleep(1000); var flag = true; var curIndex = 0; while (flag) { WeChatFriendCollection friends = WeChatHelper.GetAllMembers(curIndex, 200, WeChatRequestContext.Current.LoginInfo); Thread.Sleep(1000); foreach (var friend in friends) { friend.AccountID = account.AccountID; allFriends.Add(friend); } if (friends.Count == 0) { flag = false; } else { curIndex++; } } } foreach (var friend in allFriends) { WeChatFriendAdapter.Instance.Update(friend); } }
private void Synchronize() { try { ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance); List <WeChatFriend> allFriends = new List <WeChatFriend>(); if (ddlAccount.SelectedIndex == 0) { var allAccounts = AccountInfoAdapter.Instance.LoadAll(); foreach (var account in allAccounts) { WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password); ProcessProgress.Current.StatusText = string.Format("正在准备帐号\"{0}\"的数据...", account.UserID); ProcessProgress.Current.Response(); Thread.Sleep(1000); var flag = true; var curIndex = 0; while (flag) { WeChatFriendCollection friends = WeChatHelper.GetAllMembers(curIndex, 100, WeChatRequestContext.Current.LoginInfo); Thread.Sleep(1000); foreach (var friend in friends) { friend.AccountID = account.AccountID; allFriends.Add(friend); } if (friends.Count == 0) { flag = false; } else { curIndex++; } ProcessProgress.Current.Response(); } } } else { var account = AccountInfoAdapter.Instance.Load(p => p.AppendItem("AccountID", ddlAccount.SelectedValue)).FirstOrDefault(); WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password); ProcessProgress.Current.StatusText = string.Format("正在准备帐号\"{0}\"的数据...", account.UserID); ProcessProgress.Current.Response(); Thread.Sleep(1000); var flag = true; var curIndex = 0; while (flag) { WeChatFriendCollection friends = WeChatHelper.GetAllMembers(curIndex, 100, WeChatRequestContext.Current.LoginInfo); Thread.Sleep(1000); foreach (var friend in friends) { friend.AccountID = account.AccountID; allFriends.Add(friend); } if (friends.Count == 0) { flag = false; } else { curIndex++; } ProcessProgress.Current.Response(); } } ProcessProgress.Current.MaxStep = allFriends.Count; ProcessProgress.Current.StatusText = "开始同步..."; ProcessProgress.Current.Response(); foreach (var friend in allFriends) { WeChatFriendAdapter.Instance.Update(friend); ProcessProgress.Current.Increment(); ProcessProgress.Current.Response(); } ProcessProgress.Current.CurrentStep = 0; ProcessProgress.Current.StatusText = ""; ProcessProgress.Current.Response(); } catch (Exception ex) { WebUtility.ResponseShowClientErrorScriptBlock(ex); } finally { this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true)); this.Response.End(); } }