-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathNextActorController.cs
More file actions
142 lines (108 loc) · 3.51 KB
/
NextActorController.cs
File metadata and controls
142 lines (108 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using Microsoft.Extensions.Logging;
using Netx;
using Netx.Actor;
using Netx.Loggine;
using System.Threading.Tasks;
using ZYSQL;
namespace ActorTest
{
/// <summary>
/// 整个Actor 容器为全局唯一
/// </summary>
[ActorOption(maxQueueCount: 1000, ideltime: 3000)] //设置最大列队数1000, 设置多久没有订单后进入休眠状态
public class NextActorController : ActorController
{
public ILog Log { get; }
public NextActorController(ILogger<TestActorController> logger)
{
ZYSQL.SqlInstance.Instance.InstallConfig(new DataConnectConfig[]
{
new DataConnectConfig()
{
Name="DefautConnection",
ConnectionString="Data Source=|DataDirectory|./Test.db3;Pooling=true;FailIfMissing=false",
SqlType="SQLite",
MaxCount=100
}
});
Log = new DefaultLog(logger);
}
public int x { get; private set; }
[TAG(3001)]
public Task<int> GetX()
{
return Task.FromResult(x);
}
[TAG(3002)]
public Task<int> AddX()
{
x++;
return Task.FromResult(x);
}
[TAG(10001)]
public Task<User> GetUser(int Id)
{
using (ZYSQL.SQLiteExecuteXY obj = new SQLiteExecuteXY())
{
return obj.SqlExcuteSelectFirstAsync<User>("SELECT * FROM Users WHERE Id=@Id", new System.Data.SQLite.SQLiteParameter("@Id", Id));
}
}
[TAG(10002)]
public async Task<bool> AddUserCoin(int Id, int coin)
{
var user = await GetUser(Id);
user.Coin += coin;
using (ZYSQL.SQLiteExecuteXY obj = new SQLiteExecuteXY())
{
if (await obj.SqlExcuteUpdateOrInsertOrDeleteObjectAsync("UPDATE Users Set Coin=@Coin WHERE Id=@Id", user) == 1)
return true;
return false;
}
}
[TAG(10003)]
public async Task<bool> SubUserCoin(int Id, int coin)
{
var user = await GetUser(Id);
user.Coin -= coin;
using (ZYSQL.SQLiteExecuteXY obj = new SQLiteExecuteXY())
{
if (await obj.SqlExcuteUpdateOrInsertOrDeleteObjectAsync("UPDATE Users Set Coin=@Coin WHERE Id=@Id", user) == 1)
return true;
return false;
}
}
[TAG(10004)]
public async Task<bool> SetUserCoin(int Id, int coin)
{
var user = await GetUser(Id);
user.Coin = coin;
using (ZYSQL.SQLiteExecuteXY obj = new SQLiteExecuteXY())
{
if (await obj.SqlExcuteUpdateOrInsertOrDeleteObjectAsync("UPDATE Users Set Coin=@Coin WHERE Id=@Id", user) == 1)
return true;
return false;
}
}
[TAG(10005)]
public async Task TestWait()
{
Log.Info("Wait 5s Next...");
await Task.Delay(500);
}
[TAG(10006)]
public void TestWrite(string msg)
{
Log.Info(msg);
}
public override Task Sleeping()
{
Log.Info("Save Data ing..");
return Task.CompletedTask;
}
public override Task Awakening()
{
Log.Info("Read Data ing..");
return Task.CompletedTask;
}
}
}