Skip to content

Commit ee0423d

Browse files
committed
Add PollingClientExample
1 parent b6f3444 commit ee0423d

8 files changed

Lines changed: 419 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<configuration>
3+
4+
<connectionStrings>
5+
<add name="NEventStore" providerName="System.Data.SqlClient" connectionString="Data Source=(local);Initial Catalog=EventStore-Example;Integrated Security=SSPI;"/>
6+
</connectionStrings>
7+
8+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
namespace NEventStore.PollingClientExample
2+
{
3+
using System;
4+
using NEventStore.Client;
5+
using NEventStore.Persistence.Sql.SqlDialects;
6+
7+
internal static class MainProgram
8+
{
9+
private static readonly byte[] EncryptionKey = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
10+
11+
private static void Main()
12+
{
13+
using (var store = WireupEventStore())
14+
{
15+
var client = new PollingClient(store.Advanced);
16+
string checkpointValue = LoadCheckpoint();
17+
ICheckpoint checkpoint = string.IsNullOrEmpty(checkpointValue)
18+
? store.Advanced.StartCheckpoint
19+
: store.Advanced.ParseCheckpoint(checkpointValue);
20+
21+
using (IObserveCommits observeCommits = client.ObserveFrom(checkpoint))
22+
using (observeCommits.Subscribe(commit =>
23+
{
24+
// Project the commit etc
25+
Console.WriteLine(Resources.CommitInfo, commit.BucketId, commit.StreamId, commit.CommitSequence);
26+
// Track the most recent checkpoint
27+
checkpoint = commit.Checkpoint;
28+
}))
29+
{
30+
observeCommits.Start();
31+
32+
Console.WriteLine(Resources.PressAnyKey);
33+
Console.ReadKey();
34+
35+
SaveCheckpoint(checkpoint);
36+
}
37+
}
38+
}
39+
40+
private static string LoadCheckpoint()
41+
{
42+
// Load the checkpoint value from disk / local db/ etc
43+
return null;
44+
}
45+
46+
private static void SaveCheckpoint(ICheckpoint checkpoint)
47+
{
48+
string checkpointValue = checkpoint.Value;
49+
//Save checkpointValue to disk / whatever.
50+
}
51+
52+
private static IStoreEvents WireupEventStore()
53+
{
54+
return
55+
Wireup.Init()
56+
.LogToOutputWindow()
57+
.UsingInMemoryPersistence()
58+
.UsingSqlPersistence("NEventStore") // Connection string is in app.config
59+
.WithDialect(new MsSqlDialect()).EnlistInAmbientTransaction() // two-phase commit
60+
.InitializeStorageEngine()
61+
.TrackPerformanceInstance("example")
62+
.UsingJsonSerialization()
63+
.Compress()
64+
.EncryptWith(EncryptionKey)
65+
.Build();
66+
}
67+
}
68+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{49705881-56D3-447A-92D8-D11CA6085DBD}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>NEventStore.PollingClientExample</RootNamespace>
12+
<AssemblyName>NEventStore.PollingClientExample</AssemblyName>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<SignAssembly>false</SignAssembly>
16+
<AssemblyOriginatorKeyFile>..\..\src\NEventStore.snk</AssemblyOriginatorKeyFile>
17+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\src\</SolutionDir>
18+
<RestorePackages>true</RestorePackages>
19+
<TargetFrameworkProfile />
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
22+
<DebugSymbols>true</DebugSymbols>
23+
<DebugType>full</DebugType>
24+
<Optimize>false</Optimize>
25+
<OutputPath>bin\Debug\</OutputPath>
26+
<DefineConstants>DEBUG;TRACE</DefineConstants>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
<Prefer32Bit>false</Prefer32Bit>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32+
<DebugType>pdbonly</DebugType>
33+
<Optimize>true</Optimize>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
<Prefer32Bit>false</Prefer32Bit>
39+
</PropertyGroup>
40+
<PropertyGroup>
41+
<StartupObject />
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Compile Include="..\GlobalAssemblyInfo.cs">
45+
<Link>Properties\GlobalAssemblyInfo.cs</Link>
46+
</Compile>
47+
<Compile Include="..\VersionAssemblyInfo.cs">
48+
<Link>Properties\VersionAssemblyInfo.cs</Link>
49+
</Compile>
50+
<Compile Include="MainProgram.cs" />
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
<Compile Include="Resources.Designer.cs">
53+
<AutoGen>True</AutoGen>
54+
<DesignTime>True</DesignTime>
55+
<DependentUpon>Resources.resx</DependentUpon>
56+
</Compile>
57+
</ItemGroup>
58+
<ItemGroup>
59+
<ProjectReference Include="..\..\src\NEventStore\NEventStore.csproj" Condition="'$(ILMerged)' != 'true'">
60+
<Project>{03946843-F343-419C-88EF-3E446D08DFA6}</Project>
61+
<Name>NEventStore</Name>
62+
</ProjectReference>
63+
<Reference Include="System.Reactive.Core">
64+
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Net45\System.Reactive.Core.dll</HintPath>
65+
<Private>True</Private>
66+
</Reference>
67+
<Reference Include="System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
68+
<SpecificVersion>False</SpecificVersion>
69+
<HintPath>..\packages\Rx-Interfaces.2.1.30214.0\lib\Net45\System.Reactive.Interfaces.dll</HintPath>
70+
</Reference>
71+
<Reference Include="System.Reactive.Linq, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
72+
<SpecificVersion>False</SpecificVersion>
73+
<HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Net45\System.Reactive.Linq.dll</HintPath>
74+
</Reference>
75+
<Reference Include="System.Transactions" />
76+
</ItemGroup>
77+
<ItemGroup>
78+
<None Include="App.config" />
79+
<None Include="packages.config" />
80+
</ItemGroup>
81+
<ItemGroup>
82+
<EmbeddedResource Include="Resources.resx">
83+
<Generator>ResXFileCodeGenerator</Generator>
84+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
85+
<SubType>Designer</SubType>
86+
</EmbeddedResource>
87+
</ItemGroup>
88+
<ItemGroup>
89+
<Reference Include="System" />
90+
</ItemGroup>
91+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
92+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
93+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
[assembly: AssemblyTitle("NEventStore.Example")]
5+
[assembly: AssemblyDescription("")]
6+
[assembly: Guid("6fd621e0-9047-4449-b136-249383936d5c")]

src/NEventStore.PollingClientExample/Resources.Designer.cs

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)