This repository was archived by the owner on Feb 16, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathDeleteStreamOperation.cs
More file actions
73 lines (67 loc) · 3.7 KB
/
Copy pathDeleteStreamOperation.cs
File metadata and controls
73 lines (67 loc) · 3.7 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
using System;
using System.Threading.Tasks;
using EventStore.ClientAPI.Exceptions;
using EventStore.ClientAPI.Messages;
using EventStore.ClientAPI.SystemData;
namespace EventStore.ClientAPI.ClientOperations
{
internal class DeleteStreamOperation : OperationBase<DeleteResult, ClientMessage.DeleteStreamCompleted>
{
private readonly bool _requireMaster;
private readonly string _stream;
private readonly long _expectedVersion;
private readonly bool _hardDelete;
public DeleteStreamOperation(ILogger log, TaskCompletionSource<DeleteResult> source,
bool requireMaster, string stream, long expectedVersion, bool hardDelete,
UserCredentials userCredentials)
:base(log, source, TcpCommand.DeleteStream, TcpCommand.DeleteStreamCompleted, userCredentials)
{
_requireMaster = requireMaster;
_stream = stream;
_expectedVersion = expectedVersion;
_hardDelete = hardDelete;
}
protected override object CreateRequestDto()
{
return new ClientMessage.DeleteStream(_stream, _expectedVersion, _requireMaster, _hardDelete);
}
protected override InspectionResult InspectResponse(ClientMessage.DeleteStreamCompleted response)
{
switch (response.Result)
{
case ClientMessage.OperationResult.Success:
Succeed();
return new InspectionResult(InspectionDecision.EndOperation, "Success");
case ClientMessage.OperationResult.PrepareTimeout:
return new InspectionResult(InspectionDecision.Retry, "PrepareTimeout");
case ClientMessage.OperationResult.CommitTimeout:
return new InspectionResult(InspectionDecision.Retry, "CommitTimeout");
case ClientMessage.OperationResult.ForwardTimeout:
return new InspectionResult(InspectionDecision.Retry, "ForwardTimeout");
case ClientMessage.OperationResult.WrongExpectedVersion:
var err = string.Format("Delete stream failed due to WrongExpectedVersion. Stream: {0}, Expected version: {1}.", _stream, _expectedVersion);
Fail(new WrongExpectedVersionException(err));
return new InspectionResult(InspectionDecision.EndOperation, "WrongExpectedVersion");
case ClientMessage.OperationResult.StreamDeleted:
Fail(new StreamDeletedException(_stream));
return new InspectionResult(InspectionDecision.EndOperation, "StreamDeleted");
case ClientMessage.OperationResult.InvalidTransaction:
Fail(new InvalidTransactionException());
return new InspectionResult(InspectionDecision.EndOperation, "InvalidTransaction");
case ClientMessage.OperationResult.AccessDenied:
Fail(new AccessDeniedException(string.Format("Write access denied for stream '{0}'.", _stream)));
return new InspectionResult(InspectionDecision.EndOperation, "AccessDenied");
default:
throw new Exception(string.Format("Unexpected OperationResult: {0}.", response.Result));
}
}
protected override DeleteResult TransformResponse(ClientMessage.DeleteStreamCompleted response)
{
return new DeleteResult(new Position(response.PreparePosition ?? -1, response.CommitPosition ?? -1));
}
public override string ToString()
{
return string.Format("Stream: {0}, ExpectedVersion: {1}.", _stream, _expectedVersion);
}
}
}