Skip to content

Commit

Permalink
更新任务日志AOP,一级使用=号分隔
Browse files Browse the repository at this point in the history
  • Loading branch information
RayWangQvQ committed Apr 10, 2021
1 parent b4d902b commit 803b94f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using MethodBoundaryAspect.Fody.Attributes;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -31,18 +32,18 @@ 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);
}

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)
Expand All @@ -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,
}
}
8 changes: 1 addition & 7 deletions test/DailyTaskTest/RelationTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,14 @@ 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);

//获取天选时刻分组
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));
Expand Down

0 comments on commit 803b94f

Please sign in to comment.