Skip to content

Commit 21f8029

Browse files
committed
simplify dotnet driver
1 parent b18cb0e commit 21f8029

18 files changed

+147
-104
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
- checkout
77
- run: |
88
pushd dotnet
9-
docker build --build-arg VERSION="1.0.0-dev.$CIRCLE_BUILD_NUM.$(echo $CIRCLE_SHA1 | cut -c -7)" -t streamsdb/dotnet-driver .
9+
docker build --build-arg VERSION="0.9.0-dev.$CIRCLE_BUILD_NUM" -t streamsdb/dotnet-driver .
1010
docker run --rm --name push-packages streamsdb/dotnet-driver --source https://api.nuget.org/v3/index.json --api-key $NUGET_TOKEN
1111
popd
1212
workflows:

.vscode/launch.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/dotnet/Example/bin/Debug/netcoreapp2.2/StreamsDB.Example.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/dotnet/Example",
16+
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17+
"console": "externalTerminal",
18+
"stopAtEntry": false
19+
},
20+
{
21+
"name": ".NET Core Attach",
22+
"type": "coreclr",
23+
"request": "attach",
24+
"processId": "${command:pickProcess}"
25+
}
26+
]
27+
}

.vscode/tasks.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/dotnet/Example/Example.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/dotnet/Example/Example.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"${workspaceFolder}/dotnet/Example/Example.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}

dotnet/Client/Client.csproj

-38
This file was deleted.

dotnet/Dockerfile

-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS builder
22

33
ARG VERSION
44
ARG CONFIGURATION="Debug"
5-
ARG NUGET_KEY
6-
ARG NUGET_URL=https://api.nuget.org/v3/index.json
75
WORKDIR /sln
86

97
COPY . .
@@ -13,4 +11,3 @@ RUN dotnet build /p:Version=$VERSION -c $CONFIGURATION --no-restore
1311
RUN dotnet pack ./Client /p:Version=$VERSION -c $CONFIGURATION --no-restore --no-build -o /sln/artifacts
1412

1513
ENTRYPOINT ["dotnet", "nuget", "push", "/sln/artifacts/*.nupkg"]
16-
CMD ["--source", "https://api.nuget.org/v3/index.json"]

dotnet/Client/DB.cs dotnet/Driver/DB.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
using System.Threading.Tasks;
55
using Google.Protobuf;
66
using Grpc.Core;
7-
using StreamsDB.Wire;
7+
using StreamsDB.Driver.Wire;
8+
using static StreamsDB.Driver.Wire.Streams;
89
using Message = Client.Message;
910
using MessageInput = Client.MessageInput;
1011
using Slice = Client.Slice;
11-
using WireClient = StreamsDB.Wire.Streams.StreamsClient;
12-
using WireMessageInput = StreamsDB.Wire.MessageInput;
1312

14-
namespace StreamsDB.Client
13+
namespace StreamsDB.Driver
1514
{
1615
public class DB
1716
{
18-
private readonly WireClient _client;
17+
private readonly StreamsClient _client;
1918
private readonly string _db;
2019
private readonly Metadata _metadata = Metadata.Empty;
2120

22-
public DB(WireClient client, string db, Metadata metadata)
21+
internal DB(StreamsClient client, string db, Metadata metadata)
2322
{
2423
_client = client;
2524
_db = db;
@@ -43,7 +42,7 @@ public async Task<long> Append(string streamId, params MessageInput[] messages)
4342
throw new ArgumentNullException(nameof(m.Type), "missing type name");
4443
}
4544

46-
request.Messages.Add(new WireMessageInput
45+
request.Messages.Add(new Wire.MessageInput
4746
{
4847
Type = m.Type,
4948
Header = ByteString.CopyFrom(m.Header ?? new byte[0]),

dotnet/Driver/Driver.csproj

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<RootNamespace>StreamsDB.Driver</RootNamespace>
6+
<AssemblyName>StreamsDB.Driver</AssemblyName>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<AssemblyTitle>StreamsDB.Driver</AssemblyTitle>
11+
<Description>StreamsDB .NET driver</Description>
12+
<Company>StreamsDB</Company>
13+
<Copyright>Copyright © StreamsDB. All rights reserved.</Copyright>
14+
<Product>StreamsDB.Driver</Product>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<Description>The client driver for StreamsDB.
19+
StreamsDB is a modern stream database for advanced stream processing and event sourcing systems.
20+
21+
See: https://streamsdb.io</Description>
22+
<Authors>StreamsDB</Authors>
23+
<DebugType>portable</DebugType>
24+
<AssemblyName>StreamsDB.Driver</AssemblyName>
25+
<PackageId>StreamsDB.Driver</PackageId>
26+
<PackageTags>streamsdb;client;driver;eventstore;netstandard2.0</PackageTags>
27+
<PackageIconUrl>https://streamsdb.io/img/logo.png</PackageIconUrl>
28+
<RepositoryType>git</RepositoryType>
29+
<RepositoryUrl>https://github.com/streams/driver</RepositoryUrl>
30+
</PropertyGroup>
31+
<ItemGroup>
32+
<PackageReference Include="Google.Api.CommonProtos" Version="1.7.0" />
33+
<PackageReference Include="Google.Protobuf" Version="3.9" />
34+
<PackageReference Include="Grpc" Version="1.17.0" />
35+
<PackageReference Include="Grpc.Tools" Version="1.17.0" PrivateAssets="All" />
36+
</ItemGroup>
37+
<ItemGroup>
38+
<Protobuf Include="./Wire/api.proto" Access="internal" GrpcServices="client" />
39+
</ItemGroup>
40+
<ItemGroup>
41+
<PackageReference Include="System.Reactive" Version="4.1.5" />
42+
</ItemGroup>
43+
</Project>
File renamed without changes.
File renamed without changes.

dotnet/Client/PipeSliceEnumerator.cs dotnet/Driver/PipeSliceEnumerator.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
using Client;
55
using Grpc.Core;
66

7-
namespace StreamsDB.Client
7+
namespace StreamsDB.Driver
88
{
99
internal struct PipeSliceEnumerator : IAsyncEnumerable<Slice>, IAsyncEnumerator<Slice>
1010
{
1111
private readonly string _streamId;
12-
private readonly IAsyncStreamReader<StreamsDB.Wire.Slice> _source;
12+
private readonly IAsyncStreamReader<StreamsDB.Driver.Wire.Slice> _source;
1313

14-
public PipeSliceEnumerator(string streamId, IAsyncStreamReader<StreamsDB.Wire.Slice> source)
14+
public PipeSliceEnumerator(string streamId, IAsyncStreamReader<StreamsDB.Driver.Wire.Slice> source)
1515
{
1616
_streamId = streamId;
1717
_source = source;
File renamed without changes.
File renamed without changes.

dotnet/Client/Connection.cs dotnet/Driver/StreamsDBClient.cs

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
using System;
22
using System.Web;
33
using Grpc.Core;
4-
using StreamsDB.Wire;
5-
using WireClient = StreamsDB.Wire.Streams.StreamsClient;
4+
using StreamsDB.Driver.Wire;
5+
using static StreamsDB.Driver.Wire.Streams;
66

7-
namespace StreamsDB.Client
7+
namespace StreamsDB.Driver
88
{
9-
public class Connection
9+
public class StreamsDBClient
1010
{
1111
private readonly Channel _channel;
12-
private readonly WireClient _client;
12+
private readonly StreamsClient _client;
1313
private volatile string _db;
1414
private readonly Metadata _metadata = new Metadata();
1515

16-
private Connection(Channel channel, WireClient client, string defaultDb = null)
17-
{
18-
_channel = channel;
19-
_client = client;
20-
_db = defaultDb;
21-
}
22-
23-
public static Connection Open(string connectionString = null)
16+
public StreamsDBClient(string connectionString = null)
2417
{
2518
if (string.IsNullOrEmpty(connectionString)) {
2619
connectionString = Environment.GetEnvironmentVariable("SDB_HOST");
@@ -47,24 +40,25 @@ public static Connection Open(string connectionString = null)
4740
}
4841

4942
var channel = new Channel(uri.Host, uri.Port, cred);
50-
var client = new WireClient(channel);
43+
var apiClient = new StreamsClient(channel);
5144
String defaultDb = null;
5245
if (!string.IsNullOrEmpty(uri.AbsolutePath))
5346
{
5447
defaultDb = uri.AbsolutePath.Trim('/');
5548
}
5649

57-
var conn = new Connection(channel, client, defaultDb);
50+
_channel = channel;
51+
_client = apiClient;
52+
_db = defaultDb;
53+
5854
if(!string.IsNullOrEmpty(uri.UserInfo))
5955
{
6056
var items = uri.UserInfo.Split(new char[] {':'});
61-
var username = items[0];
62-
var password = items[1];
57+
var username = HttpUtility.UrlDecode(items[0]);
58+
var password = HttpUtility.UrlDecode(items[1]);
6359

64-
conn.Login(username, password);
60+
this.Login(username, password);
6561
}
66-
67-
return conn;
6862
}
6963

7064
public void Login(string username, string password)

dotnet/Wire/api.proto dotnet/Driver/Wire/api.proto

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
syntax = "proto3";
1515
package streamsdb.api;
1616
import "google/protobuf/timestamp.proto";
17+
1718
option go_package = "api";
18-
option csharp_namespace = "StreamsDB.Wire";
19+
option csharp_namespace = "StreamsDB.Driver.Wire";
1920

2021
service Streams {
2122
rpc GetDatabases(GetDatabasesRequest) returns (GetDatabasesReply) {
@@ -33,10 +34,8 @@ service Streams {
3334
rpc DeleteMessage(DeleteMessageRequest) returns (DeleteMessageReply) {}
3435
rpc SubscribeStream (SubscribeStreamRequest) returns (stream Slice) {}
3536
rpc ReadGlobal(ReadGlobalRequest) returns (ReadGlobalReply) {}
36-
rpc Ping (PingRequest) returns (PingReply) {
37-
};
38-
rpc GetStreams(GetStreamsRequest) returns (GetStreamsReply) {
39-
}
37+
rpc Ping (PingRequest) returns (PingReply) {}
38+
rpc GetStreams(GetStreamsRequest) returns (GetStreamsReply) {}
4039
}
4140

4241
message DeleteMessageRequest{

dotnet/Example/Example.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<ProjectReference Include="..\Client\Client.csproj" />
12+
<ProjectReference Include="..\Driver\Driver.csproj" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

dotnet/Example/Program.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using Client;
6-
using StreamsDB.Client;
6+
using StreamsDB.Driver;
77

88
namespace Example
99
{
1010
class Program
1111
{
1212
static void Main(string[] args)
1313
{
14-
var conn = Connection.Open("sdb://sdb-01.streamsdb.io:443/default");
15-
var db = conn.DB();
14+
var client = new StreamsDBClient("sdb://admin:Dotnet%23156230@sdb-01.streamsdb.io:443/default");
15+
var db = client.DB();
1616
var streamName = "chat";
1717

18-
// read user input and append it to the stream
18+
// read from stdin and write to stream
1919
var input = Task.Run(async () =>
2020
{
2121
Console.WriteLine("enter a message an press [enter]");
@@ -38,6 +38,7 @@ static void Main(string[] args)
3838
}
3939
});
4040

41+
// subscribe to stream and print messages
4142
var read = Task.Run(async () =>
4243
{
4344
try

dotnet/StreamsDB.Client.sln dotnet/StreamsDB.sln

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26124.0
55
MinimumVisualStudioVersion = 15.0.26124.0
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{956A4AE8-ABA2-4E86-A7DA-72840B1A6FBC}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Driver", "Driver\Driver.csproj", "{956A4AE8-ABA2-4E86-A7DA-72840B1A6FBC}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.csproj", "{6008058A-A507-4F24-BB33-12C6AEA4196C}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wire", "Wire\Wire.csproj", "{B10CC659-0C65-4C44-A3A4-97F7CD283E3A}"
11-
EndProject
1210
Global
1311
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1412
Debug|Any CPU = Debug|Any CPU

dotnet/Wire/Wire.csproj

-19
This file was deleted.

0 commit comments

Comments
 (0)