当前位置: 首页>>代码示例>>C#>>正文


C# Bus.Subscribe方法代码示例

本文整理汇总了C#中Bus.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# Bus.Subscribe方法的具体用法?C# Bus.Subscribe怎么用?C# Bus.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bus的用法示例。


在下文中一共展示了Bus.Subscribe方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EventTest

        public void EventTest()
        {
            var bus = new Bus(null, new HandlerRegistry());
            int called = 0;
            bus.Subscribe<WidgetCreatedEvent>((x) => called++);

            bus.Subscribe<WidgetCreatedEvent>((x) => called++);

            bus.Publish(new WidgetCreatedEvent());
            Assert.AreEqual(2, called);
        }
开发者ID:adbrowne,项目名称:Samples,代码行数:11,代码来源:BusTests.cs

示例2: When_testing_something

    public void When_testing_something()
    {
        var bus1 = new Bus();

            bus1.Subscribe("first", x => _output.WriteLine("Bus1 => ({0}) => {1}", "first", x.Json));
            bus1.Subscribe("second", x => _output.WriteLine("Bus1 => ({0}) => {1}", "second", x.Json));

            var bus2 = new Bus();

            bus2.Subscribe("first", x => _output.WriteLine("Bus2 => ({0}) => {1}", "first", x.Json));
            bus2.Subscribe("second", x => _output.WriteLine("Bus2 => ({0}) => {1}", "second", x.Json));

            var exchange = new Exchange();
            exchange.AddBus(bus1);
            exchange.AddBus(bus2);

            bus1.Publish("first", new Message { Json = "a message"});
    }
开发者ID:Pondidum,项目名称:InProcessMicroServices,代码行数:18,代码来源:notes.cs

示例3: WithBus

        public static ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator WithBus(
            this ConfigurableBootstrapper.ConfigurableBootstrapperConfigurator configure)
        {
            var bus = new Bus();
            var messages = new Collection<Message>();

            typeof (Message).Assembly.GetTypes().Union(typeof(Extensions).Assembly.GetTypes())
                            .Where(typeof (Message).IsAssignableFrom)
                            .Where(type => false == type.IsAbstract && type.IsClass)
                            .ForEach(messageType => bus.Subscribe(messageType, new AdHocHandler<Message>(
                                m =>
                                {
                                    messages.Add(m);
                                })));

            configure.ApplicationStartup(
                (_, pipelines) => pipelines.AfterRequest.AddItemToStartOfPipeline(
                    context => { context.Items[SystemUnderTest.MessagesKey] = messages; }));
            
            return configure.Dependency(bus);
        }
开发者ID:jbrahy,项目名称:derp.sales,代码行数:21,代码来源:Extensions.cs

示例4: Main

        static void Main(string[] args)
        {
            var bus = new Bus(new Dispatcher.Dispatcher());
            var printers = new[] { new Printer(bus, 1), new Printer(bus, 2), new Printer(bus, 3), new Printer(bus, 4) };

            var printerPool = printers
                .Select(printer => new WideningHandler<PrintJob, Message>(printer))
                .Select(printer => new QueuedHandler(printer, bus) { MaxQueueLength = 1 })
                .ToArray();

            var refillPool = printers
                .Select(printer => new WideningHandler<RefillPaper, Message>(printer))
                .Select(printer => new QueuedHandler(printer, bus) { MaxQueueLength = 1 })
                .ToArray();

            foreach (var printer in refillPool)
            {
                bus.Subscribe<RefillPaper>(new NarrowingHandler<RefillPaper, Message>(printer));
                // subscribe the printer directly to RefillPaper as we don't want to distribute that with the print jobs
            }

            var office = Enumerable.Range(0, 50)
                .Select(i => new Employee(bus, i))
                .ToArray();

            var loadBalancer = new RoundRobinLoadBalancer(printerPool);
            var printerRetryHandler = new RetryHandler(loadBalancer, bus);
            var retryManager = new RetryManager(bus);
            var timerService = new TimerService(bus);

            bus.Subscribe<FutureMessage>(timerService);
            bus.Subscribe<RetryMessage>(retryManager);
            bus.Subscribe<SuccessMessage>(retryManager);

            bus.Subscribe(new NarrowingHandler<PrintJob, Message>(printerRetryHandler));

            var console = new QueuedHandler(new WideningHandler<LogMessage, Message>(new ConsoleHandler()), bus);
            bus.Subscribe<LogMessage>(new NarrowingHandler<LogMessage, Message>(console));

            var porter = new Porter(bus);
            bus.Subscribe(porter);

            var converter = new LogConverter(bus);
            bus.Subscribe<PrintJob>(converter);
            bus.Subscribe<OutOfPaper>(converter);
            bus.Subscribe<PagePrinted>(converter);
            bus.Subscribe<RetryMessage>(converter);
        }
开发者ID:TWolverson,项目名称:Dispatcher,代码行数:48,代码来源:Program.cs


注:本文中的Bus.Subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。