-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathWebExample.cs
48 lines (36 loc) · 1.25 KB
/
WebExample.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
using FolkerKinzel.VCards;
namespace Examples;
public static class WebExample
{
private const string URI =
"https://raw.githubusercontent.com/FolkerKinzel/VCards/master/src/Examples/AnsiFilterExamples/German.vcf";
private static readonly HttpClient _client = new();
public static async Task AsyncExample()
{
using var cts = new CancellationTokenSource();
IReadOnlyList<VCard> vc = await Vcf.DeserializeAsync(t => _client.GetStreamAsync(URI, t),
new AnsiFilter(),
cts.Token);
Console.WriteLine(vc[0]);
}
public static void SynchronousExample()
{
using HttpResponseMessage response =
_client.Send(new HttpRequestMessage(HttpMethod.Get, URI));
IReadOnlyList<VCard> vc = Vcf.Deserialize(() => response.Content.ReadAsStream(),
new AnsiFilter());
Console.WriteLine(vc[0]);
}
}
/*
Console Output:
Version: 2.1
DisplayNames: Sören Täve Nüßlebaum
NameViews:
FamilyNames: Nüßlebaum
GivenNames: Sören
AdditionalNames: Täve
[Label: Mößlitz]
[CharSet: Windows-1252]
Addresses: Locality: Mößlitz
*/