-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIncoming.cs
116 lines (98 loc) · 3.51 KB
/
Incoming.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// ReSharper disable UnusedVariable
public class Incoming
{
#region ProcessStream
class HandlerProcessStream :
IHandleMessages<MyMessage>
{
public Task Handle(MyMessage message, HandlerContext context)
{
var attachments = context.Attachments();
return attachments.ProcessStream(
name: "attachment1",
action: async(stream, token) =>
{
// Use the attachment stream. in this example copy to a file
await using var fileToCopyTo = File.Create("FilePath.txt");
await stream.CopyToAsync(fileToCopyTo, token);
},
context.CancellationToken);
}
}
#endregion
#region ProcessStreams
class HandlerProcessStreams :
IHandleMessages<MyMessage>
{
public Task Handle(MyMessage message, HandlerContext context)
{
var attachments = context.Attachments();
return attachments.ProcessStreams(
action: async (stream, cancel) =>
{
// Use the attachment stream. in this example copy to a file
await using var file = File.Create($"{stream.Name}.txt");
await stream.CopyToAsync(file, cancel);
},
context.CancellationToken);
}
}
#endregion
#region ProcessStreamsForMessage
class HandlerProcessStreamsForMessage :
IHandleMessages<MyMessage>
{
public Task Handle(MyMessage message, HandlerContext context)
{
var attachments = context.Attachments();
return attachments.ProcessStreamsForMessage(
messageId: "theMessageId",
action: async (stream, cancel) =>
{
// Use the attachment stream. in this example copy to a file
await using var toCopyTo = File.Create($"{stream.Name}.txt");
await stream.CopyToAsync(toCopyTo, cancel);
},
context.CancellationToken);
}
}
#endregion
#region CopyTo
class HandlerCopyTo :
IHandleMessages<MyMessage>
{
public async Task Handle(MyMessage message, HandlerContext context)
{
var attachments = context.Attachments();
await using var fileToCopyTo = File.Create("FilePath.txt");
await attachments.CopyTo("attachment1", fileToCopyTo, context.CancellationToken);
}
}
#endregion
#region GetBytes
class HandlerGetBytes :
IHandleMessages<MyMessage>
{
public async Task Handle(MyMessage message, HandlerContext context)
{
var attachments = context.Attachments();
var bytes = await attachments.GetBytes("attachment1", context.CancellationToken);
// use the byte array
}
}
#endregion
#region GetStream
class HandlerGetStream :
IHandleMessages<MyMessage>
{
public async Task Handle(MyMessage message, HandlerContext context)
{
var attachments = context.Attachments();
await using var stream = await attachments.GetStream("attachment1", context.CancellationToken);
// Use the attachment stream. in this example copy to a file
await using var fileToCopyTo = File.Create("FilePath.txt");
await stream.CopyToAsync(fileToCopyTo, context.CancellationToken);
}
}
#endregion
}