├── .nuget
├── NuGet.exe
├── NuGet.Config
└── NuGet.targets
├── NEventStore.Example
├── SomeDomainEvent.cs
├── AggregateMemento.cs
├── App.config
├── packages.config
├── AuthorizationPipelineHook.cs
├── Properties
│ └── AssemblyInfo.cs
├── MainProgram.cs
├── Resources.Designer.cs
├── NEventStore.Example.csproj
├── Resources.resx
└── Settings.StyleCop
├── README.md
├── NEventStore.Example.sln.DotSettings
├── NEventStore.Example.sln
└── .gitignore
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NEventStore/Obsolete-NEventStore-Example/HEAD/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/NEventStore.Example/SomeDomainEvent.cs:
--------------------------------------------------------------------------------
1 | namespace NEventStore.Example
2 | {
3 | internal class SomeDomainEvent
4 | {
5 | public string Value { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/NEventStore.Example/AggregateMemento.cs:
--------------------------------------------------------------------------------
1 | namespace NEventStore.Example
2 | {
3 | internal class AggregateMemento
4 | {
5 | public string Value { get; set; }
6 |
7 | public override string ToString()
8 | {
9 | return Value;
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/NEventStore.Example/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/NEventStore.Example/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Obsolete NEventStore-Example
2 | ============================
3 |
4 | Collection of sample code to demonstrate how to use NEventStore.
5 |
6 | This project is outdated and not maintained on a regular basis, for some samples on how to use NEventStore check
7 | the examples inside the main library:
8 |
9 | https://github.com/NEventStore/NEventStore/tree/master/src/NEventStore.Example
10 | https://github.com/NEventStore/NEventStore/tree/master/src/NEventStore.PollingClientExample
11 |
--------------------------------------------------------------------------------
/NEventStore.Example.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | <data><IncludeFilters /><ExcludeFilters /></data>
3 | <data />
--------------------------------------------------------------------------------
/NEventStore.Example/AuthorizationPipelineHook.cs:
--------------------------------------------------------------------------------
1 | namespace NEventStore.Example
2 | {
3 | public class AuthorizationPipelineHook : PipelineHookBase
4 | {
5 | public override ICommit Select(ICommit committed)
6 | {
7 | // return null if the user isn't authorized to see this commit
8 | return committed;
9 | }
10 |
11 | public override void PostCommit(ICommit committed)
12 | {
13 | // anything to do after the commit has been persisted.
14 | }
15 |
16 | public override bool PreCommit(CommitAttempt attempt)
17 | {
18 | // Can easily do logging or other such activities here
19 | return true; // true == allow commit to continue, false = stop.
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/NEventStore.Example.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29102.190
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NEventStore.Example", "NEventStore.Example\NEventStore.Example.csproj", "{0143B48E-25AF-4CE0-BD49-A52267D359D3}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {0143B48E-25AF-4CE0-BD49-A52267D359D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {0143B48E-25AF-4CE0-BD49-A52267D359D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {0143B48E-25AF-4CE0-BD49-A52267D359D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {0143B48E-25AF-4CE0-BD49-A52267D359D3}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {6D732EA7-E523-4DD7-B261-6C8C84D418C7}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/NEventStore.Example/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("NEventStore.Example")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("NEventStore.Example")]
12 | [assembly: AssemblyCopyright("Copyright © NEventStore Dev Team 2013")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("db3e5bd6-b4b4-42dd-ae2c-3539294eaf6d")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | [assembly: AssemblyVersion("1.0.0.0")]
32 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2 | [Bb]in/
3 | [Oo]bj/
4 |
5 | # mstest test results
6 | TestResults
7 |
8 | ## Ignore Visual Studio temporary files, build results, and
9 | ## files generated by popular Visual Studio add-ons.
10 | .vs/
11 |
12 | # User-specific files
13 | *.suo
14 | *.user
15 | *.sln.docstates
16 |
17 | # Build results
18 | publish-*
19 | *nunit.TestResult.*.xml
20 | [Dd]ebug/
21 | [Rr]elease/
22 | x64/
23 | *_i.c
24 | *_p.c
25 | *.ilk
26 | *.meta
27 | *.obj
28 | *.pch
29 | *.pdb
30 | *.pgc
31 | *.pgd
32 | *.rsp
33 | *.sbr
34 | *.tlb
35 | *.tli
36 | *.tlh
37 | *.tmp
38 | *.log
39 | *.vspscc
40 | *.vssscc
41 | .builds
42 |
43 | # Visual C++ cache files
44 | ipch/
45 | *.aps
46 | *.ncb
47 | *.opensdf
48 | *.sdf
49 |
50 | # Visual Studio profiler
51 | *.psess
52 | *.vsp
53 | *.vspx
54 |
55 | # Guidance Automation Toolkit
56 | *.gpState
57 |
58 | # ReSharper is a .NET coding add-in
59 | _ReSharper*
60 |
61 | # NCrunch
62 | *.ncrunch*
63 | .*crunch*.local.xml
64 |
65 | # Installshield output folder
66 | [Ee]xpress
67 |
68 | # DocProject is a documentation generator add-in
69 | DocProject/buildhelp/
70 | DocProject/Help/*.HxT
71 | DocProject/Help/*.HxC
72 | DocProject/Help/*.hhc
73 | DocProject/Help/*.hhk
74 | DocProject/Help/*.hhp
75 | DocProject/Help/Html2
76 | DocProject/Help/html
77 |
78 | # Click-Once directory
79 | publish
80 |
81 | # Publish Web Output
82 | *.Publish.xml
83 |
84 | # NuGet Packages Directory
85 | packages
86 |
87 | # Windows Azure Build Output
88 | csx
89 | *.build.csdef
90 |
91 | # Windows Store app package directory
92 | AppPackages/
93 |
94 | # Others
95 | [Bb]in
96 | [Oo]bj
97 | sql
98 | TestResults
99 | [Tt]est[Rr]esult*
100 | *.Cache
101 | ClientBin
102 | [Ss]tyle[Cc]op.*
103 | ~$*
104 | *.dbmdl
105 | Generated_Code #added for RIA/Silverlight projects
106 | output/
107 |
108 | # Backup & report files from converting an old project file to a newer
109 | # Visual Studio version. Backup files are not needed, because we have git ;-)
110 | _UpgradeReport_Files/
111 | Backup*/
112 | UpgradeLog*.XML
113 |
114 | # Custom
115 | artifacts/
--------------------------------------------------------------------------------
/NEventStore.Example/MainProgram.cs:
--------------------------------------------------------------------------------
1 | namespace NEventStore.Example
2 | {
3 | using System;
4 | using System.Transactions;
5 | using NEventStore;
6 | using NEventStore.Persistence.Sql.SqlDialects;
7 | using NEventStore.Serialization.Json;
8 |
9 | internal static class MainProgram
10 | {
11 | private static readonly Guid StreamId = Guid.NewGuid(); // aggregate identifier
12 |
13 | private static readonly byte[] EncryptionKey = new byte[]
14 | {
15 | 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf
16 | };
17 |
18 | private static IStoreEvents store;
19 |
20 | private static void Main()
21 | {
22 | using (var scope = new TransactionScope())
23 | using (store = WireupEventStore())
24 | {
25 | OpenOrCreateStream();
26 | AppendToStream();
27 | TakeSnapshot();
28 | LoadFromSnapshotForwardAndAppend();
29 | scope.Complete();
30 | }
31 |
32 | Console.WriteLine(Resources.PressAnyKey);
33 | Console.ReadKey();
34 | }
35 |
36 | private static IStoreEvents WireupEventStore()
37 | {
38 | return Wireup.Init()
39 | .LogToOutputWindow()
40 | .UsingInMemoryPersistence()
41 | .UsingSqlPersistence("NEventStoreSql") // Connection string is in app.config
42 | .WithDialect(new MsSqlDialect())
43 | .EnlistInAmbientTransaction() // two-phase commit
44 | .InitializeStorageEngine()
45 | //.TrackPerformanceInstance("example") // uncomment to use performance tracking on full framework windows machines
46 | .UsingJsonSerialization()
47 | .Compress()
48 | .EncryptWith(EncryptionKey)
49 | .HookIntoPipelineUsing(new[] {new AuthorizationPipelineHook()})
50 | .Build();
51 | }
52 |
53 | private static void OpenOrCreateStream()
54 | {
55 | // we can call CreateStream(StreamId) if we know there isn't going to be any data.
56 | // or we can call OpenStream(StreamId, 0, int.MaxValue) to read all commits,
57 | // if no commits exist then it creates a new stream for us.
58 | using (IEventStream stream = store.OpenStream(StreamId, 0, int.MaxValue))
59 | {
60 | var @event = new SomeDomainEvent {Value = "Initial event."};
61 |
62 | stream.Add(new EventMessage {Body = @event});
63 | stream.CommitChanges(Guid.NewGuid());
64 | }
65 | }
66 |
67 | private static void AppendToStream()
68 | {
69 | using (IEventStream stream = store.OpenStream(StreamId, int.MinValue, int.MaxValue))
70 | {
71 | var @event = new SomeDomainEvent {Value = "Second event."};
72 |
73 | stream.Add(new EventMessage {Body = @event});
74 | stream.CommitChanges(Guid.NewGuid());
75 | }
76 | }
77 |
78 | private static void TakeSnapshot()
79 | {
80 | var memento = new AggregateMemento {Value = "snapshot"};
81 | store.Advanced.AddSnapshot(new Snapshot(StreamId.ToString(), 2, memento));
82 | }
83 |
84 | private static void LoadFromSnapshotForwardAndAppend()
85 | {
86 | ISnapshot latestSnapshot = store.Advanced.GetSnapshot(StreamId, int.MaxValue);
87 |
88 | using (IEventStream stream = store.OpenStream(latestSnapshot, int.MaxValue))
89 | {
90 | var @event = new SomeDomainEvent {Value = "Third event (first one after a snapshot)."};
91 |
92 | stream.Add(new EventMessage {Body = @event});
93 | stream.CommitChanges(Guid.NewGuid());
94 | }
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/NEventStore.Example/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace NEventStore.Example {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NEventStore.Example.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to Messages from commit have been dispatched: .
65 | ///
66 | internal static string MessagesDispatched {
67 | get {
68 | return ResourceManager.GetString("MessagesDispatched", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to Press any key to continue....
74 | ///
75 | internal static string PressAnyKey {
76 | get {
77 | return ResourceManager.GetString("PressAnyKey", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// Looks up a localized string similar to If for some reason we are unable to dispatch, we'd just handle it here..
83 | ///
84 | internal static string UnableToDispatch {
85 | get {
86 | return ResourceManager.GetString("UnableToDispatch", resourceCulture);
87 | }
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/NEventStore.Example/NEventStore.Example.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {0143B48E-25AF-4CE0-BD49-A52267D359D3}
9 | Exe
10 | Properties
11 | NEventStore.Example
12 | NEventStore.Example
13 | v4.5
14 | 512
15 | false
16 | ..\..\src\EventStore.snk
17 | ..\..\src\
18 | true
19 |
20 |
21 |
22 | true
23 | full
24 | false
25 | bin\Debug\
26 | DEBUG;TRACE
27 | prompt
28 | 4
29 | false
30 |
31 |
32 | pdbonly
33 | true
34 | bin\Release\
35 | TRACE
36 | prompt
37 | 4
38 | false
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | True
50 | True
51 | Resources.resx
52 |
53 |
54 |
55 |
56 |
57 | ..\packages\NEventStore.7.0.0\lib\net45\NEventStore.dll
58 |
59 |
60 | ..\packages\NEventStore.Persistence.Sql.7.2.0\lib\net45\NEventStore.Persistence.Sql.dll
61 |
62 |
63 | ..\packages\NEventStore.Serialization.Json.7.0.0\lib\net45\NEventStore.Serialization.Json.dll
64 |
65 |
66 | ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | ResXFileCodeGenerator
80 | Resources.Designer.cs
81 | Designer
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/NEventStore.Example/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | Messages from commit have been dispatched:
122 |
123 |
124 | Press any key to continue...
125 |
126 |
127 | If for some reason we are unable to dispatch, we'd just handle it here.
128 |
129 |
--------------------------------------------------------------------------------
/.nuget/NuGet.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildProjectDirectory)\..\
5 |
6 |
7 | false
8 |
9 |
10 | false
11 |
12 |
13 | true
14 |
15 |
16 | false
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
32 |
33 |
34 |
35 |
36 | $(SolutionDir).nuget
37 | packages.config
38 |
39 |
40 |
41 |
42 | $(NuGetToolsPath)\NuGet.exe
43 | @(PackageSource)
44 |
45 | "$(NuGetExePath)"
46 | mono --runtime=v4.0.30319 $(NuGetExePath)
47 |
48 | $(TargetDir.Trim('\\'))
49 |
50 | -RequireConsent
51 | -NonInteractive
52 |
53 |
54 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "
55 | $(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
56 |
57 |
58 |
59 | RestorePackages;
60 | $(BuildDependsOn);
61 |
62 |
63 |
64 |
65 | $(BuildDependsOn);
66 | BuildPackage;
67 |
68 |
69 |
70 |
71 |
72 |
73 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
88 |
89 |
92 |
93 |
94 |
95 |
97 |
98 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/NEventStore.Example/Settings.StyleCop:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | False
8 |
9 |
10 |
11 |
12 | False
13 |
14 |
15 |
16 |
17 | False
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | False
28 |
29 |
30 |
31 |
32 | False
33 |
34 |
35 |
36 |
37 | False
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | False
48 |
49 |
50 |
51 |
52 | False
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | False
63 |
64 |
65 |
66 |
67 | False
68 |
69 |
70 |
71 |
72 | False
73 |
74 |
75 |
76 |
77 | False
78 |
79 |
80 |
81 |
82 | False
83 |
84 |
85 |
86 |
87 | False
88 |
89 |
90 |
91 |
92 | False
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | False
103 |
104 |
105 |
106 |
107 | False
108 |
109 |
110 |
111 |
112 | False
113 |
114 |
115 |
116 |
117 | False
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | False
128 |
129 |
130 |
131 |
132 | False
133 |
134 |
135 |
136 |
137 | False
138 |
139 |
140 |
141 |
142 | False
143 |
144 |
145 |
146 |
147 | False
148 |
149 |
150 |
151 |
152 | False
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 | False
163 |
164 |
165 |
166 |
167 | False
168 |
169 |
170 |
171 |
172 | False
173 |
174 |
175 |
176 |
177 | False
178 |
179 |
180 |
181 |
182 |
183 |
184 |
--------------------------------------------------------------------------------