Exemplo n.º 1
0
        public static (int, IEvent[]) Run(params string[] scenarioCargo)
        {
            var cargo = scenarioCargo
                        .Select((x, i) =>
                                new Cargo(i, Location.Factory, (Location)Enum.Parse(typeof(Location), x, true))).ToArray();

            var locations = new[]
            {
                new CargoLocation(Location.Factory, cargo),
                new CargoLocation(Location.Port),
                new CargoLocation(Location.A),
                new CargoLocation(Location.B),
            };

            var routes = Route.GetRoutes();

            var transports = new[]
            {
                new Transport(0, Kind.Truck, Location.Factory),
                new Transport(1, Kind.Truck, Location.Factory),
                new Transport(2, Kind.Ship, Location.Port)
            };

            var events = Array.Empty <IEvent>();

            Console.Write(events.GetCargoLocations(locations).DrawTable());

            var time = 0;

            while (!events.GetCargoLocations(locations).AllDelivered(cargo.Length))
            {
                events = events.Append(events.GetTransports(transports).Unload(time).ToArray().ToEnvelopes(x => x.TransportId.ToString()));
                events = events.Append(Load(time, events.GetCargoLocations(locations), events.GetTransports(transports), routes).ToArray().ToEnvelopes(x => x.TransportId.ToString()));
                events = events.Append(events.GetTransports(transports).Return(time, routes).ToArray().ToEnvelopes(x => x.TransportId.ToString()));

                time++;
            }

            Console.Write(events.GetTransports(transports).DrawTable());
            Console.Write(events.GetCargoLocations(locations).DrawTable());

            new FileSystemEventStore("teststore", TypeResolver.Default())
            .AppendToStreamAsync("main", events.Select(e => e.Tap(x => x.Meta.AddTypeInfo(e))).ToArray())
            .GetAwaiter().GetResult();

            return(time - 1, events.ToArray());
        }