This repository was archived by the owner on Feb 16, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathDeletePersistentSubscriptionOperation.cs
More file actions
63 lines (56 loc) · 3.26 KB
/
Copy pathDeletePersistentSubscriptionOperation.cs
File metadata and controls
63 lines (56 loc) · 3.26 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
using System;
using System.Threading.Tasks;
using EventStore.ClientAPI.Exceptions;
using EventStore.ClientAPI.Internal;
using EventStore.ClientAPI.Messages;
using EventStore.ClientAPI.SystemData;
namespace EventStore.ClientAPI.ClientOperations
{
internal class DeletePersistentSubscriptionOperation : OperationBase<PersistentSubscriptionDeleteResult, ClientMessage.DeletePersistentSubscriptionCompleted>
{
private readonly string _stream;
private readonly string _groupName;
public DeletePersistentSubscriptionOperation(ILogger log,
TaskCompletionSource<PersistentSubscriptionDeleteResult> source,
string stream,
string groupName,
UserCredentials userCredentials)
: base(log, source, TcpCommand.DeletePersistentSubscription, TcpCommand.DeletePersistentSubscriptionCompleted, userCredentials)
{
_stream = stream;
_groupName = groupName;
}
protected override object CreateRequestDto()
{
return new ClientMessage.DeletePersistentSubscription(_groupName, _stream);
}
protected override InspectionResult InspectResponse(ClientMessage.DeletePersistentSubscriptionCompleted response)
{
switch (response.Result)
{
case ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.Success:
Succeed();
return new InspectionResult(InspectionDecision.EndOperation, "Success");
case ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.Fail:
Fail(new InvalidOperationException(String.Format("Subscription group {0} on stream {1} failed '{2}'", _groupName, _stream, response.Reason)));
return new InspectionResult(InspectionDecision.EndOperation, "Fail");
case ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.AccessDenied:
Fail(new AccessDeniedException(string.Format("Write access denied for stream '{0}'.", _stream)));
return new InspectionResult(InspectionDecision.EndOperation, "AccessDenied");
case ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.DoesNotExist:
Fail(new InvalidOperationException(String.Format("Subscription group {0} on stream {1} does not exist", _groupName, _stream)));
return new InspectionResult(InspectionDecision.EndOperation, "AlreadyExists");
default:
throw new Exception(string.Format("Unexpected OperationResult: {0}.", response.Result));
}
}
protected override PersistentSubscriptionDeleteResult TransformResponse(ClientMessage.DeletePersistentSubscriptionCompleted response)
{
return new PersistentSubscriptionDeleteResult(PersistentSubscriptionDeleteStatus.Success);
}
public override string ToString()
{
return string.Format("Stream: {0}, Group Name: {1}", _stream, _groupName);
}
}
}