Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'dev' of github.com:/EventStore/EventStore into dev

  • Loading branch information...
commit 944a58d2ef8db64fdaaf5a3b8608548f7bf36455 2 parents 1c20f62 + 5913029
@MarkiyanMatsekh MarkiyanMatsekh authored
Showing with 808 additions and 592 deletions.
  1. +1 −1  src/EventStore/EventStore.ClientAPI/ClientOperations/AppendToStreamOperation.cs
  2. +4 −1 src/EventStore/EventStore.ClientAPI/ClientOperations/CreateStreamOperation.cs
  3. +1 −1  src/EventStore/EventStore.ClientAPI/ClientOperations/TransactionalWriteOperation.cs
  4. +4 −4 src/EventStore/EventStore.ClientAPI/EventStoreConnection.cs
  5. +1 −0  src/EventStore/EventStore.ClientAPI/IEvent.cs
  6. +13 −5 src/EventStore/EventStore.ClientAPI/Messages/ClientMessage.cs
  7. +13 −13 src/EventStore/EventStore.Core.Tests/ClientAPI/AllEvents/read_all_events_backward_should.cs
  8. +16 −16 src/EventStore/EventStore.Core.Tests/ClientAPI/AllEvents/read_all_events_forward_should.cs
  9. +3 −3 src/EventStore/EventStore.Core.Tests/ClientAPI/AllEvents/subscribe_to_all_should.cs
  10. +1 −1  src/EventStore/EventStore.Core.Tests/ClientAPI/MiniNode.cs
  11. +3 −0  src/EventStore/EventStore.Core.Tests/ClientAPI/TestEvent.cs
  12. +7 −7 src/EventStore/EventStore.Core.Tests/ClientAPI/append_to_stream.cs
  13. +6 −6 src/EventStore/EventStore.Core.Tests/ClientAPI/creating_stream.cs
  14. +4 −4 src/EventStore/EventStore.Core.Tests/ClientAPI/deleting_stream.cs
  15. +8 −8 src/EventStore/EventStore.Core.Tests/ClientAPI/read_event_stream_backward_should.cs
  16. +9 −9 src/EventStore/EventStore.Core.Tests/ClientAPI/read_event_stream_forward_should.cs
  17. +5 −5 src/EventStore/EventStore.Core.Tests/ClientAPI/subscribe_should.cs
  18. +4 −4 src/EventStore/EventStore.Core.Tests/ClientAPI/transaction.cs
  19. +1 −1  src/EventStore/EventStore.Core.Tests/Services/Replication/CreateStream/when_create_stream_accepts_request.cs
  20. +1 −1  ...tStore/EventStore.Core.Tests/Services/Replication/CreateStream/when_create_stream_completes_successfully.cs
  21. +1 −1  ...tStore/EventStore.Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_already_committed.cs
  22. +1 −1  ....Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_commit_timeout_before_commit_stage.cs
  23. +1 −1  ....Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_commit_timeout_before_final_commit.cs
  24. +1 −1  ...tore.Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_prepare_timeout_after_prepares.cs
  25. +1 −1  ...ore.Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_prepare_timeout_before_prepares.cs
  26. +1 −1  ...ventStore/EventStore.Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_stream_deleted.cs
  27. +1 −1  src/EventStore/EventStore.Core.Tests/Services/Replication/RequestManagerSpecification.cs
  28. +2 −0  src/EventStore/EventStore.Core.Tests/Services/Transport/Http/auto_convertion.cs
  29. +1 −0  src/EventStore/EventStore.Core.Tests/Services/Transport/Http/ping_controller_should.cs
  30. +7 −1 src/EventStore/EventStore.Core/EventStore.Core.csproj
  31. +3 −1 src/EventStore/EventStore.Core/Messages/ClientMessage.cs
  32. +3 −0  src/EventStore/EventStore.Core/Messages/StorageMessage.cs
  33. +13 −4 src/EventStore/EventStore.Core/Messages/TcpClientMessageDto.cs
  34. +1 −1  src/EventStore/EventStore.Core/Services/RequestManager/Managers/CreateStreamTwoPhaseRequestManager.cs
  35. +54 −49 src/EventStore/EventStore.Core/Services/Transport/Http/AutoEventConverter.cs
  36. +0 −376 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs.cs
  37. +49 −0 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/Codec.cs
  38. +54 −0 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/CustomCodec.cs
  39. +72 −0 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/JsonCodec.cs
  40. +30 −0 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/ManualEncoding.cs
  41. +30 −0 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/NoCodec.cs
  42. +33 −0 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/TextCodec.cs
  43. +83 −0 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/XmlCodec.cs
  44. +1 −0  src/EventStore/EventStore.Core/Services/Transport/Http/Controllers/AdminController.cs
  45. +2 −1  src/EventStore/EventStore.Core/Services/Transport/Http/Controllers/AtomControllerDefinitions.cs
  46. +1 −0  src/EventStore/EventStore.Core/Services/Transport/Http/Controllers/PingController.cs
  47. +1 −0  src/EventStore/EventStore.Core/Services/Transport/Http/Controllers/ReadEventDataController.cs
  48. +1 −0  src/EventStore/EventStore.Core/Services/Transport/Http/Controllers/StatController.cs
  49. +1 −0  src/EventStore/EventStore.Core/Services/Transport/Http/Controllers/WebSiteController.cs
  50. +1 −0  src/EventStore/EventStore.Core/Services/Transport/Http/HttpService.cs
  51. +6 −6 src/EventStore/EventStore.Core/Services/Transport/Tcp/ClientTcpDispatcher.cs
  52. +21 −20 src/EventStore/EventStore.Core/Services/VNode/SingleVNodeController.cs
  53. +1 −0  src/EventStore/EventStore.Core/Util/MiniWeb.cs
  54. +1 −0  src/EventStore/EventStore.Projections.Core/Services/Http/ProjectionsController.cs
  55. +1 −0  src/EventStore/EventStore.TestClient/Client.cs
  56. +2 −1  src/EventStore/EventStore.TestClient/Commands/CreateStreamProcessor.cs
  57. +2 −1  src/EventStore/EventStore.TestClient/Commands/DvuBasic/BankAccountBasicProducer.cs
  58. +1 −0  src/EventStore/EventStore.TestClient/Commands/MultiWriteFloodWaiting.cs
  59. +1 −0  src/EventStore/EventStore.TestClient/Commands/MultiWriteProcessor.cs
  60. +2 −3 src/EventStore/EventStore.TestClient/Commands/ReadHttpProcessor.cs
  61. +5 −0 src/EventStore/EventStore.TestClient/Commands/RunTestScenarios/BankAccountEvent.cs
  62. +1 −0  src/EventStore/EventStore.TestClient/Commands/RunTestScenarios/ProjectionsKillScenario.cs
  63. +3 −3 src/EventStore/EventStore.TestClient/Commands/RunTestScenarios/ScenarioBase.cs
  64. +3 −0  src/EventStore/EventStore.TestClient/Commands/RunTestScenarios/TestEvent.cs
  65. +1 −0  src/EventStore/EventStore.TestClient/Commands/TransactionWriteProcessor.cs
  66. +1 −0  src/EventStore/EventStore.TestClient/Commands/WriteFloodHttpProcessor.cs
  67. +1 −0  src/EventStore/EventStore.TestClient/Commands/WriteFloodProcessor.cs
  68. +1 −0  src/EventStore/EventStore.TestClient/Commands/WriteFloodWaitingHttpProcessor.cs
  69. +1 −0  src/EventStore/EventStore.TestClient/Commands/WriteFloodWaitingProcessor.cs
  70. +1 −0  src/EventStore/EventStore.TestClient/Commands/WriteHttpProcessor.cs
  71. +149 −0 src/EventStore/EventStore.TestClient/Commands/WriteJsonProcessor.cs
  72. +1 −0  src/EventStore/EventStore.TestClient/Commands/WriteLongTermHttpProcessor.cs
  73. +1 −0  src/EventStore/EventStore.TestClient/Commands/WriteLongTermProcessor.cs
  74. +1 −0  src/EventStore/EventStore.TestClient/Commands/WriteProcessor.cs
  75. +1 −0  src/EventStore/EventStore.TestClient/EventStore.TestClient.csproj
  76. +1 −1  src/EventStore/EventStore.TestClient/MessageUtil.cs
  77. +1 −0  src/EventStore/EventStore.Transport.Http/ContentType.cs
  78. +1 −1  src/EventStore/EventStore.Transport.Http/EntityManagement/HttpEntity.cs
  79. +34 −21 src/EventStore/EventStore.Transport.Http/EntityManagement/HttpEntityManager.cs
  80. +3 −3 src/EventStore/EventStore.Transport.Http/EntityManagement/ManagerOperationState.cs
  81. +4 −2 src/EventStore/Protos/ClientAPI/ClientMessageDtos.proto
View
2  src/EventStore/EventStore.ClientAPI/ClientOperations/AppendToStreamOperation.cs
@@ -87,7 +87,7 @@ public TcpPackage CreateNetworkPackage()
{
lock (_corrIdLock)
{
- var dtos = _events.Select(x => new ClientMessage.ClientEvent(x.EventId.ToByteArray(), x.Type, x.Data, x.Metadata)).ToArray();
+ var dtos = _events.Select(x => new ClientMessage.ClientEvent(x.EventId.ToByteArray(), x.Type, x.IsJson, x.Data, x.Metadata)).ToArray();
var write = new ClientMessage.WriteEvents(_stream, _expectedVersion, dtos, _forward);
return new TcpPackage(TcpCommand.WriteEvents, _correlationId, write.Serialize());
}
View
5 src/EventStore/EventStore.ClientAPI/ClientOperations/CreateStreamOperation.cs
@@ -47,6 +47,7 @@ internal class CreateStreamOperation : IClientOperation
private readonly bool _forward;
private readonly string _stream;
+ private readonly bool _isJson;
private readonly byte[] _metadata;
public Guid CorrelationId
@@ -62,6 +63,7 @@ public Guid CorrelationId
Guid correlationId,
bool forward,
string stream,
+ bool isJson,
byte[] metadata)
{
_source = source;
@@ -69,6 +71,7 @@ public Guid CorrelationId
_correlationId = correlationId;
_forward = forward;
_stream = stream;
+ _isJson = isJson;
_metadata = metadata;
}
@@ -82,7 +85,7 @@ public TcpPackage CreateNetworkPackage()
{
lock (_corrIdLock)
{
- var dto = new ClientMessage.CreateStream(_stream, _metadata, _forward);
+ var dto = new ClientMessage.CreateStream(_stream, _metadata, _forward, _isJson);
return new TcpPackage(TcpCommand.CreateStream, _correlationId, dto.Serialize());
}
}
View
2  src/EventStore/EventStore.ClientAPI/ClientOperations/TransactionalWriteOperation.cs
@@ -87,7 +87,7 @@ public TcpPackage CreateNetworkPackage()
{
lock (_corrIdLock)
{
- var dtos = _events.Select(x => new ClientMessage.ClientEvent(x.EventId.ToByteArray(), x.Type, x.Data, x.Metadata)).ToArray();
+ var dtos = _events.Select(x => new ClientMessage.ClientEvent(x.EventId.ToByteArray(), x.Type, x.IsJson, x.Data, x.Metadata)).ToArray();
var write = new ClientMessage.TransactionWrite(_transactionId, _stream, dtos, _forward);
return new TcpPackage(TcpCommand.TransactionWrite, _corrId, write.Serialize());
}
View
8 src/EventStore/EventStore.ClientAPI/EventStoreConnection.cs
@@ -230,22 +230,22 @@ void IDisposable.Dispose()
Close();
}
- public void CreateStream(string stream, byte[] metadata)
+ public void CreateStream(string stream, bool isJson, byte[] metadata)
{
Ensure.NotNullOrEmpty(stream, "stream");
EnsureActive();
- var task = CreateStreamAsync(stream, metadata);
+ var task = CreateStreamAsync(stream, isJson, metadata);
task.Wait();
}
- public Task CreateStreamAsync(string stream, byte[] metadata)
+ public Task CreateStreamAsync(string stream, bool isJson, byte[] metadata)
{
Ensure.NotNullOrEmpty(stream, "stream");
EnsureActive();
var source = new TaskCompletionSource<object>();
- var operation = new CreateStreamOperation(source, Guid.NewGuid(), _allowForwarding, stream, metadata);
+ var operation = new CreateStreamOperation(source, Guid.NewGuid(), _allowForwarding, stream, isJson, metadata);
EnqueueOperation(operation);
return source.Task;
View
1  src/EventStore/EventStore.ClientAPI/IEvent.cs
@@ -33,6 +33,7 @@ public interface IEvent
{
Guid EventId { get; }
string Type { get; }
+ bool IsJson { get; }
byte[] Data { get; }
byte[] Metadata { get; }
View
18 src/EventStore/EventStore.ClientAPI/Messages/ClientMessage.cs
@@ -44,18 +44,22 @@ public partial class ClientEvent
[ProtoMember(2, IsRequired = false, Name=@"event_type", DataFormat = DataFormat.Default)]
public readonly string EventType;
- [ProtoMember(3, IsRequired = true, Name=@"data", DataFormat = DataFormat.Default)]
+ [ProtoMember(3, IsRequired = true, Name=@"is_json", DataFormat = DataFormat.Default)]
+ public readonly bool IsJson;
+
+ [ProtoMember(4, IsRequired = true, Name=@"data", DataFormat = DataFormat.Default)]
public readonly byte[] Data;
- [ProtoMember(4, IsRequired = false, Name=@"metadata", DataFormat = DataFormat.Default)]
+ [ProtoMember(5, IsRequired = false, Name=@"metadata", DataFormat = DataFormat.Default)]
public readonly byte[] Metadata;
private ClientEvent() {}
- public ClientEvent(byte[] eventId, string eventType, byte[] data, byte[] metadata)
+ public ClientEvent(byte[] eventId, string eventType, bool isJson, byte[] data, byte[] metadata)
{
EventId = eventId;
EventType = eventType;
+ IsJson = isJson;
Data = data;
Metadata = metadata;
}
@@ -132,14 +136,18 @@ public partial class CreateStream
[ProtoMember(3, IsRequired = true, Name=@"allow_forwarding", DataFormat = DataFormat.Default)]
public readonly bool AllowForwarding;
+
+ [ProtoMember(4, IsRequired = true, Name = @"is_json", DataFormat = DataFormat.Default)]
+ public readonly bool IsJson;
private CreateStream() {}
-
- public CreateStream(string eventStreamId, byte[] metadata, bool allowForwarding)
+
+ public CreateStream(string eventStreamId, byte[] metadata, bool allowForwarding, bool isJson)
{
EventStreamId = eventStreamId;
Metadata = metadata;
AllowForwarding = allowForwarding;
+ IsJson = isJson;
}
}
View
26 src/EventStore/EventStore.Core.Tests/ClientAPI/AllEvents/read_all_events_backward_should.cs
@@ -40,7 +40,7 @@ internal class read_all_events_backward_should
[SetUp]
public void SetUp()
{
- Node = MiniNode.Create(8111, 9111);
+ Node = MiniNode.Create(40111, 40112);
Node.Start();
}
@@ -57,7 +57,7 @@ public void return_empty_slice_if_asked_to_read_from_start()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var read = store.ReadAllEventsBackwardAsync(Position.Start, 1);
@@ -94,7 +94,7 @@ public void return_partial_slice_if_not_enough_events()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 20).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -118,7 +118,7 @@ public void return_events_in_reversed_order_compared_to_written()
store.Connect(Node.TcpEndPoint);
var testEvents = Enumerable.Range(0, 5).Select(x => new TestEvent((x + 1).ToString())).ToArray();
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var write = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, testEvents);
@@ -138,10 +138,10 @@ public void read_stream_created_events_as_well()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create1 = store.CreateStreamAsync(stream + 1, new byte[0]);
+ var create1 = store.CreateStreamAsync(stream + 1, false, new byte[0]);
Assert.DoesNotThrow(create1.Wait);
- var create2 = store.CreateStreamAsync(stream + 2, new byte[0]);
+ var create2 = store.CreateStreamAsync(stream + 2, false, new byte[0]);
Assert.DoesNotThrow(create2.Wait);
var read = store.ReadAllEventsBackwardAsync(Position.End, 2);
@@ -159,7 +159,7 @@ public void be_able_to_read_all_one_by_one_and_return_empty_slice_at_last()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 5).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -188,7 +188,7 @@ public void be_able_to_read_events_slice_at_time()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -217,10 +217,10 @@ public void not_return_events_from_deleted_streams()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create1 = store.CreateStreamAsync(stream + 1, new byte[0]);
+ var create1 = store.CreateStreamAsync(stream + 1, false, new byte[0]);
Assert.DoesNotThrow(create1.Wait);
- var create2 = store.CreateStreamAsync(stream + 2, new byte[0]);
+ var create2 = store.CreateStreamAsync(stream + 2, false, new byte[0]);
Assert.DoesNotThrow(create2.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -256,10 +256,10 @@ public void not_return_stream_deleted_records()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create1 = store.CreateStreamAsync(stream + 1, new byte[0]);
+ var create1 = store.CreateStreamAsync(stream + 1, false, new byte[0]);
Assert.DoesNotThrow(create1.Wait);
- var create2 = store.CreateStreamAsync(stream + 2, new byte[0]);
+ var create2 = store.CreateStreamAsync(stream + 2, false, new byte[0]);
Assert.DoesNotThrow(create2.Wait);
var delete1 = store.DeleteStreamAsync(stream + 1, ExpectedVersion.EmptyStream);
@@ -280,7 +280,7 @@ public void return_no_records_if_stream_created_than_deleted()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
View
32 src/EventStore/EventStore.Core.Tests/ClientAPI/AllEvents/read_all_events_forward_should.cs
@@ -43,7 +43,7 @@ internal class read_all_events_forward_should
[SetUp]
public void SetUp()
{
- Node = MiniNode.Create(8111, 9111);
+ Node = MiniNode.Create(40111, 40112);
Node.Start();
}
@@ -60,7 +60,7 @@ public void return_empty_slice_if_asked_to_read_from_end()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 5).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -104,13 +104,13 @@ public void return_events_in_same_order_as_written()
store.Connect(Node.TcpEndPoint);
var testEvents = Enumerable.Range(0, 5).Select(x => new TestEvent((x + 1).ToString())).ToArray();
- var create1 = store.CreateStreamAsync(stream + 1, new byte[0]);
+ var create1 = store.CreateStreamAsync(stream + 1, false, new byte[0]);
Assert.DoesNotThrow(create1.Wait);
var write5to1 = store.AppendToStreamAsync(stream + 1, ExpectedVersion.EmptyStream, testEvents);
Assert.DoesNotThrow(write5to1.Wait);
- var create2 = store.CreateStreamAsync(stream + 2, new byte[0]);
+ var create2 = store.CreateStreamAsync(stream + 2, false, new byte[0]);
Assert.DoesNotThrow(create2.Wait);
var write5to2 = store.AppendToStreamAsync(stream + 2, ExpectedVersion.EmptyStream, testEvents);
@@ -131,10 +131,10 @@ public void read_stream_created_events_as_well()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create1 = store.CreateStreamAsync(stream + 1, new byte[0]);
+ var create1 = store.CreateStreamAsync(stream + 1, false, new byte[0]);
Assert.DoesNotThrow(create1.Wait);
- var create2 = store.CreateStreamAsync(stream + 2, new byte[0]);
+ var create2 = store.CreateStreamAsync(stream + 2, false, new byte[0]);
Assert.DoesNotThrow(create2.Wait);
var read = store.ReadAllEventsForwardAsync(Position.Start, 2);
@@ -152,7 +152,7 @@ public void be_able_to_read_all_one_by_one_and_return_empty_slice_at_last()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 5).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -181,7 +181,7 @@ public void be_able_to_read_events_slice_at_time()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 20).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -210,7 +210,7 @@ public void return_partial_slice_if_not_enough_events()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 20).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -232,10 +232,10 @@ public void not_return_events_from_deleted_streams()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create1 = store.CreateStreamAsync(stream + 1, new byte[0]);
+ var create1 = store.CreateStreamAsync(stream + 1, false, new byte[0]);
Assert.DoesNotThrow(create1.Wait);
- var create2 = store.CreateStreamAsync(stream + 2, new byte[0]);
+ var create2 = store.CreateStreamAsync(stream + 2, false, new byte[0]);
Assert.DoesNotThrow(create2.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -271,10 +271,10 @@ public void not_return_stream_deleted_records()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create1 = store.CreateStreamAsync(stream + 1, new byte[0]);
+ var create1 = store.CreateStreamAsync(stream + 1, false, new byte[0]);
Assert.DoesNotThrow(create1.Wait);
- var create2 = store.CreateStreamAsync(stream + 2, new byte[0]);
+ var create2 = store.CreateStreamAsync(stream + 2, false, new byte[0]);
Assert.DoesNotThrow(create2.Wait);
var delete1 = store.DeleteStreamAsync(stream + 1, ExpectedVersion.EmptyStream);
@@ -295,10 +295,10 @@ public void return_no_records_if_stream_created_than_deleted()
using (var store = EventStoreConnection.Create())
{
store.Connect(Node.TcpEndPoint);
- var create1 = store.CreateStreamAsync(stream + 1, new byte[0]);
+ var create1 = store.CreateStreamAsync(stream + 1, false, new byte[0]);
Assert.DoesNotThrow(create1.Wait);
- var create2 = store.CreateStreamAsync(stream + 2, new byte[0]);
+ var create2 = store.CreateStreamAsync(stream + 2, false, new byte[0]);
Assert.DoesNotThrow(create2.Wait);
var delete1 = store.DeleteStreamAsync(stream + 1, ExpectedVersion.EmptyStream);
@@ -326,7 +326,7 @@ public void recover_from_dropped_subscription_state_using_last_known_position()
Position lastKnonwPosition = null;
var dropped = new AutoResetEvent(false);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
store.SubscribeAsync(stream,
View
6 src/EventStore/EventStore.Core.Tests/ClientAPI/AllEvents/subscribe_to_all_should.cs
@@ -41,7 +41,7 @@ internal class subscribe_to_all_should
[SetUp]
public void SetUp()
{
- Node = MiniNode.Create(8111, 9111);
+ Node = MiniNode.Create(40111, 40112);
Node.Start();
}
@@ -67,7 +67,7 @@ public void allow_multiple_subscriptions()
store.SubscribeToAllStreamsAsync(eventAppeared, subscriptionDropped);
store.SubscribeToAllStreamsAsync(eventAppeared, subscriptionDropped);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.That(create.Wait(Timeout));
Assert.That(appeared.Wait(Timeout));
@@ -109,7 +109,7 @@ public void catch_created_and_deleted_events_as_well()
store.SubscribeToAllStreamsAsync(eventAppeared, subscriptionDropped);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.That(create.Wait(Timeout));
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
Assert.That(delete.Wait(Timeout));
View
2  src/EventStore/EventStore.Core.Tests/ClientAPI/MiniNode.cs
@@ -77,7 +77,7 @@ public static MiniNode Create(int externalTcpPort, int externalHttpPort)
return new MiniNode(externalTcpPort, externalHttpPort);
}
- private MiniNode(int externalTcpPort = 4222, int externalHttpPort = 5222)
+ private MiniNode(int externalTcpPort = 41111, int externalHttpPort = 41112)
{
_oneTimeDbPath = Path.Combine(Path.GetTempPath(), string.Format("mini-node-one-time-db-{0}-{1}", externalTcpPort, externalHttpPort));
TryDeleteDirectory(_oneTimeDbPath);
View
3  src/EventStore/EventStore.Core.Tests/ClientAPI/TestEvent.cs
@@ -36,6 +36,8 @@ internal class TestEvent : IEvent
public Guid EventId { get; private set; }
public string Type { get; private set; }
+ public bool IsJson { get; private set; }
+
public byte[] Data { get; private set; }
public byte[] Metadata { get; private set; }
@@ -44,6 +46,7 @@ public TestEvent(string data = null, string metadata = null)
EventId = Guid.NewGuid();
Type = GetType().FullName;
+ IsJson = false;
Data = Encoding.UTF8.GetBytes(data ?? EventId.ToString());
Metadata = Encoding.UTF8.GetBytes(metadata ?? "metadata");
}
View
14 src/EventStore/EventStore.Core.Tests/ClientAPI/append_to_stream.cs
@@ -91,7 +91,7 @@ public void should_fail_writing_with_correct_exp_ver_to_deleted_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
@@ -110,7 +110,7 @@ public void should_fail_writing_with_any_exp_ver_to_deleted_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
@@ -129,7 +129,7 @@ public void should_fail_writing_with_invalid_exp_ver_to_deleted_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
@@ -148,7 +148,7 @@ public void should_append_with_correct_exp_ver_to_existing_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var append = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, new[] { new TestEvent() });
@@ -164,7 +164,7 @@ public void should_append_with_any_exp_ver_to_existing_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var append = store.AppendToStreamAsync(stream, ExpectedVersion.Any, new[] { new TestEvent() });
@@ -180,7 +180,7 @@ public void should_fail_appending_with_wrong_exp_ver_to_existing_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var append = store.AppendToStreamAsync(stream, 1, new[] { new TestEvent() });
@@ -196,7 +196,7 @@ public void can_append_multiple_events_at_once()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var events = Enumerable.Range(0, 100).Select(i => new TestEvent(i.ToString(), i.ToString()));
View
12 src/EventStore/EventStore.Core.Tests/ClientAPI/creating_stream.cs
@@ -43,7 +43,7 @@ public void which_does_not_exist_should_be_successfull()
using (var connection = EventStoreConnection.Create())
{
connection.Connect(MiniNode.Instance.TcpEndPoint);
- var create = connection.CreateStreamAsync(stream, new byte[0]);
+ var create = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
}
}
@@ -56,7 +56,7 @@ public void which_supposed_to_be_system_should_succees__but_on_your_own_risk()
using (var connection = EventStoreConnection.Create())
{
connection.Connect(MiniNode.Instance.TcpEndPoint);
- var create = connection.CreateStreamAsync(stream, new byte[0]);
+ var create = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
}
}
@@ -69,10 +69,10 @@ public void which_already_exists_should_fail()
using (var connection = EventStoreConnection.Create())
{
connection.Connect(MiniNode.Instance.TcpEndPoint);
- var initialCreate = connection.CreateStreamAsync(stream, new byte[0]);
+ var initialCreate = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(initialCreate.Wait);
- var secondCreate = connection.CreateStreamAsync(stream, new byte[0]);
+ var secondCreate = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.Inconclusive();
//Assert.That(() => secondCreate.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<WrongExpectedVersionException>());
}
@@ -86,13 +86,13 @@ public void which_was_deleted_should_fail()
using (var connection = EventStoreConnection.Create())
{
connection.Connect(MiniNode.Instance.TcpEndPoint);
- var create = connection.CreateStreamAsync(stream, new byte[0]);
+ var create = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
Assert.DoesNotThrow(delete.Wait);
- var secondCreate = connection.CreateStreamAsync(stream, new byte[0]);
+ var secondCreate = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.That(() => secondCreate.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDeletedException>());
}
}
View
8 src/EventStore/EventStore.Core.Tests/ClientAPI/deleting_stream.cs
@@ -43,7 +43,7 @@ public void which_already_exists_should_success_when_passed_empty_stream_expecte
using (var connection = EventStoreConnection.Create())
{
connection.Connect(MiniNode.Instance.TcpEndPoint);
- var create = connection.CreateStreamAsync(stream, new byte[0]);
+ var create = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
@@ -59,7 +59,7 @@ public void which_already_exists_should_success_when_passed_any_for_expected_ver
using (var connection = EventStoreConnection.Create())
{
connection.Connect(MiniNode.Instance.TcpEndPoint);
- var create = connection.CreateStreamAsync(stream, new byte[0]);
+ var create = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.Any);
@@ -75,7 +75,7 @@ public void with_invalid_expected_version_should_fail()
using (var connection = EventStoreConnection.Create())
{
connection.Connect(MiniNode.Instance.TcpEndPoint);
- var create = connection.CreateStreamAsync(stream, new byte[0]);
+ var create = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = connection.DeleteStreamAsync(stream, 1);
@@ -105,7 +105,7 @@ public void which_was_allready_deleted_should_fail()
using (var connection = EventStoreConnection.Create())
{
connection.Connect(MiniNode.Instance.TcpEndPoint);
- var create = connection.CreateStreamAsync(stream, new byte[0]);
+ var create = connection.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
View
16 src/EventStore/EventStore.Core.Tests/ClientAPI/read_event_stream_backward_should.cs
@@ -71,7 +71,7 @@ public void notify_using_status_code_if_stream_was_deleted()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
Assert.DoesNotThrow(delete.Wait);
@@ -91,7 +91,7 @@ public void return_single_event_when_called_on_empty_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var read = store.ReadEventStreamBackwardAsync(stream, StreamPosition.End, 1);
@@ -109,7 +109,7 @@ public void return_partial_slice_if_no_enough_events_in_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -131,7 +131,7 @@ public void return_events_reversed_compared_to_written()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -153,7 +153,7 @@ public void be_able_to_read_single_event_from_arbitrary_position()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -175,7 +175,7 @@ public void be_able_to_read_first_event()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -197,7 +197,7 @@ public void be_able_to_read_last_event()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -219,7 +219,7 @@ public void be_able_to_read_slice_from_arbitrary_position()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
View
18 src/EventStore/EventStore.Core.Tests/ClientAPI/read_event_stream_forward_should.cs
@@ -81,7 +81,7 @@ public void notify_using_status_code_if_stream_was_deleted()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
Assert.DoesNotThrow(delete.Wait);
@@ -101,7 +101,7 @@ public void return_single_event_when_called_on_empty_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var read = store.ReadEventStreamForwardAsync(stream, 0, 1);
@@ -119,7 +119,7 @@ public void return_empty_slice_when_called_on_empty_stream_starting_at_position_
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var read = store.ReadEventStreamForwardAsync(stream, 1, 1);
@@ -137,7 +137,7 @@ public void return_empty_slice_when_called_on_non_existing_range()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var write10 = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())));
@@ -158,7 +158,7 @@ public void return_partial_slice_if_no_enough_events_in_stream()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var write10 = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())));
@@ -179,7 +179,7 @@ public void return_partial_slice_when_got_int_max_value_as_maxcount()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var write10 = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())));
@@ -200,7 +200,7 @@ public void return_events_in_same_order_as_written()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -222,7 +222,7 @@ public void be_able_to_read_single_event_from_arbitrary_position()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
@@ -244,7 +244,7 @@ public void be_able_to_read_slice_from_arbitrary_position()
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.DoesNotThrow(create.Wait);
var testEvents = Enumerable.Range(0, 10).Select(x => new TestEvent((x + 1).ToString())).ToArray();
View
10 src/EventStore/EventStore.Core.Tests/ClientAPI/subscribe_should.cs
@@ -52,7 +52,7 @@ public void be_able_to_subscribe_to_non_existing_stream_and_then_catch_created_e
store.SubscribeAsync(stream, eventAppeared, subscriptionDropped);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.That(create.Wait(Timeout));
Assert.That(appeared.Wait(Timeout));
@@ -75,7 +75,7 @@ public void allow_multiple_subscriptions_to_same_stream()
store.SubscribeAsync(stream, eventAppeared, subscriptionDropped);
store.SubscribeAsync(stream, eventAppeared, subscriptionDropped);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.That(create.Wait(Timeout));
Assert.That(appeared.Wait(Timeout));
@@ -116,7 +116,7 @@ public void subscribe_to_deleted_stream_as_well_but_never_invoke_user_callbacks(
Action<RecordedEvent, Position> eventAppeared = (x, p) => appeared.Signal();
Action subscriptionDropped = () => dropped.Signal();
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.That(create.Wait(Timeout));
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
Assert.That(delete.Wait(Timeout));
@@ -140,7 +140,7 @@ public void not_call_dropped_if_stream_was_deleted()
Action<RecordedEvent, Position> eventAppeared = (x, p) => appeared.Signal();
Action subscriptionDropped = () => dropped.Signal();
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.That(create.Wait(Timeout));
var subscribe = store.SubscribeAsync(stream, eventAppeared, subscriptionDropped);
@@ -170,7 +170,7 @@ public void catch_created_and_deleted_events_as_well()
store.SubscribeAsync(stream, eventAppeared, subscriptionDropped);
- var create = store.CreateStreamAsync(stream, new byte[0]);
+ var create = store.CreateStreamAsync(stream, false, new byte[0]);
Assert.That(create.Wait(Timeout));
var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
Assert.That(delete.Wait(Timeout));
View
8 src/EventStore/EventStore.Core.Tests/ClientAPI/transaction.cs
@@ -144,7 +144,7 @@ public void should_commit_when_writing_with_exp_ver_any_even_while_somene_is_wri
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- store.CreateStream(stream, new byte[0]);
+ store.CreateStream(stream, false, new byte[0]);
}
//500 events during transaction
@@ -218,7 +218,7 @@ public void should_fail_to_commit_if_started_with_correct_ver_but_committing_wit
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- store.CreateStream(stream, new byte[0]);
+ store.CreateStream(stream, false, new byte[0]);
}
using (var store = EventStoreConnection.Create())
@@ -246,7 +246,7 @@ public void should_not_fail_to_commit_if_started_with_wrong_ver_but_committing_w
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- store.CreateStream(stream, new byte[0]);
+ store.CreateStream(stream, false, new byte[0]);
}
using (var store = EventStoreConnection.Create())
@@ -274,7 +274,7 @@ public void should_fail_to_commit_if_started_with_correct_ver_but_on_commit_stre
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
- store.CreateStream(stream, new byte[0]);
+ store.CreateStream(stream, false, new byte[0]);
}
using (var store = EventStoreConnection.Create())
View
2  ...EventStore/EventStore.Core.Tests/Services/Replication/CreateStream/when_create_stream_accepts_request.cs
@@ -50,7 +50,7 @@ protected override IEnumerable<Message> WithInitialMessages()
protected override Message When()
{
- return new StorageMessage.CreateStreamRequestCreated(CorrelationId, new NoopEnvelope(), "test123", Metadata);
+ return new StorageMessage.CreateStreamRequestCreated(CorrelationId, new NoopEnvelope(), "test123", false, Metadata);
}
[Test]
View
2  ...ore/EventStore.Core.Tests/Services/Replication/CreateStream/when_create_stream_completes_successfully.cs
@@ -46,7 +46,7 @@ protected override TwoPhaseRequestManagerBase OnManager(FakePublisher publisher)
protected override IEnumerable<Message> WithInitialMessages()
{
- yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", Metadata);
+ yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", false, Metadata);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
View
2  ...ore/EventStore.Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_already_committed.cs
@@ -45,7 +45,7 @@ protected override TwoPhaseRequestManagerBase OnManager(FakePublisher publisher)
protected override IEnumerable<Message> WithInitialMessages()
{
- yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", Metadata);
+ yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", false, Metadata);
}
protected override Message When()
View
2  ...re.Tests/Services/Replication/CreateStream/when_create_stream_gets_commit_timeout_before_commit_stage.cs
@@ -45,7 +45,7 @@ protected override TwoPhaseRequestManagerBase OnManager(FakePublisher publisher)
protected override IEnumerable<Message> WithInitialMessages()
{
- yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", Metadata);
+ yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", false, Metadata);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
}
View
2  ...re.Tests/Services/Replication/CreateStream/when_create_stream_gets_commit_timeout_before_final_commit.cs
@@ -46,7 +46,7 @@ protected override TwoPhaseRequestManagerBase OnManager(FakePublisher publisher)
protected override IEnumerable<Message> WithInitialMessages()
{
- yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", Metadata);
+ yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", false, Metadata);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
View
2  ...e.Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_prepare_timeout_after_prepares.cs
@@ -45,7 +45,7 @@ protected override TwoPhaseRequestManagerBase OnManager(FakePublisher publisher)
protected override IEnumerable<Message> WithInitialMessages()
{
- yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", Metadata);
+ yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", false, Metadata);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
yield return new StorageMessage.PrepareAck(CorrelationId, 1, PrepareFlags.SingleWrite);
View
2  ....Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_prepare_timeout_before_prepares.cs
@@ -45,7 +45,7 @@ protected override TwoPhaseRequestManagerBase OnManager(FakePublisher publisher)
protected override IEnumerable<Message> WithInitialMessages()
{
- yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", Metadata);
+ yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", false, Metadata);
}
protected override Message When()
View
2  ...tStore/EventStore.Core.Tests/Services/Replication/CreateStream/when_create_stream_gets_stream_deleted.cs
@@ -45,7 +45,7 @@ protected override TwoPhaseRequestManagerBase OnManager(FakePublisher publisher)
protected override IEnumerable<Message> WithInitialMessages()
{
- yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", Metadata);
+ yield return new StorageMessage.CreateStreamRequestCreated(CorrelationId, Envelope, "test123", false, Metadata);
}
protected override Message When()
View
2  src/EventStore/EventStore.Core.Tests/Services/Replication/RequestManagerSpecification.cs
@@ -52,7 +52,7 @@ public abstract class RequestManagerSpecification
protected Event DummyEvent()
{
- return new Event(Guid.NewGuid(), "test", true, EventData, Metadata);
+ return new Event(Guid.NewGuid(), "test", false, EventData, Metadata);
}
[SetUp]
View
2  src/EventStore/EventStore.Core.Tests/Services/Transport/Http/auto_convertion.cs
@@ -1,9 +1,11 @@
using System;
+using System.Collections.Generic;
using System.Text;
using EventStore.Core.Data;
using EventStore.Core.Messages;
using EventStore.Core.Services.Storage.ReaderIndex;
using EventStore.Core.Services.Transport.Http;
+using EventStore.Core.Services.Transport.Http.Codecs;
using EventStore.Core.TransactionLog.LogRecords;
using NUnit.Framework;
using System.Linq;
View
1  src/EventStore/EventStore.Core.Tests/Services/Transport/Http/ping_controller_should.cs
@@ -31,6 +31,7 @@
using EventStore.Common.Utils;
using EventStore.Core.Messages;
using EventStore.Core.Services.Transport.Http;
+using EventStore.Core.Services.Transport.Http.Codecs;
using EventStore.Transport.Http;
using NUnit.Framework;
View
8 src/EventStore/EventStore.Core/EventStore.Core.csproj
@@ -144,6 +144,12 @@
<Compile Include="Services\Storage\StorageScavenger.cs" />
<Compile Include="Services\SystemNames.cs" />
<Compile Include="Services\RequestManager\Managers\TransactionCommitTwoPhaseRequestManager.cs" />
+ <Compile Include="Services\Transport\Http\Codecs\CustomCodec.cs" />
+ <Compile Include="Services\Transport\Http\Codecs\JsonCodec.cs" />
+ <Compile Include="Services\Transport\Http\Codecs\ManualEncoding.cs" />
+ <Compile Include="Services\Transport\Http\Codecs\NoCodec.cs" />
+ <Compile Include="Services\Transport\Http\Codecs\TextCodec.cs" />
+ <Compile Include="Services\Transport\Http\Codecs\XmlCodec.cs" />
<Compile Include="Services\Transport\Http\Controllers\WebSiteController.cs" />
<Compile Include="Services\RequestManager\Managers\TwoPhaseRequestManagerBase.cs" />
<Compile Include="Services\RequestManager\Managers\WriteStreamTwoPhaseRequestManager.cs" />
@@ -209,7 +215,7 @@
<Compile Include="Services\Storage\ReaderIndex\ReadIndexStats.cs" />
<Compile Include="Services\Storage\StorageChaser.cs" />
<Compile Include="Services\Storage\StorageReader.cs" />
- <Compile Include="Services\Transport\Http\Codecs.cs" />
+ <Compile Include="Services\Transport\Http\Codecs\Codec.cs" />
<Compile Include="Services\Transport\Http\ControllerAction.cs" />
<Compile Include="Services\Transport\Http\Controllers\AdminController.cs" />
<Compile Include="Services\Transport\Http\Controllers\CommunicationController.cs" />
View
4 src/EventStore/EventStore.Core/Messages/ClientMessage.cs
@@ -103,9 +103,10 @@ public class CreateStream: WriteRequestMessage
public readonly bool AllowForwarding;
public readonly string EventStreamId;
+ public readonly bool IsJson;
public readonly byte[] Metadata;
- public CreateStream(Guid correlationId, IEnvelope envelope, bool allowForwarding, string eventStreamId, byte[] metadata)
+ public CreateStream(Guid correlationId, IEnvelope envelope, bool allowForwarding, string eventStreamId, bool isJson, byte[] metadata)
{
Ensure.NotNull(envelope, "envelope");
Ensure.NotNull(eventStreamId, "eventStreamId");
@@ -114,6 +115,7 @@ public CreateStream(Guid correlationId, IEnvelope envelope, bool allowForwarding
Envelope = envelope;
AllowForwarding = allowForwarding;
EventStreamId = eventStreamId;
+ IsJson = isJson;
Metadata = metadata;
}
}
View
3  src/EventStore/EventStore.Core/Messages/StorageMessage.cs
@@ -261,11 +261,13 @@ public class CreateStreamRequestCreated : Message
public readonly Guid CorrelationId;
public readonly IEnvelope Envelope;
public readonly string EventStreamId;
+ public readonly bool IsJson;
public readonly byte[] Metadata;
public CreateStreamRequestCreated(Guid correlationId,
IEnvelope envelope,
string eventStreamId,
+ bool isJson,
byte[] metadata)
{
Ensure.NotEmptyGuid(correlationId, "correlationId");
@@ -276,6 +278,7 @@ public class CreateStreamRequestCreated : Message
CorrelationId = correlationId;
Envelope = envelope;
EventStreamId = eventStreamId;
+ IsJson = isJson;
Metadata = metadata;
}
}
View
17 src/EventStore/EventStore.Core/Messages/TcpClientMessageDto.cs
@@ -44,18 +44,22 @@ public partial class ClientEvent
[ProtoMember(2, IsRequired = false, Name=@"event_type", DataFormat = DataFormat.Default)]
public readonly string EventType;
- [ProtoMember(3, IsRequired = true, Name=@"data", DataFormat = DataFormat.Default)]
+ [ProtoMember(3, IsRequired = true, Name=@"is_json", DataFormat = DataFormat.Default)]
+ public readonly bool IsJson;
+
+ [ProtoMember(4, IsRequired = true, Name=@"data", DataFormat = DataFormat.Default)]
public readonly byte[] Data;
- [ProtoMember(4, IsRequired = false, Name=@"metadata", DataFormat = DataFormat.Default)]
+ [ProtoMember(5, IsRequired = false, Name=@"metadata", DataFormat = DataFormat.Default)]
public readonly byte[] Metadata;
private ClientEvent() {}
- public ClientEvent(byte[] eventId, string eventType, byte[] data, byte[] metadata)
+ public ClientEvent(byte[] eventId, string eventType, bool isJson, byte[] data, byte[] metadata)
{
EventId = eventId;
EventType = eventType;
+ IsJson = isJson;
Data = data;
Metadata = metadata;
}
@@ -132,14 +136,19 @@ public partial class CreateStream
[ProtoMember(3, IsRequired = true, Name=@"allow_forwarding", DataFormat = DataFormat.Default)]
public readonly bool AllowForwarding;
+
+ [ProtoMember(4, IsRequired = true, Name = @"is_json", DataFormat = DataFormat.Default)]
+ public readonly bool IsJson;
+
private CreateStream() {}
- public CreateStream(string eventStreamId, byte[] metadata, bool allowForwarding)
+ public CreateStream(string eventStreamId, byte[] metadata, bool allowForwarding, bool isJson)
{
EventStreamId = eventStreamId;
Metadata = metadata;
AllowForwarding = allowForwarding;
+ IsJson = isJson;
}
}
View
2  src/EventStore/EventStore.Core/Services/RequestManager/Managers/CreateStreamTwoPhaseRequestManager.cs
@@ -56,7 +56,7 @@ public void Handle(StorageMessage.CreateStreamRequestCreated request)
_publishEnvelope,
request.EventStreamId,
ExpectedVersion.NoStream,
- new[] { new Event(Guid.NewGuid(), "StreamCreated", true, LogRecord.NoData, request.Metadata) },
+ new[] { new Event(Guid.NewGuid(), "StreamCreated", request.IsJson, LogRecord.NoData, request.Metadata) },
allowImplicitStreamCreation: false,
liveUntil: DateTime.UtcNow + Timeouts.PrepareWriteMessageTimeout));
Publisher.Publish(TimerMessage.Schedule.Create(Timeouts.PrepareTimeout,
View
103 src/EventStore/EventStore.Core/Services/Transport/Http/AutoEventConverter.cs
@@ -27,13 +27,14 @@
//
using System;
-using System.Collections.Generic;
using System.IO;
using System.Text;
+using System.Xml;
using System.Xml.Linq;
using EventStore.Common.Log;
using EventStore.Core.Data;
using EventStore.Core.Messages;
+using EventStore.Core.Services.Transport.Http.Codecs;
using EventStore.Core.TransactionLog.LogRecords;
using EventStore.Transport.Http;
using Newtonsoft.Json;
@@ -47,16 +48,6 @@ public static class AutoEventConverter
{
private static readonly ILogger Log = LogManager.GetLogger("AutoEventConverter");
- public static Tuple<int, Event[]> SmartParse(string request, ICodec sourceCodec)
- {
- var write = Load(request, sourceCodec);
- if (write == null || write.Events == null || write.Events.Length == 0)
- return new Tuple<int, Event[]>(-1, null);
-
- var events = Parse(write.Events);
- return new Tuple<int, Event[]>(write.ExpectedVersion, events);
- }
-
public static string SmartFormat(ClientMessage.ReadEventCompleted completed, ICodec targetCodec)
{
var dto = new HttpClientMessageDto.ReadEventCompletedText(completed);
@@ -71,26 +62,48 @@ public static string SmartFormat(ClientMessage.ReadEventCompleted completed, ICo
dto.Metadata = deserializedMetadata;
}
- if (new[] { ContentType.Xml, "application/xml", ContentType.Atom }.Contains(targetCodec.ContentType))
+ switch (targetCodec.ContentType)
{
- var serializeObject = JsonConvert.SerializeObject(dto);
- var deserializeXmlNode = JsonConvert.DeserializeXmlNode(serializeObject, "read-event-result");
- return deserializeXmlNode.InnerXml;
+ case ContentType.Xml:
+ case ContentType.ApplicationXml:
+ case ContentType.Atom:
+ {
+ var serializeObject = JsonConvert.SerializeObject(dto);
+ var deserializeXmlNode = JsonConvert.DeserializeXmlNode(serializeObject, "read-event-result");
+ return deserializeXmlNode.InnerXml;
+ }
+
+ default:
+ return targetCodec.To(dto);
}
+ }
- return targetCodec.To(dto);
+ public static Tuple<int, Event[]> SmartParse(string request, ICodec sourceCodec)
+ {
+ var write = Load(request, sourceCodec);
+ if (write == null || write.Events == null || write.Events.Length == 0)
+ return new Tuple<int, Event[]>(-1, null);
+
+ var events = Parse(write.Events);
+ return new Tuple<int, Event[]>(write.ExpectedVersion, events);
}
- private static HttpClientMessageDto.WriteEventsDynamic Load(string s, ICodec sourceCodec)
+ private static HttpClientMessageDto.WriteEventsDynamic Load(string data, ICodec sourceCodec)
{
- var requestType = sourceCodec.ContentType;
+ switch(sourceCodec.ContentType)
+ {
+ case ContentType.Json:
+ case ContentType.AtomJson:
+ return LoadFromJson(data);
- if (new[] {ContentType.Json, ContentType.AtomJson}.Contains(requestType))
- return LoadFromJson(s);
- if (new[] {ContentType.Xml, "application/xml", ContentType.Atom}.Contains(requestType))
- return LoadFromXml(s);
+ case ContentType.Xml:
+ case ContentType.ApplicationXml:
+ case ContentType.Atom:
+ return LoadFromXml(data);
- return null;
+ default:
+ return null;
+ }
}
private static HttpClientMessageDto.WriteEventsDynamic LoadFromJson(string json)
@@ -102,14 +115,12 @@ private static HttpClientMessageDto.WriteEventsDynamic LoadFromXml(string xml)
{
try
{
- XDocument doc;
- using(var reader = new StringReader(xml))
- doc = XDocument.Load(reader);
+ XDocument doc = XDocument.Parse(xml);
- XNamespace jsonNs = "http://james.newtonking.com/projects/json";
- XName jsonName = XNamespace.Xmlns + "json";
+ XNamespace jsonNsValue = "http://james.newtonking.com/projects/json";
+ XName jsonNsName = XNamespace.Xmlns + "json";
- doc.Root.SetAttributeValue(jsonName, jsonNs);
+ doc.Root.SetAttributeValue(jsonNsName, jsonNsValue);
var expectedVersion = doc.Root.Element("ExpectedVersion");
var events = doc.Root.Descendants("event").ToArray();
@@ -117,16 +128,19 @@ private static HttpClientMessageDto.WriteEventsDynamic LoadFromXml(string xml)
foreach (var @event in events)
{
@event.Name = "Events";
- @event.SetAttributeValue(jsonNs + "Array", "true");
+ @event.SetAttributeValue(jsonNsValue + "Array", "true");
}
doc.Root.ReplaceNodes(events);
foreach (var element in doc.Root.Descendants("Data").Concat(doc.Root.Descendants("Metadata")))
+ {
element.RemoveAttributes();
+ }
var json = JsonConvert.SerializeXNode(doc, Formatting.None, false);
- var dynamicEvents = JsonConvert.DeserializeObject<JObject>(json)["write-events"]["Events"].ToObject<HttpClientMessageDto.ClientEventDynamic[]>();
+ var root = JsonConvert.DeserializeObject<JObject>(json);
+ var dynamicEvents = root["write-events"]["Events"].ToObject<HttpClientMessageDto.ClientEventDynamic[]>();
return new HttpClientMessageDto.WriteEventsDynamic(int.Parse(expectedVersion.Value), dynamicEvents.ToArray());
}
catch (Exception e)
@@ -138,39 +152,30 @@ private static HttpClientMessageDto.WriteEventsDynamic LoadFromXml(string xml)
private static Event[] Parse(HttpClientMessageDto.ClientEventDynamic[] dynamicEvents)
{
- var events = new List<Event>(dynamicEvents.Length);
- foreach (var textEvent in dynamicEvents)
+ var events = new Event[dynamicEvents.Length];
+ for (int i = 0, n = dynamicEvents.Length; i < n; ++i)
{
+ var textEvent = dynamicEvents[i];
bool dataIsJson;
bool metadataIsJson;
var data = AsBytes(textEvent.Data, out dataIsJson);
var metadata = AsBytes(textEvent.Metadata, out metadataIsJson);
- events.Add(new Event(textEvent.EventId, textEvent.EventType, dataIsJson || metadataIsJson, data, metadata));
+ events[i] = new Event(textEvent.EventId, textEvent.EventType, dataIsJson || metadataIsJson, data, metadata);
}
return events.ToArray();
}
private static byte[] AsBytes(object obj, out bool isJson)
{
- isJson = true;
- if (IsJObject(obj))
+ if (obj is JObject)
+ {
+ isJson = true;
return Encoding.UTF8.GetBytes(Codec.Json.To(obj));
+ }
isJson = false;
- return Encoding.UTF8.GetBytes(AsString(obj));
- }
-
- private static string AsString(object obj)
- {
- if(obj == null)
- return string.Empty;
- return (obj as string) ?? string.Empty;
- }
-
- private static bool IsJObject(object obj)
- {
- return obj is JObject;
+ return Encoding.UTF8.GetBytes((obj as string) ?? string.Empty);
}
}
}
View
376 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs.cs
@@ -1,376 +0,0 @@
-// Copyright (c) 2012, Event Store LLP
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-// Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-// Neither the name of the Event Store LLP nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-using System;
-using System.IO;
-using System.Text;
-using System.Xml;
-using System.Xml.Serialization;
-using EventStore.Common.Log;
-using EventStore.Common.Utils;
-using EventStore.Transport.Http;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Converters;
-using Newtonsoft.Json.Serialization;
-using Formatting = Newtonsoft.Json.Formatting;
-
-namespace EventStore.Core.Services.Transport.Http
-{
- public static class Codec
- {
- public static readonly NoCodec NoCodec = new NoCodec();
- public static readonly ICodec[] NoCodecs = new ICodec[0];
- public static readonly ManualEncoding ManualEncoding = new ManualEncoding();
-
- public static readonly JsonCodec Json = new JsonCodec();
- public static readonly XmlCodec Xml = new XmlCodec();
- public static readonly CustomCodec ApplicationXml = new CustomCodec(Xml, "application/xml");
- public static readonly TextCodec Text = new TextCodec();
-
- public static ICodec CreateCustom(ICodec codec, string contentType)
- {
- return new CustomCodec(codec, contentType);
- }
- }
-
- public class NoCodec : ICodec
- {
- public string ContentType
- {
- get
- {
- throw new NotSupportedException();
- }
- }
-
- public bool CanParse(string format)
- {
- return false;
- }
-
- public bool SuitableForReponse(AcceptComponent component)
- {
- return false;
- }
-
- public T From<T>(string text)
- {
- throw new NotSupportedException();
- }
-
- public string To<T>(T value)
- {
- throw new NotSupportedException();
- }
- }
-
- public class ManualEncoding : ICodec
- {
- public string ContentType
- {
- get
- {
- throw new InvalidOperationException();
- }
- }
-
- public bool CanParse(string format)
- {
- return true;
- }
-
- public bool SuitableForReponse(AcceptComponent component)
- {
- return true;
- }
-
- public T From<T>(string text)
- {
- throw new InvalidOperationException();
- }
-
- public string To<T>(T value)
- {
- throw new InvalidOperationException();
- }
- }
-
- public class CustomCodec : ICodec
- {
- public ICodec BaseCodec
- {
- get
- {
- return _codec;
- }
- }
-
- private readonly ICodec _codec;
- private readonly string _contentType;
- private readonly string _type;
- private readonly string _subtype;
-
- internal CustomCodec(ICodec codec, string contentType)
- {
- Ensure.NotNull(codec, "codec");
- Ensure.NotNull(contentType, "contentType");
-
- _codec = codec;
- _contentType = contentType;
- var parts = contentType.Split(new[] {'/'}, 2);
- if (parts.Length != 2)
- throw new ArgumentException("contentType");
- _type = parts[0];
- _subtype = parts[1];
- }
-
- public string ContentType
- {
- get
- {
- return _contentType;
- }
- }
-
- public bool CanParse(string format)
- {
- return string.Equals(format, _contentType, StringComparison.OrdinalIgnoreCase);
- }
-
- public bool SuitableForReponse(AcceptComponent component)
- {
- return component.MediaType == "*"
- || (string.Equals(component.MediaType, _type)
- && (component.MediaSubtype == "*"
- || string.Equals(component.MediaSubtype, _subtype, StringComparison.OrdinalIgnoreCase)));
- }
-
- public T From<T>(string text)
- {
- return _codec.From<T>(text);
- }
-
- public string To<T>(T value)
- {
- return _codec.To(value);
- }
- }
-
- public class JsonCodec : ICodec
- {
- private static readonly ILogger Log = LogManager.GetLoggerFor<JsonCodec>();
-
- private static readonly JsonSerializerSettings JsonSettings = new JsonSerializerSettings
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- DateFormatHandling = DateFormatHandling.IsoDateFormat,
- NullValueHandling = NullValueHandling.Ignore,
- DefaultValueHandling = DefaultValueHandling.Ignore,
- MissingMemberHandling = MissingMemberHandling.Ignore,
- TypeNameHandling = TypeNameHandling.None,
- Converters = new JsonConverter[]
- {
- new StringEnumConverter()
- }
- };
-
- public static Formatting Formatting = Formatting.Indented;
-
- public string ContentType
- {
- get
- {
- return EventStore.Transport.Http.ContentType.Json;
- }
- }
-
- public bool CanParse(string format)
- {
- return string.Equals(ContentType, format, StringComparison.OrdinalIgnoreCase);
- }
-
- public bool SuitableForReponse(AcceptComponent component)
- {
- return component.MediaType == "*"
- || (string.Equals(component.MediaType, "application")
- && (component.MediaSubtype == "*"
- || string.Equals(component.MediaSubtype, "json", StringComparison.OrdinalIgnoreCase)));
- }
-
- public T From<T>(string text)
- {
- try
- {
- return JsonConvert.DeserializeObject<T>(text, JsonSettings);
- }
- catch (Exception e)
- {
- Log.ErrorException(e, "'{0}' is not a valid serialized {1}", text, typeof(T).FullName);
- return default(T);
- }
- }
-
- public string To<T>(T value)
- {
- try
- {
- return JsonConvert.SerializeObject(value, Formatting, JsonSettings);
- }
- catch (Exception ex)
- {
- Log.ErrorException(ex, "Error serializing object {0}", value);
- return null;
- }
- }
- }
-
- public class XmlCodec : ICodec
- {
- private static readonly ILogger Log = LogManager.GetLoggerFor<XmlCodec>();
-
- public string ContentType
- {
- get
- {
- return EventStore.Transport.Http.ContentType.Xml;
- }
- }
-
- public bool CanParse(string format)
- {
- return string.Equals(ContentType, format, StringComparison.OrdinalIgnoreCase);
- }
-
- public bool SuitableForReponse(AcceptComponent component)
- {
- return component.MediaType == "*"
- || (string.Equals(component.MediaType, "text")
- && (component.MediaSubtype == "*"
- || string.Equals(component.MediaSubtype, "xml", StringComparison.OrdinalIgnoreCase)));
- }
-
- public T From<T>(string text)
- {
- if (string.IsNullOrEmpty(text))
- return default(T);
-
- try
- {
- using (var reader = new StringReader(text))
- return (T) new XmlSerializer(typeof (T)).Deserialize(reader);
- }
- catch (Exception e)
- {
- Log.ErrorException(e, "'{0}' is not a valid serialized {1}", text, typeof(T).FullName);
- return default(T);
- }
- }
-
- public string To<T>(T value)
- {
- if ((object)value == null)
- return null;
-
- var serializable = value as IXmlSerializable;
- if (serializable != null)
- return ToSerializable(serializable);
-
- try
- {
- using (var memory = new MemoryStream())
- {
- new XmlSerializer(typeof (T)).Serialize(memory, value);
- memory.Flush();
- memory.Seek(0L, SeekOrigin.Begin);
- return Encoding.UTF8.GetString(memory.GetBuffer(), 0, (int)memory.Length);
- }
- }
- catch (Exception ex)
- {
- Log.ErrorException(ex, "Error serializing object {0}", value);
- return null;
- }
- }
-
- private string ToSerializable(IXmlSerializable serializable)
- {
- try
- {
- using (var memory = new MemoryStream())
- using (var writer = XmlWriter.Create(memory))
- {
- writer.WriteStartDocument();
- serializable.WriteXml(writer);
- writer.WriteEndDocument();
- writer.Flush();
-
- memory.Seek(0L, SeekOrigin.Begin);
- return Encoding.UTF8.GetString(memory.GetBuffer(), 0, (int)memory.Length);
- }
- }
- catch (Exception e)
- {
- Log.ErrorException(e, "Error serializing object of type {0}", serializable.GetType().FullName);
- return null;
- }
- }
- }
-
- public class TextCodec : ICodec
- {
- public string ContentType
- {
- get
- {
- return EventStore.Transport.Http.ContentType.PlainText;
- }
- }
-
- public bool CanParse(string format)
- {
- return string.Equals(ContentType, format, StringComparison.OrdinalIgnoreCase);
- }
-
- public bool SuitableForReponse(AcceptComponent component)
- {
- return component.MediaType == "*"
- || (string.Equals(component.MediaType, "text")
- && (component.MediaSubtype == "*"
- || string.Equals(component.MediaSubtype, "plain", StringComparison.OrdinalIgnoreCase)));
- }
-
- public T From<T>(string text)
- {
- throw new NotSupportedException();
- }
-
- public string To<T>(T value)
- {
- return ((object) value) != null ? value.ToString() : null;
- }
- }
-}
View
49 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/Codec.cs
@@ -0,0 +1,49 @@
+// Copyright (c) 2012, Event Store LLP
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Event Store LLP nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+using EventStore.Transport.Http;
+
+namespace EventStore.Core.Services.Transport.Http.Codecs
+{
+ public static class Codec
+ {
+ public static readonly NoCodec NoCodec = new NoCodec();
+ public static readonly ICodec[] NoCodecs = new ICodec[0];
+ public static readonly ManualEncoding ManualEncoding = new ManualEncoding();
+
+ public static readonly JsonCodec Json = new JsonCodec();
+ public static readonly XmlCodec Xml = new XmlCodec();
+ public static readonly CustomCodec ApplicationXml = new CustomCodec(Xml, ContentType.ApplicationXml);
+ public static readonly TextCodec Text = new TextCodec();
+
+ public static ICodec CreateCustom(ICodec codec, string contentType)
+ {
+ return new CustomCodec(codec, contentType);
+ }
+ }
+}
View
54 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/CustomCodec.cs
@@ -0,0 +1,54 @@
+using System;
+using EventStore.Common.Utils;
+using EventStore.Transport.Http;
+
+namespace EventStore.Core.Services.Transport.Http.Codecs
+{
+ public class CustomCodec : ICodec
+ {
+ public ICodec BaseCodec { get { return _codec; } }
+ public string ContentType { get { return _contentType; } }
+
+ private readonly ICodec _codec;
+ private readonly string _contentType;
+ private readonly string _type;
+ private readonly string _subtype;
+
+ internal CustomCodec(ICodec codec, string contentType)
+ {
+ Ensure.NotNull(codec, "codec");
+ Ensure.NotNull(contentType, "contentType");
+
+ _codec = codec;
+ _contentType = contentType;
+ var parts = contentType.Split(new[] {'/'}, 2);
+ if (parts.Length != 2)
+ throw new ArgumentException("contentType");
+ _type = parts[0];
+ _subtype = parts[1];
+ }
+
+ public bool CanParse(string format)
+ {
+ return string.Equals(format, _contentType, StringComparison.OrdinalIgnoreCase);
+ }
+
+ public bool SuitableForReponse(AcceptComponent component)
+ {
+ return component.MediaType == "*"
+ || (string.Equals(component.MediaType, _type, StringComparison.OrdinalIgnoreCase)
+ && (component.MediaSubtype == "*"
+ || string.Equals(component.MediaSubtype, _subtype, StringComparison.OrdinalIgnoreCase)));
+ }
+
+ public T From<T>(string text)
+ {
+ return _codec.From<T>(text);
+ }
+
+ public string To<T>(T value)
+ {
+ return _codec.To(value);
+ }
+ }
+}
View
72 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/JsonCodec.cs
@@ -0,0 +1,72 @@
+using System;
+using EventStore.Common.Log;
+using EventStore.Transport.Http;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
+using Newtonsoft.Json.Serialization;
+
+namespace EventStore.Core.Services.Transport.Http.Codecs
+{
+ public class JsonCodec : ICodec
+ {
+ public static Formatting Formatting = Formatting.Indented;
+
+ private static readonly ILogger Log = LogManager.GetLoggerFor<JsonCodec>();
+
+ private static readonly JsonSerializerSettings JsonSettings = new JsonSerializerSettings
+ {
+ ContractResolver = new CamelCasePropertyNamesContractResolver(),
+ DateFormatHandling = DateFormatHandling.IsoDateFormat,
+ NullValueHandling = NullValueHandling.Ignore,
+ DefaultValueHandling = DefaultValueHandling.Ignore,
+ MissingMemberHandling = MissingMemberHandling.Ignore,
+ TypeNameHandling = TypeNameHandling.None,
+ Converters = new JsonConverter[]
+ {
+ new StringEnumConverter()
+ }
+ };
+
+
+ public string ContentType { get { return EventStore.Transport.Http.ContentType.Json; } }
+
+ public bool CanParse(string format)
+ {
+ return string.Equals(ContentType, format, StringComparison.OrdinalIgnoreCase);
+ }
+
+ public bool SuitableForReponse(AcceptComponent component)
+ {
+ return component.MediaType == "*"
+ || (string.Equals(component.MediaType, "application", StringComparison.OrdinalIgnoreCase)
+ && (component.MediaSubtype == "*"
+ || string.Equals(component.MediaSubtype, "json", StringComparison.OrdinalIgnoreCase)));
+ }
+
+ public T From<T>(string text)
+ {
+ try
+ {
+ return JsonConvert.DeserializeObject<T>(text, JsonSettings);
+ }
+ catch (Exception e)
+ {
+ Log.ErrorException(e, "'{0}' is not a valid serialized {1}", text, typeof(T).FullName);
+ return default(T);
+ }
+ }
+
+ public string To<T>(T value)
+ {
+ try
+ {
+ return JsonConvert.SerializeObject(value, Formatting, JsonSettings);
+ }
+ catch (Exception ex)
+ {
+ Log.ErrorException(ex, "Error serializing object {0}", value);
+ return null;
+ }
+ }
+ }
+}
View
30 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/ManualEncoding.cs
@@ -0,0 +1,30 @@
+using System;
+using EventStore.Transport.Http;
+
+namespace EventStore.Core.Services.Transport.Http.Codecs
+{
+ public class ManualEncoding : ICodec
+ {
+ public string ContentType { get { throw new InvalidOperationException(); } }
+
+ public bool CanParse(string format)
+ {
+ return true;
+ }
+
+ public bool SuitableForReponse(AcceptComponent component)
+ {
+ return true;
+ }
+
+ public T From<T>(string text)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public string To<T>(T value)
+ {
+ throw new InvalidOperationException();
+ }
+ }
+}
View
30 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/NoCodec.cs
@@ -0,0 +1,30 @@
+using System;
+using EventStore.Transport.Http;
+
+namespace EventStore.Core.Services.Transport.Http.Codecs
+{
+ public class NoCodec : ICodec
+ {
+ public string ContentType { get { throw new NotSupportedException(); } }
+
+ public bool CanParse(string format)
+ {
+ return false;
+ }
+
+ public bool SuitableForReponse(AcceptComponent component)
+ {
+ return false;
+ }
+
+ public T From<T>(string text)
+ {
+ throw new NotSupportedException();
+ }
+
+ public string To<T>(T value)
+ {
+ throw new NotSupportedException();
+ }
+ }
+}
View
33 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/TextCodec.cs
@@ -0,0 +1,33 @@
+using System;
+using EventStore.Transport.Http;
+
+namespace EventStore.Core.Services.Transport.Http.Codecs
+{
+ public class TextCodec : ICodec
+ {
+ public string ContentType { get { return EventStore.Transport.Http.ContentType.PlainText; } }
+
+ public bool CanParse(string format)
+ {
+ return string.Equals(ContentType, format, StringComparison.OrdinalIgnoreCase);
+ }
+
+ public bool SuitableForReponse(AcceptComponent component)
+ {
+ return component.MediaType == "*"
+ || (string.Equals(component.MediaType, "text", StringComparison.OrdinalIgnoreCase)
+ && (component.MediaSubtype == "*"
+ || string.Equals(component.MediaSubtype, "plain", StringComparison.OrdinalIgnoreCase)));
+ }
+
+ public T From<T>(string text)
+ {
+ throw new NotSupportedException();
+ }
+
+ public string To<T>(T value)
+ {
+ return ((object) value) != null ? value.ToString() : null;
+ }
+ }
+}
View
83 src/EventStore/EventStore.Core/Services/Transport/Http/Codecs/XmlCodec.cs
@@ -0,0 +1,83 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Xml;
+using System.Xml.Serialization;
+using EventStore.Common.Log;
+using EventStore.Transport.Http;
+
+namespace EventStore.Core.Services.Transport.Http.Codecs
+{
+ public class XmlCodec : ICodec
+ {
+ private static readonly ILogger Log = LogManager.GetLoggerFor<XmlCodec>();
+ private static readonly UTF8Encoding UTF8 = new UTF8Encoding(false); // we use our own encoding which doesn't produce BOM
+
+ public string ContentType { get { return EventStore.Transport.Http.ContentType.Xml; } }
+
+ public bool CanParse(string format)
+ {
+ return string.Equals(ContentType, format, StringComparison.OrdinalIgnoreCase);
+ }
+
+ public bool SuitableForReponse(AcceptComponent component)
+ {
+ return component.MediaType == "*"
+ || (string.Equals(component.MediaType, "text", StringComparison.OrdinalIgnoreCase)
+ && (component.MediaSubtype == "*"
+ || string.Equals(component.MediaSubtype, "xml", StringComparison.OrdinalIgnoreCase)));
+ }
+
+ public T From<T>(string text)
+ {
+ if (string.IsNullOrEmpty(text))
+ return default(T);
+
+ try
+ {
+ using (var reader = new StringReader(text))
+ {
+ return (T) new XmlSerializer(typeof (T)).Deserialize(reader);
+ }
+ }
+ catch (Exception e)
+ {
+ Log.ErrorException(e, "'{0}' is not a valid serialized {1}", text, typeof(T).FullName);
+ return default(T);
+ }
+ }
+
+ public string To<T>(T value)
+ {
+ if ((object)value == null)
+ return null;
+
+ try
+ {
+ using (var memory = new MemoryStream())
+ using (var writer = new XmlTextWriter(memory, UTF8))
+ {
+ var serializable = value as IXmlSerializable;
+ if (serializable != null)
+ {
+ writer.WriteStartDocument();
+ serializable.WriteXml(writer);
+ writer.WriteEndDocument();
+ }
+ else
+ {
+ new XmlSerializer(typeof (T)).Serialize(writer, value);
+ }
+
+ writer.Flush();
+ return UTF8.GetString(memory.GetBuffer(), 0, (int)memory.Length);
+ }
+ }
+ catch (Exception exc)
+ {