<commit_before>namespace EventStore.Example
{
	using System;
	using System.Transactions;
	using Dispatcher;

	internal static class MainProgram
	{
		private static readonly Guid StreamId = Guid.NewGuid(); // aggregate identifier
		private static readonly byte[] EncryptionKey = new byte[]
		{
			0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf
		};
		private static IStoreEvents store;

		private static void Main()
		{
			using (var scope = new TransactionScope())
			using (store = WireupEventStore())
			{
				OpenOrCreateStream();
				AppendToStream();
				TakeSnapshot();
				LoadFromSnapshotForwardAndAppend();
				scope.Complete();
			}

			Console.WriteLine(Resources.PressAnyKey);
			Console.ReadKey();
		}

		private static IStoreEvents WireupEventStore()
		{
			 return Wireup.Init()
				.LogToOutputWindow()
				.UsingSqlPersistence("EventStore") // Connection string is in app.config
					.EnlistInAmbientTransaction() // two-phase commit
					.InitializeStorageEngine()
					.UsingJsonSerialization()
						.Compress()
						.EncryptWith(EncryptionKey)
				.HookIntoPipelineUsing(new[] { new AuthorizationPipelineHook() })
				.UsingAsynchronousDispatchScheduler()
					.DispatchTo(new DelegateMessageDispatcher(DispatchCommit))
				.Build();
		}
		private static void DispatchCommit(Commit commit)
		{
			// This is where we'd hook into our messaging infrastructure, such as NServiceBus,
			// MassTransit, WCF, or some other communications infrastructure.
			// This can be a class as well--just implement IDispatchCommits.
			try
			{
				foreach (var @event in commit.Events)
					Console.WriteLine(Resources.MessagesDispatched + ((SomeDomainEvent)@event.Body).Value);
			}
			catch (Exception)<commit_msg>Changed the example project to use the synchronous dispatcher for now because the async dispatcher was conflicting with the "using (store = WireupEventStore())" statement.  Specifically, execution could and usually did exit the using block, causing the IStoreEvents object and all of its dependencies to be disposed, before the async dispatcher had a chance to mark the last commit as dispatched in the SQL database.  This would cause unexpected output on the next execution of the example program as it first dispatched commits that hadn't been dispatched by the last execution, or sometimes it would simply crash with an ObjectDisposedException.<commit_after>namespace EventStore.Example
{
	using System;
	using System.Transactions;
	using Dispatcher;

	internal static class MainProgram
	{
		private static readonly Guid StreamId = Guid.NewGuid(); // aggregate identifier
		private static readonly byte[] EncryptionKey = new byte[]
		{
			0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf
		};
		private static IStoreEvents store;

		private static void Main()
		{
			using (var scope = new TransactionScope())
			using (store = WireupEventStore())
			{
				OpenOrCreateStream();
				AppendToStream();
				TakeSnapshot();
				LoadFromSnapshotForwardAndAppend();
				scope.Complete();
			}

			Console.WriteLine(Resources.PressAnyKey);
			Console.ReadKey();
		}

		private static IStoreEvents WireupEventStore()
		{
			 return Wireup.Init()
				.LogToOutputWindow()
				.UsingSqlPersistence("EventStore") // Connection string is in app.config
					.EnlistInAmbientTransaction() // two-phase commit
					.InitializeStorageEngine()
					.UsingJsonSerialization()
						.Compress()
						.EncryptWith(EncryptionKey)
				.HookIntoPipelineUsing(new[] { new AuthorizationPipelineHook() })
				.UsingSynchronousDispatchScheduler()
					.DispatchTo(new DelegateMessageDispatcher(DispatchCommit))
				.Build();
		}
		private static void DispatchCommit(Commit commit)
		{
			// This is where we'd hook into our messaging infrastructure, such as NServiceBus,
			// MassTransit, WCF, or some other communications infrastructure.
			// This can be a class as well--just implement IDispatchCommits.
			try
			{
				foreach (var @event in commit.Events)
					Console.WriteLine(Resources.MessagesDispatched + ((SomeDomainEvent)@event.Body).Value);
			}
			catch (Exception)
{'fraction_non_alphanumeric': 0.08954863625392227, 'fraction_numerical': 0.01255129133478156, 'mean_word_length': 3.968824940047962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1350628', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1154, 'n_words': 368}