Skip to content

Commit 50bfad4

Browse files
committed
feat 迁移到asp.net core
1 parent bb24b11 commit 50bfad4

File tree

80 files changed

+4345
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4345
-39
lines changed
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace XinjingdailyBot.Infrastructure.Attribute
2+
{
3+
/// <summary>
4+
/// 参考地址:https://www.cnblogs.com/kelelipeng/p/10643556.html
5+
/// 标记服务
6+
/// 如何使用?
7+
/// 1、如果服务是本身 直接在类上使用[AppService]
8+
/// 2、如果服务是接口 在类上使用 [AppService(ServiceType = typeof(实现接口))]
9+
/// </summary>
10+
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
11+
public sealed class AppServiceAttribute : System.Attribute
12+
{
13+
/// <summary>
14+
/// 服务声明周期
15+
/// 不给默认值的话注册的是AddSingleton
16+
/// </summary>
17+
public LifeTime ServiceLifetime { get; set; } = LifeTime.Scoped;
18+
/// <summary>
19+
/// 指定服务类型
20+
/// </summary>
21+
public Type? ServiceType { get; set; }
22+
/// <summary>
23+
/// 是否可以从第一个接口获取服务类型
24+
/// </summary>
25+
public bool InterfaceServiceType { get; set; }
26+
}
27+
28+
public enum LifeTime
29+
{
30+
/// <summary>
31+
/// 瞬时
32+
/// </summary>
33+
Transient,
34+
/// <summary>
35+
/// 范围
36+
/// </summary>
37+
Scoped,
38+
/// <summary>
39+
/// 单例
40+
/// </summary>
41+
Singleton
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
namespace XinjingdailyBot.Infrastructure.Constant
2+
{
3+
public class HttpStatus
4+
{
5+
/// <summary>
6+
/// 操作成功
7+
/// </summary>
8+
public static readonly int SUCCESS = 200;
9+
/// <summary>
10+
/// 对象创建成功
11+
/// </summary>
12+
public static readonly int CREATED = 201;
13+
14+
/// <summary>
15+
/// 请求已经被接受
16+
/// </summary>
17+
public static readonly int ACCEPTED = 202;
18+
19+
/// <summary>
20+
/// 操作已经执行成功,但是没有返回数据
21+
/// </summary>
22+
public static readonly int NO_CONTENT = 204;
23+
24+
/// <summary>
25+
/// 资源已被移除
26+
/// </summary>
27+
public static readonly int MOVED_PERM = 301;
28+
29+
/// <summary>
30+
/// 重定向
31+
/// </summary>
32+
public static readonly int SEE_OTHER = 303;
33+
34+
/// <summary>
35+
/// 资源没有被修改
36+
/// </summary>
37+
public static readonly int NOT_MODIFIED = 304;
38+
39+
/**
40+
* 参数列表错误(缺少,格式不匹配)
41+
*/
42+
public static readonly int BAD_REQUEST = 400;
43+
44+
/// <summary>
45+
/// 未授权
46+
/// </summary>
47+
public static readonly int UNAUTHORIZED = 401;
48+
49+
/**
50+
* 访问受限,授权过期
51+
*/
52+
public static readonly int FORBIDDEN = 403;
53+
54+
/**
55+
* 资源,服务未找到
56+
*/
57+
public static readonly int NOT_FOUND = 404;
58+
59+
/**
60+
* 不允许的http方法
61+
*/
62+
public static readonly int BAD_METHOD = 405;
63+
64+
/**
65+
* 资源冲突,或者资源被锁
66+
*/
67+
public static readonly int CONFLICT = 409;
68+
69+
/**
70+
* 不支持的数据,媒体类型
71+
*/
72+
public static readonly int UNSUPPORTED_TYPE = 415;
73+
74+
/**
75+
* 系统内部错误
76+
*/
77+
public static readonly int ERROR = 500;
78+
79+
/**
80+
* 接口未实现
81+
*/
82+
public static readonly int NOT_IMPLEMENTED = 501;
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace XinjingdailyBot.Infrastructure.Constant
2+
{
3+
public class HubsConstant
4+
{
5+
private const string V = "receiveNotice";
6+
public static string ReceiveNotice = V;
7+
public static string OnlineNum = "onlineNum";
8+
public static string MoreNotice = "moreNotice";
9+
public static string OnlineUser = "onlineUser";
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace XinjingdailyBot.Infrastructure.CustomException
2+
{
3+
public class CustomException : Exception
4+
{
5+
public int Code { get; set; }
6+
public string Msg { get; set; }
7+
public string LogMsg { get; set; }
8+
9+
public CustomException(string msg) : base(msg)
10+
{
11+
}
12+
public CustomException(int code, string msg) : base(msg)
13+
{
14+
Code = code;
15+
Msg = msg;
16+
}
17+
18+
public CustomException(ResultCode resultCode, string msg) : base(msg)
19+
{
20+
Code = (int)resultCode;
21+
}
22+
23+
/// <summary>
24+
/// 自定义异常
25+
/// </summary>
26+
/// <param name="resultCode"></param>
27+
/// <param name="msg"></param>
28+
/// <param name="errorMsg">用于记录详细日志到输出介质</param>
29+
public CustomException(ResultCode resultCode, string msg, object errorMsg) : base(msg)
30+
{
31+
Code = (int)resultCode;
32+
LogMsg = errorMsg.ToString();
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.ComponentModel;
2+
3+
namespace XinjingdailyBot.Infrastructure.CustomException
4+
{
5+
public enum ResultCode
6+
{
7+
[Description("success")]
8+
SUCCESS = 200,
9+
10+
[Description("参数错误")]
11+
PARAM_ERROR = 101,
12+
13+
[Description("验证码错误")]
14+
CAPTCHA_ERROR = 103,
15+
16+
[Description("登录错误")]
17+
LOGIN_ERROR = 105,
18+
19+
[Description("操作失败")]
20+
FAIL = 1,
21+
22+
[Description("服务端出错啦")]
23+
GLOBAL_ERROR = 500,
24+
25+
[Description("自定义异常")]
26+
CUSTOM_ERROR = 110,
27+
28+
[Description("非法请求")]
29+
INVALID_REQUEST = 116,
30+
31+
[Description("授权失败")]
32+
OAUTH_FAIL = 201,
33+
34+
[Description("未授权")]
35+
DENY = 401,
36+
37+
[Description("授权访问失败")]
38+
FORBIDDEN = 403,
39+
40+
[Description("Bad Request")]
41+
BAD_REQUEST = 400
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Telegram.Bot.Types;
2+
3+
namespace XinjingdailyBot.Helpers
4+
{
5+
internal static class ChatExtension
6+
{
7+
internal static string ChatID(this Chat chat)
8+
{
9+
return string.IsNullOrEmpty(chat.Username) ? $"#{chat.Id}" : $"@{chat.Username}";
10+
}
11+
12+
internal static string ChatProfile(this Chat chat)
13+
{
14+
return $"{chat.Title} {chat.ChatID()}";
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)