Example #1
0
        static async Task Main(string[] args)
        {
            await SubscriptionsTest();

            EventStoreClientSettings settings = Program.ConfigureEventStoreSettings();

            EventStoreClient client = new(settings);


            EventStoreProjectionManagementClient projectionManagementClient = new EventStoreProjectionManagementClient(settings);

            //var x = await projectionManagementClient.GetStatusAsync("$by_category", cancellationToken: CancellationToken.None);

            IEventStoreContext context = new EventStoreContext(client, projectionManagementClient);
            IAggregateRepository <TestAggregate, DomainEvent> aggregateRepository = new AggregateRepository <TestAggregate, DomainEvent>(context);

            Guid          aggregateId = Guid.Parse("02398284-8284-8284-8284-165402398284");
            TestAggregate aggregate   = await aggregateRepository.GetLatestVersion(aggregateId, CancellationToken.None);

            aggregate.SetAggregateName("Test Name");
            //aggregate.SetAggregateName("Test Name1");
            //aggregate.SetAggregateName("Test Name2");
            //aggregate.SetAggregateName("Test Name3");
            //aggregate.SetAggregateName("Test Name4");

            await aggregateRepository.SaveChanges(aggregate, CancellationToken.None);

            //TestDockerHelper t = new TestDockerHelper();
            //await t.StartContainersForScenarioRun("");
        }
Example #2
0
        private static async Task <EventStoreClient> SetupConnection()
        {
            var settings = EventStoreClientSettings
                           .Create("esdb://localhost:2113?tls=false");
            var client            = new EventStoreClient(settings);
            var projectionsClient = new EventStoreProjectionManagementClient(settings);
            await projectionsClient.EnableAsync("$by_category");

            await Task.Delay(TimeSpan.FromSeconds(3));

            return(client);
        }
Example #3
0
        private async Task LoadEventStoreProjections()
        {
            //Start our Continous Projections - we might decide to do this at a different stage, but now lets try here
            String projectionsFolder = "../../../projections/continuous";

            IPAddress[] ipAddresses = Dns.GetHostAddresses("127.0.0.1");

            if (!String.IsNullOrWhiteSpace(projectionsFolder))
            {
                DirectoryInfo di = new DirectoryInfo(projectionsFolder);

                if (di.Exists)
                {
                    FileInfo[] files = di.GetFiles();

                    EventStoreProjectionManagementClient projectionClient = new EventStoreProjectionManagementClient(ConfigureEventStoreSettings(this.EventStoreHttpPort));

                    foreach (FileInfo file in files)
                    {
                        String projection     = File.ReadAllText(file.FullName);
                        String projectionName = file.Name.Replace(".js", String.Empty);

                        try
                        {
                            Logger.LogInformation($"Creating projection [{projectionName}]");
                            await projectionClient.CreateContinuousAsync(projectionName, projection, trackEmittedStreams : true).ConfigureAwait(false);
                        }
                        catch (Exception e)
                        {
                            Logger.LogError(new Exception($"Projection [{projectionName}] error", e));
                        }
                    }
                }
            }

            Logger.LogInformation("Loaded projections");
        }
        static async Task Main(string[] args)
        {
            //esdb://localhost:2113?tls=false

            var settings = EventStoreClientSettings
                           .Create("esdb://localhost:2113?tls=false");
            var client = new EventStoreClient(settings);

            //await TestReadFromtombstoned(client);

            var projectionClient = new EventStoreProjectionManagementClient(settings);
            var operationsClient = new EventStoreOperationsClient(settings);

            await client.SoftDeleteAsync("dokimi-1", StreamState.Any);

            await client.SoftDeleteAsync("dokimi-2", StreamState.Any);

            await client.SoftDeleteAsync("dokimi-3", StreamState.Any);


            //await projectionClient.DisableAsync("$by_category");
            //var result = await operationsClient.StartScavengeAsync();
            //await Task.Delay(TimeSpan.FromSeconds(20));
            //await projectionClient.EnableAsync("$by_category");
            //await projectionClient.ResetAsync("$by_category");
            //var readDeltedStreamResult = client.ReadStreamAsync(Direction.Forwards, "test", StreamPosition.Start);

            //Console.WriteLine("Stream existed: {0}\nSteam was empty: {1}",
            //    await readDeltedStreamResult.ReadState,
            //    await readDeltedStreamResult.CountAsync());

            var data = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new Data()
            {
                Value = 5
            }));
            var writeResult = await client.AppendToStreamAsync("dokimi-1", StreamRevision.FromInt64(-1),
                                                               new[] { new EventData(Uuid.NewUuid(), "TestType", data) });

            writeResult = await client.AppendToStreamAsync("dokimi-2", StreamRevision.FromInt64(-1),
                                                           new[] { new EventData(Uuid.NewUuid(), "TestType", data) });

            writeResult = await client.AppendToStreamAsync("dokimi-3", StreamRevision.FromInt64(-1),
                                                           new[] { new EventData(Uuid.NewUuid(), "TestType", data) });

            await Task.Delay(TimeSpan.FromSeconds(10));

            var readResult = client.ReadStreamAsync(Direction.Forwards, "$ce-dokimi",
                                                    StreamPosition.Start,
                                                    resolveLinkTos: true);
            var isSuccess = await readResult.ReadState;
            var events    = await readResult.Where(x => x.Event != null).ToListAsync();

            var eventCount = events.Count;

            var readResultStream = client.ReadStreamAsync(Direction.Forwards, "dokimi-2", StreamPosition.Start);
            var isSuccessStream  = await readResultStream.ReadState;
            var eventsInStream   = await readResultStream.ToListAsync();

            var eventCountStream = eventsInStream.Count;

            Console.WriteLine("Could read stream: {0}", isSuccess);
            Console.WriteLine("Found {0} events", eventCount);

            Console.WriteLine("Press any key to exit!");
            Console.ReadKey();
        }
        public EventStoreProjectionClient(EventStoreClientSettings settings, string projectionPrefix)
        {
            client = new EventStoreProjectionManagementClient(settings);

            this.projectionPrefix = projectionPrefix;
        }
Example #6
0
 /// <summary>
 /// The user credentials
 /// </summary>
 /// <param name="eventStoreClient">The event store client.</param>
 /// <param name="projectionManagementClient"></param>
 public EventStoreContext(EventStoreClient eventStoreClient, EventStoreProjectionManagementClient projectionManagementClient)
 {
     this.EventStoreClient           = eventStoreClient;
     this.ProjectionManagementClient = projectionManagementClient;
 }