From 803b94f8c4ad068b3ed1d2f8ce5d37d44499a35d Mon Sep 17 00:00:00 2001 From: RayWang <2271272653@qq.com> Date: Sat, 10 Apr 2021 11:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=BB=E5=8A=A1=E6=97=A5?= =?UTF-8?q?=E5=BF=97AOP=EF=BC=8C=E4=B8=80=E7=BA=A7=E4=BD=BF=E7=94=A8=3D?= =?UTF-8?q?=E5=8F=B7=E5=88=86=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attributes/TaskInterceptorAttribute.cs | 43 ++++++++++++++----- test/DailyTaskTest/RelationTags.cs | 8 +--- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/Ray.BiliBiliTool.Application/Attributes/TaskInterceptorAttribute.cs b/src/Ray.BiliBiliTool.Application/Attributes/TaskInterceptorAttribute.cs index b8323a6..63eb3e2 100644 --- a/src/Ray.BiliBiliTool.Application/Attributes/TaskInterceptorAttribute.cs +++ b/src/Ray.BiliBiliTool.Application/Attributes/TaskInterceptorAttribute.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Text; using MethodBoundaryAspect.Fody.Attributes; using Microsoft.Extensions.DependencyInjection; @@ -31,7 +32,7 @@ public override void OnEntry(MethodExecutionArgs arg) { if (_taskName == null) return; string end = _taskLevel == TaskLevel.One ? Environment.NewLine : ""; - string delimiter = GetDelimiter(); + string delimiter = GetDelimiters(); _logger.LogInformation(delimiter + "开始 {taskName} " + delimiter + end, _taskName); } @@ -39,10 +40,10 @@ public override void OnExit(MethodExecutionArgs arg) { if (_taskName == null) return; - string delimiter = GetDelimiter(); - var s = new string('-', _taskName.Length); + string delimiter = GetDelimiters(); + var append = new string(GetDelimiter(), _taskName.Length); - _logger.LogInformation(delimiter + s + "结束" + s + delimiter + Environment.NewLine); + _logger.LogInformation(delimiter + append + "结束" + append + delimiter + Environment.NewLine); } public override void OnException(MethodExecutionArgs arg) @@ -58,17 +59,39 @@ public override void OnException(MethodExecutionArgs arg) arg.FlowBehavior = FlowBehavior.Continue; } - private string GetDelimiter() + private string GetDelimiters() { - int count = (int)_taskLevel; - return new string('-', count); + char delimiter = GetDelimiter(); + + int count = Convert.ToInt32(_taskLevel.DefaultValue()); + return new string(delimiter, count); + } + + private char GetDelimiter() + { + switch (_taskLevel) + { + case TaskLevel.One: + return '='; + case TaskLevel.Two: + return '-'; + case TaskLevel.Three: + return '-'; + default: + throw new ArgumentOutOfRangeException(nameof(_taskLevel), _taskLevel, null); + } } } public enum TaskLevel { - One = 5, - Two = 3, - Three = 2, + [DefaultValue(5)] + One, + + [DefaultValue(3)] + Two, + + [DefaultValue(2)] + Three, } } diff --git a/test/DailyTaskTest/RelationTags.cs b/test/DailyTaskTest/RelationTags.cs index 5f8c10c..b94db30 100644 --- a/test/DailyTaskTest/RelationTags.cs +++ b/test/DailyTaskTest/RelationTags.cs @@ -77,7 +77,6 @@ public void CopyUpsToGroup() var ups = api.GetFollowings(new GetFollowingsRequest(long.Parse(cookie.UserId), FollowingsOrderType.TimeDesc)) .GetAwaiter().GetResult(); var followingIds = ups.Data.List.Take(2).Select(x => x.Mid); - var fids = string.Join(",", followingIds); string referer = string.Format(RelationApiConstant.GetTagsReferer, cookie.UserId); @@ -85,12 +84,7 @@ public void CopyUpsToGroup() var groups = api.GetTags(referer).GetAwaiter().GetResult(); int tagId = groups.Data.Find(x => x.Name == "ѡʱ")?.Tagid ?? 0; - var re = api.CopyUpsToGroup(new CopyUserToGroupRequest - { - Fids = fids, - Csrf = cookie.BiliJct, - Tagids = tagId.ToString() - }, referer) + var re = api.CopyUpsToGroup(new CopyUserToGroupRequest(followingIds.ToList(), tagId.ToString(), cookie.BiliJct), referer) .GetAwaiter().GetResult(); Debug.WriteLine(JsonSerializer.Serialize(re));