public void InitExample(ExampleId exampleId) { _topMenu = _uiManager.CreateUIMediator <TopMenuMediator>(); _topMenu.SetExampleId(exampleId); switch (exampleId) { case ExampleId.Popup: _example = _popUpManager.ShowPopUp <ExamplePopupMediator>(); break; case ExampleId.Tabs: _example = _uiManager.CreateUIMediator <ExampleTabPanelMediator>("TabPanel/"); break; case ExampleId.List: _example = _uiManager.CreateUIMediator <ExampleListPanelMediator>("ListPanel/"); break; case ExampleId.VirtualList: _example = _uiManager.CreateUIMediator <ExampleVirtualListPanelMediator>("VirtualListPanel/"); break; default: throw new ArgumentOutOfRangeException("exampleId", exampleId, null); } }
public static IExampleSpace <TResult> MergeInternal <T, TResult>( List <IExampleSpace <T> > exampleSpaces, Func <List <T>, TResult> mergeValues, ShrinkFunc <List <IExampleSpace <T> > > shrinkExampleSpaces, MeasureFunc <List <IExampleSpace <T> > > measureMerge, ImmutableHashSet <ExampleId> encounteredIds, bool enableSmallestExampleSpacesOptimization, bool isRoot) { IExampleSpace <TResult> GenerateNextExampleSpace(IEnumerable <IExampleSpace <T> > exampleSpaces, ImmutableHashSet <ExampleId> encounteredIds) { return(MergeInternal( exampleSpaces.ToList(), mergeValues, shrinkExampleSpaces, measureMerge, encounteredIds, enableSmallestExampleSpacesOptimization, false)); } var mergedId = exampleSpaces.Aggregate( ExampleId.Primitive(exampleSpaces.Count()), (acc, curr) => ExampleId.Combine(acc, curr.Current.Id)); var mergedValue = mergeValues(exampleSpaces.Select(es => es.Current.Value).ToList()); var mergedDistance = measureMerge(exampleSpaces); var current = new Example <TResult>( mergedId, mergedValue, mergedDistance); var smallestExampleSpacesShrink = enableSmallestExampleSpacesOptimization && isRoot && exampleSpaces.Any(exampleSpace => exampleSpace.Subspace.Any()) ? exampleSpaces .Select(exampleSpace => { var smallestExampleSpace = exampleSpace.Subspace.FirstOrDefault() ?? exampleSpace; return(smallestExampleSpace); }) .ToList() : null; var exampleSpaceCullingShrinks = shrinkExampleSpaces(exampleSpaces); var subspaceMergingShrinks = exampleSpaces .Select((exampleSpace, index) => LiftAndInsertSubspace(exampleSpaces, exampleSpace.Subspace, index)) .SelectMany(exampleSpaces => exampleSpaces); var shrinks = TraverseUnencountered( Enumerable.Concat( smallestExampleSpacesShrink == null ? Enumerable.Empty <List <IExampleSpace <T> > >() : new[] { smallestExampleSpacesShrink }.AsEnumerable(), Enumerable.Concat(exampleSpaceCullingShrinks, subspaceMergingShrinks)), encounteredIds, GenerateNextExampleSpace); return(new ExampleSpace <TResult>(current, shrinks)); }
public async Task PassingTest() { using (var resolver = EventFlowOptions.New .UseAutofacContainerBuilder(new ContainerBuilder()) .Configure(c => c.ThrowSubscriberExceptions = true) .AddEvents(typeof(ExampleEvent)) .AddEvents(typeof(ResetEvent)) .AddCommands(typeof(ExampleCommand)) .AddCommands(typeof(ResetCommand)) .AddCommandHandlers(typeof(ExampleCommandHandler)) .AddCommandHandlers(typeof(ResetCommandHandler)) .ConfigureEventStore() .ConfigureMongoDb(MongoClient, SNAPSHOT_CONTAINER_NAME) .AddSnapshots(typeof(ExampleSnaphost)) .UseMongoDbSnapshotStore() .UseInMemoryReadStoreFor <ExampleReadModel>() .RegisterServices(sr => sr.Register(i => SnapshotEveryFewVersionsStrategy.Default)) .RegisterServices(DecorateCommandBus) .PublishToRabbitMq(RabbitMqConfiguration.With(RabbitMqUri, true, 4, "eventflow")) .Configure(c => c.IsAsynchronousSubscribersEnabled = true) .AddJobs(typeof(ExampleJob)) .CreateResolver()) { Int32 magicNumber = 2; CommandBus = resolver.Resolve <ICommandBus>(); ExampleId exampleId = PublishCommand.GetStreamName("Tenant", "EXAMPLE"); CommandReturnResult result = await CommandBus.PublishAsync( new ExampleCommand(exampleId, magicNumber), CancellationToken.None) .ConfigureAwait(false); IAggregateStore aggregateStore = resolver.Resolve <IAggregateStore>(); var @aggregate = await aggregateStore.LoadAsync <ExampleAggregate, ExampleId>(exampleId, CancellationToken.None); //Command side result.IsSuccess.Should().BeTrue(); result.AggregateRoot.Should().NotBeNull(); result.AggregateRoot.Version.Should().Be(1); result.AggregateRoot.Name.Value.Should().Be("ExampleAggregate"); result.AggregateRoot.GetIdentity().Value.Should().Be(exampleId.Value); @aggregate.Should().NotBeNull(); result.AggregateRoot.Should().Equals(@aggregate); } }
static IExampleSpace <TResult> JoinExampleSpaces( IExampleSpace <T> leftExampleSpace, IExampleSpace <TResult> rightExampleSpace, Func <T, IGen <TResult> > selector, GenParameters parameters) { var jointExampleSpace = rightExampleSpace.MapExamples(example => new Example <TResult>( ExampleId.Combine(leftExampleSpace.Current.Id, example.Id), example.Value, leftExampleSpace.Current.Distance + example.Distance)); var boundLeftSubspace = leftExampleSpace.Subspace.SelectMany(leftExampleSubspace => BindSubspace(leftExampleSubspace, selector, parameters)); return(ExampleSpaceFactory.Create( jointExampleSpace.Current, Enumerable.Concat(boundLeftSubspace, rightExampleSpace.Subspace))); }
public async Task ReadModelTest() { using (var resolver = EventFlowOptions.New .UseAutofacContainerBuilder(new ContainerBuilder()) .Configure(c => c.ThrowSubscriberExceptions = true) .AddEvents(typeof(ExampleEvent)) .AddEvents(typeof(ResetEvent)) .AddCommands(typeof(ExampleCommand)) .AddCommands(typeof(ResetCommand)) .AddCommandHandlers(typeof(ExampleCommandHandler)) .AddCommandHandlers(typeof(ResetCommandHandler)) .ConfigureEventStore() .ConfigureMongoDb(MongoClient, SNAPSHOT_CONTAINER_NAME) .AddSnapshots(typeof(ExampleSnaphost)) .UseMongoDbSnapshotStore() .UseInMemoryReadStoreFor <ExampleReadModel>() .RegisterServices(sr => sr.Register(i => SnapshotEveryFewVersionsStrategy.Default)) .RegisterServices(DecorateCommandBus) .PublishToRabbitMq(RabbitMqConfiguration.With(RabbitMqUri, true, 4, "eventflow")) .Configure(c => c.IsAsynchronousSubscribersEnabled = true) .AddJobs(typeof(ExampleJob)) .CreateResolver()) { Int32 magicNumber = 2; CommandBus = resolver.Resolve <ICommandBus>(); ExampleId exampleId = PublishCommand.GetStreamName("Tenant", "EXAMPLE"); CommandReturnResult result = await CommandBus.PublishAsync( new ExampleCommand(exampleId, magicNumber), CancellationToken.None) .ConfigureAwait(false); var queryProcessor = resolver.Resolve <IQueryProcessor>(); ExampleReadModel exampleReadModel = await queryProcessor.ProcessAsync( new ReadModelByIdQuery <ExampleReadModel>(exampleId), CancellationToken.None) .ConfigureAwait(false); exampleReadModel.Should().NotBeNull(); exampleReadModel.MagicNumber.Should().ContainSingle(); exampleReadModel.MagicNumber.First().Should().Be(2); } }
private static IExampleSpace <IEnumerable <T> > CreateInfiniteEnumerableSpace( IGen <T> elementGen, GenParameters parameters, int?iterationLimit) { IEnumerable <T> SealEnumerable(IEnumerable <T> source) => ThrowOnLimit(source.Repeat(), iterationLimit); var enumerable = CreateInfiniteEnumerable(elementGen, parameters, iterationLimit); IExample <IEnumerable <T> > rootExample = new Example <IEnumerable <T> >( ExampleId.Primitive(parameters.Rng.Seed), enumerable.Select(x => x.Current.Value), 100); return(ExampleSpaceFactory.Delay( rootExample, () => { if (enumerable.MaxIterations == 0) { return Enumerable.Empty <IExampleSpace <IEnumerable <T> > >(); } if (enumerable.MaxIterations == 1) { var exampleSpace = enumerable.First().Map(element => SealEnumerable(new[] { element })); return new[] { exampleSpace }; } var exampleSpaces = enumerable.Take(enumerable.MaxIterations).ToList(); var rootExampleExplored = ExampleSpaceFactory.Merge( exampleSpaces, xs => xs, ShrinkTowardsLength(1), (_) => 0, enableSmallestExampleSpacesOptimization: false); return rootExampleExplored.Subspace.Select(es => es.Map(SealEnumerable)); })); }
public async Task PassingTest() { // We wire up EventFlow with all of our classes. Instead of adding events, // commands, etc. explicitly, we could have used the the simpler // AddDefaults(Assembly) instead. using (var resolver = EventFlowOptions.New .AddEvents(typeof(ExampleEvent)) .AddCommands(typeof(ExampleCommand)) .AddCommandHandlers(typeof(ExampleCommandHandler)) .UseInMemoryReadStoreFor <ExampleReadModel>() .CreateResolver()) { // Create a new identity for our aggregate root var exampleId = new ExampleId(Guid.NewGuid().ToString()); // Resolve the command bus and use it to publish a command CommandBus = resolver.Resolve <ICommandBus>(); BenchmarkRunner.Run <CommandPublish>(); //var executionResult = await PublishCommand(commandBus, exampleId, magicNumber); // Verify that we didn't trigger our domain validation //executionResult.IsSuccess.Should().BeTrue(); // Resolve the query handler and use the built-in query for fetching // read models by identity to get our read model representing the // state of our aggregate root var queryProcessor = resolver.Resolve <IQueryProcessor>(); var exampleReadModel = await queryProcessor.ProcessAsync( new ReadModelByIdQuery <ExampleReadModel>(exampleId), CancellationToken.None) .ConfigureAwait(false); // Verify that the read model has the expected magic number //exampleReadModel.MagicNumber.Should().Be(42); } }
public MenuDataProvider(ExampleId itemIdId, string label) { ItemIdId = itemIdId; Label = label; }
private MenuDataProvider CreateDataProvider(ExampleId exampleId) { return(new MenuDataProvider(exampleId, _titles[exampleId])); }
public MenuDataProvider GetMenuItemById(ExampleId id) { return(CreateDataProvider(id)); }
public static IdentifyFunc <T> Default <T>() => (value) => ExampleId.Primitive(value);
public async Task PublishCommandAsync() { var client = new MongoClient("mongodb://*****:*****@"amqp://test:test@localhost:5672"), true, 4, "eventflow")) //.ConfigureSagas() //.UseNullLog() //.UseInMemoryReadStoreFor<Aggregates.ReadModels.ExampleReadModel>() .Configure(c => c.IsAsynchronousSubscribersEnabled = true) //.AddAsynchronousSubscriber<ExampleAggregate, Aggregates.Events.ExampleId, ExampleEvent, RabbitMqConsumePersistanceService>() //.RegisterServices(s => { // s.Register<IHostedService, RabbitConsumePersistenceService>(Lifetime.Singleton); // s.Register<IHostedService, RabbitMqConsumePersistanceService>(Lifetime.Singleton); //}) //.AddSubscribers(new Type[] { typeof(ExampleSyncSubscriber) }) // .UseHangfireJobScheduler() .AddJobs(typeof(ExampleJob)) .CreateResolver()) { Int32 magicNumber = 2; CommandBus = resolver.Resolve <ICommandBus>(); var clock = new Stopwatch(); clock.Start(); ExampleId exampleId = GetStreamName("Tenant", "EXAMPLE"); for (int i = 0; i < 1; i++) { IExecutionResult result = await CommandBus.PublishAsync(new ExampleCommand(exampleId, magicNumber), CancellationToken.None) .ConfigureAwait(false); #region Comments //result.IsSuccess.Should().BeTrue(); //IAggregateStore aggregateStore = resolver.Resolve<IAggregateStore>(); //var @object = aggregateStore.LoadAsync<ExampleAggregate, ExampleId>(exampleId, CancellationToken.None); ////Obsolete ////IEventStore eventStore = resolver.Resolve<IEventStore>(); ////var aggregate = await eventStore.LoadAggregateAsync<ExampleAggregate, ExampleId>(exampleId, CancellationToken.None); ////state of our aggregate root //var queryProcessor = resolver.Resolve<IQueryProcessor>(); //var result = await queryProcessor.ProcessAsync( // new ReadModelByIdQuery<ExampleReadModel>(exampleId), // CancellationToken.None) // .ConfigureAwait(false); //// Verify that the read model has the expected magic number //exampleReadModel.MagicNumber.Should().Be(42); #endregion } clock.Stop(); Console.WriteLine("Duration: " + clock.ElapsedMilliseconds + "ms"); } Console.ReadLine(); }
public void SetExampleId(ExampleId exampleId) { View.TitleText.text = _menuModel.GetMenuItemById(exampleId).Label; }
public MenuItemSelectedEvent(ExampleId exampleId) { ExampleId = exampleId; }
public ExamplesState(ExampleId exampleId) { _exampleId = exampleId; }
private static ExampleId RandomId() => ExampleId.Primitive(Guid.NewGuid().GetHashCode());