-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
120 lines (100 loc) · 2.99 KB
/
Program.cs
File metadata and controls
120 lines (100 loc) · 2.99 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
using Greeter.Client.Configuration;
using Greeter.Common;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using static Greeter.Common.Title;
using static System.Console;
using var host = Host.CreateDefaultBuilder(args).Build();
var config = host.Services
.GetRequiredService<IConfiguration>()
.GetRequiredSection("GreeterService")
.Get<GrpcConfiguration>();
var client = new Greeter.Common.Grpc.GreeterServiceGrpcClient(config, false);
WriteLine(client.SayHello("World"));
WriteLine(await client.SayHelloAsync("Async"));
WriteLine();
var person = new Person
{
Name = new()
{
Title = Mr,
FirstName = "Eric",
LastName = "Cartman",
},
OtherNames = new()
{
new(Miss, "Erica", "Cartman"),
new(Miss, "Mitch", "Conner"),
},
Aliases = new[]
{
"The Coon",
"A.W.E.S.O.M.-O 4000",
},
Details = new()
{
DateOfBirth = new(DateTime.Now.Year - 10, 7, 1),
Height = 5.5,
Length = 1.4M,
Addresses = new Address[]
{
new()
{
Street = new[] { "28201 E. Bonanza St." },
City = "South Park",
State = "Colorado",
Country = "USA",
Postcode = 80440
},
},
}
};
var people = person.OtherNames
.Select(otherName => person with { Name = otherName })
.Prepend(person);
void WriteGreeting(Greeting greeting)
{
WriteLine(greeting.Subject);
foreach(var line in greeting.Lines)
{
WriteLine(line);
}
}
var extendedClient = new Greeter.Common.Grpc.GreeterExtendedServiceGrpcClient(config, false);
WriteGreeting(extendedClient.SayGreeting(person));
WriteGreeting(await extendedClient.SayGreetingAsync(person));
var streamedClient = new Greeter.Common.Grpc.GreeterStreamedServiceGrpcClient(config, false);
foreach(var greeting in streamedClient.SayGreetings(people))
{
WriteGreeting(greeting);
}
await foreach(var greeting in streamedClient.SayGreetingsAsync(people))
{
WriteGreeting(greeting);
}
foreach(var line in streamedClient.StreamGreeting(person))
{
WriteLine(line);
}
await foreach(var line in streamedClient.StreamGreetingAsync(person))
{
WriteLine(line);
}
foreach(var line in streamedClient.StreamGreetings(people, new[] { "---" }))
{
WriteLine(line);
}
await foreach(var line in streamedClient.StreamGreetingsAsync(people, new[] { "---", "---", "---" }))
{
WriteLine(line);
}
foreach(var line in streamedClient.StreamGreetingsEx(people.Select((p, i) => (p, new[] { $"-{i}-" }))))
{
WriteLine(line);
}
await foreach(var line in streamedClient.StreamGreetingsExAsync(people.Select(p => (p, new[] { "---", $"{DateTime.Now.Millisecond}", "---" }))))
{
await Task.Delay(TimeSpan.FromMilliseconds(1));
WriteLine(line);
}