From 2b8d1044e9df0626c69ba1e1e6d57c2417315e42 Mon Sep 17 00:00:00 2001 From: dogdie233 Date: Wed, 9 Oct 2024 00:14:34 +0800 Subject: [PATCH] nya nya nya --- Lagrange.Core/Common/Interface/Api/BotExt.cs | 18 +- .../Common/Interface/Api/GroupExt.cs | 140 ++++----- .../Common/Interface/Api/OperationExt.cs | 178 +++++------ .../Internal/Context/BusinessContext.cs | 24 +- .../Internal/Context/HighwayContext.cs | 12 +- .../Logic/Implementation/CachingLogic.cs | 56 ++-- .../Logic/Implementation/MessagingLogic.cs | 100 +++--- .../Logic/Implementation/OperationLogic.cs | 294 +++++++++--------- .../Logic/Implementation/WtExchangeLogic.cs | 180 ++++++----- .../Internal/Context/Logic/LogicBase.cs | 6 +- .../Internal/Context/PacketContext.cs | 16 +- .../Internal/Context/SocketContext.cs | 31 +- .../Internal/Context/Uploader/Common.cs | 6 +- .../Internal/Context/Uploader/FileUploader.cs | 18 +- .../Context/Uploader/IHighwayUploader.cs | 6 +- .../Context/Uploader/ImageUploader.cs | 14 +- .../Internal/Context/Uploader/PttUploader.cs | 14 +- .../Context/Uploader/VideoUploader.cs | 18 +- .../Internal/Network/ClientListener.cs | 11 +- Lagrange.Core/Utility/Network/Http.cs | 8 +- 20 files changed, 583 insertions(+), 567 deletions(-) diff --git a/Lagrange.Core/Common/Interface/Api/BotExt.cs b/Lagrange.Core/Common/Interface/Api/BotExt.cs index ee3262fea..951b2946b 100644 --- a/Lagrange.Core/Common/Interface/Api/BotExt.cs +++ b/Lagrange.Core/Common/Interface/Api/BotExt.cs @@ -15,8 +15,8 @@ public static class BotExt /// Fetch the qrcode for QRCode Login /// /// return url and qrcode image in PNG format - public static Task<(string Url, byte[] QrCode)?> FetchQrCode(this BotContext bot, CancellationToken ct) - => bot.ContextCollection.Business.WtExchangeLogic.FetchQrCode(ct); + public static Task<(string Url, byte[] QrCode)?> FetchQrCode(this BotContext bot, CancellationToken cancellationToken) + => bot.ContextCollection.Business.WtExchangeLogic.FetchQrCode(cancellationToken); /// /// Use this method to login by QrCode, you should call first @@ -27,8 +27,8 @@ public static Task LoginByQrCode(this BotContext bot) /// /// Use this method to login by QrCode, you should call first /// - public static Task LoginByQrCode(this BotContext bot, CancellationToken ct) - => bot.ContextCollection.Business.WtExchangeLogic.LoginByQrCode(ct); + public static Task LoginByQrCode(this BotContext bot, CancellationToken cancellationToken) + => bot.ContextCollection.Business.WtExchangeLogic.LoginByQrCode(cancellationToken); /// /// Use this method to login by password, EasyLogin may be preformed if there is sig in @@ -39,8 +39,8 @@ public static Task LoginByPassword(this BotContext bot) /// /// Use this method to login by password, EasyLogin may be preformed if there is sig in /// - public static Task LoginByPassword(this BotContext bot, CancellationToken ct) - => bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword(ct); + public static Task LoginByPassword(this BotContext bot, CancellationToken cancellationToken) + => bot.ContextCollection.Business.WtExchangeLogic.LoginByPassword(cancellationToken); /// /// Submit the captcha of the url given by the @@ -52,8 +52,8 @@ public static bool SubmitCaptcha(this BotContext bot, string ticket, string rand public static Task SetNeedToConfirmSwitch(this BotContext bot, bool needToConfirm) => bot.ContextCollection.Business.OperationLogic.SetNeedToConfirmSwitch(needToConfirm, CancellationToken.None); - public static Task SetNeedToConfirmSwitch(this BotContext bot, bool needToConfirm, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetNeedToConfirmSwitch(needToConfirm, ct); + public static Task SetNeedToConfirmSwitch(this BotContext bot, bool needToConfirm, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetNeedToConfirmSwitch(needToConfirm, cancellationToken); /// /// Use this method to update keystore, so EasyLogin may be preformed next time by using this keystore @@ -68,4 +68,4 @@ public static BotKeystore UpdateKeystore(this BotContext bot) /// public static BotDeviceInfo UpdateDeviceInfo(this BotContext bot) => bot.ContextCollection.Device; -} \ No newline at end of file +} diff --git a/Lagrange.Core/Common/Interface/Api/GroupExt.cs b/Lagrange.Core/Common/Interface/Api/GroupExt.cs index ae148bf3f..2cd4f0224 100644 --- a/Lagrange.Core/Common/Interface/Api/GroupExt.cs +++ b/Lagrange.Core/Common/Interface/Api/GroupExt.cs @@ -26,10 +26,10 @@ public static Task MuteGroupMember(this BotContext bot, uint groupUin, uin /// The uin for target group /// The uin for target member in such group /// The duration in seconds, 0 for unmute member - /// The cancellation token + /// The cancellation token /// Successfully muted or not - public static Task MuteGroupMember(this BotContext bot, uint groupUin, uint targetUin, uint duration, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.MuteGroupMember(groupUin, targetUin, duration, ct); + public static Task MuteGroupMember(this BotContext bot, uint groupUin, uint targetUin, uint duration, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.MuteGroupMember(groupUin, targetUin, duration, cancellationToken); /// /// Mute the group @@ -47,10 +47,10 @@ public static Task MuteGroupGlobal(this BotContext bot, uint groupUin, boo /// target BotContext /// The uin for target group /// true for mute and false for unmute - /// The cancellation token + /// The cancellation token /// Successfully muted or not - public static Task MuteGroupGlobal(this BotContext bot, uint groupUin, bool isMute, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.MuteGroupGlobal(groupUin, isMute, ct); + public static Task MuteGroupGlobal(this BotContext bot, uint groupUin, bool isMute, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.MuteGroupGlobal(groupUin, isMute, cancellationToken); /// /// @@ -71,194 +71,194 @@ public static Task KickGroupMember(this BotContext bot, uint groupUin, uin /// The uin for target group /// The uin for target member in such group /// whether the kicked member can request - /// The cancellation token + /// The cancellation token /// Successfully kicked or not - public static Task KickGroupMember(this BotContext bot, uint groupUin, uint targetUin, bool rejectAddRequest, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.KickGroupMember(groupUin, targetUin, rejectAddRequest, "", ct); + public static Task KickGroupMember(this BotContext bot, uint groupUin, uint targetUin, bool rejectAddRequest, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.KickGroupMember(groupUin, targetUin, rejectAddRequest, "", cancellationToken); public static Task KickGroupMember(this BotContext bot, uint groupUin, uint targetUin, bool rejectAddRequest, string reason) => bot.ContextCollection.Business.OperationLogic.KickGroupMember(groupUin, targetUin, rejectAddRequest, reason, CancellationToken.None); - public static Task KickGroupMember(this BotContext bot, uint groupUin, uint targetUin, bool rejectAddRequest, string reason, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.KickGroupMember(groupUin, targetUin, rejectAddRequest, reason, ct); + public static Task KickGroupMember(this BotContext bot, uint groupUin, uint targetUin, bool rejectAddRequest, string reason, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.KickGroupMember(groupUin, targetUin, rejectAddRequest, reason, cancellationToken); public static Task SetGroupAdmin(this BotContext bot, uint groupUin, uint targetUin, bool isAdmin) => bot.ContextCollection.Business.OperationLogic.SetGroupAdmin(groupUin, targetUin, isAdmin, CancellationToken.None); - public static Task SetGroupAdmin(this BotContext bot, uint groupUin, uint targetUin, bool isAdmin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetGroupAdmin(groupUin, targetUin, isAdmin, ct); + public static Task SetGroupAdmin(this BotContext bot, uint groupUin, uint targetUin, bool isAdmin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetGroupAdmin(groupUin, targetUin, isAdmin, cancellationToken); public static Task SetGroupBot(this BotContext bot, uint targetUin, uint On, uint groupUin) => bot.ContextCollection.Business.OperationLogic.SetGroupBot(targetUin, On, groupUin, CancellationToken.None); - public static Task SetGroupBot(this BotContext bot, uint targetUin, uint On, uint groupUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetGroupBot(targetUin, On, groupUin, ct); + public static Task SetGroupBot(this BotContext bot, uint targetUin, uint On, uint groupUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetGroupBot(targetUin, On, groupUin, cancellationToken); [Obsolete("Cosider using SetGroupBotHD(BotContext, uint, uint, string?, string?) instead")] public static Task SetGroupBotHD(this BotContext bot, uint targetUin, uint groupUin) => bot.SetGroupBotHD(targetUin, groupUin, null, null); public static Task SetGroupBotHD(this BotContext bot, uint targetUin, uint groupUin, string? data_1, string? data_2) => bot.ContextCollection.Business.OperationLogic.SetGroupBotHD(targetUin, groupUin, data_1, data_2, CancellationToken.None); - public static Task SetGroupBotHD(this BotContext bot, uint targetUin, uint groupUin, string? data_1, string? data_2, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetGroupBotHD(targetUin, groupUin, data_1, data_2, ct); + public static Task SetGroupBotHD(this BotContext bot, uint targetUin, uint groupUin, string? data_1, string? data_2, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetGroupBotHD(targetUin, groupUin, data_1, data_2, cancellationToken); public static Task RenameGroupMember(this BotContext bot, uint groupUin, uint targetUin, string targetName) => bot.ContextCollection.Business.OperationLogic.RenameGroupMember(groupUin, targetUin, targetName, CancellationToken.None); - public static Task RenameGroupMember(this BotContext bot, uint groupUin, uint targetUin, string targetName, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RenameGroupMember(groupUin, targetUin, targetName, ct); + public static Task RenameGroupMember(this BotContext bot, uint groupUin, uint targetUin, string targetName, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RenameGroupMember(groupUin, targetUin, targetName, cancellationToken); public static Task RenameGroup(this BotContext bot, uint groupUin, string targetName) => bot.ContextCollection.Business.OperationLogic.RenameGroup(groupUin, targetName, CancellationToken.None); - public static Task RenameGroup(this BotContext bot, uint groupUin, string targetName, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RenameGroup(groupUin, targetName, ct); + public static Task RenameGroup(this BotContext bot, uint groupUin, string targetName, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RenameGroup(groupUin, targetName, cancellationToken); public static Task RemarkGroup(this BotContext bot, uint groupUin, string targetRemark) => bot.ContextCollection.Business.OperationLogic.RemarkGroup(groupUin, targetRemark, CancellationToken.None); - public static Task RemarkGroup(this BotContext bot, uint groupUin, string targetRemark, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RemarkGroup(groupUin, targetRemark, ct); + public static Task RemarkGroup(this BotContext bot, uint groupUin, string targetRemark, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RemarkGroup(groupUin, targetRemark, cancellationToken); public static Task LeaveGroup(this BotContext bot, uint groupUin) => bot.ContextCollection.Business.OperationLogic.LeaveGroup(groupUin, CancellationToken.None); - public static Task LeaveGroup(this BotContext bot, uint groupUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.LeaveGroup(groupUin, ct); + public static Task LeaveGroup(this BotContext bot, uint groupUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.LeaveGroup(groupUin, cancellationToken); public static Task InviteGroup(this BotContext bot, uint groupUin, Dictionary invitedUins) => bot.ContextCollection.Business.OperationLogic.InviteGroup(groupUin, invitedUins, CancellationToken.None); - public static Task InviteGroup(this BotContext bot, uint groupUin, Dictionary invitedUins, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.InviteGroup(groupUin, invitedUins, ct); + public static Task InviteGroup(this BotContext bot, uint groupUin, Dictionary invitedUins, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.InviteGroup(groupUin, invitedUins, cancellationToken); public static Task SetGroupRequest(this BotContext bot, BotGroupRequest request, bool accept = true, string reason = "") => bot.ContextCollection.Business.OperationLogic.SetGroupRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept, reason, CancellationToken.None); - public static Task SetGroupRequest(this BotContext bot, BotGroupRequest request, CancellationToken ct, bool accept = true, string reason = "") - => bot.ContextCollection.Business.OperationLogic.SetGroupRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept, reason, ct); + public static Task SetGroupRequest(this BotContext bot, BotGroupRequest request, bool accept, string reason, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetGroupRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept, reason, cancellationToken); public static Task SetGroupFilteredRequest(this BotContext bot, BotGroupRequest request, bool accept = true, string reason = "") => bot.ContextCollection.Business.OperationLogic.SetGroupFilteredRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept, reason, CancellationToken.None); - public static Task SetGroupFilteredRequest(this BotContext bot, BotGroupRequest request, CancellationToken ct, bool accept = true, string reason = "") - => bot.ContextCollection.Business.OperationLogic.SetGroupFilteredRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept, reason, ct); + public static Task SetGroupFilteredRequest(this BotContext bot, BotGroupRequest request, bool accept, string reason, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetGroupFilteredRequest(request.GroupUin, request.Sequence, (uint)request.EventType, accept, reason, cancellationToken); public static Task SetFriendRequest(this BotContext bot, FriendRequestEvent request, bool accept = true) => bot.ContextCollection.Business.OperationLogic.SetFriendRequest(request.SourceUid, accept, CancellationToken.None); - public static Task SetFriendRequest(this BotContext bot, FriendRequestEvent request, CancellationToken ct, bool accept = true) - => bot.ContextCollection.Business.OperationLogic.SetFriendRequest(request.SourceUid, accept, ct); + public static Task SetFriendRequest(this BotContext bot, FriendRequestEvent request, bool accept, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetFriendRequest(request.SourceUid, accept, cancellationToken); public static Task GroupPoke(this BotContext bot, uint groupUin, uint friendUin) => bot.ContextCollection.Business.OperationLogic.GroupPoke(groupUin, friendUin, CancellationToken.None); - public static Task GroupPoke(this BotContext bot, uint groupUin, uint friendUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupPoke(groupUin, friendUin, ct); + public static Task GroupPoke(this BotContext bot, uint groupUin, uint friendUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupPoke(groupUin, friendUin, cancellationToken); public static Task SetEssenceMessage(this BotContext bot, MessageChain chain) => bot.ContextCollection.Business.OperationLogic.SetEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF), CancellationToken.None); - public static Task SetEssenceMessage(this BotContext bot, MessageChain chain, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF), ct); + public static Task SetEssenceMessage(this BotContext bot, MessageChain chain, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF), cancellationToken); public static Task RemoveEssenceMessage(this BotContext bot, MessageChain chain) => bot.ContextCollection.Business.OperationLogic.RemoveEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF), CancellationToken.None); - public static Task RemoveEssenceMessage(this BotContext bot, MessageChain chain, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RemoveEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF), ct); + public static Task RemoveEssenceMessage(this BotContext bot, MessageChain chain, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RemoveEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF), cancellationToken); public static Task GroupSetSpecialTitle(this BotContext bot, uint groupUin, uint targetUin, string title) => bot.ContextCollection.Business.OperationLogic.GroupSetSpecialTitle(groupUin, targetUin, title, CancellationToken.None); - public static Task GroupSetSpecialTitle(this BotContext bot, uint groupUin, uint targetUin, string title, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupSetSpecialTitle(groupUin, targetUin, title, ct); + public static Task GroupSetSpecialTitle(this BotContext bot, uint groupUin, uint targetUin, string title, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupSetSpecialTitle(groupUin, targetUin, title, cancellationToken); public static Task GroupSetMessageReaction(this BotContext bot, uint groupUin, uint sequence, string code) => bot.ContextCollection.Business.OperationLogic.SetMessageReaction(groupUin, sequence, code, true, CancellationToken.None); - public static Task GroupSetMessageReaction(this BotContext bot, uint groupUin, uint sequence, string code, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetMessageReaction(groupUin, sequence, code, true, ct); + public static Task GroupSetMessageReaction(this BotContext bot, uint groupUin, uint sequence, string code, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetMessageReaction(groupUin, sequence, code, true, cancellationToken); public static Task GroupSetMessageReaction(this BotContext bot, uint groupUin, uint sequence, string code, bool isSet) => bot.ContextCollection.Business.OperationLogic.SetMessageReaction(groupUin, sequence, code, isSet, CancellationToken.None); - public static Task GroupSetMessageReaction(this BotContext bot, uint groupUin, uint sequence, string code, bool isSet, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetMessageReaction(groupUin, sequence, code, isSet, ct); + public static Task GroupSetMessageReaction(this BotContext bot, uint groupUin, uint sequence, string code, bool isSet, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetMessageReaction(groupUin, sequence, code, isSet, cancellationToken); public static Task GroupSetAvatar(this BotContext bot, uint groupUin, ImageEntity imageEntity) => bot.ContextCollection.Business.OperationLogic.GroupSetAvatar(groupUin, imageEntity, CancellationToken.None); - public static Task GroupSetAvatar(this BotContext bot, uint groupUin, ImageEntity imageEntity, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupSetAvatar(groupUin, imageEntity, ct); + public static Task GroupSetAvatar(this BotContext bot, uint groupUin, ImageEntity imageEntity, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupSetAvatar(groupUin, imageEntity, cancellationToken); public static Task<(uint, uint)> GroupRemainAtAll(this BotContext bot, uint groupUin) => bot.ContextCollection.Business.OperationLogic.GroupRemainAtAll(groupUin, CancellationToken.None); - public static Task<(uint, uint)> GroupRemainAtAll(this BotContext bot, uint groupUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupRemainAtAll(groupUin, ct); + public static Task<(uint, uint)> GroupRemainAtAll(this BotContext bot, uint groupUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupRemainAtAll(groupUin, cancellationToken); #region Group File System public static Task FetchGroupFSSpace(this BotContext bot, uint groupUin) => bot.ContextCollection.Business.OperationLogic.FetchGroupFSSpace(groupUin, CancellationToken.None); - public static Task FetchGroupFSSpace(this BotContext bot, uint groupUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FetchGroupFSSpace(groupUin, ct); + public static Task FetchGroupFSSpace(this BotContext bot, uint groupUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchGroupFSSpace(groupUin, cancellationToken); public static Task FetchGroupFSCount(this BotContext bot, uint groupUin) => bot.ContextCollection.Business.OperationLogic.FetchGroupFSCount(groupUin, CancellationToken.None); - public static Task FetchGroupFSCount(this BotContext bot, uint groupUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FetchGroupFSCount(groupUin, ct); + public static Task FetchGroupFSCount(this BotContext bot, uint groupUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchGroupFSCount(groupUin, cancellationToken); public static Task> FetchGroupFSList(this BotContext bot, uint groupUin, string targetDirectory = "/") => bot.ContextCollection.Business.OperationLogic.FetchGroupFSList(groupUin, targetDirectory, CancellationToken.None); - public static Task> FetchGroupFSList(this BotContext bot, uint groupUin, CancellationToken ct, string targetDirectory = "/") - => bot.ContextCollection.Business.OperationLogic.FetchGroupFSList(groupUin, targetDirectory, ct); + public static Task> FetchGroupFSList(this BotContext bot, uint groupUin, string targetDirectory, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchGroupFSList(groupUin, targetDirectory, cancellationToken); public static Task FetchGroupFSDownload(this BotContext bot, uint groupUin, string fileId) => bot.ContextCollection.Business.OperationLogic.FetchGroupFSDownload(groupUin, fileId, CancellationToken.None); - public static Task FetchGroupFSDownload(this BotContext bot, uint groupUin, string fileId, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FetchGroupFSDownload(groupUin, fileId, ct); + public static Task FetchGroupFSDownload(this BotContext bot, uint groupUin, string fileId, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchGroupFSDownload(groupUin, fileId, cancellationToken); public static Task<(int RetCode, string RetMsg)> GroupFSMove(this BotContext bot, uint groupUin, string fileId, string parentDirectory, string targetDirectory) => bot.ContextCollection.Business.OperationLogic.GroupFSMove(groupUin, fileId, parentDirectory, targetDirectory, CancellationToken.None); - public static Task<(int RetCode, string RetMsg)> GroupFSMove(this BotContext bot, uint groupUin, string fileId, string parentDirectory, string targetDirectory, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupFSMove(groupUin, fileId, parentDirectory, targetDirectory, ct); + public static Task<(int RetCode, string RetMsg)> GroupFSMove(this BotContext bot, uint groupUin, string fileId, string parentDirectory, string targetDirectory, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupFSMove(groupUin, fileId, parentDirectory, targetDirectory, cancellationToken); public static Task<(int RetCode, string RetMsg)> GroupFSDelete(this BotContext bot, uint groupUin, string fileId) => bot.ContextCollection.Business.OperationLogic.GroupFSDelete(groupUin, fileId, CancellationToken.None); - public static Task<(int RetCode, string RetMsg)> GroupFSDelete(this BotContext bot, uint groupUin, string fileId, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupFSDelete(groupUin, fileId, ct); + public static Task<(int RetCode, string RetMsg)> GroupFSDelete(this BotContext bot, uint groupUin, string fileId, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupFSDelete(groupUin, fileId, cancellationToken); public static Task<(int RetCode, string RetMsg)> GroupFSCreateFolder(this BotContext bot, uint groupUin, string name) => bot.ContextCollection.Business.OperationLogic.GroupFSCreateFolder(groupUin, name, CancellationToken.None); - public static Task<(int RetCode, string RetMsg)> GroupFSCreateFolder(this BotContext bot, uint groupUin, string name, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupFSCreateFolder(groupUin, name, ct); + public static Task<(int RetCode, string RetMsg)> GroupFSCreateFolder(this BotContext bot, uint groupUin, string name, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupFSCreateFolder(groupUin, name, cancellationToken); public static Task<(int RetCode, string RetMsg)> GroupFSDeleteFolder(this BotContext bot, uint groupUin, string folderId) => bot.ContextCollection.Business.OperationLogic.GroupFSDeleteFolder(groupUin, folderId, CancellationToken.None); - public static Task<(int RetCode, string RetMsg)> GroupFSDeleteFolder(this BotContext bot, uint groupUin, string folderId, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupFSDeleteFolder(groupUin, folderId, ct); + public static Task<(int RetCode, string RetMsg)> GroupFSDeleteFolder(this BotContext bot, uint groupUin, string folderId, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupFSDeleteFolder(groupUin, folderId, cancellationToken); public static Task<(int RetCode, string RetMsg)> GroupFSRenameFolder(this BotContext bot, uint groupUin, string folderId, string newFolderName) => bot.ContextCollection.Business.OperationLogic.GroupFSRenameFolder(groupUin, folderId, newFolderName, CancellationToken.None); - public static Task<(int RetCode, string RetMsg)> GroupFSRenameFolder(this BotContext bot, uint groupUin, string folderId, string newFolderName, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupFSRenameFolder(groupUin, folderId, newFolderName, ct); + public static Task<(int RetCode, string RetMsg)> GroupFSRenameFolder(this BotContext bot, uint groupUin, string folderId, string newFolderName, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupFSRenameFolder(groupUin, folderId, newFolderName, cancellationToken); public static Task GroupFSUpload(this BotContext bot, uint groupUin, FileEntity fileEntity, string targetDirectory = "/") => bot.ContextCollection.Business.OperationLogic.GroupFSUpload(groupUin, fileEntity, targetDirectory, CancellationToken.None); - public static Task GroupFSUpload(this BotContext bot, uint groupUin, FileEntity fileEntity, CancellationToken ct, string targetDirectory = "/") - => bot.ContextCollection.Business.OperationLogic.GroupFSUpload(groupUin, fileEntity, targetDirectory, ct); + public static Task GroupFSUpload(this BotContext bot, uint groupUin, FileEntity fileEntity, string targetDirectory, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupFSUpload(groupUin, fileEntity, targetDirectory, cancellationToken); #endregion -} \ No newline at end of file +} diff --git a/Lagrange.Core/Common/Interface/Api/OperationExt.cs b/Lagrange.Core/Common/Interface/Api/OperationExt.cs index 83cf69682..292842e04 100644 --- a/Lagrange.Core/Common/Interface/Api/OperationExt.cs +++ b/Lagrange.Core/Common/Interface/Api/OperationExt.cs @@ -20,11 +20,11 @@ public static Task> FetchFriends(this BotContext bot, bool refre /// Fetch the friend list of account from server or cache /// /// target BotContext - /// The cancellation token + /// The cancellation token /// force the cache to be refreshed /// - public static Task> FetchFriends(this BotContext bot, CancellationToken ct, bool refreshCache = false) - => bot.ContextCollection.Business.OperationLogic.FetchFriends(ct, refreshCache); + public static Task> FetchFriends(this BotContext bot, bool refreshCache, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchFriends(cancellationToken, refreshCache); /// /// Fetch the member list of the group from server or cache @@ -41,11 +41,11 @@ public static Task> FetchMembers(this BotContext bot, uint /// /// target BotContext /// - /// The cancellation token + /// The cancellation token /// force the cache to be refreshed /// - public static Task> FetchMembers(this BotContext bot, uint groupUin, CancellationToken ct, bool refreshCache = false) - => bot.ContextCollection.Business.OperationLogic.FetchMembers(groupUin, ct, refreshCache); + public static Task> FetchMembers(this BotContext bot, uint groupUin, bool refreshCache, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchMembers(groupUin, cancellationToken, refreshCache); /// /// Fetch the group list of the account from server or cache @@ -60,11 +60,11 @@ public static Task> FetchGroups(this BotContext bot, bool refresh /// Fetch the group list of the account from server or cache /// /// target BotContext - /// The cancellation token + /// The cancellation token /// force the cache to be refreshed /// - public static Task> FetchGroups(this BotContext bot, CancellationToken ct, bool refreshCache = false) - => bot.ContextCollection.Business.OperationLogic.FetchGroups(refreshCache, ct); + public static Task> FetchGroups(this BotContext bot, bool refreshCache, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchGroups(refreshCache, cancellationToken); /// /// Fetch the cookies/pskey for accessing other site @@ -80,10 +80,10 @@ public static Task> FetchCookies(this BotContext bot, List /// /// target BotContext /// the domain for the cookie to be valid - /// The cancellation token + /// The cancellation token /// the list of cookies - public static Task> FetchCookies(this BotContext bot, List domains, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GetCookies(domains, ct); + public static Task> FetchCookies(this BotContext bot, List domains, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GetCookies(domains, cancellationToken); /// /// Send the message @@ -98,9 +98,9 @@ public static Task SendMessage(this BotContext bot, MessageChain /// /// target BotContext /// the chain constructed by - /// The cancellation token - public static Task SendMessage(this BotContext bot, MessageChain chain, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SendMessage(chain, ct); + /// The cancellation token + public static Task SendMessage(this BotContext bot, MessageChain chain, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SendMessage(chain, cancellationToken); /// /// Recall the group message from Bot itself by @@ -118,10 +118,10 @@ public static Task RecallGroupMessage(this BotContext bot, uint groupUin, /// target BotContext /// The uin for target group of the message /// The return value for - /// The cancellation token + /// The cancellation token /// Successfully recalled or not - public static Task RecallGroupMessage(this BotContext bot, uint groupUin, MessageResult result, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RecallGroupMessage(groupUin, result, ct); + public static Task RecallGroupMessage(this BotContext bot, uint groupUin, MessageResult result, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RecallGroupMessage(groupUin, result, cancellationToken); /// /// Recall the group message by @@ -137,10 +137,10 @@ public static Task RecallGroupMessage(this BotContext bot, MessageChain ch /// /// target BotContext /// target MessageChain, must be Group - /// The cancellation token + /// The cancellation token /// Successfully recalled or not - public static Task RecallGroupMessage(this BotContext bot, MessageChain chain, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RecallGroupMessage(chain, ct); + public static Task RecallGroupMessage(this BotContext bot, MessageChain chain, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RecallGroupMessage(chain, cancellationToken); /// /// Recall the group message by sequence @@ -158,10 +158,10 @@ public static Task RecallGroupMessage(this BotContext bot, uint groupUin, /// target BotContext /// The uin for target group of the message /// The sequence for target message - /// The cancellation token + /// The cancellation token /// Successfully recalled or not - public static Task RecallGroupMessage(this BotContext bot, uint groupUin, uint sequence, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RecallGroupMessage(groupUin, sequence, ct); + public static Task RecallGroupMessage(this BotContext bot, uint groupUin, uint sequence, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RecallGroupMessage(groupUin, sequence, cancellationToken); /// /// Recall the group message from Bot itself by @@ -179,10 +179,10 @@ public static Task RecallFriendMessage(this BotContext bot, uint friendUin /// target BotContext /// The uin for target friend of the message /// The return value for - /// The cancellation token + /// The cancellation token /// Successfully recalled or not - public static Task RecallFriendMessage(this BotContext bot, uint friendUin, MessageResult result, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RecallFriendMessage(friendUin, result, ct); + public static Task RecallFriendMessage(this BotContext bot, uint friendUin, MessageResult result, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RecallFriendMessage(friendUin, result, cancellationToken); /// /// Recall the group message by @@ -198,10 +198,10 @@ public static Task RecallFriendMessage(this BotContext bot, MessageChain c /// /// target BotContext /// target MessageChain, must be Friend - /// The cancellation token + /// The cancellation token /// Successfully recalled or not - public static Task RecallFriendMessage(this BotContext bot, MessageChain chain, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.RecallFriendMessage(chain, ct); + public static Task RecallFriendMessage(this BotContext bot, MessageChain chain, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RecallFriendMessage(chain, cancellationToken); /// /// Fetch Notifications and requests such as friend requests and Group Join Requests @@ -215,10 +215,10 @@ public static Task RecallFriendMessage(this BotContext bot, MessageChain c /// Fetch Notifications and requests such as friend requests and Group Join Requests /// /// target BotContext - /// The cancellation token + /// The cancellation token /// - public static Task?> FetchGroupRequests(this BotContext bot, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FetchGroupRequests(ct); + public static Task?> FetchGroupRequests(this BotContext bot, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchGroupRequests(cancellationToken); /// /// @@ -232,10 +232,10 @@ public static Task RecallFriendMessage(this BotContext bot, MessageChain c /// /// /// - /// The cancellation token + /// The cancellation token /// - public static Task?> FetchFriendRequests(this BotContext bot, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FetchFriendRequests(ct); + public static Task?> FetchFriendRequests(this BotContext bot, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchFriendRequests(cancellationToken); /// /// set status @@ -251,10 +251,10 @@ public static Task SetStatus(this BotContext bot, uint status) /// /// target BotContext /// The status code - /// The cancellation token + /// The cancellation token /// - public static Task SetStatus(this BotContext bot, uint status, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetStatus(status, ct); + public static Task SetStatus(this BotContext bot, uint status, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetStatus(status, cancellationToken); /// /// set custom status @@ -272,28 +272,28 @@ public static Task SetCustomStatus(this BotContext bot, uint faceId, strin /// target BotContext /// faceId that is same as the /// text that would shown - /// The cancellation token + /// The cancellation token /// - public static Task SetCustomStatus(this BotContext bot, uint faceId, string text, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetCustomStatus(faceId, text, ct); + public static Task SetCustomStatus(this BotContext bot, uint faceId, string text, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetCustomStatus(faceId, text, cancellationToken); public static Task GroupTransfer(this BotContext bot, uint groupUin, uint targetUin) => bot.ContextCollection.Business.OperationLogic.GroupTransfer(groupUin, targetUin, CancellationToken.None); - public static Task GroupTransfer(this BotContext bot, uint groupUin, uint targetUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupTransfer(groupUin, targetUin, ct); + public static Task GroupTransfer(this BotContext bot, uint groupUin, uint targetUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupTransfer(groupUin, targetUin, cancellationToken); public static Task RequestFriend(this BotContext bot, uint targetUin, string question = "", string message = "") => bot.ContextCollection.Business.OperationLogic.RequestFriend(targetUin, question, message, CancellationToken.None); - public static Task RequestFriend(this BotContext bot, uint targetUin, CancellationToken ct, string question = "", string message = "") - => bot.ContextCollection.Business.OperationLogic.RequestFriend(targetUin, question, message, ct); + public static Task RequestFriend(this BotContext bot, uint targetUin, string question, string message, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.RequestFriend(targetUin, question, message, cancellationToken); public static Task Like(this BotContext bot, uint targetUin, uint count = 1) => bot.ContextCollection.Business.OperationLogic.Like(targetUin, count, CancellationToken.None); - public static Task Like(this BotContext bot, uint targetUin, CancellationToken ct, uint count = 1) - => bot.ContextCollection.Business.OperationLogic.Like(targetUin, count, ct); + public static Task Like(this BotContext bot, uint targetUin, uint count, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.Like(targetUin, count, cancellationToken); /// /// Get the client key for all sites @@ -304,8 +304,8 @@ public static Task Like(this BotContext bot, uint targetUin, CancellationT /// /// Get the client key for all sites /// - public static Task GetClientKey(this BotContext bot, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GetClientKey(ct); + public static Task GetClientKey(this BotContext bot, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GetClientKey(cancellationToken); /// /// Get the history message record, max 30 seqs @@ -324,9 +324,9 @@ public static Task Like(this BotContext bot, uint targetUin, CancellationT /// target GroupUin /// Start Sequence of the message /// End Sequence of the message - /// The cancellation token - public static Task?> GetGroupMessage(this BotContext bot, uint groupUin, uint startSequence, uint endSequence, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GetGroupMessage(groupUin, startSequence, endSequence, ct); + /// The cancellation token + public static Task?> GetGroupMessage(this BotContext bot, uint groupUin, uint startSequence, uint endSequence, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GetGroupMessage(groupUin, startSequence, endSequence, cancellationToken); /// /// Get the history message record for private message @@ -345,9 +345,9 @@ public static Task Like(this BotContext bot, uint targetUin, CancellationT /// target FriendUin /// timestamp of the message chain /// number of message to be fetched before timestamp - /// The cancellation token - public static Task?> GetRoamMessage(this BotContext bot, uint friendUin, uint timestamp, uint count, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GetRoamMessage(friendUin, timestamp, count, ct); + /// The cancellation token + public static Task?> GetRoamMessage(this BotContext bot, uint friendUin, uint timestamp, uint count, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GetRoamMessage(friendUin, timestamp, count, cancellationToken); /// /// Get the history message record for private message @@ -367,11 +367,11 @@ public static Task Like(this BotContext bot, uint targetUin, CancellationT /// target BotContext /// target chain /// number of message to be fetched before timestamp - /// The cancellation token - public static Task?> GetRoamMessage(this BotContext bot, MessageChain targetChain, uint count, CancellationToken ct) + /// The cancellation token + public static Task?> GetRoamMessage(this BotContext bot, MessageChain targetChain, uint count, CancellationToken cancellationToken) { uint timestamp = (uint)new DateTimeOffset(targetChain.Time).ToUnixTimeSeconds(); - return bot.ContextCollection.Business.OperationLogic.GetRoamMessage(targetChain.FriendUin, timestamp, count, ct); + return bot.ContextCollection.Business.OperationLogic.GetRoamMessage(targetChain.FriendUin, timestamp, count, cancellationToken); } public static Task?> GetC2cMessage(this BotContext bot, uint friendUin, uint startSequence, uint endSequence) @@ -379,9 +379,9 @@ public static Task Like(this BotContext bot, uint targetUin, CancellationT return bot.ContextCollection.Business.OperationLogic.GetC2cMessage(friendUin, startSequence, endSequence, CancellationToken.None); } - public static Task?> GetC2cMessage(this BotContext bot, uint friendUin, uint startSequence, uint endSequence, CancellationToken ct) + public static Task?> GetC2cMessage(this BotContext bot, uint friendUin, uint startSequence, uint endSequence, CancellationToken cancellationToken) { - return bot.ContextCollection.Business.OperationLogic.GetC2cMessage(friendUin, startSequence, endSequence, ct); + return bot.ContextCollection.Business.OperationLogic.GetC2cMessage(friendUin, startSequence, endSequence, cancellationToken); } public static Task<(int code, List? chains)> GetMessagesByResId(this BotContext bot, string resId) @@ -389,9 +389,9 @@ public static Task Like(this BotContext bot, uint targetUin, CancellationT return bot.ContextCollection.Business.OperationLogic.GetMessagesByResId(resId, CancellationToken.None); } - public static Task<(int code, List? chains)> GetMessagesByResId(this BotContext bot, string resId, CancellationToken ct) + public static Task<(int code, List? chains)> GetMessagesByResId(this BotContext bot, string resId, CancellationToken cancellationToken) { - return bot.ContextCollection.Business.OperationLogic.GetMessagesByResId(resId, ct); + return bot.ContextCollection.Business.OperationLogic.GetMessagesByResId(resId, cancellationToken); } /// @@ -408,28 +408,28 @@ public static Task GroupClockIn(this BotContext bot, uint /// /// target BotContext /// target groupUin - /// The cancellation token + /// The cancellation token /// - public static Task GroupClockIn(this BotContext bot, uint groupUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.GroupClockIn(groupUin, ct); + public static Task GroupClockIn(this BotContext bot, uint groupUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.GroupClockIn(groupUin, cancellationToken); public static Task FetchUserInfo(this BotContext bot, uint uin, bool refreshCache = false) => bot.ContextCollection.Business.OperationLogic.FetchUserInfo(uin, CancellationToken.None, refreshCache); - public static Task FetchUserInfo(this BotContext bot, uint uin, CancellationToken ct, bool refreshCache = false) - => bot.ContextCollection.Business.OperationLogic.FetchUserInfo(uin, ct, refreshCache); + public static Task FetchUserInfo(this BotContext bot, uint uin, bool refreshCache, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchUserInfo(uin, cancellationToken, refreshCache); public static Task?> FetchCustomFace(this BotContext bot) => bot.ContextCollection.Business.OperationLogic.FetchCustomFace(CancellationToken.None); - public static Task?> FetchCustomFace(this BotContext bot, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FetchCustomFace(ct); + public static Task?> FetchCustomFace(this BotContext bot, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchCustomFace(cancellationToken); public static Task UploadLongMessage(this BotContext bot, List chains) => bot.ContextCollection.Business.OperationLogic.UploadLongMessage(chains, CancellationToken.None); - public static Task UploadLongMessage(this BotContext bot, List chains, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.UploadLongMessage(chains, ct); + public static Task UploadLongMessage(this BotContext bot, List chains, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.UploadLongMessage(chains, cancellationToken); public static Task MarkAsRead(this BotContext bot, MessageChain targetChain) { @@ -437,23 +437,23 @@ public static Task MarkAsRead(this BotContext bot, MessageChain targetChai return bot.ContextCollection.Business.OperationLogic.MarkAsRead(targetChain.GroupUin ?? 0, targetChain.Uid, targetChain.Sequence, timestamp, CancellationToken.None); } - public static Task MarkAsRead(this BotContext bot, MessageChain targetChain, CancellationToken ct) + public static Task MarkAsRead(this BotContext bot, MessageChain targetChain, CancellationToken cancellationToken) { uint timestamp = (uint)(targetChain.Time - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; - return bot.ContextCollection.Business.OperationLogic.MarkAsRead(targetChain.GroupUin ?? 0, targetChain.Uid, targetChain.Sequence, timestamp, ct); + return bot.ContextCollection.Business.OperationLogic.MarkAsRead(targetChain.GroupUin ?? 0, targetChain.Uid, targetChain.Sequence, timestamp, cancellationToken); } public static Task UploadFriendFile(this BotContext bot, uint targetUin, FileEntity fileEntity) => bot.ContextCollection.Business.OperationLogic.UploadFriendFile(targetUin, fileEntity, CancellationToken.None); - public static Task UploadFriendFile(this BotContext bot, uint targetUin, FileEntity fileEntity, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.UploadFriendFile(targetUin, fileEntity, ct); + public static Task UploadFriendFile(this BotContext bot, uint targetUin, FileEntity fileEntity, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.UploadFriendFile(targetUin, fileEntity, cancellationToken); public static Task FriendPoke(this BotContext bot, uint friendUin) => bot.ContextCollection.Business.OperationLogic.FriendPoke(friendUin, CancellationToken.None); - public static Task FriendPoke(this BotContext bot, uint friendUin, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FriendPoke(friendUin, ct); + public static Task FriendPoke(this BotContext bot, uint friendUin, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FriendPoke(friendUin, cancellationToken); /// /// Send a special window shake to friend @@ -470,9 +470,9 @@ public static Task FriendSpecialShake(this BotContext bot, uint f /// target friend uin /// face type /// count of face - /// The cancellation token - public static Task FriendSpecialShake(this BotContext bot, uint friendUin, SpecialPokeFaceType type, uint count, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FriendSpecialShake(friendUin, type, count, ct); + /// The cancellation token + public static Task FriendSpecialShake(this BotContext bot, uint friendUin, SpecialPokeFaceType type, uint count, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FriendSpecialShake(friendUin, type, count, cancellationToken); /// /// Send a window shake to friend @@ -489,15 +489,15 @@ public static Task FriendShake(this BotContext bot, uint friendUi /// target friend uin /// face type /// How big the face will be displayed ([0,3] is valid) - /// The cancellation token - public static Task FriendShake(this BotContext bot, uint friendUin, PokeFaceType type, ushort strength, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FriendShake(friendUin, type, strength, ct); + /// The cancellation token + public static Task FriendShake(this BotContext bot, uint friendUin, PokeFaceType type, ushort strength, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FriendShake(friendUin, type, strength, cancellationToken); public static Task?> FetchMarketFaceKey(this BotContext bot, List faceIds) => bot.ContextCollection.Business.OperationLogic.FetchMarketFaceKey(faceIds, CancellationToken.None); - public static Task?> FetchMarketFaceKey(this BotContext bot, List faceIds, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.FetchMarketFaceKey(faceIds, ct); + public static Task?> FetchMarketFaceKey(this BotContext bot, List faceIds, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.FetchMarketFaceKey(faceIds, cancellationToken); /// /// Set the avatar of the bot itself @@ -512,7 +512,7 @@ public static Task SetAvatar(this BotContext bot, ImageEntity avatar) /// /// target /// The avatar object, - /// The cancellation token - public static Task SetAvatar(this BotContext bot, ImageEntity avatar, CancellationToken ct) - => bot.ContextCollection.Business.OperationLogic.SetAvatar(avatar, ct); + /// The cancellation token + public static Task SetAvatar(this BotContext bot, ImageEntity avatar, CancellationToken cancellationToken) + => bot.ContextCollection.Business.OperationLogic.SetAvatar(avatar, cancellationToken); } diff --git a/Lagrange.Core/Internal/Context/BusinessContext.cs b/Lagrange.Core/Internal/Context/BusinessContext.cs index 1fafac9cb..40f213054 100644 --- a/Lagrange.Core/Internal/Context/BusinessContext.cs +++ b/Lagrange.Core/Internal/Context/BusinessContext.cs @@ -73,14 +73,14 @@ private void RegisterLogics() } } - public async Task PushEvent(ProtocolEvent @event, CancellationToken ct) + public async Task PushEvent(ProtocolEvent @event, CancellationToken cancellationToken) { try { var packets = Collection.Service.ResolvePacketByEvent(@event); foreach (var packet in packets) { - ct.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); await Collection.Packet.PostPacket(packet); } } @@ -95,23 +95,23 @@ public async Task PushEvent(ProtocolEvent @event, CancellationToken ct) /// /// Send Event to the Server, goes through the given context /// - public async Task> SendEvent(ProtocolEvent @event, CancellationToken ct) + public async Task> SendEvent(ProtocolEvent @event, CancellationToken cancellationToken) { - await HandleOutgoingEvent(@event, ct); + await HandleOutgoingEvent(@event, cancellationToken); var result = new List(); - ct.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); try { var packets = Collection.Service.ResolvePacketByEvent(@event); foreach (var packet in packets) { - var returnVal = await Collection.Packet.SendPacket(packet, ct); + var returnVal = await Collection.Packet.SendPacket(packet, cancellationToken); var resolved = Collection.Service.ResolveEventByPacket(returnVal); foreach (var protocol in resolved) { - await HandleIncomingEvent(protocol, ct); + await HandleIncomingEvent(protocol, cancellationToken); result.Add(protocol); } } @@ -130,7 +130,7 @@ public async Task> SendEvent(ProtocolEvent @event, Cancellat return result; } - public async Task HandleIncomingEvent(ProtocolEvent @event, CancellationToken ct) + public async Task HandleIncomingEvent(ProtocolEvent @event, CancellationToken cancellationToken) { _businessLogics.TryGetValue(typeof(ProtocolEvent), out var baseLogics); _businessLogics.TryGetValue(@event.GetType(), out var normalLogics); @@ -143,7 +143,7 @@ public async Task HandleIncomingEvent(ProtocolEvent @event, CancellationTo { try { - await logic.Incoming(@event, ct); + await logic.Incoming(@event, cancellationToken); } catch (TaskCanceledException) { @@ -161,7 +161,7 @@ public async Task HandleIncomingEvent(ProtocolEvent @event, CancellationTo return true; } - public async Task HandleOutgoingEvent(ProtocolEvent @event, CancellationToken ct) + public async Task HandleOutgoingEvent(ProtocolEvent @event, CancellationToken cancellationToken) { _businessLogics.TryGetValue(typeof(ProtocolEvent), out var baseLogics); _businessLogics.TryGetValue(@event.GetType(), out var normalLogics); @@ -174,7 +174,7 @@ public async Task HandleOutgoingEvent(ProtocolEvent @event, CancellationTo { try { - await logic.Outgoing(@event, ct); + await logic.Outgoing(@event, cancellationToken); } catch (TaskCanceledException) { @@ -220,4 +220,4 @@ public async Task HandleServerPacket(SsoPacket packet) return success; } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/HighwayContext.cs b/Lagrange.Core/Internal/Context/HighwayContext.cs index 648dd521d..a28a5eb1e 100644 --- a/Lagrange.Core/Internal/Context/HighwayContext.cs +++ b/Lagrange.Core/Internal/Context/HighwayContext.cs @@ -57,7 +57,7 @@ public HighwayContext(ContextCollection collection, BotKeystore keystore, BotApp _concurrent = config.HighwayConcurrent; } - public async Task UploadResources(MessageChain chain, CancellationToken ct) + public async Task UploadResources(MessageChain chain, CancellationToken cancellationToken) { foreach (var entity in chain) { @@ -65,8 +65,8 @@ public async Task UploadResources(MessageChain chain, CancellationToken ct) { try { - if (chain.IsGroup) await uploader.UploadGroup(Collection, chain, entity, ct); - else await uploader.UploadPrivate(Collection, chain, entity, ct); + if (chain.IsGroup) await uploader.UploadGroup(Collection, chain, entity, cancellationToken); + else await uploader.UploadPrivate(Collection, chain, entity, cancellationToken); } catch { @@ -76,7 +76,7 @@ public async Task UploadResources(MessageChain chain, CancellationToken ct) } } - public async Task ManualUploadEntity(IMessageEntity entity, CancellationToken ct) + public async Task ManualUploadEntity(IMessageEntity entity, CancellationToken cancellationToken) { if (_uploaders.TryGetValue(entity.GetType(), out var uploader)) { @@ -86,7 +86,7 @@ public async Task ManualUploadEntity(IMessageEntity entity, CancellationToken ct string uid = Collection.Keystore.Uid ?? ""; var chain = new MessageChain(uin, uid, uid) { entity }; - await uploader.UploadPrivate(Collection, chain, entity, ct); + await uploader.UploadPrivate(Collection, chain, entity, cancellationToken); } catch { @@ -242,4 +242,4 @@ public void Dispose() { _client.Dispose(); } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/CachingLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/CachingLogic.cs index fa9e4372c..ddfd32f94 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/CachingLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/CachingLogic.cs @@ -37,25 +37,25 @@ internal CachingLogic(ContextCollection collection) : base(collection) _cacheUsers = new ConcurrentDictionary(); } - public override Task Incoming(ProtocolEvent e, CancellationToken ct) + public override Task Incoming(ProtocolEvent e, CancellationToken cancellationToken) { return e switch { - GroupSysDecreaseEvent groupSysDecreaseEvent when groupSysDecreaseEvent.MemberUid != Collection.Keystore.Uid => CacheUid(groupSysDecreaseEvent.GroupUin, ct, force: true), - GroupSysIncreaseEvent groupSysIncreaseEvent => CacheUid(groupSysIncreaseEvent.GroupUin, ct, force: true), - GroupSysAdminEvent groupSysAdminEvent => CacheUid(groupSysAdminEvent.GroupUin, ct, force: true), + GroupSysDecreaseEvent groupSysDecreaseEvent when groupSysDecreaseEvent.MemberUid != Collection.Keystore.Uid => CacheUid(groupSysDecreaseEvent.GroupUin, cancellationToken, force: true), + GroupSysIncreaseEvent groupSysIncreaseEvent => CacheUid(groupSysIncreaseEvent.GroupUin, cancellationToken, force: true), + GroupSysAdminEvent groupSysAdminEvent => CacheUid(groupSysAdminEvent.GroupUin, cancellationToken, force: true), _ => Task.CompletedTask, }; } - public async Task> GetCachedGroups(bool refreshCache, CancellationToken ct) + public async Task> GetCachedGroups(bool refreshCache, CancellationToken cancellationToken) { if (_cachedGroupEntities.Count == 0 || refreshCache) { _cachedGroupEntities.Clear(); var fetchGroupsEvent = FetchGroupsEvent.Create(); - var events = await Collection.Business.SendEvent(fetchGroupsEvent, ct); + var events = await Collection.Business.SendEvent(fetchGroupsEvent, cancellationToken); var groups = ((FetchGroupsEvent)events[0]).Groups; _cachedGroupEntities.AddRange(groups); @@ -65,60 +65,60 @@ public async Task> GetCachedGroups(bool refreshCache, Cancellatio return _cachedGroupEntities; } - public async Task ResolveUid(uint? groupUin, uint friendUin, CancellationToken ct) + public async Task ResolveUid(uint? groupUin, uint friendUin, CancellationToken cancellationToken) { - if (_uinToUid.Count == 0) await ResolveFriendsUidAndFriendGroups(ct); + if (_uinToUid.Count == 0) await ResolveFriendsUidAndFriendGroups(cancellationToken); if (groupUin == null) return _uinToUid.GetValueOrDefault(friendUin); - await CacheUid(groupUin.Value, ct); + await CacheUid(groupUin.Value, cancellationToken); return _uinToUid.GetValueOrDefault(friendUin); } - public async Task ResolveUin(uint? groupUin, string friendUid, CancellationToken ct, bool force = false) + public async Task ResolveUin(uint? groupUin, string friendUid, CancellationToken cancellationToken, bool force = false) { - if (_uinToUid.Count == 0) await ResolveFriendsUidAndFriendGroups(ct); + if (_uinToUid.Count == 0) await ResolveFriendsUidAndFriendGroups(cancellationToken); if (groupUin == null) return _uinToUid.FirstOrDefault(x => x.Value == friendUid).Key; - await CacheUid(groupUin.Value, ct, force: force); + await CacheUid(groupUin.Value, cancellationToken, force: force); return _uinToUid.FirstOrDefault(x => x.Value == friendUid).Key; } - public async Task> GetCachedMembers(uint groupUin, bool refreshCache, CancellationToken ct) + public async Task> GetCachedMembers(uint groupUin, bool refreshCache, CancellationToken cancellationToken) { if (!_cachedGroupMembers.TryGetValue(groupUin, out var members) || refreshCache) { - await ResolveMembersUid(groupUin, ct); + await ResolveMembersUid(groupUin, cancellationToken); return _cachedGroupMembers.TryGetValue(groupUin, out members) ? members : new List(); } return members; } - public async Task> GetCachedFriends(bool refreshCache, CancellationToken ct) + public async Task> GetCachedFriends(bool refreshCache, CancellationToken cancellationToken) { - if (_cachedFriends.Count == 0 || refreshCache) await ResolveFriendsUidAndFriendGroups(ct); + if (_cachedFriends.Count == 0 || refreshCache) await ResolveFriendsUidAndFriendGroups(cancellationToken); return _cachedFriends; } - public async Task GetCachedUsers(uint uin, bool refreshCache, CancellationToken ct) + public async Task GetCachedUsers(uint uin, bool refreshCache, CancellationToken cancellationToken) { - if (!_cacheUsers.ContainsKey(uin) || refreshCache) await ResolveUser(uin, ct); + if (!_cacheUsers.ContainsKey(uin) || refreshCache) await ResolveUser(uin, cancellationToken); if (!_cacheUsers.TryGetValue(uin, out BotUserInfo? info)) return null; return info; } - private async Task CacheUid(uint groupUin, CancellationToken ct, bool force = false) + private async Task CacheUid(uint groupUin, CancellationToken cancellationToken, bool force = false) { if (!_cachedGroups.Contains(groupUin) || force) { Collection.Log.LogVerbose(Tag, $"Caching group members: {groupUin}"); - await ResolveMembersUid(groupUin, ct); + await ResolveMembersUid(groupUin, cancellationToken); _cachedGroups.Add(groupUin); } } - private async Task ResolveFriendsUidAndFriendGroups(CancellationToken ct) + private async Task ResolveFriendsUidAndFriendGroups(CancellationToken cancellationToken) { uint? next = null; var friends = new List(); @@ -126,7 +126,7 @@ private async Task ResolveFriendsUidAndFriendGroups(CancellationToken ct) do { var @event = FetchFriendsEvent.Create(next); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count == 0) { @@ -153,10 +153,10 @@ private async Task ResolveFriendsUidAndFriendGroups(CancellationToken ct) _cachedFriends.AddRange(friends); } - private async Task ResolveMembersUid(uint groupUin, CancellationToken ct) + private async Task ResolveMembersUid(uint groupUin, CancellationToken cancellationToken) { var fetchFriendsEvent = FetchMembersEvent.Create(groupUin); - var events = await Collection.Business.SendEvent(fetchFriendsEvent, ct); + var events = await Collection.Business.SendEvent(fetchFriendsEvent, cancellationToken); if (events.Count != 0) { @@ -166,7 +166,7 @@ private async Task ResolveMembersUid(uint groupUin, CancellationToken ct) while (token != null) { var next = FetchMembersEvent.Create(groupUin, token); - var results = await Collection.Business.SendEvent(next, ct); + var results = await Collection.Business.SendEvent(next, cancellationToken); @event.Members.AddRange(((FetchMembersEvent)results[0]).Members); token = ((FetchMembersEvent)results[0]).Token; } @@ -181,13 +181,13 @@ private async Task ResolveMembersUid(uint groupUin, CancellationToken ct) } } - private async Task ResolveUser(uint uin, CancellationToken ct) + private async Task ResolveUser(uint uin, CancellationToken cancellationToken) { - var events = await Collection.Business.SendEvent(FetchUserInfoEvent.Create(uin), ct); + var events = await Collection.Business.SendEvent(FetchUserInfoEvent.Create(uin), cancellationToken); if (events.Count != 0 && events[0] is FetchUserInfoEvent { } @event) { _cacheUsers.AddOrUpdate(uin, @event.UserInfo, (_key, _value) => @event.UserInfo); } } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs index 6037fb3aa..e5484cb40 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/MessagingLogic.cs @@ -45,15 +45,15 @@ internal class MessagingLogic : LogicBase internal MessagingLogic(ContextCollection collection) : base(collection) { } - public override async Task Incoming(ProtocolEvent e, CancellationToken ct) + public override async Task Incoming(ProtocolEvent e, CancellationToken cancellationToken) { switch (e) { case PushMessageEvent push: { if (push.Chain.Count == 0) return; - await ResolveIncomingChain(push.Chain, ct); - await ResolveChainMetadata(push.Chain, ct); + await ResolveIncomingChain(push.Chain, cancellationToken); + await ResolveChainMetadata(push.Chain, cancellationToken); MessageFilter.Filter(push.Chain); var chain = push.Chain; @@ -75,8 +75,8 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) foreach (var chain in get.Chains) { if (chain.Count == 0) return; - await ResolveIncomingChain(chain, ct); - await ResolveChainMetadata(chain, ct); + await ResolveIncomingChain(chain, cancellationToken); + await ResolveChainMetadata(chain, cancellationToken); MessageFilter.Filter(chain); } break; @@ -86,40 +86,40 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) foreach (var chain in get.Chains) { if (chain.Count == 0) return; - await ResolveIncomingChain(chain, ct); - await ResolveChainMetadata(chain, ct); + await ResolveIncomingChain(chain, cancellationToken); + await ResolveChainMetadata(chain, cancellationToken); MessageFilter.Filter(chain); } break; } case GroupSysInviteEvent invite: { - uint invitorUin = await Collection.Business.CachingLogic.ResolveUin(null, invite.InvitorUid, ct) ?? 0; + uint invitorUin = await Collection.Business.CachingLogic.ResolveUin(null, invite.InvitorUid, cancellationToken) ?? 0; var inviteArgs = new GroupInvitationEvent(invite.GroupUin, invitorUin); Collection.Invoker.PostEvent(inviteArgs); break; } case GroupSysAdminEvent admin: { - uint adminUin = await Collection.Business.CachingLogic.ResolveUin(admin.GroupUin, admin.Uid, ct) ?? 0; + uint adminUin = await Collection.Business.CachingLogic.ResolveUin(admin.GroupUin, admin.Uid, cancellationToken) ?? 0; var adminArgs = new GroupAdminChangedEvent(admin.GroupUin, adminUin, admin.IsPromoted); Collection.Invoker.PostEvent(adminArgs); break; } case GroupSysIncreaseEvent increase: { - uint memberUin = await Collection.Business.CachingLogic.ResolveUin(increase.GroupUin, increase.MemberUid, ct, true) ?? 0; + uint memberUin = await Collection.Business.CachingLogic.ResolveUin(increase.GroupUin, increase.MemberUid, cancellationToken, true) ?? 0; uint? invitorUin = null; - if (increase.InvitorUid != null) invitorUin = await Collection.Business.CachingLogic.ResolveUin(increase.GroupUin, increase.InvitorUid, ct); + if (increase.InvitorUid != null) invitorUin = await Collection.Business.CachingLogic.ResolveUin(increase.GroupUin, increase.InvitorUid, cancellationToken); var increaseArgs = new GroupMemberIncreaseEvent(increase.GroupUin, memberUin, invitorUin, increase.Type); Collection.Invoker.PostEvent(increaseArgs); break; } case GroupSysDecreaseEvent decrease: { - uint memberUin = await Collection.Business.CachingLogic.ResolveUin(decrease.GroupUin, decrease.MemberUid, ct) ?? 0; + uint memberUin = await Collection.Business.CachingLogic.ResolveUin(decrease.GroupUin, decrease.MemberUid, cancellationToken) ?? 0; uint? operatorUin = null; - if (decrease.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(decrease.GroupUin, decrease.OperatorUid, ct); + if (decrease.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(decrease.GroupUin, decrease.OperatorUid, cancellationToken); var decreaseArgs = new GroupMemberDecreaseEvent(decrease.GroupUin, memberUin, operatorUin, decrease.Type); Collection.Invoker.PostEvent(decreaseArgs); break; @@ -138,7 +138,7 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) } case GroupSysReactionEvent reaction: { - uint operatorUin = await Collection.Business.CachingLogic.ResolveUin(reaction.TargetGroupUin, reaction.OperatorUid, ct) ?? 0; + uint operatorUin = await Collection.Business.CachingLogic.ResolveUin(reaction.TargetGroupUin, reaction.OperatorUid, cancellationToken) ?? 0; var pokeArgs = new GroupReactionEvent(reaction.TargetGroupUin, reaction.TargetSequence, operatorUin, reaction.IsAdd, reaction.Code, reaction.Count); Collection.Invoker.PostEvent(pokeArgs); break; @@ -158,25 +158,25 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) case GroupSysMuteEvent groupMute: { uint? operatorUin = null; - if (groupMute.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(groupMute.GroupUin, groupMute.OperatorUid, ct); + if (groupMute.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(groupMute.GroupUin, groupMute.OperatorUid, cancellationToken); var muteArgs = new GroupMuteEvent(groupMute.GroupUin, operatorUin, groupMute.IsMuted); Collection.Invoker.PostEvent(muteArgs); break; } case GroupSysMemberMuteEvent memberMute: { - uint memberUin = await Collection.Business.CachingLogic.ResolveUin(memberMute.GroupUin, memberMute.TargetUid, ct) ?? 0; + uint memberUin = await Collection.Business.CachingLogic.ResolveUin(memberMute.GroupUin, memberMute.TargetUid, cancellationToken) ?? 0; uint? operatorUin = null; - if (memberMute.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(memberMute.GroupUin, memberMute.OperatorUid, ct); + if (memberMute.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(memberMute.GroupUin, memberMute.OperatorUid, cancellationToken); var muteArgs = new GroupMemberMuteEvent(memberMute.GroupUin, memberUin, operatorUin, memberMute.Duration); Collection.Invoker.PostEvent(muteArgs); break; } case GroupSysRecallEvent recall: { - uint authorUin = await Collection.Business.CachingLogic.ResolveUin(recall.GroupUin, recall.AuthorUid, ct) ?? 0; + uint authorUin = await Collection.Business.CachingLogic.ResolveUin(recall.GroupUin, recall.AuthorUid, cancellationToken) ?? 0; uint operatorUin = 0; - if (recall.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(recall.GroupUin, recall.OperatorUid, ct) ?? 0; + if (recall.OperatorUid != null) operatorUin = await Collection.Business.CachingLogic.ResolveUin(recall.GroupUin, recall.OperatorUid, cancellationToken) ?? 0; var recallArgs = new GroupRecallEvent(recall.GroupUin, authorUin, operatorUin, recall.Sequence, recall.Time, recall.Random, recall.Tip); Collection.Invoker.PostEvent(recallArgs); break; @@ -184,7 +184,7 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) case GroupSysRequestJoinEvent join: { var fetchUidEvent = FetchUserInfoEvent.Create(join.TargetUid); - var results = await Collection.Business.SendEvent(fetchUidEvent, ct); + var results = await Collection.Business.SendEvent(fetchUidEvent, cancellationToken); uint targetUin = results.Count == 0 ? 0 : ((FetchUserInfoEvent)results[0]).UserInfo.Uin; var joinArgs = new GroupJoinRequestEvent(join.GroupUin, targetUin); @@ -193,10 +193,10 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) } case GroupSysRequestInvitationEvent invitation: { - uint invitorUin = await Collection.Business.CachingLogic.ResolveUin(invitation.GroupUin, invitation.InvitorUid, ct) ?? 0; + uint invitorUin = await Collection.Business.CachingLogic.ResolveUin(invitation.GroupUin, invitation.InvitorUid, cancellationToken) ?? 0; var fetchUidEvent = FetchUserInfoEvent.Create(invitation.TargetUid); - var results = await Collection.Business.SendEvent(fetchUidEvent, ct); + var results = await Collection.Business.SendEvent(fetchUidEvent, cancellationToken); uint targetUin = results.Count == 0 ? 0 : ((FetchUserInfoEvent)results[0]).UserInfo.Uin; var invitationArgs = new GroupInvitationRequestEvent(invitation.GroupUin, targetUin, invitorUin); @@ -205,7 +205,7 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) } case FriendSysRecallEvent recall: { - uint fromUin = await Collection.Business.CachingLogic.ResolveUin(null, recall.FromUid, ct) ?? 0; + uint fromUin = await Collection.Business.CachingLogic.ResolveUin(null, recall.FromUid, cancellationToken) ?? 0; var recallArgs = new FriendRecallEvent(fromUin, recall.ClientSequence, recall.Time, recall.Random, recall.Tip); Collection.Invoker.PostEvent(recallArgs); break; @@ -229,7 +229,7 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) foreach (var chain in multi.Chains) { if (chain.Count == 0) continue; - await ResolveIncomingChain(chain, ct); + await ResolveIncomingChain(chain, cancellationToken); MessageFilter.Filter(chain); } } @@ -238,7 +238,7 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken ct) } } - public override async Task Outgoing(ProtocolEvent e, CancellationToken ct) + public override async Task Outgoing(ProtocolEvent e, CancellationToken cancellationToken) { switch (e) { @@ -246,23 +246,23 @@ public override async Task Outgoing(ProtocolEvent e, CancellationToken ct) { foreach (var chain in chains) { - await ResolveChainMetadata(chain, ct); - await ResolveOutgoingChain(chain, ct); - await Collection.Highway.UploadResources(chain, ct); + await ResolveChainMetadata(chain, cancellationToken); + await ResolveOutgoingChain(chain, cancellationToken); + await Collection.Highway.UploadResources(chain, cancellationToken); } break; } case SendMessageEvent send: // resolve Uin to Uid { - await ResolveChainMetadata(send.Chain, ct); - await ResolveOutgoingChain(send.Chain, ct); - await Collection.Highway.UploadResources(send.Chain, ct); + await ResolveChainMetadata(send.Chain, cancellationToken); + await ResolveOutgoingChain(send.Chain, cancellationToken); + await Collection.Highway.UploadResources(send.Chain, cancellationToken); break; } } } - private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct) + private async Task ResolveIncomingChain(MessageChain chain, CancellationToken cancellationToken) { foreach (var entity in chain) { @@ -271,7 +271,7 @@ private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct case FileEntity { FileHash: not null, FileUuid: not null } file: // private { var @event = FileDownloadEvent.Create(file.FileUuid, file.FileHash, chain.Uid, chain.SelfUid); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count != 0) { var result = (FileDownloadEvent)results[0]; @@ -283,7 +283,7 @@ private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct case FileEntity { FileId: not null } file when chain.GroupUin is not null: // group { var @event = GroupFSDownloadEvent.Create(chain.GroupUin.Value, file.FileId); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count != 0) { var result = (GroupFSDownloadEvent)results[0]; @@ -295,7 +295,7 @@ private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct case MultiMsgEntity { ResId: not null } multi: { var @event = MultiMsgDownloadEvent.Create(chain.Uid ?? "", multi.ResId); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count != 0) { var result = (MultiMsgDownloadEvent)results[0]; @@ -310,7 +310,7 @@ private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct ? RecordGroupDownloadEvent.Create(chain.GroupUin ?? 0, record.MsgInfo) : RecordDownloadEvent.Create(chain.Uid ?? string.Empty, record.MsgInfo); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count != 0) { var result = (RecordDownloadEvent)results[0]; @@ -325,7 +325,7 @@ private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct ? RecordGroupDownloadEvent.Create(chain.GroupUin ?? 0, record.AudioUuid) : RecordDownloadEvent.Create(chain.Uid ?? string.Empty, record.AudioUuid); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count != 0) { var result = (RecordDownloadEvent)results[0]; @@ -337,10 +337,10 @@ private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct case VideoEntity { VideoUuid: not null } video: { string uid = (chain.IsGroup - ? await Collection.Business.CachingLogic.ResolveUid(chain.GroupUin, chain.FriendUin, ct) + ? await Collection.Business.CachingLogic.ResolveUid(chain.GroupUin, chain.FriendUin, cancellationToken) : chain.Uid) ?? ""; var @event = VideoDownloadEvent.Create(video.VideoUuid, uid, video.FilePath, "", "", chain.IsGroup); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count != 0) { var result = (VideoDownloadEvent)results[0]; @@ -355,7 +355,7 @@ private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct ? ImageGroupDownloadEvent.Create(image.GroupUin ?? 0, image.MsgInfo) : ImageDownloadEvent.Create(image.FriendUid ?? string.Empty, image.MsgInfo); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count != 0) { var result = (ImageDownloadEvent)results[0]; @@ -368,7 +368,7 @@ private async Task ResolveIncomingChain(MessageChain chain, CancellationToken ct } } - private async Task ResolveOutgoingChain(MessageChain chain, CancellationToken ct) + private async Task ResolveOutgoingChain(MessageChain chain, CancellationToken cancellationToken) { foreach (var entity in chain) { @@ -377,24 +377,24 @@ private async Task ResolveOutgoingChain(MessageChain chain, CancellationToken ct case ForwardEntity forward when forward.TargetUin != 0: { var cache = Collection.Business.CachingLogic; - forward.Uid = await cache.ResolveUid(chain.GroupUin, forward.TargetUin, ct) ?? throw new Exception($"Failed to resolve Uid for Uin {forward.TargetUin}"); + forward.Uid = await cache.ResolveUid(chain.GroupUin, forward.TargetUin, cancellationToken) ?? throw new Exception($"Failed to resolve Uid for Uin {forward.TargetUin}"); break; } case MentionEntity mention when mention.Uin != 0: { var cache = Collection.Business.CachingLogic; - mention.Uid = await cache.ResolveUid(chain.GroupUin, mention.Uin, ct) ?? throw new Exception($"Failed to resolve Uid for Uin {mention.Uin}"); + mention.Uid = await cache.ResolveUid(chain.GroupUin, mention.Uin, cancellationToken) ?? throw new Exception($"Failed to resolve Uid for Uin {mention.Uin}"); if (chain is { IsGroup: true, GroupUin: not null } && mention.Name is null) { - var members = await Collection.Business.CachingLogic.GetCachedMembers(chain.GroupUin.Value, false, ct); + var members = await Collection.Business.CachingLogic.GetCachedMembers(chain.GroupUin.Value, false, cancellationToken); var member = members.FirstOrDefault(x => x.Uin == mention.Uin); if (member != null) mention.Name = $"@{member.MemberCard ?? member.MemberName}"; } else if (chain is { IsGroup: false } && mention.Name is null) { - var friends = await Collection.Business.CachingLogic.GetCachedFriends(false, ct); + var friends = await Collection.Business.CachingLogic.GetCachedFriends(false, cancellationToken); string? friend = friends.FirstOrDefault(x => x.Uin == mention.Uin)?.Nickname; if (friend != null) mention.Name = $"@{friend}"; } @@ -406,7 +406,7 @@ private async Task ResolveOutgoingChain(MessageChain chain, CancellationToken ct if (chain.GroupUin != null) foreach (var c in multiMsg.Chains) c.GroupUin = chain.GroupUin; var multiMsgEvent = MultiMsgUploadEvent.Create(chain.GroupUin, multiMsg.Chains); - var results = await Collection.Business.SendEvent(multiMsgEvent, ct); + var results = await Collection.Business.SendEvent(multiMsgEvent, cancellationToken); if (results.Count != 0) { var result = (MultiMsgUploadEvent)results[0]; @@ -417,7 +417,7 @@ private async Task ResolveOutgoingChain(MessageChain chain, CancellationToken ct case MultiMsgEntity { ResId: not null, Chains.Count: 0 } multiMsg: { var @event = MultiMsgDownloadEvent.Create(chain.Uid ?? "", multiMsg.ResId); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count != 0) { var result = (MultiMsgDownloadEvent)results[0]; @@ -434,11 +434,11 @@ private async Task ResolveOutgoingChain(MessageChain chain, CancellationToken ct /// for both Incoming and Outgoing MessageChain /// /// The target chain - private async Task ResolveChainMetadata(MessageChain chain, CancellationToken ct) + private async Task ResolveChainMetadata(MessageChain chain, CancellationToken cancellationToken) { if (chain is { IsGroup: true, GroupUin: not null }) { - var groups = await Collection.Business.CachingLogic.GetCachedMembers(chain.GroupUin.Value, false, ct); + var groups = await Collection.Business.CachingLogic.GetCachedMembers(chain.GroupUin.Value, false, cancellationToken); chain.GroupMemberInfo = chain.FriendUin == 0 ? groups.FirstOrDefault(x => x.Uin == Collection.Keystore.Uin) : groups.FirstOrDefault(x => x.Uin == chain.FriendUin); @@ -447,7 +447,7 @@ private async Task ResolveChainMetadata(MessageChain chain, CancellationToken ct } else { - var friends = await Collection.Business.CachingLogic.GetCachedFriends(false, ct); + var friends = await Collection.Business.CachingLogic.GetCachedFriends(false, cancellationToken); if (friends.FirstOrDefault(x => x.Uin == chain.FriendUin) is { } friend) { chain.FriendInfo = friend; diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs index f4c7636d0..b64a24932 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs @@ -25,14 +25,14 @@ public async Task> GetCookies(List domains, CancellationTok return events.Count != 0 ? ((FetchCookieEvent)events[0]).Cookies : new List(); } - public Task> FetchFriends(CancellationToken ct, bool refreshCache = false) => - Collection.Business.CachingLogic.GetCachedFriends(refreshCache, ct); + public Task> FetchFriends(CancellationToken cancellationToken, bool refreshCache = false) => + Collection.Business.CachingLogic.GetCachedFriends(refreshCache, cancellationToken); - public Task> FetchMembers(uint groupUin, CancellationToken ct, bool refreshCache = false) => - Collection.Business.CachingLogic.GetCachedMembers(groupUin, refreshCache, ct); + public Task> FetchMembers(uint groupUin, CancellationToken cancellationToken, bool refreshCache = false) => + Collection.Business.CachingLogic.GetCachedMembers(groupUin, refreshCache, cancellationToken); - public Task> FetchGroups(bool refreshCache, CancellationToken ct) => - Collection.Business.CachingLogic.GetCachedGroups(refreshCache, ct); + public Task> FetchGroups(bool refreshCache, CancellationToken cancellationToken) => + Collection.Business.CachingLogic.GetCachedGroups(refreshCache, cancellationToken); public async Task SendMessage(MessageChain chain, CancellationToken cancellation) { @@ -49,110 +49,110 @@ public async Task SendMessage(MessageChain chain, CancellationTok return result; } - public async Task MuteGroupMember(uint groupUin, uint targetUin, uint duration, CancellationToken ct) + public async Task MuteGroupMember(uint groupUin, uint targetUin, uint duration, CancellationToken cancellationToken) { - string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, ct); + string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, cancellationToken); if (uid == null) return false; var muteGroupMemberEvent = GroupMuteMemberEvent.Create(groupUin, duration, uid); - var events = await Collection.Business.SendEvent(muteGroupMemberEvent, ct); + var events = await Collection.Business.SendEvent(muteGroupMemberEvent, cancellationToken); return events.Count != 0 && ((GroupMuteMemberEvent)events[0]).ResultCode == 0; } - public async Task MuteGroupGlobal(uint groupUin, bool isMute, CancellationToken ct) + public async Task MuteGroupGlobal(uint groupUin, bool isMute, CancellationToken cancellationToken) { var muteGroupMemberEvent = GroupMuteGlobalEvent.Create(groupUin, isMute); - var events = await Collection.Business.SendEvent(muteGroupMemberEvent, ct); + var events = await Collection.Business.SendEvent(muteGroupMemberEvent, cancellationToken); return events.Count != 0 && ((GroupMuteGlobalEvent)events[0]).ResultCode == 0; } - public async Task KickGroupMember(uint groupUin, uint targetUin, bool rejectAddRequest, string reason, CancellationToken ct) + public async Task KickGroupMember(uint groupUin, uint targetUin, bool rejectAddRequest, string reason, CancellationToken cancellationToken) { - string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, ct); + string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, cancellationToken); if (uid == null) return false; var muteGroupMemberEvent = GroupKickMemberEvent.Create(groupUin, uid, rejectAddRequest, reason); - var events = await Collection.Business.SendEvent(muteGroupMemberEvent, ct); + var events = await Collection.Business.SendEvent(muteGroupMemberEvent, cancellationToken); return events.Count != 0 && ((GroupKickMemberEvent)events[0]).ResultCode == 0; } - public async Task SetGroupAdmin(uint groupUin, uint targetUin, bool isAdmin, CancellationToken ct) + public async Task SetGroupAdmin(uint groupUin, uint targetUin, bool isAdmin, CancellationToken cancellationToken) { - string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, ct); + string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, cancellationToken); if (uid == null) return false; var muteGroupMemberEvent = GroupSetAdminEvent.Create(groupUin, uid, isAdmin); - var events = await Collection.Business.SendEvent(muteGroupMemberEvent, ct); + var events = await Collection.Business.SendEvent(muteGroupMemberEvent, cancellationToken); return events.Count != 0 && ((GroupSetAdminEvent)events[0]).ResultCode == 0; } - public async Task SetGroupBot(uint BotId, uint On, uint groupUin, CancellationToken ct) + public async Task SetGroupBot(uint BotId, uint On, uint groupUin, CancellationToken cancellationToken) { var muteBotEvent = GroupSetBotEvent.Create(BotId, On, groupUin); - var events = await Collection.Business.SendEvent(muteBotEvent, ct); + var events = await Collection.Business.SendEvent(muteBotEvent, cancellationToken); return events.Count != 0 && ((GroupSetBotEvent)events[0]).ResultCode == 0; } - public async Task SetGroupBotHD(uint BotId, uint groupUin, string? data_1, string? data_2, CancellationToken ct) + public async Task SetGroupBotHD(uint BotId, uint groupUin, string? data_1, string? data_2, CancellationToken cancellationToken) { var muteBotEvent = GroupSetBothdEvent.Create(BotId, groupUin, data_1, data_2); - var events = await Collection.Business.SendEvent(muteBotEvent, ct); + var events = await Collection.Business.SendEvent(muteBotEvent, cancellationToken); return events.Count != 0 && ((GroupSetBothdEvent)events[0]).ResultCode == 0; } - public async Task RenameGroupMember(uint groupUin, uint targetUin, string targetName, CancellationToken ct) + public async Task RenameGroupMember(uint groupUin, uint targetUin, string targetName, CancellationToken cancellationToken) { - string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, ct); + string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, cancellationToken); if (uid == null) return false; var renameGroupEvent = RenameMemberEvent.Create(groupUin, uid, targetName); - var events = await Collection.Business.SendEvent(renameGroupEvent, ct); + var events = await Collection.Business.SendEvent(renameGroupEvent, cancellationToken); return events.Count != 0 && ((RenameMemberEvent)events[0]).ResultCode == 0; } - public async Task RenameGroup(uint groupUin, string targetName, CancellationToken ct) + public async Task RenameGroup(uint groupUin, string targetName, CancellationToken cancellationToken) { var renameGroupEvent = GroupRenameEvent.Create(groupUin, targetName); - var events = await Collection.Business.SendEvent(renameGroupEvent, ct); + var events = await Collection.Business.SendEvent(renameGroupEvent, cancellationToken); return events.Count != 0 && ((GroupRenameEvent)events[0]).ResultCode == 0; } - public async Task RemarkGroup(uint groupUin, string targetRemark, CancellationToken ct) + public async Task RemarkGroup(uint groupUin, string targetRemark, CancellationToken cancellationToken) { var renameGroupEvent = GroupRemarkEvent.Create(groupUin, targetRemark); - var events = await Collection.Business.SendEvent(renameGroupEvent, ct); + var events = await Collection.Business.SendEvent(renameGroupEvent, cancellationToken); return events.Count != 0 && ((GroupRemarkEvent)events[0]).ResultCode == 0; } - public async Task LeaveGroup(uint groupUin, CancellationToken ct) + public async Task LeaveGroup(uint groupUin, CancellationToken cancellationToken) { var leaveGroupEvent = GroupLeaveEvent.Create(groupUin); - var events = await Collection.Business.SendEvent(leaveGroupEvent, ct); + var events = await Collection.Business.SendEvent(leaveGroupEvent, cancellationToken); return events.Count != 0 && ((GroupLeaveEvent)events[0]).ResultCode == 0; } - public async Task FetchGroupFSSpace(uint groupUin, CancellationToken ct) + public async Task FetchGroupFSSpace(uint groupUin, CancellationToken cancellationToken) { var groupFSSpaceEvent = GroupFSSpaceEvent.Create(groupUin); - var events = await Collection.Business.SendEvent(groupFSSpaceEvent, ct); + var events = await Collection.Business.SendEvent(groupFSSpaceEvent, cancellationToken); return ((GroupFSSpaceEvent)events[0]).TotalSpace - ((GroupFSSpaceEvent)events[0]).UsedSpace; } - public async Task FetchGroupFSCount(uint groupUin, CancellationToken ct) + public async Task FetchGroupFSCount(uint groupUin, CancellationToken cancellationToken) { var groupFSSpaceEvent = GroupFSCountEvent.Create(groupUin); - var events = await Collection.Business.SendEvent(groupFSSpaceEvent, ct); + var events = await Collection.Business.SendEvent(groupFSSpaceEvent, cancellationToken); return ((GroupFSCountEvent)events[0]).FileCount; } - public async Task> FetchGroupFSList(uint groupUin, string targetDirectory, CancellationToken ct) + public async Task> FetchGroupFSList(uint groupUin, string targetDirectory, CancellationToken cancellationToken) { uint startIndex = 0; var entries = new List(); while (true) { var groupFSListEvent = GroupFSListEvent.Create(groupUin, targetDirectory, startIndex, 20); - var events = await Collection.Business.SendEvent(groupFSListEvent, ct); + var events = await Collection.Business.SendEvent(groupFSListEvent, cancellationToken); if (events.Count == 0) break; entries.AddRange(((GroupFSListEvent)events[0]).FileEntries); if (((GroupFSListEvent)events[0]).IsEnd) break; @@ -161,63 +161,63 @@ public async Task> FetchGroupFSList(uint groupUin, string targ return entries; } - public async Task FetchGroupFSDownload(uint groupUin, string fileId, CancellationToken ct) + public async Task FetchGroupFSDownload(uint groupUin, string fileId, CancellationToken cancellationToken) { var groupFSDownloadEvent = GroupFSDownloadEvent.Create(groupUin, fileId); - var events = await Collection.Business.SendEvent(groupFSDownloadEvent, ct); + var events = await Collection.Business.SendEvent(groupFSDownloadEvent, cancellationToken); return $"{((GroupFSDownloadEvent)events[0]).FileUrl}{fileId}"; } - public async Task<(int, string)> GroupFSMove(uint groupUin, string fileId, string parentDirectory, string targetDirectory, CancellationToken ct) + public async Task<(int, string)> GroupFSMove(uint groupUin, string fileId, string parentDirectory, string targetDirectory, CancellationToken cancellationToken) { var groupFSMoveEvent = GroupFSMoveEvent.Create(groupUin, fileId, parentDirectory, targetDirectory); - var events = await Collection.Business.SendEvent(groupFSMoveEvent, ct); + var events = await Collection.Business.SendEvent(groupFSMoveEvent, cancellationToken); int retCode = events.Count > 0 ? ((GroupFSMoveEvent)events[0]).ResultCode : -1; string retMsg = events.Count > 0 ? ((GroupFSMoveEvent)events[0]).RetMsg : string.Empty; return (retCode, retMsg); } - public async Task<(int, string)> GroupFSDelete(uint groupUin, string fileId, CancellationToken ct) + public async Task<(int, string)> GroupFSDelete(uint groupUin, string fileId, CancellationToken cancellationToken) { var groupFSDeleteEvent = GroupFSDeleteEvent.Create(groupUin, fileId); - var events = await Collection.Business.SendEvent(groupFSDeleteEvent, ct); + var events = await Collection.Business.SendEvent(groupFSDeleteEvent, cancellationToken); int retCode = events.Count > 0 ? ((GroupFSDeleteEvent)events[0]).ResultCode : -1; string retMsg = events.Count > 0 ? ((GroupFSDeleteEvent)events[0]).RetMsg : string.Empty; return (retCode, retMsg); } - public async Task<(int, string)> GroupFSCreateFolder(uint groupUin, string name, CancellationToken ct) + public async Task<(int, string)> GroupFSCreateFolder(uint groupUin, string name, CancellationToken cancellationToken) { var groupFSCreateFolderEvent = GroupFSCreateFolderEvent.Create(groupUin, name); - var events = await Collection.Business.SendEvent(groupFSCreateFolderEvent, ct); + var events = await Collection.Business.SendEvent(groupFSCreateFolderEvent, cancellationToken); int retCode = events.Count > 0 ? ((GroupFSCreateFolderEvent)events[0]).ResultCode : -1; string retMsg = events.Count > 0 ? ((GroupFSCreateFolderEvent)events[0]).RetMsg : string.Empty; return (retCode, retMsg); } - public async Task<(int, string)> GroupFSDeleteFolder(uint groupUin, string folderId, CancellationToken ct) + public async Task<(int, string)> GroupFSDeleteFolder(uint groupUin, string folderId, CancellationToken cancellationToken) { var groupFSDeleteFolderEvent = GroupFSDeleteFolderEvent.Create(groupUin, folderId); - var events = await Collection.Business.SendEvent(groupFSDeleteFolderEvent, ct); + var events = await Collection.Business.SendEvent(groupFSDeleteFolderEvent, cancellationToken); int retCode = events.Count > 0 ? ((GroupFSDeleteFolderEvent)events[0]).ResultCode : -1; string retMsg = events.Count > 0 ? ((GroupFSDeleteFolderEvent)events[0]).RetMsg : string.Empty; return (retCode, retMsg); } - public async Task<(int, string)> GroupFSRenameFolder(uint groupUin, string folderId, string newFolderName, CancellationToken ct) + public async Task<(int, string)> GroupFSRenameFolder(uint groupUin, string folderId, string newFolderName, CancellationToken cancellationToken) { var groupFSDeleteFolderEvent = GroupFSRenameFolderEvent.Create(groupUin, folderId, newFolderName); - var events = await Collection.Business.SendEvent(groupFSDeleteFolderEvent, ct); + var events = await Collection.Business.SendEvent(groupFSDeleteFolderEvent, cancellationToken); int retCode = events.Count > 0 ? ((GroupFSRenameFolderEvent)events[0]).ResultCode : -1; string retMsg = events.Count > 0 ? ((GroupFSRenameFolderEvent)events[0]).RetMsg : ""; return (retCode, retMsg); } - public Task GroupFSUpload(uint groupUin, FileEntity fileEntity, string targetDirectory, CancellationToken ct) + public Task GroupFSUpload(uint groupUin, FileEntity fileEntity, string targetDirectory, CancellationToken cancellationToken) { try { - return FileUploader.UploadGroup(Collection, MessageBuilder.Group(groupUin).Build(), fileEntity, targetDirectory, ct); + return FileUploader.UploadGroup(Collection, MessageBuilder.Group(groupUin).Build(), fileEntity, targetDirectory, cancellationToken); } catch (TaskCanceledException) { @@ -229,14 +229,14 @@ public Task GroupFSUpload(uint groupUin, FileEntity fileEntity, string tar } } - public async Task UploadFriendFile(uint targetUin, FileEntity fileEntity, CancellationToken ct) + public async Task UploadFriendFile(uint targetUin, FileEntity fileEntity, CancellationToken cancellationToken) { - string? uid = await Collection.Business.CachingLogic.ResolveUid(null, targetUin, ct); + string? uid = await Collection.Business.CachingLogic.ResolveUid(null, targetUin, cancellationToken); var chain = new MessageChain(targetUin, Collection.Keystore.Uid ?? "", uid ?? "") { fileEntity }; try { - return await FileUploader.UploadPrivate(Collection, chain, fileEntity, ct); + return await FileUploader.UploadPrivate(Collection, chain, fileEntity, cancellationToken); } catch (TaskCanceledException) { @@ -248,55 +248,55 @@ public async Task UploadFriendFile(uint targetUin, FileEntity fileEntity, } } - public async Task RecallGroupMessage(uint groupUin, MessageResult result, CancellationToken ct) + public async Task RecallGroupMessage(uint groupUin, MessageResult result, CancellationToken cancellationToken) { if (result.Sequence == null) return false; var recallMessageEvent = RecallGroupMessageEvent.Create(groupUin, result.Sequence.Value); - var events = await Collection.Business.SendEvent(recallMessageEvent, ct); + var events = await Collection.Business.SendEvent(recallMessageEvent, cancellationToken); return events.Count != 0 && ((RecallGroupMessageEvent)events[0]).ResultCode == 0; } - public async Task RecallGroupMessage(MessageChain chain, CancellationToken ct) + public async Task RecallGroupMessage(MessageChain chain, CancellationToken cancellationToken) { if (chain.GroupUin == null) return false; var recallMessageEvent = RecallGroupMessageEvent.Create(chain.GroupUin.Value, chain.Sequence); - var events = await Collection.Business.SendEvent(recallMessageEvent, ct); + var events = await Collection.Business.SendEvent(recallMessageEvent, cancellationToken); return events.Count != 0 && ((RecallGroupMessageEvent)events[0]).ResultCode == 0; } - public async Task RecallGroupMessage(uint groupUin, uint sequence, CancellationToken ct) + public async Task RecallGroupMessage(uint groupUin, uint sequence, CancellationToken cancellationToken) { var recallMessageEvent = RecallGroupMessageEvent.Create(groupUin, sequence); - var events = await Collection.Business.SendEvent(recallMessageEvent, ct); + var events = await Collection.Business.SendEvent(recallMessageEvent, cancellationToken); return events.Count != 0 && ((RecallGroupMessageEvent)events[0]).ResultCode == 0; } - public async Task RecallFriendMessage(uint friendUin, MessageResult result, CancellationToken ct) + public async Task RecallFriendMessage(uint friendUin, MessageResult result, CancellationToken cancellationToken) { if (result.Sequence == null) return false; - if (await Collection.Business.CachingLogic.ResolveUid(null, friendUin, ct) is not { } uid) return false; + if (await Collection.Business.CachingLogic.ResolveUid(null, friendUin, cancellationToken) is not { } uid) return false; var recallMessageEvent = RecallFriendMessageEvent.Create(uid, result.ClientSequence, result.Sequence ?? 0, (uint)(result.MessageId & uint.MaxValue), result.Timestamp); - var events = await Collection.Business.SendEvent(recallMessageEvent, ct); + var events = await Collection.Business.SendEvent(recallMessageEvent, cancellationToken); return events.Count != 0 && ((RecallFriendMessageEvent)events[0]).ResultCode == 0; } - public async Task RecallFriendMessage(MessageChain chain, CancellationToken ct) + public async Task RecallFriendMessage(MessageChain chain, CancellationToken cancellationToken) { - if (await Collection.Business.CachingLogic.ResolveUid(null, chain.TargetUin, ct) is not { } uid) return false; + if (await Collection.Business.CachingLogic.ResolveUid(null, chain.TargetUin, cancellationToken) is not { } uid) return false; uint timestamp = (uint)new DateTimeOffset(chain.Time).ToUnixTimeSeconds(); var recallMessageEvent = RecallFriendMessageEvent.Create(uid, chain.ClientSequence, chain.Sequence, (uint)(chain.MessageId & uint.MaxValue), timestamp); - var events = await Collection.Business.SendEvent(recallMessageEvent, ct); + var events = await Collection.Business.SendEvent(recallMessageEvent, cancellationToken); return events.Count != 0 && ((RecallFriendMessageEvent)events[0]).ResultCode == 0; } - public async Task?> FetchGroupRequests(CancellationToken ct) + public async Task?> FetchGroupRequests(CancellationToken cancellationToken) { var fetchRequestsEvent = FetchGroupRequestsEvent.Create(); - var events = await Collection.Business.SendEvent(fetchRequestsEvent, ct); + var events = await Collection.Business.SendEvent(fetchRequestsEvent, cancellationToken); if (events.Count == 0) return null; var resolved = events.Cast().SelectMany(e => e.Events).ToList(); @@ -332,15 +332,15 @@ async Task ResolveUid(string? uid) if (uid == null) return 0; var fetchUidEvent = FetchUserInfoEvent.Create(uid); - var e = await Collection.Business.SendEvent(fetchUidEvent, ct); + var e = await Collection.Business.SendEvent(fetchUidEvent, cancellationToken); return e.Count == 0 ? 0 : ((FetchUserInfoEvent)e[0]).UserInfo.Uin; } } - public async Task?> FetchFriendRequests(CancellationToken ct) + public async Task?> FetchFriendRequests(CancellationToken cancellationToken) { var fetchRequestsEvent = FetchFriendsRequestsEvent.Create(); - var events = await Collection.Business.SendEvent(fetchRequestsEvent, ct); + var events = await Collection.Business.SendEvent(fetchRequestsEvent, cancellationToken); if (events.Count == 0) return null; var resolved = ((FetchFriendsRequestsEvent)events[0]).Requests; @@ -358,132 +358,132 @@ async Task ResolveUid(string? uid) if (uid == null) return 0; var fetchUidEvent = FetchUserInfoEvent.Create(uid); - var e = await Collection.Business.SendEvent(fetchUidEvent, ct); + var e = await Collection.Business.SendEvent(fetchUidEvent, cancellationToken); return e.Count == 0 ? 0 : ((FetchUserInfoEvent)e[0]).UserInfo.Uin; } } - public async Task GroupTransfer(uint groupUin, uint targetUin, CancellationToken ct) + public async Task GroupTransfer(uint groupUin, uint targetUin, CancellationToken cancellationToken) { - string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, ct); + string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, cancellationToken); if (uid == null || Collection.Keystore.Uid is not { } source) return false; var transferEvent = GroupTransferEvent.Create(groupUin, source, uid); - var results = await Collection.Business.SendEvent(transferEvent, ct); + var results = await Collection.Business.SendEvent(transferEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task SetStatus(uint status, CancellationToken ct) + public async Task SetStatus(uint status, CancellationToken cancellationToken) { var setStatusEvent = SetStatusEvent.Create(status, 0); - var results = await Collection.Business.SendEvent(setStatusEvent, ct); + var results = await Collection.Business.SendEvent(setStatusEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task SetCustomStatus(uint faceId, string text, CancellationToken ct) + public async Task SetCustomStatus(uint faceId, string text, CancellationToken cancellationToken) { var setCustomStatusEvent = SetCustomStatusEvent.Create(faceId, text); - var results = await Collection.Business.SendEvent(setCustomStatusEvent, ct); + var results = await Collection.Business.SendEvent(setCustomStatusEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task RequestFriend(uint targetUin, string question, string message, CancellationToken ct) + public async Task RequestFriend(uint targetUin, string question, string message, CancellationToken cancellationToken) { var requestFriendSearchEvent = RequestFriendSearchEvent.Create(targetUin); - var searchEvents = await Collection.Business.SendEvent(requestFriendSearchEvent, ct); + var searchEvents = await Collection.Business.SendEvent(requestFriendSearchEvent, cancellationToken); if (searchEvents.Count == 0) return false; await Task.Delay(5000); var requestFriendSettingEvent = RequestFriendSettingEvent.Create(targetUin); - var settingEvents = await Collection.Business.SendEvent(requestFriendSettingEvent, ct); + var settingEvents = await Collection.Business.SendEvent(requestFriendSettingEvent, cancellationToken); if (settingEvents.Count == 0) return false; var requestFriendEvent = RequestFriendEvent.Create(targetUin, message, question); - var events = await Collection.Business.SendEvent(requestFriendEvent, ct); + var events = await Collection.Business.SendEvent(requestFriendEvent, cancellationToken); return events.Count != 0 && ((RequestFriendEvent)events[0]).ResultCode == 0; } - public async Task Like(uint targetUin, uint count, CancellationToken ct) + public async Task Like(uint targetUin, uint count, CancellationToken cancellationToken) { - var uid = await Collection.Business.CachingLogic.ResolveUid(null, targetUin, ct); + var uid = await Collection.Business.CachingLogic.ResolveUid(null, targetUin, cancellationToken); if (uid == null) return false; var friendLikeEvent = FriendLikeEvent.Create(uid, count); - var results = await Collection.Business.SendEvent(friendLikeEvent, ct); + var results = await Collection.Business.SendEvent(friendLikeEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task InviteGroup(uint targetGroupUin, Dictionary invitedUins, CancellationToken ct) + public async Task InviteGroup(uint targetGroupUin, Dictionary invitedUins, CancellationToken cancellationToken) { var invitedUids = new Dictionary(invitedUins.Count); foreach (var (friendUin, groupUin) in invitedUins) { - string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, friendUin, ct); + string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, friendUin, cancellationToken); if (uid != null) invitedUids[uid] = groupUin; } var @event = GroupInviteEvent.Create(targetGroupUin, invitedUids); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task GetClientKey(CancellationToken ct) + public async Task GetClientKey(CancellationToken cancellationToken) { var clientKeyEvent = FetchClientKeyEvent.Create(); - var events = await Collection.Business.SendEvent(clientKeyEvent, ct); + var events = await Collection.Business.SendEvent(clientKeyEvent, cancellationToken); return events.Count == 0 ? null : ((FetchClientKeyEvent)events[0]).ClientKey; } - public async Task SetGroupRequest(uint groupUin, ulong sequence, uint type, bool accept, string reason, CancellationToken ct) + public async Task SetGroupRequest(uint groupUin, ulong sequence, uint type, bool accept, string reason, CancellationToken cancellationToken) { var inviteEvent = SetGroupRequestEvent.Create(accept, groupUin, sequence, type, reason); - var results = await Collection.Business.SendEvent(inviteEvent, ct); + var results = await Collection.Business.SendEvent(inviteEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task SetGroupFilteredRequest(uint groupUin, ulong sequence, uint type, bool accept, string reason, CancellationToken ct) + public async Task SetGroupFilteredRequest(uint groupUin, ulong sequence, uint type, bool accept, string reason, CancellationToken cancellationToken) { var inviteEvent = SetGroupFilteredRequestEvent.Create(accept, groupUin, sequence, type, reason); - var results = await Collection.Business.SendEvent(inviteEvent, ct); + var results = await Collection.Business.SendEvent(inviteEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task SetFriendRequest(string targetUid, bool accept, CancellationToken ct) + public async Task SetFriendRequest(string targetUid, bool accept, CancellationToken cancellationToken) { var inviteEvent = SetFriendRequestEvent.Create(targetUid, accept); - var results = await Collection.Business.SendEvent(inviteEvent, ct); + var results = await Collection.Business.SendEvent(inviteEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task?> GetGroupMessage(uint groupUin, uint startSequence, uint endSequence, CancellationToken ct) + public async Task?> GetGroupMessage(uint groupUin, uint startSequence, uint endSequence, CancellationToken cancellationToken) { var getMsgEvent = GetGroupMessageEvent.Create(groupUin, startSequence, endSequence); - var results = await Collection.Business.SendEvent(getMsgEvent, ct); + var results = await Collection.Business.SendEvent(getMsgEvent, cancellationToken); return results.Count != 0 ? ((GetGroupMessageEvent)results[0]).Chains : null; } - public async Task?> GetRoamMessage(uint friendUin, uint time, uint count, CancellationToken ct) + public async Task?> GetRoamMessage(uint friendUin, uint time, uint count, CancellationToken cancellationToken) { - if (await Collection.Business.CachingLogic.ResolveUid(null, friendUin, ct) is not { } uid) return null; + if (await Collection.Business.CachingLogic.ResolveUid(null, friendUin, cancellationToken) is not { } uid) return null; var roamEvent = GetRoamMessageEvent.Create(uid, time, count); - var results = await Collection.Business.SendEvent(roamEvent, ct); + var results = await Collection.Business.SendEvent(roamEvent, cancellationToken); return results.Count != 0 ? ((GetRoamMessageEvent)results[0]).Chains : null; } - public async Task?> GetC2cMessage(uint friendUin, uint startSequence, uint endSequence, CancellationToken ct) + public async Task?> GetC2cMessage(uint friendUin, uint startSequence, uint endSequence, CancellationToken cancellationToken) { - if (await Collection.Business.CachingLogic.ResolveUid(null, friendUin, ct) is not { } uid) return null; + if (await Collection.Business.CachingLogic.ResolveUid(null, friendUin, cancellationToken) is not { } uid) return null; var c2cEvent = GetC2cMessageEvent.Create(uid, startSequence, endSequence); - var results = await Collection.Business.SendEvent(c2cEvent, ct); + var results = await Collection.Business.SendEvent(c2cEvent, cancellationToken); return results.Count != 0 ? ((GetC2cMessageEvent)results[0]).Chains : null; } - public async Task<(int code, List? chains)> GetMessagesByResId(string resId, CancellationToken ct) + public async Task<(int code, List? chains)> GetMessagesByResId(string resId, CancellationToken cancellationToken) { var @event = MultiMsgDownloadEvent.Create(Collection.Keystore.Uid ?? "", resId); - var results = await Collection.Business.SendEvent(@event, ct); + var results = await Collection.Business.SendEvent(@event, cancellationToken); if (results.Count == 0) return (-9999, null); var result = (MultiMsgDownloadEvent)results[0]; @@ -491,142 +491,142 @@ public async Task SetFriendRequest(string targetUid, bool accept, Cancella return (result.ResultCode, result.Chains); } - public async Task?> FetchCustomFace(CancellationToken ct) + public async Task?> FetchCustomFace(CancellationToken cancellationToken) { var fetchCustomFaceEvent = FetchCustomFaceEvent.Create(); - var results = await Collection.Business.SendEvent(fetchCustomFaceEvent, ct); + var results = await Collection.Business.SendEvent(fetchCustomFaceEvent, cancellationToken); return results.Count != 0 ? ((FetchCustomFaceEvent)results[0]).Urls : null; } - public async Task UploadLongMessage(List chains, CancellationToken ct) + public async Task UploadLongMessage(List chains, CancellationToken cancellationToken) { var multiMsgUploadEvent = MultiMsgUploadEvent.Create(null, chains); - var results = await Collection.Business.SendEvent(multiMsgUploadEvent, ct); + var results = await Collection.Business.SendEvent(multiMsgUploadEvent, cancellationToken); return results.Count != 0 ? ((MultiMsgUploadEvent)results[0]).ResId : null; } - public async Task MarkAsRead(uint groupUin, string? targetUid, uint startSequence, uint time, CancellationToken ct) + public async Task MarkAsRead(uint groupUin, string? targetUid, uint startSequence, uint time, CancellationToken cancellationToken) { var markAsReadEvent = MarkReadedEvent.Create(groupUin, targetUid, startSequence, time); - var results = await Collection.Business.SendEvent(markAsReadEvent, ct); + var results = await Collection.Business.SendEvent(markAsReadEvent, cancellationToken); return results.Count != 0 && ((MarkReadedEvent)results[0]).ResultCode == 0; } - public async Task FriendPoke(uint friendUin, CancellationToken ct) + public async Task FriendPoke(uint friendUin, CancellationToken cancellationToken) { var friendPokeEvent = FriendPokeEvent.Create(friendUin); - var results = await Collection.Business.SendEvent(friendPokeEvent, ct); + var results = await Collection.Business.SendEvent(friendPokeEvent, cancellationToken); return results.Count != 0 && ((FriendPokeEvent)results[0]).ResultCode == 0; } - public async Task GroupPoke(uint groupUin, uint friendUin, CancellationToken ct) + public async Task GroupPoke(uint groupUin, uint friendUin, CancellationToken cancellationToken) { var friendPokeEvent = GroupPokeEvent.Create(friendUin, groupUin); - var results = await Collection.Business.SendEvent(friendPokeEvent, ct); + var results = await Collection.Business.SendEvent(friendPokeEvent, cancellationToken); return results.Count != 0 && ((FriendPokeEvent)results[0]).ResultCode == 0; } - public async Task SetEssenceMessage(uint groupUin, uint sequence, uint random, CancellationToken ct) + public async Task SetEssenceMessage(uint groupUin, uint sequence, uint random, CancellationToken cancellationToken) { var setEssenceMessageEvent = SetEssenceMessageEvent.Create(groupUin, sequence, random); - var results = await Collection.Business.SendEvent(setEssenceMessageEvent, ct); + var results = await Collection.Business.SendEvent(setEssenceMessageEvent, cancellationToken); return results.Count != 0 && ((SetEssenceMessageEvent)results[0]).ResultCode == 0; } - public async Task RemoveEssenceMessage(uint groupUin, uint sequence, uint random, CancellationToken ct) + public async Task RemoveEssenceMessage(uint groupUin, uint sequence, uint random, CancellationToken cancellationToken) { var removeEssenceMessageEvent = RemoveEssenceMessageEvent.Create(groupUin, sequence, random); - var results = await Collection.Business.SendEvent(removeEssenceMessageEvent, ct); + var results = await Collection.Business.SendEvent(removeEssenceMessageEvent, cancellationToken); return results.Count != 0 && ((RemoveEssenceMessageEvent)results[0]).ResultCode == 0; } - public async Task GroupSetSpecialTitle(uint groupUin, uint targetUin, string title, CancellationToken ct) + public async Task GroupSetSpecialTitle(uint groupUin, uint targetUin, string title, CancellationToken cancellationToken) { - string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, ct); + string? uid = await Collection.Business.CachingLogic.ResolveUid(groupUin, targetUin, cancellationToken); if (uid == null) return false; var groupSetSpecialTitleEvent = GroupSetSpecialTitleEvent.Create(groupUin, uid, title); - var events = await Collection.Business.SendEvent(groupSetSpecialTitleEvent, ct); + var events = await Collection.Business.SendEvent(groupSetSpecialTitleEvent, cancellationToken); return events.Count != 0 && ((GroupSetSpecialTitleEvent)events[0]).ResultCode == 0; } - public async Task FetchUserInfo(uint uin, CancellationToken ct, bool refreshCache = false) + public async Task FetchUserInfo(uint uin, CancellationToken cancellationToken, bool refreshCache = false) { - return await Collection.Business.CachingLogic.GetCachedUsers(uin, refreshCache, ct); + return await Collection.Business.CachingLogic.GetCachedUsers(uin, refreshCache, cancellationToken); } - public async Task SetMessageReaction(uint groupUin, uint sequence, string code, bool isAdd, CancellationToken ct) + public async Task SetMessageReaction(uint groupUin, uint sequence, string code, bool isAdd, CancellationToken cancellationToken) { if (isAdd) { var addReactionEvent = GroupAddReactionEvent.Create(groupUin, sequence, code); - var results = await Collection.Business.SendEvent(addReactionEvent, ct); + var results = await Collection.Business.SendEvent(addReactionEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } else { var reduceReactionEvent = GroupReduceReactionEvent.Create(groupUin, sequence, code); - var results = await Collection.Business.SendEvent(reduceReactionEvent, ct); + var results = await Collection.Business.SendEvent(reduceReactionEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } } - public async Task SetNeedToConfirmSwitch(bool enableNoNeed, CancellationToken ct) + public async Task SetNeedToConfirmSwitch(bool enableNoNeed, CancellationToken cancellationToken) { var setNeedToConfirmSwitchEvent = SetNeedToConfirmSwitchEvent.Create(enableNoNeed); - var results = await Collection.Business.SendEvent(setNeedToConfirmSwitchEvent, ct); + var results = await Collection.Business.SendEvent(setNeedToConfirmSwitchEvent, cancellationToken); return results.Count != 0 && results[0].ResultCode == 0; } - public async Task?> FetchMarketFaceKey(List faceIds, CancellationToken ct) + public async Task?> FetchMarketFaceKey(List faceIds, CancellationToken cancellationToken) { var fetchMarketFaceKeyEvent = FetchMarketFaceKeyEvent.Create(faceIds); - var results = await Collection.Business.SendEvent(fetchMarketFaceKeyEvent, ct); + var results = await Collection.Business.SendEvent(fetchMarketFaceKeyEvent, cancellationToken); return results.Count != 0 ? ((FetchMarketFaceKeyEvent)results[0]).Keys : null; } - public async Task GroupClockIn(uint groupUin, CancellationToken ct) + public async Task GroupClockIn(uint groupUin, CancellationToken cancellationToken) { var groupClockInEvent = GroupClockInEvent.Create(groupUin); - var results = await Collection.Business.SendEvent(groupClockInEvent, ct); + var results = await Collection.Business.SendEvent(groupClockInEvent, cancellationToken); return ((GroupClockInEvent)results[0]).ResultInfo ?? new BotGroupClockInResult(false); } - public Task FriendSpecialShake(uint friendUin, SpecialPokeFaceType type, uint count, CancellationToken ct) + public Task FriendSpecialShake(uint friendUin, SpecialPokeFaceType type, uint count, CancellationToken cancellationToken) { var chain = MessageBuilder.Friend(friendUin) .SpecialPoke(type, count) .Build(); - return SendMessage(chain, ct); + return SendMessage(chain, cancellationToken); } - public Task FriendShake(uint friendUin, PokeFaceType type, uint strength, CancellationToken ct) + public Task FriendShake(uint friendUin, PokeFaceType type, uint strength, CancellationToken cancellationToken) { var chain = MessageBuilder.Friend(friendUin) .Poke(type, strength) .Build(); - return SendMessage(chain, ct); + return SendMessage(chain, cancellationToken); } - public async Task SetAvatar(ImageEntity avatar, CancellationToken ct) + public async Task SetAvatar(ImageEntity avatar, CancellationToken cancellationToken) { if (avatar.ImageStream == null) return false; var highwayUrlEvent = HighwayUrlEvent.Create(); - var highwayUrlResults = await Collection.Business.SendEvent(highwayUrlEvent, ct); + var highwayUrlResults = await Collection.Business.SendEvent(highwayUrlEvent, cancellationToken); if (highwayUrlResults.Count == 0) return false; var ticket = ((HighwayUrlEvent)highwayUrlResults[0]).SigSession; var md5 = avatar.ImageStream.Value.Md5().UnHex(); - return await Collection.Highway.UploadSrcByStreamAsync(90, avatar.ImageStream.Value, ticket, md5, ct, extendInfo: Array.Empty()); + return await Collection.Highway.UploadSrcByStreamAsync(90, avatar.ImageStream.Value, ticket, md5, cancellationToken, extendInfo: Array.Empty()); } - public async Task GroupSetAvatar(uint groupUin, ImageEntity avatar, CancellationToken ct) + public async Task GroupSetAvatar(uint groupUin, ImageEntity avatar, CancellationToken cancellationToken) { if (avatar.ImageStream == null) return false; var highwayUrlEvent = HighwayUrlEvent.Create(); - var highwayUrlResults = await Collection.Business.SendEvent(highwayUrlEvent, ct); + var highwayUrlResults = await Collection.Business.SendEvent(highwayUrlEvent, cancellationToken); if (highwayUrlResults.Count == 0) return false; var ticket = ((HighwayUrlEvent)highwayUrlResults[0]).SigSession; @@ -639,16 +639,16 @@ public async Task GroupSetAvatar(uint groupUin, ImageEntity avatar, Cancel Field5 = 3, Field6 = 1 }.Serialize().ToArray(); - return await Collection.Highway.UploadSrcByStreamAsync(3000, avatar.ImageStream.Value, ticket, md5, ct, extendInfo: extra); + return await Collection.Highway.UploadSrcByStreamAsync(3000, avatar.ImageStream.Value, ticket, md5, cancellationToken, extendInfo: extra); } - public async Task<(uint, uint)> GroupRemainAtAll(uint groupUin, CancellationToken ct) + public async Task<(uint, uint)> GroupRemainAtAll(uint groupUin, CancellationToken cancellationToken) { var groupRemainAtAllEvent = FetchGroupAtAllRemainEvent.Create(groupUin); - var results = await Collection.Business.SendEvent(groupRemainAtAllEvent, ct); + var results = await Collection.Business.SendEvent(groupRemainAtAllEvent, cancellationToken); if (results.Count == 0) return (0, 0); var ret = (FetchGroupAtAllRemainEvent)results[0]; return (ret.RemainAtAllCountForUin, ret.RemainAtAllCountForGroup); } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs index 1cbadc6c7..9636444d5 100644 --- a/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs +++ b/Lagrange.Core/Internal/Context/Logic/Implementation/WtExchangeLogic.cs @@ -27,7 +27,7 @@ internal class WtExchangeLogic : LogicBase private const string Tag = nameof(WtExchangeLogic); private readonly Timer _reLoginTimer; - + private TaskCompletionSource _transEmpTask = new(); private TaskCompletionSource<(string, string)> _captchaTask = new(); @@ -39,7 +39,7 @@ internal class WtExchangeLogic : LogicBase internal WtExchangeLogic(ContextCollection collection) : base(collection) { - _reLoginTimer = new Timer(async _ => await ReLogin(), null, Timeout.Infinite, Timeout.Infinite); + _reLoginTimer = new Timer(async _ => await ReLogin(CancellationToken.None), null, Timeout.Infinite, Timeout.Infinite); } public override async Task Incoming(ProtocolEvent e, CancellationToken _) @@ -50,7 +50,7 @@ public override async Task Incoming(ProtocolEvent e, CancellationToken _) Collection.Log.LogFatal(Tag, $"KickNTEvent: {kick.Tag}: {kick.Message}"); Collection.Log.LogFatal(Tag, "Bot will be offline in 5 seconds..."); await Task.Delay(5000); - + Collection.Invoker.PostEvent(new BotOfflineEvent(kick.Tag, kick.Message)); // TODO: Fill in the reason of offline Collection.Scheduler.Dispose(); break; @@ -75,28 +75,21 @@ private void OnCancellation() /// 1. resolve wtlogin.trans_emp CMD0x31 packet /// 2. Schedule wtlogin.trans_emp CMD0x12 Task /// - public async Task<(string, byte[])?> FetchQrCode(CancellationToken ct) + public async Task<(string, byte[])?> FetchQrCode(CancellationToken cancellationToken) { Collection.Log.LogInfo(Tag, "Connecting Servers..."); - if (!await Collection.Socket.Connect()) return null; - Collection.Scheduler.Interval(HeartbeatEvent, 10 * 1000, async () => - { - if (ct.IsCancellationRequested) - { - Collection.Scheduler.Cancel(HeartbeatEvent); - return; - } - await Collection.Business.PushEvent(AliveEvent.Create(), CancellationToken.None); - }); + if (!await Collection.Socket.Connect(cancellationToken)) return null; + ScheduleWithCancellation(HeartbeatEvent, 10 * 1000, + async () => await Collection.Business.PushEvent(AliveEvent.Create(), cancellationToken), cancellationToken); if (Collection.Keystore.Session.D2.Length != 0) { Collection.Log.LogWarning(Tag, "Invalid Session found, try to clean D2Key, D2 and TGT Token"); Collection.Keystore.ClearSession(); } - + var transEmp = TransEmpEvent.Create(TransEmpEvent.State.FetchQrCode); - var result = await Collection.Business.SendEvent(transEmp, ct); + var result = await Collection.Business.SendEvent(transEmp, cancellationToken); if (result.Count != 0) { @@ -111,10 +104,10 @@ private void OnCancellation() return null; } - public Task LoginByQrCode(CancellationToken ct) + public Task LoginByQrCode(CancellationToken cancellationToken) { Reset(); - ct.Register(OnCancellation); + cancellationToken.Register(OnCancellation); Collection.Scheduler.Interval(QueryEvent, 2 * 1000, async () => await QueryTransEmpState(async @event => { @@ -125,21 +118,21 @@ public Task LoginByQrCode(CancellationToken ct) Collection.Keystore.Session.NoPicSig = @event.NoPicSig; } - return await DoWtLogin(); - }, ct)); + return await DoWtLogin(cancellationToken); + }, cancellationToken)); return _transEmpTask.Task; } - public async Task LoginByPassword(CancellationToken ct) + public async Task LoginByPassword(CancellationToken cancellationToken) { Reset(); - ct.Register(OnCancellation); + cancellationToken.Register(OnCancellation); if (!Collection.Socket.Connected) // if socket not connected, try to connect { - if (!await Collection.Socket.Connect()) return false; - Collection.Scheduler.Interval(HeartbeatEvent, 10 * 1000, async () => await Collection.Business.PushEvent(AliveEvent.Create(), CancellationToken.None)); + if (!await Collection.Socket.Connect(cancellationToken)) return false; + ScheduleWithCancellation(HeartbeatEvent, 10 * 1000, async () => await Collection.Business.PushEvent(AliveEvent.Create(), cancellationToken), cancellationToken); } if (Collection.Keystore.Session.D2.Length > 0 && Collection.Keystore.Session.Tgt.Length > 0 && @@ -148,7 +141,7 @@ public async Task LoginByPassword(CancellationToken ct) Collection.Log.LogInfo(Tag, "Session has not expired, using session to login and register status"); try { - if (await BotOnline()) return true; + if (await BotOnline(cancellationToken: cancellationToken)) return true; Collection.Log.LogWarning(Tag, "Register by session failed, try to login by EasyLogin"); } @@ -162,7 +155,7 @@ public async Task LoginByPassword(CancellationToken ct) { Collection.Keystore.ClearSession(); - if (!await KeyExchange()) + if (!await KeyExchange(cancellationToken)) { Collection.Log.LogInfo(Tag, "Key Exchange Failed, please try again later"); return false; @@ -182,7 +175,7 @@ public async Task LoginByPassword(CancellationToken ct) case LoginCommon.Error.Success: { Collection.Log.LogInfo(Tag, "Login Success, try to register services"); - return await BotOnline(); + return await BotOnline(cancellationToken: cancellationToken); } case LoginCommon.Error.UnusualVerify: { @@ -199,20 +192,20 @@ public async Task LoginByPassword(CancellationToken ct) if (e.TempPassword != null) { Collection.Keystore.Session.TempPassword = e.TempPassword; - return await DoUnusualEasyLogin(); + return await DoUnusualEasyLogin(cancellationToken); } return false; - }, ct)); + }, cancellationToken)); bool result = await _transEmpTask.Task; - return result && await BotOnline(); + return result && await BotOnline(cancellationToken: cancellationToken); } default: { Collection.Log.LogWarning(Tag, $"Fast Login Failed with code {easyLoginResult[0].ResultCode}, trying to Login by Password..."); Collection.Keystore.Session.TempPassword = null; // clear temp password - return await LoginByPassword(ct); // try password login + return await LoginByPassword(cancellationToken); // try password login } } } @@ -232,7 +225,7 @@ public async Task LoginByPassword(CancellationToken ct) { Collection.Log.LogInfo(Tag, "Login Success"); - await BotOnline(); + await BotOnline(cancellationToken: cancellationToken); return true; } case LoginCommon.Error.UnusualVerify: @@ -253,7 +246,7 @@ public async Task LoginByPassword(CancellationToken ct) var (ticket, randStr) = await _captchaTask.Task; Collection.Keystore.Session.Captcha = new ValueTuple(ticket, randStr, aid); - return await LoginByPassword(ct); + return await LoginByPassword(cancellationToken); } Collection.Log.LogInfo(Tag, "Captcha Url is null, please try again later"); @@ -279,8 +272,8 @@ public async Task LoginByPassword(CancellationToken ct) }; var client = new HttpClient(); - var response = await client.PostAsJsonAsync(url, request, cancellationToken: ct); - var json = await response.Content.ReadFromJsonAsync(cancellationToken: ct); + var response = await client.PostAsJsonAsync(url, request, cancellationToken: cancellationToken); + var json = await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken); if (json == null) return false; var newDeviceEvent = new BotNewDeviceVerifyEvent(json.StrUrl, Array.Empty()); @@ -289,25 +282,20 @@ public async Task LoginByPassword(CancellationToken ct) string? original = HttpUtility.ParseQueryString(json.StrUrl.Split("?")[1])["str_url"]; if (original == null) return false; - - Collection.Scheduler.Interval(QueryEvent, 2 * 1000, async () => + + ScheduleWithCancellation(QueryEvent, 2 * 1000, async () => { - if (ct.IsCancellationRequested) - { - Collection.Scheduler.Cancel(QueryEvent); - return; - } var query = new NTNewDeviceQrCodeQuery { Uint32Flag = 0, Token = Convert.ToBase64String(Encoding.UTF8.GetBytes(original)) }; - var resp = await client.PostAsJsonAsync(url, query, ct); - var responseJson = await resp.Content.ReadFromJsonAsync(cancellationToken: ct); + var resp = await client.PostAsJsonAsync(url, query, cancellationToken); + var responseJson = await resp.Content.ReadFromJsonAsync(cancellationToken: cancellationToken); if (!string.IsNullOrEmpty(responseJson?.StrNtSuccToken)) { Collection.Scheduler.Cancel(QueryEvent); // cancel the event - + Collection.Keystore.Session.TempPassword = Encoding.UTF8.GetBytes(responseJson.StrNtSuccToken); _transEmpTask.SetResult(true); client.Dispose(); @@ -316,14 +304,14 @@ public async Task LoginByPassword(CancellationToken ct) { Collection.Log.LogInfo(Tag, "NewDeviceLogin is waiting for scanning"); } - }); + }, cancellationToken); if (await _transEmpTask.Task) { Collection.Log.LogInfo(Tag, "Trying to Login by NewDeviceLogin..."); var newDeviceLogin = NewDeviceLoginEvent.Create(); - _ = await Collection.Business.SendEvent(newDeviceLogin, ct); - return await BotOnline(); + _ = await Collection.Business.SendEvent(newDeviceLogin, cancellationToken); + return await BotOnline(cancellationToken: cancellationToken); } return false; @@ -343,10 +331,10 @@ public async Task LoginByPassword(CancellationToken ct) return false; } - private async Task KeyExchange() + private async Task KeyExchange(CancellationToken cancellationToken) { var keyExchangeEvent = KeyExchangeEvent.Create(); - var exchangeResult = await Collection.Business.SendEvent(keyExchangeEvent, CancellationToken.None); + var exchangeResult = await Collection.Business.SendEvent(keyExchangeEvent, cancellationToken); if (exchangeResult.Count != 0) { Collection.Log.LogInfo(Tag, "Key Exchange successfully!"); @@ -356,14 +344,14 @@ private async Task KeyExchange() return false; } - private async Task DoWtLogin() + private async Task DoWtLogin(CancellationToken cancellationToken) { Collection.Log.LogInfo(Tag, "Doing Login..."); Collection.Keystore.Session.Sequence = 0; Collection.Keystore.SecpImpl = new EcdhImpl(EcdhImpl.CryptMethod.Secp192K1); var loginEvent = LoginEvent.Create(); - var result = await Collection.Business.SendEvent(loginEvent, CancellationToken.None); + var result = await Collection.Business.SendEvent(loginEvent, cancellationToken); if (result.Count != 0) { @@ -373,7 +361,7 @@ private async Task DoWtLogin() Collection.Log.LogInfo(Tag, "Login Success"); Collection.Keystore.Info = new BotKeystore.BotInfo(@event.Age, @event.Sex, @event.Name); Collection.Log.LogInfo(Tag, Collection.Keystore.Info.ToString()); - return await BotOnline(); + return await BotOnline(cancellationToken: cancellationToken); } Collection.Log.LogFatal(Tag, $"Login failed: {@event.ResultCode}"); @@ -383,12 +371,12 @@ private async Task DoWtLogin() return false; } - private async Task QueryTransEmpState(Func> callback, CancellationToken ct) + private async Task QueryTransEmpState(Func> callback, CancellationToken cancellationToken) { - if (ct.IsCancellationRequested) + if (cancellationToken.IsCancellationRequested) { Collection.Scheduler.Cancel(QueryEvent); - _transEmpTask.SetCanceled(ct); + _transEmpTask.SetCanceled(cancellationToken); return; } if (Collection.Keystore.Session.QrString != null) @@ -401,13 +389,13 @@ private async Task QueryTransEmpState(Func> callback, }; var payload = JsonSerializer.SerializeToUtf8Bytes(request); - var response = await Http.PostAsync(Interface, payload, "application/json", ct); + var response = await Http.PostAsync(Interface, payload, "application/json", cancellationToken); var info = JsonSerializer.Deserialize(response); if (info != null) Collection.Keystore.Uin = info.Uin; } var transEmp = TransEmpEvent.Create(TransEmpEvent.State.QueryResult); - var result = await Collection.Business.SendEvent(transEmp, ct); + var result = await Collection.Business.SendEvent(transEmp, cancellationToken); if (result.Count != 0) { @@ -448,12 +436,12 @@ private async Task QueryTransEmpState(Func> callback, } } - public async Task BotOnline(BotOnlineEvent.OnlineReason reason = BotOnlineEvent.OnlineReason.Login) + public async Task BotOnline(BotOnlineEvent.OnlineReason reason = BotOnlineEvent.OnlineReason.Login, CancellationToken cancellationToken = default) { - var ct = CancellationToken.None; var registerEvent = StatusRegisterEvent.Create(); - var registerResponse = await Collection.Business.SendEvent(registerEvent, ct); - var heartbeatDelegate = new Action(async () => await Collection.Business.PushEvent(SsoAliveEvent.Create(), ct)); + var registerResponse = await Collection.Business.SendEvent(registerEvent, cancellationToken); + // Cancellation token use default here is because the heartbeatDelegate is order to keep alive after online + var heartbeatDelegate = new Action(async () => await Collection.Business.PushEvent(SsoAliveEvent.Create(), CancellationToken.None)); if (registerResponse.Count != 0) { @@ -468,7 +456,8 @@ public async Task BotOnline(BotOnlineEvent.OnlineReason reason = BotOnline var onlineEvent = new BotOnlineEvent(reason); Collection.Invoker.PostEvent(onlineEvent); - await Collection.Business.PushEvent(InfoSyncEvent.Create(), ct); + // cancellation token use default here is because the bot have online + await Collection.Business.PushEvent(InfoSyncEvent.Create(), CancellationToken.None); _reLoginTimer.Change(TimeSpan.FromDays(15), TimeSpan.FromDays(15)); Collection.Log.LogInfo(Tag, "AutoReLogin Enabled, session would be refreshed in 15 days period"); @@ -494,15 +483,15 @@ private async Task FetchUnusual() return false; } - private async Task DoUnusualEasyLogin() + private async Task DoUnusualEasyLogin(CancellationToken cancellationToken) { Collection.Log.LogInfo(Tag, "Trying to Login by EasyLogin..."); var unusualEvent = UnusualEasyLoginEvent.Create(); - var result = await Collection.Business.SendEvent(unusualEvent, CancellationToken.None); + var result = await Collection.Business.SendEvent(unusualEvent, cancellationToken); return result.Count != 0 && ((UnusualEasyLoginEvent)result[0]).Success; } - private async Task ReLogin() + private async Task ReLogin(CancellationToken cancellationToken) { Collection.Log.LogInfo(Tag, "Session is about to expire, try to relogin and refresh"); if (Collection.Keystore.Session.TempPassword == null) @@ -517,35 +506,56 @@ private async Task ReLogin() Collection.Socket.Disconnect(); Collection.Keystore.ClearSession(); - await Collection.Socket.Connect(); - if (await KeyExchange()) + try { - var easyLoginEvent = EasyLoginEvent.Create(); - var easyLoginResult = await Collection.Business.SendEvent(easyLoginEvent, CancellationToken.None); - if (easyLoginResult.Count != 0) + await Collection.Socket.Connect(cancellationToken); + + if (await KeyExchange(cancellationToken)) { - var result = (EasyLoginEvent)easyLoginResult[0]; - if ((LoginCommon.Error)result.ResultCode == LoginCommon.Error.Success) + var easyLoginEvent = EasyLoginEvent.Create(); + var easyLoginResult = await Collection.Business.SendEvent(easyLoginEvent, CancellationToken.None); + if (easyLoginResult.Count != 0) { - Collection.Log.LogInfo(Tag, "Login Success, try to register services"); - if (await BotOnline(BotOnlineEvent.OnlineReason.Reconnect)) return; - - Collection.Log.LogInfo(Tag, "Re-login failed, please refresh manually"); + var result = (EasyLoginEvent)easyLoginResult[0]; + if ((LoginCommon.Error)result.ResultCode == LoginCommon.Error.Success) + { + Collection.Log.LogInfo(Tag, "Login Success, try to register services"); + if (await BotOnline(BotOnlineEvent.OnlineReason.Reconnect, cancellationToken)) return; + + Collection.Log.LogInfo(Tag, "Re-login failed, please refresh manually"); + } } } + else + { + Collection.Log.LogInfo(Tag, "Key Exchange Failed, trying to online, please refresh manually"); + } } - else + catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) { - Collection.Log.LogInfo(Tag, "Key Exchange Failed, trying to online, please refresh manually"); + Collection.Keystore.Session.D2 = d2; + Collection.Keystore.Session.D2Key = d2Key; + Collection.Keystore.Session.Tgt = tgt; + throw; } - - Collection.Keystore.Session.D2 = d2; - Collection.Keystore.Session.D2Key = d2Key; - Collection.Keystore.Session.Tgt = tgt; - await BotOnline(BotOnlineEvent.OnlineReason.Reconnect); + await BotOnline(BotOnlineEvent.OnlineReason.Reconnect, cancellationToken); } public bool SubmitCaptcha(string ticket, string randStr) => _captchaTask.TrySetResult((ticket, randStr)); -} \ No newline at end of file + + private void ScheduleWithCancellation(string tag, int interval, Action func, CancellationToken ct) + { + Collection.Scheduler.Interval(tag, interval, () => + { + if (ct.IsCancellationRequested) + { + Collection.Scheduler.Cancel(tag); + return; + } + + func(); + }); + } +} diff --git a/Lagrange.Core/Internal/Context/Logic/LogicBase.cs b/Lagrange.Core/Internal/Context/Logic/LogicBase.cs index 2ef9a31df..a93c2dc13 100644 --- a/Lagrange.Core/Internal/Context/Logic/LogicBase.cs +++ b/Lagrange.Core/Internal/Context/Logic/LogicBase.cs @@ -8,7 +8,7 @@ internal abstract class LogicBase protected LogicBase(ContextCollection collection) => Collection = collection; - public virtual Task Incoming(ProtocolEvent e, CancellationToken ct) => Task.CompletedTask; + public virtual Task Incoming(ProtocolEvent e, CancellationToken cancellationToken) => Task.CompletedTask; - public virtual Task Outgoing(ProtocolEvent e, CancellationToken ct) => Task.CompletedTask; -} \ No newline at end of file + public virtual Task Outgoing(ProtocolEvent e, CancellationToken cancellationToken) => Task.CompletedTask; +} diff --git a/Lagrange.Core/Internal/Context/PacketContext.cs b/Lagrange.Core/Internal/Context/PacketContext.cs index 6c4a027a1..29746a2f7 100644 --- a/Lagrange.Core/Internal/Context/PacketContext.cs +++ b/Lagrange.Core/Internal/Context/PacketContext.cs @@ -17,7 +17,7 @@ internal class PacketContext : ContextBase { internal SignProvider SignProvider { private get; set; } - private readonly ConcurrentDictionary task, CancellationToken ct)> _pendingTasks; + private readonly ConcurrentDictionary task, CancellationToken cancellationToken)> _pendingTasks; public PacketContext(ContextCollection collection, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, BotConfig config) : base(collection, keystore, appInfo, device) @@ -29,13 +29,13 @@ public PacketContext(ContextCollection collection, BotKeystore keystore, BotAppI "Linux" => new LinuxSigner(), _ => throw new Exception("Unknown System Found") }; - _pendingTasks = new ConcurrentDictionary task, CancellationToken ct)>(); + _pendingTasks = new ConcurrentDictionary task, CancellationToken cancellationToken)>(); } /// /// Send the packet and wait for the corresponding response by the packet's sequence number. /// - public Task SendPacket(SsoPacket packet, CancellationToken ct) + public Task SendPacket(SsoPacket packet, CancellationToken cancellationToken) { byte[] data; switch (packet.PacketType) @@ -57,10 +57,10 @@ public Task SendPacket(SsoPacket packet, CancellationToken ct) throw new Exception("Unknown Packet Type"); } - ct.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); var task = new TaskCompletionSource(); - _pendingTasks.TryAdd(packet.Sequence, (task, ct)); + _pendingTasks.TryAdd(packet.Sequence, (task, cancellationToken)); // We have to wait packet to be sent before we can return the task // Because the packet's sequence number is used to identify the response @@ -101,9 +101,9 @@ public void DispatchPacket(BinaryPacket packet) if (_pendingTasks.TryRemove(sso.Sequence, out var pendingTask)) { - if (pendingTask.ct.IsCancellationRequested) + if (pendingTask.cancellationToken.IsCancellationRequested) { - pendingTask.task.SetCanceled(pendingTask.ct); + pendingTask.task.SetCanceled(pendingTask.cancellationToken); return; } if (sso is { RetCode: not 0, Extra: { } extra}) @@ -121,4 +121,4 @@ public void DispatchPacket(BinaryPacket packet) Collection.Business.HandleServerPacket(sso); } } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/SocketContext.cs b/Lagrange.Core/Internal/Context/SocketContext.cs index e722f1081..ba956f929 100644 --- a/Lagrange.Core/Internal/Context/SocketContext.cs +++ b/Lagrange.Core/Internal/Context/SocketContext.cs @@ -35,20 +35,20 @@ public SocketContext(ContextCollection collection, BotKeystore keystore, BotAppI _config = config; } - public async Task Connect() + public async Task Connect(CancellationToken cancellationToken) { if (_tcpClient.Connected) return true; - var servers = await OptimumServer(_config.GetOptimumServer, _config.UseIPv6Network); + var servers = await OptimumServer(_config.GetOptimumServer, _config.UseIPv6Network, cancellationToken); ServerUri = servers.First(); - return await _tcpClient.Connect(ServerUri.Host, ServerUri.Port); + return await _tcpClient.Connect(ServerUri.Host, ServerUri.Port, cancellationToken); } - private async Task Reconnect() + private async Task Reconnect(CancellationToken cancellationToken) { if (ServerUri != null && !_tcpClient.Connected) { - bool reconnect = await _tcpClient.Connect(ServerUri.Host, ServerUri.Port); + bool reconnect = await _tcpClient.Connect(ServerUri.Host, ServerUri.Port, cancellationToken); if (reconnect) { Collection.Log.LogInfo(Tag, $"Reconnect to {ServerUri}"); @@ -77,10 +77,15 @@ public void OnDisconnect() if (_config.AutoReconnect) { - Collection.Scheduler.Interval("Reconnect", 10 * 1000, async () => + var cancellationToken = CancellationToken.None; + + async void DoScheduleReconnect() { - if (await Reconnect()) Collection.Scheduler.Cancel("Reconnect"); - }); + if (cancellationToken.IsCancellationRequested || await Reconnect(cancellationToken)) + Collection.Scheduler.Cancel("Reconnect"); + } + + Collection.Scheduler.Interval("Reconnect", 10 * 1000, DoScheduleReconnect); } } @@ -109,12 +114,12 @@ public void OnSocketError(Exception e, ReadOnlyMemory data = default) new("http://119.147.190.138:8080") }; - private async Task> OptimumServer(bool requestMsf, bool useIPv6Network = false) + private async Task> OptimumServer(bool requestMsf, bool useIPv6Network = false, CancellationToken cancellationToken = default) { - var result = requestMsf ? await ResolveDns(useIPv6Network) : useIPv6Network ? HardCodeIPv6Uris : TestIPv4HardCodes; + var result = requestMsf ? await ResolveDns(useIPv6Network, cancellationToken: cancellationToken) : useIPv6Network ? HardCodeIPv6Uris : TestIPv4HardCodes; var latencyTasks = result.Select(uri => Icmp.PingAsync(uri)).ToArray(); - var latency = await Task.WhenAll(latencyTasks); + var latency = await Task.WhenAll(latencyTasks).WaitAsync(cancellationToken); Array.Sort(latency, result); var list = result.ToList(); @@ -122,10 +127,10 @@ private async Task> OptimumServer(bool requestMsf, bool useIPv6Network return list; } - private static async Task ResolveDns(bool useIPv6Network = false) + private static async Task ResolveDns(bool useIPv6Network = false, CancellationToken cancellationToken = default) { string dns = useIPv6Network ? "msfwifiv6.3g.qq.com" : "msfwifi.3g.qq.com"; - var addresses = await Dns.GetHostEntryAsync(dns); + var addresses = await Dns.GetHostEntryAsync(dns, cancellationToken); var result = new Uri[addresses.AddressList.Length]; for (int i = 0; i < addresses.AddressList.Length; i++) result[i] = new Uri($"http://{addresses.AddressList[i]}:8080"); diff --git a/Lagrange.Core/Internal/Context/Uploader/Common.cs b/Lagrange.Core/Internal/Context/Uploader/Common.cs index c2d28a1a7..6e7a766af 100644 --- a/Lagrange.Core/Internal/Context/Uploader/Common.cs +++ b/Lagrange.Core/Internal/Context/Uploader/Common.cs @@ -49,10 +49,10 @@ internal static class Common }; } - public static async Task GetTicket(ContextCollection context, CancellationToken ct) + public static async Task GetTicket(ContextCollection context, CancellationToken cancellationToken) { var hwUrlEvent = HighwayUrlEvent.Create(); - var highwayUrlResult = await context.Business.SendEvent(hwUrlEvent, ct); + var highwayUrlResult = await context.Business.SendEvent(hwUrlEvent, cancellationToken); return ((HighwayUrlEvent)highwayUrlResult[0]).SigSession; } @@ -110,4 +110,4 @@ private static string ConvertIP(uint raw) var ip = BitConverter.GetBytes(raw); return $"{ip[0]}.{ip[1]}.{ip[2]}.{ip[3]}"; } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/Uploader/FileUploader.cs b/Lagrange.Core/Internal/Context/Uploader/FileUploader.cs index f82828012..bf3640f4f 100644 --- a/Lagrange.Core/Internal/Context/Uploader/FileUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/FileUploader.cs @@ -11,14 +11,14 @@ namespace Lagrange.Core.Internal.Context.Uploader; /// internal static class FileUploader { - public static async Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct) + public static async Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken) { if (entity is not FileEntity { FileStream: not null } file) return false; try { var uploadEvent = FileUploadEvent.Create(chain.Uid ?? "", file); - var result = await context.Business.SendEvent(uploadEvent, ct); + var result = await context.Business.SendEvent(uploadEvent, cancellationToken); var uploadResp = (FileUploadEvent)result[0]; if (!uploadResp.IsExist) @@ -69,7 +69,7 @@ public static async Task UploadPrivate(ContextCollection context, MessageC file.FileUuid = uploadResp.FileId; bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(95, file.FileStream, - await Common.GetTicket(context, ct), file.FileMd5, ct, extendInfo: ext.Serialize().ToArray()); + await Common.GetTicket(context, cancellationToken), file.FileMd5, cancellationToken, extendInfo: ext.Serialize().ToArray()); if (!hwSuccess) return false; } } @@ -79,11 +79,11 @@ public static async Task UploadPrivate(ContextCollection context, MessageC } var sendEvent = SendMessageEvent.Create(chain); - var sendResult = await context.Business.SendEvent(sendEvent, ct); + var sendResult = await context.Business.SendEvent(sendEvent, cancellationToken); return sendResult.Count != 0 && ((SendMessageEvent)sendResult[0]).MsgResult.Result == 0; } - public static async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, string targetDirectory, CancellationToken ct) + public static async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, string targetDirectory, CancellationToken cancellationToken) { if (entity is not FileEntity { FileStream: not null } file) return false; @@ -91,7 +91,7 @@ public static async Task UploadGroup(ContextCollection context, MessageCha try { var uploadEvent = GroupFSUploadEvent.Create(chain.GroupUin ?? 0, targetDirectory, file); - var result = await context.Business.SendEvent(uploadEvent, ct); + var result = await context.Business.SendEvent(uploadEvent, cancellationToken); var uploadResp = (GroupFSUploadEvent)result[0]; if (!uploadResp.IsExist) @@ -143,7 +143,7 @@ public static async Task UploadGroup(ContextCollection context, MessageCha }; bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(71, file.FileStream, - await Common.GetTicket(context, ct), file.FileMd5, ct, extendInfo: ext.Serialize().ToArray()); + await Common.GetTicket(context, cancellationToken), file.FileMd5, cancellationToken, extendInfo: ext.Serialize().ToArray()); if (!hwSuccess) return false; fileId = uploadResp.FileId; @@ -155,7 +155,7 @@ public static async Task UploadGroup(ContextCollection context, MessageCha } var sendEvent = GroupSendFileEvent.Create(chain.GroupUin ?? 0, fileId); - var sendResult = await context.Business.SendEvent(sendEvent, ct); + var sendResult = await context.Business.SendEvent(sendEvent, cancellationToken); return sendResult.Count != 0 && ((GroupSendFileEvent)sendResult[0]).ResultCode == 0; } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/Uploader/IHighwayUploader.cs b/Lagrange.Core/Internal/Context/Uploader/IHighwayUploader.cs index 21d8196e0..8c756820c 100644 --- a/Lagrange.Core/Internal/Context/Uploader/IHighwayUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/IHighwayUploader.cs @@ -4,7 +4,7 @@ namespace Lagrange.Core.Internal.Context.Uploader; internal interface IHighwayUploader { - public Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct); + public Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken); - public Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct); -} \ No newline at end of file + public Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken); +} diff --git a/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs b/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs index cf1000423..41f83cd39 100644 --- a/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/ImageUploader.cs @@ -8,18 +8,18 @@ namespace Lagrange.Core.Internal.Context.Uploader; [HighwayUploader(typeof(ImageEntity))] internal class ImageUploader : IHighwayUploader { - public async Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct) + public async Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken) { if (entity is ImageEntity { ImageStream: { } stream } image) { var uploadEvent = ImageUploadEvent.Create(image, chain.FriendInfo?.Uid ?? ""); - var uploadResult = await context.Business.SendEvent(uploadEvent, ct); + var uploadResult = await context.Business.SendEvent(uploadEvent, cancellationToken); var metaResult = (ImageUploadEvent)uploadResult[0]; if (Common.GenerateExt(metaResult) is { } ext) { var hash = metaResult.MsgInfo.MsgInfoBody[0].Index.Info.FileHash.UnHex(); - bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1003, stream.Value, await Common.GetTicket(context, ct), hash, ct, extendInfo: ext.Serialize().ToArray()); + bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1003, stream.Value, await Common.GetTicket(context, cancellationToken), hash, cancellationToken, extendInfo: ext.Serialize().ToArray()); if (!hwSuccess) { await stream.Value.DisposeAsync(); @@ -33,18 +33,18 @@ public async Task UploadPrivate(ContextCollection context, MessageChain chain, I } } - public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct) + public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken) { if (entity is ImageEntity { ImageStream: { } stream } image) { var uploadEvent = ImageGroupUploadEvent.Create(image, chain.GroupUin ?? 0); - var uploadResult = await context.Business.SendEvent(uploadEvent, ct); + var uploadResult = await context.Business.SendEvent(uploadEvent, cancellationToken); var metaResult = (ImageGroupUploadEvent)uploadResult[0]; if (Common.GenerateExt(metaResult) is { } ext) { var hash = metaResult.MsgInfo.MsgInfoBody[0].Index.Info.FileHash.UnHex(); - bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1004, stream.Value, await Common.GetTicket(context, ct), hash, ct, extendInfo: ext.Serialize().ToArray()); + bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1004, stream.Value, await Common.GetTicket(context, cancellationToken), hash, cancellationToken, extendInfo: ext.Serialize().ToArray()); if (!hwSuccess) { await stream.Value.DisposeAsync(); @@ -57,4 +57,4 @@ public async Task UploadGroup(ContextCollection context, MessageChain chain, IMe await image.ImageStream.Value.DisposeAsync(); } } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/Uploader/PttUploader.cs b/Lagrange.Core/Internal/Context/Uploader/PttUploader.cs index bbdb156c1..44345d73e 100644 --- a/Lagrange.Core/Internal/Context/Uploader/PttUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/PttUploader.cs @@ -8,18 +8,18 @@ namespace Lagrange.Core.Internal.Context.Uploader; [HighwayUploader(typeof(RecordEntity))] internal class PttUploader : IHighwayUploader { - public async Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct) + public async Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken) { if (entity is RecordEntity { AudioStream: { } stream } record) { var uploadEvent = RecordUploadEvent.Create(record, chain.FriendInfo?.Uid ?? ""); - var uploadResult = await context.Business.SendEvent(uploadEvent, ct); + var uploadResult = await context.Business.SendEvent(uploadEvent, cancellationToken); var metaResult = (RecordUploadEvent)uploadResult[0]; if (Common.GenerateExt(metaResult) is { } ext) { var hash = metaResult.MsgInfo.MsgInfoBody[0].Index.Info.FileHash.UnHex(); - bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1007, stream.Value, await Common.GetTicket(context, ct), hash, ct, extendInfo: ext.Serialize().ToArray()); + bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1007, stream.Value, await Common.GetTicket(context, cancellationToken), hash, cancellationToken, extendInfo: ext.Serialize().ToArray()); if (!hwSuccess) { await stream.Value.DisposeAsync(); @@ -33,18 +33,18 @@ public async Task UploadPrivate(ContextCollection context, MessageChain chain, I } } - public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct) + public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken) { if (entity is RecordEntity { AudioStream: { } stream } record) { var uploadEvent = RecordGroupUploadEvent.Create(record, chain.GroupUin ?? 0); - var uploadResult = await context.Business.SendEvent(uploadEvent, ct); + var uploadResult = await context.Business.SendEvent(uploadEvent, cancellationToken); var metaResult = (RecordGroupUploadEvent)uploadResult[0]; if (Common.GenerateExt(metaResult) is { } ext) { var hash = metaResult.MsgInfo.MsgInfoBody[0].Index.Info.FileHash.UnHex(); - bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1008, stream.Value, await Common.GetTicket(context, ct), hash, ct, extendInfo: ext.Serialize().ToArray()); + bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1008, stream.Value, await Common.GetTicket(context, cancellationToken), hash, cancellationToken, extendInfo: ext.Serialize().ToArray()); if (!hwSuccess) { await stream.Value.DisposeAsync(); @@ -57,4 +57,4 @@ public async Task UploadGroup(ContextCollection context, MessageChain chain, IMe await record.AudioStream.Value.DisposeAsync(); } } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs b/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs index 620a35d9c..5f35a8af7 100644 --- a/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs @@ -8,12 +8,12 @@ namespace Lagrange.Core.Internal.Context.Uploader; [HighwayUploader(typeof(VideoEntity))] internal class VideoUploader : IHighwayUploader { - public async Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct) + public async Task UploadPrivate(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken) { if (entity is VideoEntity { VideoStream: { } stream, ThumbnailStream: { } thumbnail } video) { var uploadEvent = VideoUploadEvent.Create(video, chain.FriendInfo?.Uid ?? ""); - var uploadResult = await context.Business.SendEvent(uploadEvent, ct); + var uploadResult = await context.Business.SendEvent(uploadEvent, cancellationToken); var metaResult = (VideoUploadEvent)uploadResult[0]; if (Common.GenerateExt(metaResult) is { } ext) @@ -21,7 +21,7 @@ public async Task UploadPrivate(ContextCollection context, MessageChain chain, I ext.Hash.FileSha1 = Common.CalculateStreamBytes(stream.Value); var hash = metaResult.MsgInfo.MsgInfoBody[0].Index.Info.FileHash.UnHex(); - bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1001, stream.Value, await Common.GetTicket(context, ct), hash, ct, extendInfo: ext.Serialize().ToArray()); + bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1001, stream.Value, await Common.GetTicket(context, cancellationToken), hash, cancellationToken, extendInfo: ext.Serialize().ToArray()); if (!hwSuccess) { await stream.Value.DisposeAsync(); @@ -32,7 +32,7 @@ public async Task UploadPrivate(ContextCollection context, MessageChain chain, I if (Common.GenerateExt(metaResult, metaResult.SubFiles[0]) is { } subExt) { var hash = metaResult.MsgInfo.MsgInfoBody[1].Index.Info.FileHash.UnHex(); - bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1002, thumbnail.Value, await Common.GetTicket(context, ct), hash, ct, extendInfo: subExt.Serialize().ToArray()); + bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1002, thumbnail.Value, await Common.GetTicket(context, cancellationToken), hash, cancellationToken, extendInfo: subExt.Serialize().ToArray()); if (!hwSuccess) { await stream.Value.DisposeAsync(); @@ -48,12 +48,12 @@ public async Task UploadPrivate(ContextCollection context, MessageChain chain, I } } - public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken ct) + public async Task UploadGroup(ContextCollection context, MessageChain chain, IMessageEntity entity, CancellationToken cancellationToken) { if (entity is VideoEntity { VideoStream: { } stream, ThumbnailStream: { } thumbnail } video) { var uploadEvent = VideoGroupUploadEvent.Create(video, chain.GroupUin ?? 0); - var uploadResult = await context.Business.SendEvent(uploadEvent, ct); + var uploadResult = await context.Business.SendEvent(uploadEvent, cancellationToken); var metaResult = (VideoGroupUploadEvent)uploadResult[0]; if (Common.GenerateExt(metaResult) is { } ext) @@ -61,7 +61,7 @@ public async Task UploadGroup(ContextCollection context, MessageChain chain, IMe ext.Hash.FileSha1 = Common.CalculateStreamBytes(stream.Value); var hash = metaResult.MsgInfo.MsgInfoBody[0].Index.Info.FileHash.UnHex(); - bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1005, stream.Value, await Common.GetTicket(context, ct), hash, ct, extendInfo: ext.Serialize().ToArray()); + bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1005, stream.Value, await Common.GetTicket(context, cancellationToken), hash, cancellationToken, extendInfo: ext.Serialize().ToArray()); if (!hwSuccess) { await stream.Value.DisposeAsync(); @@ -72,7 +72,7 @@ public async Task UploadGroup(ContextCollection context, MessageChain chain, IMe if (Common.GenerateExt(metaResult, metaResult.SubFiles[0]) is { } subExt) { var hash = metaResult.MsgInfo.MsgInfoBody[1].Index.Info.FileHash.UnHex(); - bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1006, thumbnail.Value, await Common.GetTicket(context, ct), hash, ct, extendInfo: subExt.Serialize().ToArray()); + bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1006, thumbnail.Value, await Common.GetTicket(context, cancellationToken), hash, cancellationToken, extendInfo: subExt.Serialize().ToArray()); if (!hwSuccess) { await stream.Value.DisposeAsync(); @@ -87,4 +87,4 @@ public async Task UploadGroup(ContextCollection context, MessageChain chain, IMe await thumbnail.Value.DisposeAsync(); } } -} \ No newline at end of file +} diff --git a/Lagrange.Core/Internal/Network/ClientListener.cs b/Lagrange.Core/Internal/Network/ClientListener.cs index 9682b773b..58e963ea8 100644 --- a/Lagrange.Core/Internal/Network/ClientListener.cs +++ b/Lagrange.Core/Internal/Network/ClientListener.cs @@ -20,12 +20,12 @@ internal abstract partial class ClientListener : IClientListener /// public ClientListener() { } - private async Task InternalConnectAsync(SocketSession session, string host, int port) + private async Task InternalConnectAsync(SocketSession session, string host, int port, CancellationToken cancellationToken) { try { - await session.Socket.ConnectAsync(host, port); - _ = ReceiveLoop(session); + await session.Socket.ConnectAsync(host, port, cancellationToken); + _ = ReceiveLoop(session, cancellationToken); return true; } catch (Exception e) @@ -41,8 +41,9 @@ private async Task InternalConnectAsync(SocketSession session, string host /// /// /// + /// /// - public Task Connect(string host, int port) + public Task Connect(string host, int port, CancellationToken cancellationToken) { SocketSession? previousSession = Session, createdSession = null; if (previousSession != null || // The client has been connected @@ -52,7 +53,7 @@ public Task Connect(string host, int port) return Task.FromResult(false); } - return InternalConnectAsync(createdSession, host, port); // Connect to server + return InternalConnectAsync(createdSession, host, port, cancellationToken); // Connect to server } /// diff --git a/Lagrange.Core/Utility/Network/Http.cs b/Lagrange.Core/Utility/Network/Http.cs index 3dab1b8d4..a986d037c 100644 --- a/Lagrange.Core/Utility/Network/Http.cs +++ b/Lagrange.Core/Utility/Network/Http.cs @@ -43,11 +43,11 @@ public static async Task PostAsync(string url, byte[] payload, string co return await response.Content.ReadAsByteArrayAsync(); } - public static async Task PostAsync(string url, byte[] payload, string content, CancellationToken ct) + public static async Task PostAsync(string url, byte[] payload, string content, CancellationToken cancellationToken) { var contentData = new ByteArrayContent(payload); contentData.Headers.ContentType = new MediaTypeHeaderValue(content); - var response = await Client.PostAsync(url, contentData, ct); - return await response.Content.ReadAsByteArrayAsync(ct); + using var response = await Client.PostAsync(url, contentData, cancellationToken); + return await response.Content.ReadAsByteArrayAsync(cancellationToken); } -} \ No newline at end of file +}