Skip to content

Commit e566695

Browse files
committed
Started work on higher (stream/message) and lower (byte) level api.
1 parent 371388c commit e566695

14 files changed

+185
-0
lines changed

src/StreamSource.Tests/StreamSource.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Name>StreamSource</Name>
5858
</ProjectReference>
5959
</ItemGroup>
60+
<ItemGroup />
6061
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6162
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6263
Other similar extension points exist, see Microsoft.Common.targets.
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace StreamSource
2+
{
3+
public interface IStreamStoreWriter
4+
{
5+
void Write(StreamChangeset changeset);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using StreamSource.Naming;
2+
3+
namespace StreamSource
4+
{
5+
public interface IStreamStoreWriterSelector
6+
{
7+
IStreamStoreWriter Select(StreamName name);
8+
}
9+
}

src/StreamSource/Metadatum.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace StreamSource
4+
{
5+
public class Metadatum
6+
{
7+
public readonly string Name;
8+
public readonly string Value;
9+
10+
public Metadatum(string name, string value)
11+
{
12+
if (name == null) throw new ArgumentNullException("name");
13+
if (value == null) throw new ArgumentNullException("value");
14+
Name = name;
15+
Value = value;
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace StreamSource.Serialization
2+
{
3+
public interface IMessageDeserializer
4+
{
5+
object Deserialize(MessageRecord record);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace StreamSource.Serialization
2+
{
3+
public interface IMessageSerializer
4+
{
5+
MessageRecord Serialize(object message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace StreamSource.Serialization
2+
{
3+
public interface IMetadataDeserializer
4+
{
5+
Metadatum[] Deserialize(byte[] data);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace StreamSource.Serialization
2+
{
3+
public interface IMetadataSerializer
4+
{
5+
byte[] Deserialize(Metadatum[] metadata);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace StreamSource.Serialization
4+
{
5+
public class MessageRecord
6+
{
7+
public readonly string Contract;
8+
public readonly byte[] Data;
9+
10+
public MessageRecord(string contract, byte[] data)
11+
{
12+
if (contract == null) throw new ArgumentNullException("contract");
13+
if (data == null) throw new ArgumentNullException("data");
14+
Contract = contract;
15+
Data = data;
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace StreamSource.Storage
2+
{
3+
public interface IStreamStoreRecordWriter
4+
{
5+
void Write(StreamRecord[] records);
6+
}
7+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
3+
namespace StreamSource.Storage
4+
{
5+
public class StreamRecord
6+
{
7+
public readonly byte[] StreamId;
8+
public readonly int StreamExpectedVersion;
9+
public readonly string StreamName;
10+
public readonly Guid MessageId;
11+
public readonly byte[] MessageData;
12+
public readonly string MessageDataContract;
13+
public readonly byte[] MessageMetadata;
14+
public readonly int MessageOrdinal;
15+
public readonly Guid CausationId;
16+
public readonly Guid CorrelationId;
17+
18+
public StreamRecord(byte[] streamId, string streamName, int streamExpectedVersion, Guid messageId, byte[] messageData, string messageDataContract, byte[] messageMetadata, int messageOrdinal, Guid causationId, Guid correlationId)
19+
{
20+
if (streamId == null) throw new ArgumentNullException("streamId");
21+
if (streamExpectedVersion < 0) throw new ArgumentOutOfRangeException("streamExpectedVersion", streamExpectedVersion, "The expected version must be greater than or equal to 0.");
22+
if (streamName == null) throw new ArgumentNullException("streamName");
23+
if (messageData == null) throw new ArgumentNullException("messageData");
24+
if (messageDataContract == null) throw new ArgumentNullException("messageDataContract");
25+
if (messageMetadata == null) throw new ArgumentNullException("messageMetadata");
26+
if (messageOrdinal < 0) throw new ArgumentOutOfRangeException("messageOrdinal", messageOrdinal, "The message ordinal must be greater than or equal to 0.");
27+
StreamId = streamId;
28+
StreamExpectedVersion = streamExpectedVersion;
29+
StreamName = streamName;
30+
MessageId = messageId;
31+
MessageData = messageData;
32+
MessageDataContract = messageDataContract;
33+
MessageMetadata = messageMetadata;
34+
MessageOrdinal = messageOrdinal;
35+
CausationId = causationId;
36+
CorrelationId = correlationId;
37+
}
38+
}
39+
}

src/StreamSource/StreamChange.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
namespace StreamSource
4+
{
5+
public class StreamChange
6+
{
7+
public readonly Guid MessageId;
8+
public readonly object Message;
9+
public readonly Metadatum[] Metadata;
10+
11+
public StreamChange(Guid messageId, object message, Metadatum[] metadata)
12+
{
13+
if (message == null) throw new ArgumentNullException("message");
14+
if (metadata == null) throw new ArgumentNullException("metadata");
15+
MessageId = messageId;
16+
Message = message;
17+
Metadata = metadata;
18+
}
19+
}
20+
}

src/StreamSource/StreamChangeset.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using StreamSource.Naming;
3+
4+
namespace StreamSource
5+
{
6+
public class StreamChangeset
7+
{
8+
public readonly StreamName Name;
9+
public readonly int ExpectedVersion;
10+
public readonly Guid CausationId;
11+
public readonly Guid CorrelationId;
12+
public readonly StreamChange[] Changes;
13+
14+
public StreamChangeset(StreamName name, int expectedVersion, Guid causationId, Guid correlationId, StreamChange[] changes)
15+
{
16+
if (name == null) throw new ArgumentNullException("name");
17+
if (expectedVersion < 0) throw new ArgumentOutOfRangeException("expectedVersion", expectedVersion, "The expected version must be greater than or equal to 0.");
18+
if (changes == null) throw new ArgumentNullException("changes");
19+
Name = name;
20+
ExpectedVersion = expectedVersion;
21+
CausationId = causationId;
22+
CorrelationId = correlationId;
23+
Changes = changes;
24+
}
25+
}
26+
}

src/StreamSource/StreamSource.csproj

+12
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,22 @@
3737
<Reference Include="System.Xml" />
3838
</ItemGroup>
3939
<ItemGroup>
40+
<Compile Include="Serialization\IMessageDeserializer.cs" />
41+
<Compile Include="Serialization\IMessageSerializer.cs" />
42+
<Compile Include="Storage\IStreamStoreRecordWriter.cs" />
43+
<Compile Include="IStreamStoreWriterSelector.cs" />
44+
<Compile Include="Metadatum.cs" />
45+
<Compile Include="Serialization\IMetadataDeserializer.cs" />
46+
<Compile Include="Serialization\IMetadataSerializer.cs" />
47+
<Compile Include="Serialization\MessageRecord.cs" />
48+
<Compile Include="StreamChange.cs" />
49+
<Compile Include="StreamChangeset.cs" />
50+
<Compile Include="Storage\StreamRecord.cs" />
4051
<Compile Include="Naming\StreamName.cs" />
4152
<Compile Include="Naming\StreamNameComponent.cs" />
4253
<Compile Include="Naming\StreamNameFormat.cs" />
4354
<Compile Include="Properties\AssemblyInfo.cs" />
55+
<Compile Include="IStreamStoreWriter.cs" />
4456
</ItemGroup>
4557
<ItemGroup />
4658
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

0 commit comments

Comments
 (0)