-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
CancelAddParticipantOperationResult.cs
119 lines (101 loc) · 5.09 KB
/
CancelAddParticipantOperationResult.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
117
118
119
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Azure.Communication.CallAutomation
{
/// <summary>AddParticipantsResult Result.</summary>
public class CancelAddParticipantOperationResult
{
private CallAutomationEventProcessor _evHandler;
private string _callConnectionId;
private string _operationContext;
internal CancelAddParticipantOperationResult(CancelAddParticipantResponseInternal internalObj)
{
OperationContext = internalObj.OperationContext;
InvitationId = internalObj.InvitationId;
}
internal CancelAddParticipantOperationResult(string invitationId, string operationcontext)
{
InvitationId = invitationId;
OperationContext = operationcontext;
}
/// <summary>The operation context provided by client.</summary>
public string OperationContext { get; }
/// <summary>
/// Invitation ID used to cancel the add participant action.
/// </summary>
public string InvitationId { get; }
internal void SetEventProcessor(CallAutomationEventProcessor evHandler, string callConnectionId, string operationContext)
{
_evHandler = evHandler;
_callConnectionId = callConnectionId;
_operationContext = operationContext;
}
/// <summary>
/// This is blocking call. Wait for <see cref="CancelAddParticipantEventResult"/> using <see cref="CallAutomationEventProcessor"/>.
/// </summary>
/// <param name="cancellationToken">Cancellation Token can be used to set timeout or cancel this WaitForEventProcessor.</param>
/// <returns>Returns <see cref="CancelAddParticipantEventResult"/> which contains either <see cref="CancelAddParticipantSucceeded"/> event or <see cref="CancelAddParticipantFailed"/> event.</returns>
public CancelAddParticipantEventResult WaitForEventProcessor(CancellationToken cancellationToken = default)
{
if (_evHandler is null)
{
throw new NullReferenceException(nameof(_evHandler));
}
var returnedEvent = _evHandler.WaitForEventProcessor(filter
=> filter.CallConnectionId == _callConnectionId
&& (filter.OperationContext == _operationContext || _operationContext is null)
&& (filter.GetType() == typeof(CancelAddParticipantSucceeded)
|| filter.GetType() == typeof(CancelAddParticipantFailed)),
cancellationToken);
return SetReturnedEvent(returnedEvent);
}
/// <summary>
/// Wait for <see cref="CancelAddParticipantEventResult"/> using <see cref="CallAutomationEventProcessor"/>.
/// </summary>
/// <param name="cancellationToken">Cancellation Token can be used to set timeout or cancel this WaitForEventProcessor.</param>
/// <returns>Returns <see cref="CancelAddParticipantEventResult"/> which contains either <see cref="CancelAddParticipantSucceeded"/> event or <see cref="CancelAddParticipantFailed"/> event.</returns>
public async Task<CancelAddParticipantEventResult> WaitForEventProcessorAsync(CancellationToken cancellationToken = default)
{
if (_evHandler is null)
{
throw new NullReferenceException(nameof(_evHandler));
}
var returnedEvent = await _evHandler.WaitForEventProcessorAsync(filter
=> filter.CallConnectionId == _callConnectionId
&& (filter.OperationContext == _operationContext || _operationContext is null)
&& (filter.GetType() == typeof(CancelAddParticipantSucceeded)
|| filter.GetType() == typeof(CancelAddParticipantFailed)),
cancellationToken).ConfigureAwait(false);
return SetReturnedEvent(returnedEvent);
}
private static CancelAddParticipantEventResult SetReturnedEvent(CallAutomationEventBase returnedEvent)
{
switch (returnedEvent)
{
case CancelAddParticipantSucceeded:
{
var successEvent = returnedEvent as CancelAddParticipantSucceeded;
return new CancelAddParticipantEventResult(
true,
successEvent,
null,
successEvent?.InvitationId);
}
case CancelAddParticipantFailed:
{
var failedEvent = returnedEvent as CancelAddParticipantFailed;
return new CancelAddParticipantEventResult(
false,
null,
failedEvent,
failedEvent?.InvitationId);
}
default:
throw new NotSupportedException(returnedEvent.GetType().Name);
}
}
}
}