-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathProgram.cs
60 lines (53 loc) · 2.11 KB
/
Program.cs
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
using BeetleX.EventArgs;
using BeetleX.XRPC;
using BeetleX.XRPC.Hosting;
using BeetleX.XRPC.Packets;
using Microsoft.Extensions.Hosting;
using Northwind.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Server
{
class Program
{
private static XRPCServer mXRPCServer;
static void Main(string[] args)
{
var builder = new HostBuilder()
.ConfigureServices((hostContext, services) =>
{
services.UseXRPC(s =>
{
s.ServerOptions.LogLevel = LogType.Warring;
s.RPCOptions.ParameterFormater = new JsonPacket();
}, c =>
{
c.AddDelegate<ListEmployees>(() => Task.FromResult(DataHelper.Defalut.Employees));
c.AddDelegate<ListCustomers>(() => Task.FromResult(DataHelper.Defalut.Customers));
c.AddDelegate<ListOrders>((emp, cust) =>
{
Func<Order, bool> filter = (o) => (emp == 0 || o.EmployeeID == emp) && (String.IsNullOrEmpty(cust) || o.CustomerID == cust);
return Task.FromResult((from a in DataHelper.Defalut.Orders where filter(a) select a).ToList());
});
Task.Run(() => {
while(true)
{
foreach (var item in c.Server.GetOnlines())
{
c.Delegate<Action<DateTime>>(item)(DateTime.Now);
System.Threading.Thread.Sleep(1000);
}
}
});
},
typeof(Program).Assembly);
});
builder.Build().Run();
}
}
public delegate Task<List<Order>> ListOrders(int employee, string employeeid);
public delegate Task<List<Employee>> ListEmployees();
public delegate Task<List<Customer>> ListCustomers();
}