Permalink
Browse files

Add PollingClientExample

  • Loading branch information...
damianh committed Sep 4, 2013
1 parent b6f3444 commit ee0423d91001f1efe0b16d01003aff11a363d11a
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<configuration>
+
+ <connectionStrings>
+ <add name="NEventStore" providerName="System.Data.SqlClient" connectionString="Data Source=(local);Initial Catalog=EventStore-Example;Integrated Security=SSPI;"/>
+ </connectionStrings>
+
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
@@ -0,0 +1,68 @@
+namespace NEventStore.PollingClientExample
+{
+ using System;
+ using NEventStore.Client;
+ using NEventStore.Persistence.Sql.SqlDialects;
+
+ internal static class MainProgram
+ {
+ private static readonly byte[] EncryptionKey = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
+
+ private static void Main()
+ {
+ using (var store = WireupEventStore())
+ {
+ var client = new PollingClient(store.Advanced);
+ string checkpointValue = LoadCheckpoint();
+ ICheckpoint checkpoint = string.IsNullOrEmpty(checkpointValue)
+ ? store.Advanced.StartCheckpoint
+ : store.Advanced.ParseCheckpoint(checkpointValue);
+
+ using (IObserveCommits observeCommits = client.ObserveFrom(checkpoint))
+ using (observeCommits.Subscribe(commit =>
+ {
+ // Project the commit etc
+ Console.WriteLine(Resources.CommitInfo, commit.BucketId, commit.StreamId, commit.CommitSequence);
+ // Track the most recent checkpoint
+ checkpoint = commit.Checkpoint;
+ }))
+ {
+ observeCommits.Start();
+
+ Console.WriteLine(Resources.PressAnyKey);
+ Console.ReadKey();
+
+ SaveCheckpoint(checkpoint);
+ }
+ }
+ }
+
+ private static string LoadCheckpoint()
+ {
+ // Load the checkpoint value from disk / local db/ etc
+ return null;
+ }
+
+ private static void SaveCheckpoint(ICheckpoint checkpoint)
+ {
+ string checkpointValue = checkpoint.Value;
+ //Save checkpointValue to disk / whatever.
+ }
+
+ private static IStoreEvents WireupEventStore()
+ {
+ return
+ Wireup.Init()
+ .LogToOutputWindow()
+ .UsingInMemoryPersistence()
+ .UsingSqlPersistence("NEventStore") // Connection string is in app.config
+ .WithDialect(new MsSqlDialect()).EnlistInAmbientTransaction() // two-phase commit
+ .InitializeStorageEngine()
+ .TrackPerformanceInstance("example")
+ .UsingJsonSerialization()
+ .Compress()
+ .EncryptWith(EncryptionKey)
+ .Build();
+ }
+ }
+}
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{49705881-56D3-447A-92D8-D11CA6085DBD}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NEventStore.PollingClientExample</RootNamespace>
+ <AssemblyName>NEventStore.PollingClientExample</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>false</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\src\NEventStore.snk</AssemblyOriginatorKeyFile>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\src\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="..\GlobalAssemblyInfo.cs">
+ <Link>Properties\GlobalAssemblyInfo.cs</Link>
+ </Compile>
+ <Compile Include="..\VersionAssemblyInfo.cs">
+ <Link>Properties\VersionAssemblyInfo.cs</Link>
+ </Compile>
+ <Compile Include="MainProgram.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\NEventStore\NEventStore.csproj" Condition="'$(ILMerged)' != 'true'">
+ <Project>{03946843-F343-419C-88EF-3E446D08DFA6}</Project>
+ <Name>NEventStore</Name>
+ </ProjectReference>
+ <Reference Include="System.Reactive.Core">
+ <HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Net45\System.Reactive.Core.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Rx-Interfaces.2.1.30214.0\lib\Net45\System.Reactive.Interfaces.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Linq, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Net45\System.Reactive.Linq.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Transactions" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
+</Project>
@@ -0,0 +1,6 @@
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("NEventStore.Example")]
+[assembly: AssemblyDescription("")]
+[assembly: Guid("6fd621e0-9047-4449-b136-249383936d5c")]

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit ee0423d

Please sign in to comment.