示例#1
0
 public static ShippingModule Initialize(IAdvancedEventStore store, Func <IEvent[], Task> pub)
 => new Configuration <ShippingModule>((c, p, q, s) => new ShippingModule(c, p, q, s))
 .Commands(
     Commands.GuaranteeCorrelation <ICommand>(),
     cmd => ApplicationService.ExecuteAsync(cmd, () => (new[] { new GoodsShipped() }), pub))
 .Updates(events => store.AppendToStreamAsync("order", events.Filter(typeof(Payment.PaymentRecieved), typeof(Warehouse.GoodsPicked))))
 .Triggers(async(events, d) =>
示例#2
0
 public static GameModule Initialize(
     IAdvancedEventStore store,
     ISnapshotStore snapshotStore,
     Func <IEvent[], Task> pub)
 => new Configuration <GameModule>((c, p, q, s) => new GameModule(c, p, q, s))
 .Commands(
     Commands.Validate <ICommand>(),
     Commands.GuaranteeCorrelation <ICommand>(),
     cmd => store.ExecuteAsync <GameState>(cmd, state =>
                                           Game.Handle(cmd, state),
                                           async events =>
 {
     await snapshotStore.Apply <GamesView>(events.Select(e => e.Event).Apply);
     await pub(events);
 }, snapshotStore, state => state.Version, (newVersion, state) => state.Pipe(x => x with {
示例#3
0
文件: App.cs 项目: crapitan/Fiffi
        public static async Task <(int, IEvent[])> RunAsync(IAdvancedEventStore store, params string[] scenarioCargo)
        {
            var    events = new List <IEvent>();
            Module module = null;

            module = TTDModule.Initialize(store, async evts =>
            {
                events.AddRange(evts);
                await module.WhenAsync(evts);
            });

            var commands = scenarioCargo
                           .Select((x, i) => new PlanCargo
            {
                CargoId     = i,
                Destination = (Location)Enum.Parse(typeof(Location), x, true)
            });

            foreach (var cmd in commands)
            {
                await module.DispatchAsync(cmd);
            }

            var readyTransports = new[] {
                new ReadyTransport {
                    TransportId = 0,
                    Kind        = Kind.Truck,
                    Location    = Location.Factory
                },
                new ReadyTransport {
                    TransportId = 1,
                    Kind        = Kind.Truck,
                    Location    = Location.Factory
                },
                new ReadyTransport {
                    TransportId = 2,
                    Kind        = Kind.Ship,
                    Location    = Location.Port
                }
            };

            foreach (var cmd in readyTransports)
            {
                await module.DispatchAsync(cmd);
            }

            var time = 1;

            //TODO all delivered as event + projection for loop
            while (!(await module.QueryAsync(new CargoLocationQuery())).Locations.AllDelivered(scenarioCargo.Length))
            {
                await module.DispatchAsync(new AdvanceTime { Time = time });

                time++;
                if (time >= 100)
                {
                    break;
                }
                //throw new TimeoutException("Time over 100");
            }

            var l = (await module.QueryAsync(new CargoLocationQuery())).Locations;
            var b = l.AllDelivered(scenarioCargo.Length);

            Console.WriteLine(l.DrawTable());

            var t = await store.GetAsync <Transport, ITransportEvent>("all");

            Console.WriteLine(t.DrawTable());

            return(time - 1, events.ToArray());
        }
示例#4
0
 public static Module Initialize(IAdvancedEventStore store, Func <IEvent[], Task> pub)
 => new Configuration <TTDModule>((c, p, q, s) => new TTDModule(c, p, q, s))
 .Commands(Commands.GuaranteeCorrelation <ICommand>(),
           cmd => cmd switch
 {
示例#5
0
 public static PaymentModule Initialize(IAdvancedEventStore store, Func <IEvent[], Task> pub)
 => new Configuration <PaymentModule>((c, p, q, s) => new PaymentModule(c, p, q, s))
 .Commands(
     Commands.GuaranteeCorrelation <ICommand>(),
     cmd => ApplicationService.ExecuteAsync(cmd, () => new[] { new PaymentRecieved() }, pub))
 .Triggers(async(events, d) =>