public void Subscription_push_can_be_dispatched_on_designated_thread_blocking_scenario()
        {
            var  threadId         = -2;
            var  threadIdFromTest = -1;
            IBus bus = null;

            var resetEvent = new ManualResetEvent(false);

            var uiThread = new Thread(
                () =>
            {
                var sync  = Helpers.CreateDispatchContext();
                var frame = new DispatcherFrame();
                threadId  = Thread.CurrentThread.ManagedThreadId;
                bus       = BusSetup.StartWith <RichClientFrontend>().Construct();
                bus.Observe <MessageB>().ObserveOn(sync).Subscribe(msg =>
                {
                    threadIdFromTest = Thread.CurrentThread.ManagedThreadId;
                    frame.Continue   = false;
                });
                resetEvent.Set();
                Dispatcher.PushFrame(frame);
            });

            uiThread.Start();
            resetEvent.WaitOne();
            bus.Publish(new MessageB());
            uiThread.Join();
            threadIdFromTest.ShouldBeEqualTo(threadId);
        }
 public MemBusAdapter(IocAdapter iocAdapter)
 {
     this.memBus =
         BusSetup.StartWith <AsyncConfiguration>()
         .Apply <IoCSupport>(s => s.SetAdapter(iocAdapter).SetHandlerInterface(typeof(IHandle <>)))
         .Construct();
 }
示例#3
0
        public void A_shape_gets_access_to_services()
        {
            var testShaper = new TestShaper("Test");

            BusSetup.StartWith <Conservative>(new BusSetupPutShapeOnMsgA(testShaper)).Construct();
            testShaper.Services.ShouldNotBeNull();
        }
示例#4
0
        private static IBus ConstructBus(AppModel model)
        {
            var setup = BusSetup.StartWith <Conservative>();

            setup.Apply(model.MemBusSetups.ToArray());
            return(setup.Construct());
        }
示例#5
0
 public IntegrationScenarioInteractionWithSubscriber()
 {
     _bus = BusSetup.StartWith <Conservative>()
            .Apply <FlexibleSubscribeAdapter>(a => a.RegisterMethods("Handle"))
            .Apply <BlockSpecialsIfsuspended>()
            .Construct();
 }
示例#6
0
        public void Exceptions_are_made_available_as_messages()
        {
            var evt = new ManualResetEvent(false);
            ExceptionOccurred capturedMessage = null;
            var bus = BusSetup.StartWith <AsyncConfiguration>().Construct();

            bus.Subscribe <MessageB>(msg =>
            {
                throw new ArgumentException("Bad message");
            });
            bus.Subscribe <ExceptionOccurred>(x =>
            {
                capturedMessage = x;
                evt.Set();
            });

            bus.Publish(new MessageB());
            var signaled = evt.WaitOne(TimeSpan.FromSeconds(2));

            if (!signaled)
            {
                Assert.Fail("Exception was never captured!");
            }

            capturedMessage.Exception.ShouldBeOfType <AggregateException>();
            var xes = ((AggregateException)capturedMessage.Exception).InnerExceptions;

            xes[0].ShouldBeOfType <ArgumentException>();
            xes[0].Message.ShouldBeEqualTo("Bad message");
        }
示例#7
0
        public static void Main(string[] args)
        {
            var bus = BusSetup.StartWith <Conservative>()
                      .Apply <FlexibleSubscribeAdapter>(a =>
            {
                a.ByInterface(typeof(IEventHandler <>));
                a.ByInterface(typeof(ICommandHandler <>));
            }).Construct();

            var someAwesomeUi = new SomeAwesomeUi(bus);

            using (store = WireupEventStore(bus))
            {
                var repository = new EventStoreRepository(store, new AggregateFactory(), new ConflictDetector());

                var handler  = new CreateAccountCommandHandler(repository);
                var handler2 = new CloseAccountCommandHandler(repository);
                bus.Subscribe(handler);
                bus.Subscribe(handler2);
                bus.Subscribe(new KaChingNotifier());
                bus.Subscribe(new OmgSadnessNotifier());

                someAwesomeUi.CreateNewAccount(AggregateId, "Luiz", "@luizdamim");
                someAwesomeUi.CloseAccount(AggregateId);
            }

            Console.ReadLine();
        }
        /// <summary>
        /// </summary>
        /// <param name="zoneServer">
        /// </param>
        /// <param name="playfieldIdentity">
        /// </param>
        public Playfield(ZoneServer zoneServer, Identity playfieldIdentity)
            : base(Identity.None, playfieldIdentity)
        {
            this.server       = zoneServer;
            this.playfieldBus = BusSetup.StartWith <AsyncConfiguration>().Construct();

            this.memBusDisposeContainer.Add(
                this.playfieldBus.Subscribe <IMSendAOtomationMessageToClient>(SendAOtomationMessageToClient));
            this.memBusDisposeContainer.Add(
                this.playfieldBus.Subscribe <IMSendAOtomationMessageToPlayfield>(this.SendAOtomationMessageToPlayfield));
            this.memBusDisposeContainer.Add(
                this.playfieldBus.Subscribe <IMSendAOtomationMessageToPlayfieldOthers>(
                    this.SendAOtomationMessageToPlayfieldOthers));
            this.memBusDisposeContainer.Add(
                this.playfieldBus.Subscribe <IMSendAOtomationMessageBodyToClient>(this.SendAOtomationMessageBodyToClient));
            this.memBusDisposeContainer.Add(
                this.playfieldBus.Subscribe <IMSendAOtomationMessageBodiesToClient>(
                    this.SendAOtomationMessageBodiesToClient));
            this.memBusDisposeContainer.Add(this.playfieldBus.Subscribe <IMSendPlayerSCFUs>(this.SendSCFUsToClient));
            this.memBusDisposeContainer.Add(this.playfieldBus.Subscribe <IMExecuteFunction>(this.ExecuteFunction));
            this.heartBeat = new Timer(this.HeartBeatTimer, null, 10, 0);

            this.statels = PlayfieldLoader.PFData[this.Identity.Instance].Statels;
            this.LoadMobSpawns(playfieldIdentity);
            this.LoadVendors(playfieldIdentity);
            this.LoadStaticDynels(playfieldIdentity);
        }
示例#9
0
 public static BusSetup UseAutofac(this BusSetup setup, ILifetimeScope componentContext)
 {
     setup.AddService <IComponentContext>(componentContext);
     setup.AddService <ILifetimeScope>(componentContext);
     setup.AddService <IServiceContainer>(c => new ScopeServiceContainer(componentContext, c));
     return(setup);
 }
示例#10
0
        /// <summary>
        /// </summary>
        public ZoneServer()
        {
            // TODO: Get the Server id from chatengine or config file
            this.Id = 0x356;
            this.ClientDisconnected += this.ZoneServerClientDisconnected;

            // New Bus initialization
            this.zoneBus = BusSetup.StartWith <AsyncConfiguration>().Construct();

            this.subscribedMessageHandlers.Clear();

            IEnumerable <Type> types =
                Assembly.GetExecutingAssembly()
                .GetTypes()
                .Where(
                    x =>
                    x.GetCustomAttributes(typeof(MessageHandlerAttribute), false)
                    .Any(
                        y => ((MessageHandlerAttribute)y).Direction != MessageHandlerDirection.OutboundOnly));

            MethodInfo subscriptMethodInfo = typeof(ZoneServer).GetMethod(
                "SubscribeMessage",
                BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (Type type in
                     types)
            {
                Type[]     temp    = type.BaseType.GetGenericArguments();
                MethodInfo generic = subscriptMethodInfo.MakeGenericMethod(new Type[] { temp[1], temp[0] });
                generic.Invoke(this, null);
            }
            this.CheckSubscribedMessageHandlers();
        }
示例#11
0
 public When_Using_Ioc_Support()
 {
     _testAdapter = new TestAdapter();
     _bus         = BusSetup
                    .StartWith <Conservative>()
                    .Apply <IoCSupport>(s => s.SetAdapter(_testAdapter).SetHandlerInterface(typeof(GimmeMsg <>)))
                    .Construct();
 }
示例#12
0
        // Test for https://github.com/flq/MemBus/issues/17
        public void Large_number_of_subscribers()
        {
            var b = BusSetup.StartWith <AsyncConfiguration>().Construct();

            for (var i = 0; i < 100000; i++)
            {
                b.Subscribe((int x) => Console.WriteLine(x));
            }
        }
示例#13
0
        public void Resolvers_will_get_access_to_services()
        {
            var simpleResolver = new SimpleResolver();

            using (BusSetup.StartWith <Conservative>(cb => cb.AddResolver(simpleResolver)).Construct())
            {
                simpleResolver.Services.ShouldNotBeNull();
            }
        }
示例#14
0
        public void A_disposed_bus_throws()
        {
            var bus = BusSetup.StartWith <Conservative>().Construct();

            bus.Dispose();
            (new Action(() => bus.Publish(new MessageA()))).Throws <ObjectDisposedException>();
            (new Action(() => bus.Subscribe <MessageA>(msg => {}))).Throws <ObjectDisposedException>();
            (new Action(() => bus.Observe <MessageA>())).Throws <ObjectDisposedException>();
        }
示例#15
0
文件: Store.cs 项目: TAGC/AsyncRedux
 /// <inheritdoc />
 public Store(
     [NotNull] Reducer <TState> reducer,
     [CanBeNull] TState initialState,
     [NotNull][ItemNotNull] IEnumerable <Middleware <TState> > middleware)
 {
     _reducer    = reducer;
     _dispatcher = CreateDispatcher(middleware);
     _bus        = BusSetup.CreateBus();
     State       = initialState;
 }
示例#16
0
 public When_Using_Ioc_Support_With_Type_Resolver()
 {
     _testAdapter = new TestAdapter();
     _bus         = BusSetup
                    .StartWith <Conservative>()
                    .Apply <IoCSupport>(s => s.SetAdapter(_testAdapter).SetHandlerInterface(typeof(GimmeMsgTypeResolver <>))
                                        .SetMessageTypeResolver(msgT => msgT.GenericTypeArguments[0]) // unwrap from envelope
                                        )
                    .Construct();
 }
示例#17
0
        public void The_default_is_applied_when_no_specials_apply()
        {
            var sb  = new StringBuilder();
            var bus = BusSetup.StartWith <Conservative>(new BusSetupWithDefaultShape(sb)).Construct();

            using (bus.Subscribe <MessageA>(msg => { }))
                bus.Publish(new MessageA());

            sb.ToString().ShouldBeEqualTo("Bar");
        }
示例#18
0
 public void fail_with_bad_types(Type handlerType)
 {
     Assert.Throws <ArgumentException>(() =>
                                       BusSetup
                                       .StartWith <Conservative>()
                                       .Apply <IoCSupport>(s => s
                                                           .SetAdapter(_testAdapter)
                                                           .SetHandlerInterface(handlerType))
                                       .Construct());
 }
示例#19
0
        public void Conventions_allow_changing_the_shape()
        {
            var sb  = new StringBuilder();
            var bus = BusSetup.StartWith <Conservative>(new BusSetupWithTestShapers(sb)).Construct();

            using (bus.Subscribe <MessageB>(msg => { }))
                bus.Publish(new MessageB());

            sb.ToString().ShouldBeEqualTo("AB");
        }
示例#20
0
        public async Task using_the_awaitable_publish()
        {
            var b = BusSetup.StartWith <Conservative>().Construct();
            var messageReceived = false;

            b.Subscribe((string h) => messageReceived = true);
            await b.PublishAsync("Hello");

            Assert.True(messageReceived);
        }
示例#21
0
        public void default_pubish_pipeline_is_replaceable()
        {
            var t = new PublishPipelineTester <MessageB>();
            var b = BusSetup.StartWith <Conservative>()
                    .Apply(cb => cb.ConfigurePublishing(cp => cp.DefaultPublishPipeline(t.Mock1Object)))
                    .Construct();

            b.Publish(new MessageB());

            t.Mock1.VerifyCalled();
        }
示例#22
0
        public void Default_setup_provides_subscription_shape()
        {
            var received = 0;
            var b        = BusSetup.StartWith <Conservative>().Construct();

            using (b.Subscribe <MessageA>(msg => received++))
            {
                b.Publish(new MessageA());
                received.ShouldBeEqualTo(1);
            }
        }
示例#23
0
        private static void Main()
        {
            var bus = BusSetup.StartWith <Fast>().Construct();
            var s   = new CompositeSubscriptionPerformanceTest();

            for (var i = 0; i < 10; i++)
            {
                Run(s, bus);
            }
            Console.ReadLine();
        }
示例#24
0
        public void A_disposed_subscription_is_gone()
        {
            int received = 0;
            var bus      = BusSetup.StartWith <Conservative>().Construct();
            var d        = bus.Subscribe <MessageA>(msg => received++);

            bus.Publish(new MessageA());
            received.ShouldBeEqualTo(1);
            d.Dispose();
            bus.Publish(new MessageA());
            received.ShouldBeEqualTo(1);
        }
示例#25
0
        public void Default_setup_routes_the_message_correctly()
        {
            var sub = new SubscriptionThatFakesHandles <MessageA>();

            var b = BusSetup
                    .StartWith <Conservative>(cb => cb.AddSubscription(sub))
                    .Construct();
            var messageA = new MessageA();

            b.Publish(messageA);
            sub.PushCalls.ShouldBeEqualTo(1);
        }
示例#26
0
        public Unexpected_Disposal_Of_Subscriptions()
        {
            _bus = BusSetup.StartWith <Conservative>()
                   .Apply <FlexibleSubscribeAdapter>(adp => adp.RegisterMethods("Handle"))
                   .Construct();
            _bus.Subscribe(_partnerInCrime1 = new Subscriber());
            _bus.Subscribe(_partnerInCrime2 = new Subscriber());

            // One disposes the other. That way we keep independent of call sequence
            _partnerInCrime1.Aquaint(_partnerInCrime2);
            _partnerInCrime2.Aquaint(_partnerInCrime1);
        }
示例#27
0
        public static ILifetimeScope Build()
        {
            var builder = new ContainerBuilder();

            builder.Register(c =>
            {
                var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113));
                connection.Connect();
                return(connection);
            }).As <IEventStoreConnection>().SingleInstance();

            builder.Register(c =>
            {
                var context = c.Resolve <IComponentContext>();
                return(BusSetup.StartWith <Conservative>()
                       .Apply <IoCSupport>(s => s.SetAdapter(new AutofacAdaptor(context)).SetHandlerInterface(typeof(IConsume <>)))
                       .Construct());
            }).As <IBus>();

            builder.Register(x =>
            {
                var client = new MongoClient("mongodb://localhost");
                return(client.GetServer());
            }).As <MongoServer>().SingleInstance();

            builder.Register(x => x.Resolve <MongoServer>().GetDatabase("Risk"))
            .As <MongoDatabase>()
            .InstancePerDependency();



            builder.RegisterAssemblyTypes(typeof(IConsume <>).Assembly, Assembly.GetExecutingAssembly()).AsClosedTypesOf(typeof(IConsume <>));

            builder.RegisterType <GetEventStoreRepository>().As <IRepository>();

            builder.RegisterType <AcceptInvitationHandler>().As <ICommandHandler <AcceptInvitation> >();
            builder.RegisterType <CreateLobbyHandler>().As <ICommandHandler <CreateLobby> >();
            builder.RegisterType <InvitePlayerHandler>().As <ICommandHandler <InvitePlayer> >();
            builder.RegisterType <LeaveLobbyHandler>().As <ICommandHandler <LeaveLobby> >();
            builder.RegisterType <StartGameHandler>().As <ICommandHandler <StartGame> >();

            builder.RegisterType <StartGameSetupHandler>().As <ICommandHandler <StartGameSetup> >();
            builder.RegisterType <PlaceInfantryUnitHandler>().As <ICommandHandler <PlaceInfantryUnit> >();

            builder.RegisterType <AutofacCommandHandlerResolver>().As <ICommandHandlerResolver>();

            builder.RegisterType <CommandDispatcher>().AsSelf();

            var container = builder.Build();

            return(container);
        }
 public FlexibleSubscribingIntegrationContext()
 {
     Bus = BusSetup
           .StartWith <Conservative>()
           .Apply <FlexibleSubscribeAdapter>(ConfigureAdapter)
           .Construct();
     Bus.Subscribe <object>(MessageCapturing);
     foreach (var endpoints in GetEndpoints())
     {
         Bus.Subscribe(endpoints);
     }
     AdditionalSetup();
 }
示例#29
0
        public void Using_shape_overload_directly_works()
        {
            var b       = BusSetup.StartWith <Conservative>().Construct();
            var counter = 0;

            using (var d = b.Subscribe((string s) => counter++, new ShapeToFilter <string>(s => s == "A")))
            {
                d.ShouldNotBeNull();
                b.Publish("A");
                b.Publish("B");
            }
            counter.ShouldBeEqualTo(1);
        }
示例#30
0
 /// <summary>
 /// </summary>
 public Playfield()
 {
     this.playfieldBus = BusSetup.StartWith <AsyncConfiguration>().Construct();
     this.memBusDisposeContainer.Add(
         this.playfieldBus.Subscribe <IMSendAOtMessageToClient>(SendAOtMessageToClient));
     this.memBusDisposeContainer.Add(
         this.playfieldBus.Subscribe <IMSendAOtMessageToPlayfield>(this.SendAOtMessageToPlayfield));
     this.memBusDisposeContainer.Add(
         this.playfieldBus.Subscribe <IMSendAOtMessageToPlayfieldOthers>(this.SendAOtMessageToPlayfieldOthers));
     this.memBusDisposeContainer.Add(
         this.playfieldBus.Subscribe <IMSendAOtMessageBodyToClient>(this.SendAOtMessageBodyToClient));
     this.memBusDisposeContainer.Add(this.playfieldBus.Subscribe <IMSendPlayerSCFUs>(this.SendSCFUsToClient));
     this.memBusDisposeContainer.Add(this.playfieldBus.Subscribe <IMExecuteFunction>(this.ExecuteFunction));
     this.Entities = new HashSet <IInstancedEntity>();
 }