10000 #升级到.NET8# · APIJSON/APIJSON-CSharp@462977a · GitHub
[go: up one dir, main page]

Skip to content

Commit 462977a

Browse files
committed
#升级到.NET8#
1 parent bd1f3db commit 462977a

Some cont F438 ent is hidden

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

48 files changed

+3320
-1969
lines changed

APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj renamed to APIJSON.NET/APIJSON.Data/APIJSON.Data.csproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Version>0.0.11</Version>
66
<Description>
77
0.0.11 升级sqlSugarCore版本 解决如果查找字段是关键字(例如:key)时出错的问题
@@ -20,13 +20,12 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.2.0" />
24-
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
25-
<PackageReference Include="sqlSugarCore" Version="5.0.9.1" />
23+
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" />
24+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
25+
<PackageReference Include="sqlSugarCore" Version="5.1.4.140" />
26+
<PackageReference Include="Volo.Abp.Autofac" Version="8.0.2" />
2627
</ItemGroup>
2728

28-
<ItemGroup>
29-
<Folder Include="Properties\" />
30-
</ItemGroup>
29+
3130

3231
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Volo.Abp.Autofac;
5+
using Volo.Abp.Modularity;
6+
7+
namespace APIJSON.Data;
8+
[DependsOn(
9+
typeof(AbpAutofacModule))]
10+
public class ApiJsonNetDataModule : AbpModule
11+
{
12+
public override void ConfigureServices(ServiceConfigurationContext context)
13+
{
14+
15+
}
16+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using APIJSON.Data.Models;
2+
using Microsoft.Extensions.Configuration;
3+
using SqlSugar;
4+
using System;
5+
using System.Collections.Generic;
6+
using Volo.Abp.DependencyInjection;
7+
namespace APIJSON.Data;
8+
9+
public class DbContext:ISingletonDependency
10+
{
11+
public DbContext(IConfiguration options)
12+
{
13+
Db = new SqlSugarClient(new ConnectionConfig()
14+
{
15+
ConnectionString = options.GetConnectionString("ConnectionString"),
16+
DbType = (DbType)Enum.Parse(typeof(DbType), options.GetConnectionString("DbType")), InitKeyType= InitKeyType.Attribute,
17+
IsAutoCloseConnection = true
18+
});
19+
Db.Aop.OnLogExecuted = (sql, pars) => //SQL执行完事件
20+
{
21+
22+
};
23+
Db.Aop.OnLogExecuting = (sql, pars) => //SQL执行前事件
24+
{
25+
26+
};
27+
}
28+
public SqlSugarClient Db;
29+
public DbSet<Login> LoginDb { get { return new DbSet<Login>(Db); } }
30+
}
31+
public class DbSet<T> : SimpleClient<T> where T : class, new()
32+
{
33+
public DbSet(SqlSugarClient context) : base(context)
34+
{
35+
36+
}
37+
public List<T> GetByIds(dynamic[] ids)
38+
{
39+
return Context.Queryable<T>().In(ids).ToList(); ;
40+
}
41+
}

APIJSON.NET/APIJSON.Data/FuncList.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace APIJSON.Data;
5+
6+
/// <summary>
7+
/// 自定义方法
8+
/// </summary>
9+
public class FuncList
10+
{
11+
/// <summary>
12+
///
13+
/// </summary>
14+
/// <param name="a"></param>
15+
/// <param name="b"></param>
16+
/// <returns></returns>
17+
public string Merge(object a, object b)
18+
{
19+ return a.ToString() + b.ToString();
20+
}
21+
22+
/// <summary>
23+
///
24+
/// </summary>
25+
/// <param name="a"></param>
26+
/// <param name="b"></param>
27+
/// <returns></returns>
28+
public object MergeObj(object a, object b)
29+
{
30+
return new { a, b };
31+
}
32+
33+
/// <summary>
34+
///
35+
/// </summary>
36+
/// <param name="a"></param>
37+
/// <param name="b"></param>
38+
/// <returns></returns>
39+
public bool isContain(object a, object b)
40+
{
41+
return a.ToString().Split(',').Contains(b);
42+
}
43+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System;
2+
using System.IO;
3+
using System.Security.Cryptography;
4+
using System.Text;
5+
6+
namespace APIJSON.Data;
7+
8+
public class SimpleStringCipher
9+
{
10+
public static SimpleStringCipher Instance { get; }
11+
12+
/// <summary>
13+
/// This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
14+
/// This size of the IV (in bytes) must = (keysize / 8). Default keysize is 256, so the IV must be
15+
/// 32 bytes long. Using a 16 character string here gives us 32 bytes when converted to a byte array.
16+
/// </summary>
17+
public byte[] InitVectorBytes;
18+
19+
/// <summary>
20+
/// Default password to encrypt/decrypt texts.
21+
/// It's recommented to set to another value for security.
22+
/// Default value: "gsKnGZ041HLL4IM8"
23+
/// </summary>
24+
public static string DefaultPassPhrase { get; set; }
25+
26+
/// <summary>
27+
/// Default value: Encoding.ASCII.GetBytes("jkE49230Tf093b42")
28+
/// </summary>
29+
public static byte[] DefaultInitVectorBytes { get; set; }
30+
31+
/// <summary>
32+
/// Default value: Encoding.ASCII.GetBytes("hgt!16kl")
33+
/// </summary>
34+
public static byte[] DefaultSalt { get; set; }
35+
36+
/// <summary>
37+
/// This constant is used to determine the keysize of the encryption algorithm.
38+
/// </summary>
39+
public const int Keysize = 256;
40+
41+
static SimpleStringCipher()
42+
{
43+
DefaultPassPhrase = "gsKnGZ041HLL4IM9";
44+
DefaultInitVectorBytes = Encoding.ASCII.GetBytes("jkE49230Tf093b42");
45+
DefaultSalt = Encoding.ASCII.GetBytes("hgt!11kl");
46+
Instance = new SimpleStringCipher();
47+
}
48+
49+
public SimpleStringCipher()
50+
{
51+
InitVectorBytes = DefaultInitVectorBytes;
52+
}
53+
54+
public string Encrypt(string plainText, string passPhrase = null, byte[] salt = null)
55+
{
56+
if (plainText == null)
57+
{
58+
return null;
59+
}
60+
61+
if (passPhrase == null)
62+
{
63+
passPhrase = DefaultPassPhrase;
64+
}
65+
66+
if (salt == null)
67+
{
68+
salt = DefaultSalt;
69+
}
70+
71+
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
72+
using (var password = new Rfc2898DeriveBytes(passPhrase, salt))
73+
{
74+
var keyBytes = password.GetBytes(Keysize / 8);
75+
using (var symmetricKey = Aes.Create())
76+
{
77+
symmetricKey.Mode = CipherMode.CBC;
78+
using (var encryptor = symmetricKey.CreateEncryptor(keyBytes, InitVectorBytes))
79+
{
80+
using (var memoryStream = new MemoryStream())
81+
{
82+
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
83+
{
84+
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
85+
cryptoStream.FlushFinalBlock();
86+
var cipherTextBytes = memoryStream.ToArray();
87+
return Convert.ToBase64String(cipherTextBytes);
88+
}
89+
}
90+
}
91+
}
92+
}
93+
}
94+
95+
public string Decrypt(string cipherText, string passPhrase = null, byte[] salt = null)
96+
{
97+
if (string.IsNullOrEmpty(cipherText))
98+
{
99+
return null;
100+
}
101+
102+
if (passPhrase == null)
103+
{
104+
passPhrase = DefaultPassPhrase;
105+
}
106+
107+
if (salt == null)
108+
{
109+
salt = DefaultSalt;
110+
}
111+
112+
var cipherTextBytes = Convert.FromBase64String(cipherText);
113+
using (var password = new Rfc2898DeriveBytes(passPhrase, salt))
114+
{
115+
var keyBytes = password.GetBytes(Keysize / 8);
116+
using (var symmetricKey = Aes.Create())
117+
{
118+
symmetricKey.Mode = CipherMode.CBC;
119+
using (var decryptor = symmetricKey.CreateDecryptor(keyBytes, InitVectorBytes))
120+
{
121+
using (var memoryStream = new MemoryStream(cipherTextBytes))
122+
{
123+
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
124+
{
125+
var plainTextBytes = new byte[cipherTextBytes.Length];
126+
var decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
127+
return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
128+
}
129+
}
130+
}
131+
}
132+
}
133+
}
134+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace APIJSON.Data;
2+
3+
using System;
4+
using System.Text.RegularExpressions;
5+
public static class StringExtensions
6+
{
7+
8+
/// <summary>
9+
/// 是否有值
10+
/// </summary>
11+
/// <param name="str"></param>
12+
/// <returns></returns>
13+
public static bool IsValue(this object str)
14+
{
15+
return str != null && !string.IsNullOrEmpty(str.ToString());
16+
}
17+
18+
/// <summary>
19+
///
20+
/// </summary>
21+
/// <param name="param"></param>
22+
/// <returns></returns>
23+
public static string GetParamName(this string param)
24+
{
25+
return param + new Random().Next(1, 100);
26+
}
27+
28+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace APIJSON.Data;
2+
3+
using global::SqlSugar;
4+
public class DbOptions
5+
{
6+
/// <summary>
7+
///
8+
/// </summary>
9+
public DbType DbType { get; set; }
10+
11+
/// <summary>
12+
///
13+
/// </summary>
14+
public string ConnectionString { get; set; }
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using SqlSugar;
2+
using System;
3+
4+
namespace APIJSON.Data.Models;
5+
6+
public class Login
7+
{
8+
[SugarColumn(IsNullable = false, IsPrimaryKey = true)]
9+
public int userId { get; set; }
10+
[SugarColumn(Length = 100, ColumnDescription = "用户名")]
11+
public string userName { get; set; }
12+
[SugarColumn(Length = 200, ColumnDescription = "密码")]
13+
public string passWord { get; set; }
14+
[SugarColumn(Length = 100, ColumnDescription = "密码盐")]
15+
public string passWordSalt { get; set; }
16+
[SugarColumn(Length = 100, ColumnDescription = "权限组")]
17+
public string roleCode { get; set; }
18+
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace APIJSON.Data.Models;
2+
3+
public class RoleItem
4+
{
5+
public string[] Table { get; set; }
6+
public string[] Column { get; set; }
7+
public string[] Filter { get; set; }
8+
}
9+
public class Role
10+
{
11+
public string Name { get; set; }
12+
public RoleItem Select { get; set; }
13+
public RoleItem Update { get; set; }
14+
public RoleItem Insert { get; set; }
15+
public RoleItem Delete { get; set; }
16+
17+
}
18+

0 commit comments

Comments
 (0)
0