Skip to content

Commit cf7075e

Browse files
committed
support netcore 3.1
1 parent 9178aa8 commit cf7075e

File tree

841 files changed

+362379
-61377
lines changed

Some content is hidden

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

841 files changed

+362379
-61377
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
/Nuget/TestNuget/packages
99
/packages
1010
/Nuget/TestNuget/.vs
11+
/NetCore/App.HttpApiCore/obj
12+
/NetCore/App.HttpApiCore.Test/obj

HttpApi.sln

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.29306.81
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App.HttpApi", "App.HttpApi\App.HttpApi.csproj", "{F74D6B50-EF4D-4521-A7D5-D5CAC6422F24}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App.HttpApi", "NetFramework\App.HttpApi\App.HttpApi.csproj", "{F74D6B50-EF4D-4521-A7D5-D5CAC6422F24}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App.HttpApi.Test", "App.HttpApi.Test\App.HttpApi.Test.csproj", "{1D132C72-95C0-4401-B2E3-19039D6EB0C3}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App.HttpApi.Test", "NetFramework\App.HttpApi.Test\App.HttpApi.Test.csproj", "{1D132C72-95C0-4401-B2E3-19039D6EB0C3}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DD772976-24A5-4C80-BBBD-655F00B8F1C2}"
1111
ProjectSection(SolutionItems) = preProject
@@ -14,6 +14,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
Task.txt = Task.txt
1515
EndProjectSection
1616
EndProject
17+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App.HttpApiCore.Test", "NetCore\App.HttpApiCore.Test\App.HttpApiCore.Test.csproj", "{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}"
18+
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NetFramework", "NetFramework", "{D3444337-92DE-4624-AE0E-E390CB321A0D}"
20+
EndProject
21+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NetCore", "NetCore", "{D575CC06-760E-4440-86CC-70FB5E5B3A45}"
22+
EndProject
23+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App.HttpApiCore", "NetCore\App.HttpApiCore\App.HttpApiCore.csproj", "{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}"
24+
EndProject
1725
Global
1826
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1927
Debug|Any CPU = Debug|Any CPU
@@ -34,10 +42,32 @@ Global
3442
{1D132C72-95C0-4401-B2E3-19039D6EB0C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
3543
{1D132C72-95C0-4401-B2E3-19039D6EB0C3}.Release|Any CPU.Build.0 = Release|Any CPU
3644
{1D132C72-95C0-4401-B2E3-19039D6EB0C3}.Release|x86.ActiveCfg = Release|Any CPU
45+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}.Debug|x86.ActiveCfg = Debug|Any CPU
48+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}.Debug|x86.Build.0 = Debug|Any CPU
49+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
50+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}.Release|Any CPU.Build.0 = Release|Any CPU
51+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}.Release|x86.ActiveCfg = Release|Any CPU
52+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8}.Release|x86.Build.0 = Release|Any CPU
53+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}.Debug|x86.ActiveCfg = Debug|Any CPU
56+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}.Debug|x86.Build.0 = Debug|Any CPU
57+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}.Release|Any CPU.ActiveCfg = Release|Any CPU
58+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}.Release|Any CPU.Build.0 = Release|Any CPU
59+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}.Release|x86.ActiveCfg = Release|Any CPU
60+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E}.Release|x86.Build.0 = Release|Any CPU
3761
EndGlobalSection
3862
GlobalSection(SolutionProperties) = preSolution
3963
HideSolutionNode = FALSE
4064
EndGlobalSection
65+
GlobalSection(NestedProjects) = preSolution
66+
{F74D6B50-EF4D-4521-A7D5-D5CAC6422F24} = {D3444337-92DE-4624-AE0E-E390CB321A0D}
67+
{1D132C72-95C0-4401-B2E3-19039D6EB0C3} = {D3444337-92DE-4624-AE0E-E390CB321A0D}
68+
{255EF00E-BE0B-429D-9D8B-C601E70E4DD8} = {D575CC06-760E-4440-86CC-70FB5E5B3A45}
69+
{DFE7CEFE-C2DA-464E-8EB0-3CC541B6970E} = {D575CC06-760E-4440-86CC-70FB5E5B3A45}
70+
EndGlobalSection
4171
GlobalSection(ExtensibilityGlobals) = postSolution
4272
SolutionGuid = {9415A69D-02F7-4D43-9C3A-9DA3B420B86A}
4373
EndGlobalSection
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Web;
4+
using System.Data;
5+
using System.Drawing;
6+
using App.HttpApi;
7+
using System.ComponentModel;
8+
//using App.Core;
9+
using Newtonsoft.Json;
10+
using System.Xml.Serialization;
11+
//using System.Web.Script.Serialization;
12+
using System.Collections;
13+
14+
namespace App
15+
{
16+
public partial class Demo
17+
{
18+
19+
//---------------------------------------------
20+
// 自定义类
21+
//---------------------------------------------
22+
[HttpApi("Complex type parameter")]
23+
[HttpParam("father", "Father,如:{Name:'Kevin', Birth:'1979-12-01', Sex:0}")]
24+
public Person CreateGirl(Person father)
25+
{
26+
return new Person()
27+
{
28+
Name = father?.Name + "'s dear daughter",
29+
Birth = System.DateTime.Now,
30+
Sex = Sex.Female,
31+
Father = father
32+
};
33+
}
34+
35+
[HttpApi("null值处理")]
36+
public static Person CreateNull()
37+
{
38+
return null;
39+
}
40+
41+
[HttpApi("返回复杂对象")]
42+
public static Person GetPerson()
43+
{
44+
var father = new Person() { Name = "Father" };
45+
var mother = new Person() { Name = "Mother" };
46+
var son = new Person() { Name = "Son", Father = father, Mather=mother};
47+
var grandson = new Person() { Name = "GrandSon", Father = son };
48+
son.Children.Add(grandson);
49+
father.Children.Add(son);
50+
return father;
51+
}
52+
53+
54+
[HttpApi("返回Xml对象", Type = ResponseType.XML)]
55+
public static Person GetPersonXml()
56+
{
57+
return new Person() { Name = "Cherry" };
58+
}
59+
60+
[HttpApi("返回复杂对象,并用APIResult进行封装", Wrap = true)]
61+
public static Person GetPersonData()
62+
{
63+
return new Person() { Name = "Kevin" };
64+
}
65+
66+
[HttpApi("返回APIResult对象")]
67+
public static APIResult GetPersons()
68+
{
69+
var persons = new List<Person>(){
70+
new Person(){ Name="Kevin", Sex=Sex.Male, Birth=new DateTime(2000, 01, 01)},
71+
new Person(){ Name="Cherry", Sex=Sex.Female, Birth=new DateTime(2010, 01, 01)}
72+
};
73+
return new APIResult(true, "", persons);
74+
}
75+
}
76+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Web;
4+
using System.Data;
5+
using System.Drawing;
6+
using App.HttpApi;
7+
using System.ComponentModel;
8+
//using App.Core;
9+
//using Newtonsoft.Json;
10+
//using System.Xml.Serialization;
11+
//using System.Web.Script.Serialization;
12+
using System.Collections;
13+
using App.Web;
14+
15+
namespace App
16+
{
17+
public partial class Demo
18+
{
19+
20+
//---------------------------------------------
21+
// Token 机制
22+
// 1. 获取动态token
23+
// 2. 访问需要健权的接口,带上token参数
24+
// 3. 服务器端统一在 global 里面做token校验
25+
//---------------------------------------------
26+
[HttpApi("获取Token")]
27+
public string GetToken(string appKey, string appSecret)
28+
{
29+
return Token.Create(appKey, appSecret, 1);
30+
}
31+
32+
33+
[HttpApi("NeedTokenApi", AuthToken=true)]
34+
public string GetData()
35+
{
36+
var now = DateTime.Now;
37+
return now.ToString();
38+
}
39+
40+
41+
42+
//---------------------------------------------
43+
// 控制访问权限
44+
//---------------------------------------------
45+
[HttpApi("User login", AuthTraffic=1)]
46+
public string Login(string name, string password)
47+
{
48+
AuthHelper.Login("1", "Admin", "Admins", DateTime.Now.AddDays(1));
49+
System.Threading.Thread.Sleep(200);
50+
return "Login success";
51+
}
52+
53+
[HttpApi("注销")]
54+
public string Logout()
55+
{
56+
AuthHelper.Logout();
57+
System.Threading.Thread.Sleep(200);
58+
return "注销成功";
59+
}
60+
61+
62+
[HttpApi("用户必须登录后才能访问该接口,若无授权则返回401错误", AuthLogin=true)]
63+
public string LimitLogin()
64+
{
65+
System.Threading.Thread.Sleep(200);
66+
return "访问成功(已登录)";
67+
}
68+
69+
[HttpApi("限制用户访问,若无授权则返回401错误", AuthUsers = "Admin,Kevin")]
70+
public string LimitUser()
71+
{
72+
System.Threading.Thread.Sleep(200);
73+
return "访问成功(限制用户Admin,Kevin)";
74+
}
75+
76+
[HttpApi("限制角色访问,若无授权则返回401错误", AuthRoles = "Admins")]
77+
public string LimitRole()
78+
{
79+
System.Threading.Thread.Sleep(200);
80+
return "访问成功(限制角色Admins)";
81+
}
82+
83+
}
84+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Web;
4+
using System.Data;
5+
//using System.Drawing;
6+
using App.HttpApi;
7+
using System.ComponentModel;
8+
//using App.Core;
9+
//using Newtonsoft.Json;
10+
//using System.Xml.Serialization;
11+
//using System.Web.Script.Serialization;
12+
using System.Collections;
13+
using App.Utils;
14+
using System.DrawingCore;
15+
16+
namespace App
17+
{
18+
public partial class Demo
19+
{
20+
//---------------------------------------------
21+
// 返回各种基础对象
22+
//---------------------------------------------
23+
[HttpApi("plist文件下载示例", CacheSeconds = 30, MimeType = "text/plist", FileName = "app.plist")]
24+
public string GetFile(string info)
25+
{
26+
System.Threading.Thread.Sleep(200);
27+
return string.Format("This is plist file demo! {0} {1}", info, DateTime.Now);
28+
}
29+
30+
[HttpApi("输出系统时间", CacheSeconds = 30)]
31+
public DateTime GetTime()
32+
{
33+
return System.DateTime.Now;
34+
}
35+
36+
[HttpApi("输出DataTable")]
37+
public DataTable GetDataTable()
38+
{
39+
DataTable dt = new DataTable("test");
40+
dt.Columns.Add("column1");
41+
dt.Columns.Add("column2");
42+
dt.Rows.Add("a1", "b1");
43+
dt.Rows.Add("a2", "b2");
44+
return dt;
45+
}
46+
47+
[HttpApi("输出DataRow")]
48+
public DataRow GetDataRow()
49+
{
50+
DataTable dt = new DataTable("test");
51+
dt.Columns.Add("column1");
52+
dt.Columns.Add("column2");
53+
dt.Rows.Add("a1", "b1");
54+
dt.Rows.Add("a2", "b2");
55+
return dt.Rows[0];
56+
}
57+
58+
[HttpApi("输出Dictionary")]
59+
public IDictionary GetDictionary()
60+
{
61+
var dict = new Dictionary<int, Person>();
62+
dict.Add(0, new Person() { Name = "Marry" });
63+
dict.Add(1, new Person() { Name = "Cherry" });
64+
return dict;
65+
}
66+
67+
[HttpApi("输出图像", CacheSeconds = 60)]
68+
public Image GetImage(string text)
69+
{
70+
Bitmap bmp = new Bitmap(200, 200);
71+
Graphics g = Graphics.FromImage(bmp);
72+
g.DrawString(
73+
text,
74+
new Font("Arial", 16, FontStyle.Bold),
75+
new SolidBrush(Color.FromArgb(255, 206, 97)),
76+
new PointF(5, 5)
77+
);
78+
return bmp;
79+
}
80+
81+
}
82+
}

0 commit comments

Comments
 (0)