88 lines
3.1 KiB
C#
88 lines
3.1 KiB
C#
using Chat.Framework.WXSdk.Implement;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using UI.Framework.Forms;
|
|
using Weixin.CircleTools.Properties;
|
|
|
|
namespace CircleFriendsTools
|
|
{
|
|
public partial class XtraForm1 : BaseForm
|
|
{
|
|
private string name; //要检测的账号
|
|
|
|
public XtraForm1(string name)
|
|
{
|
|
InitializeComponent();
|
|
this.Text = Resources.CheckFormTitle;
|
|
this.name = name;
|
|
}
|
|
private void AddText(string text, Color color)
|
|
{
|
|
if (!this.IsDisposed)
|
|
{
|
|
this.richTextBox1.Invoke(new Action(delegate
|
|
{
|
|
richTextBox1.AppendTextColorful(text, color);
|
|
|
|
}));
|
|
}
|
|
}
|
|
|
|
private CancellationTokenSource tokenSource = new CancellationTokenSource();
|
|
|
|
private void XtraForm1_Load(object sender, EventArgs e)
|
|
{
|
|
richTextBox1.AppendTextColorful($"正在检测....", Color.Black);
|
|
Task.Factory.StartNew(delegate
|
|
{
|
|
try
|
|
{
|
|
var clients = Chat.Framework.ChatClient.WXClient;
|
|
var flag = false;//判断朋友集合中(key值)是否存在,查询的wxId
|
|
foreach (WeixinBase item in clients.Values)
|
|
{
|
|
try
|
|
{
|
|
if (item.WeixinType == WeixinType.Grpc微信 && item.Status == Chat.Framework.WXSdk.WxStatus.在线)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(name))
|
|
{
|
|
flag = false;
|
|
var ipad = item as WXClientImpl_IPAD;
|
|
if (ipad == null) continue;
|
|
flag = ipad.GetContact(name) != null ? true : false;
|
|
var friends = ipad.Friends;
|
|
|
|
if (flag) AddText($"{item.User.Nick}({item.WeixinHao}) 正常", Color.Green);
|
|
else AddText($"{item.User.Nick}({item.WeixinHao}) 异常", Color.Red);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
AddText($"检测异常:{ex.Message}", Color.Yellow);
|
|
}
|
|
}
|
|
AddText($"检测完毕....", Color.Black);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!this.IsDisposed)
|
|
{
|
|
this.Invoke(new Action(delegate
|
|
{
|
|
if(!this.IsDisposed)ShowError(ex);
|
|
}));
|
|
}
|
|
}
|
|
}, tokenSource.Token);
|
|
}
|
|
|
|
private void XtraForm1_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
|
|
{
|
|
tokenSource.Cancel();
|
|
}
|
|
}
|
|
} |