-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathHelloRpcServer.cs
99 lines (87 loc) · 2.65 KB
/
HelloRpcServer.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
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
using Czar.Rpc.Exceptions;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Net;
using Czar.Rpc.Common;
namespace Demo.Rpc.Server
{
public class HelloRpcServer: IHelloRpc
{
public EndPoint CzarEndPoint { get; set; }
public string Hello(int no, string name)
{
string result = $"{no}: Hi, {name}";
Console.WriteLine(result);
return result + " callback";
}
public void HelloHolder(int no, out string name)
{
name = no.ToString() + " out";
}
public async Task HelloOneway(int no, string name)
{
await Task.Delay(10000);
Console.WriteLine($"From oneway - {no}: Hi, {name}");
}
public Task<string> HelloTask(int no, string name)
{
return Task.FromResult(Hello(no, name));
}
public ValueTask<string> HelloValueTask(int no, string name)
{
return new ValueTask<string>(Hello(no, name));
}
public Task TestBusinessExceptionInterceptor()
{
throw new BusinessException()
{
CzarCode = "1",
CzarMessage = "test"
};
}
public DemoModel HelloModel(int D1, string D2, DateTime D3)
{
return new DemoModel()
{
T1 = D1 + 1,
T2 = D2 + "2",
T3 = D3.AddDays(1)
};
}
public async Task<DemoModel> HelloModelAsync(int D1, string D2, DateTime D3)
{
return await Task.FromResult(
new DemoModel()
{
T1 = D1 + 1,
T2 = D2 + "77777",
T3 = D3.AddDays(1)
}
);
}
public DemoModel HelloSendModel(DemoModel model)
{
model.T1 = model.T1 + 10;
model.T2 = model.T2 + "11";
model.T3 = model.T3.AddDays(12);
return model;
}
public DemoModel HelloSendModelParm(string name, DemoModel model)
{
model.T1 = model.T1 + 10;
model.T2 = model.T2 + "11";
model.T3 = model.T3.AddDays(12);
if (model.Child != null)
{
model.Child.C1 = name+"说:"+ model.Child.C1;
}
return model;
}
public List<DemoModel> HelloSendModelList(List<DemoModel> model)
{
return model.Select(t => new DemoModel() { T1=t.T1+10,T2=t.T2+"13",T3=t.T3.AddYears(1),Child=t.Child }).ToList();
}
}
}