public static IEnumerable <object> Project(ItemPurchased purchased, Guid nextEventId, int checkpointPosition)
        {
            yield return(TSql.NonQueryStatement(@"insert into ItemsPurchased (StockKeepingUnit) values (@StockKeepingUnit)", new
            {
                StockKeepingUnit = TSql.VarCharMax(purchased.StockKeepingUnit)
            }));

            yield return(TSql.NonQueryStatement(@"insert into StreamCheckpoint (Position) values (@Position)", new
            {
                Position = TSql.Int(checkpointPosition)
            }));

            yield return(new WriteToStream(nextEventId, "egress", new CheckpointEvent(checkpointPosition)));
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            var runtime = Runtime.StartNewAsync().Result;

            var connection = EventStoreConnection
                             .Create(ConnectionSettings.Create().Build(), new IPEndPoint(IPAddress.Loopback, 1113));

            connection.ConnectAsync().Wait();

            Console.WriteLine(@"Type ""q"" to quit");
            Console.WriteLine(@"Type ""a"" to append an event");

            string input;

            do
            {
                input = Console.ReadLine();

                if (input != "a")
                {
                    continue;
                }

                var @event   = new ItemPurchased(GuidEncoder.Encode(Guid.NewGuid()));
                var metadata = new Dictionary <string, string>
                {
                    { "tenantId", "Warehouse A" },
                    { "$correlationId", GuidEncoder.Encode(Guid.NewGuid()) }
                };
                var eventData = EventSerializer.Serialize(Guid.NewGuid(), @event, metadata);

                connection.AppendToStreamAsync("ingress", ExpectedVersion.Any, eventData).Wait();

                Console.WriteLine("Appended event");
            } while (!string.Equals(input, "q"));

            runtime.Stop();
            Console.WriteLine("Stopping...");
        }