public static void Output(this WeChatFriendCollection friends) { foreach (WeChatFriend friend in friends) { Console.WriteLine("Friend ID: {0}, Name: {1}, Group ID: {2}", friend.FakeID, friend.NickName, friend.GroupID); } }
public override void Execute(string argument) { int groupID = -1; if (int.TryParse(argument, out groupID) == false) { groupID = -1; } WeChatFriendCollection friends = WeChatHelper.GetGroupMembers(groupID, 0, 30, WeChatRequestContext.Current.LoginInfo); friends.Output(); }
protected override void ProcessResponseText(string responseText) { Regex GroupRex = new Regex(@"(?<=""contacts"":).*(?=\}\).contacts)"); MatchCollection mcGroup = GroupRex.Matches(responseText); WeChatFriendCollection result = new WeChatFriendCollection(); if (mcGroup.Count > 0) { result = JSONSerializerExecute.Deserialize <WeChatFriendCollection>(mcGroup[0].Value); } else { result = new WeChatFriendCollection(); } this._Friends = result; }
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(); } }
protected override void ProcessResponseText(string responseText) { Regex GroupRex = new Regex(@"(?<=""contacts"":).*(?=\}\).contacts)"); MatchCollection mcGroup = GroupRex.Matches(responseText); WeChatFriendCollection result = new WeChatFriendCollection(); if (mcGroup.Count > 0) result = JSONSerializerExecute.Deserialize<WeChatFriendCollection>(mcGroup[0].Value); else result = new WeChatFriendCollection(); this._Friends = result; }