本文整理汇总了C#中Bus类的典型用法代码示例。如果您正苦于以下问题:C# Bus类的具体用法?C# Bus怎么用?C# Bus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bus类属于命名空间,在下文中一共展示了Bus类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Coordinator
public Coordinator(Bus.Attachment.IFactory attachmentFactory, Bus.Object.IFactory objectFactory)
{
_attachmentFactory = attachmentFactory;
_objectFactory = objectFactory;
_objects = new Dictionary<string, Object.Instance>();
}
开发者ID:Zananok,项目名称:Harmonize,代码行数:7,代码来源:Coordinator.cs
示例2: Build
internal static Bus Build(BusBuilderConfiguration configuration)
{
var logger = configuration.Logger;
logger.Debug("Constructing bus...");
var container = new PoorMansIoC();
RegisterPropertiesFromConfigurationObject(container, configuration);
RegisterPropertiesFromConfigurationObject(container, configuration.LargeMessageStorageConfiguration);
RegisterPropertiesFromConfigurationObject(container, configuration.Debugging);
container.Register<Func<NamespaceManager>> (() =>
{
var ns = NamespaceManager.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>());
ns.Settings.OperationTimeout = configuration.DefaultTimeout;
return ns;
});
container.Register<Func<MessagingFactory>>(() =>
{
var messagingFactory = MessagingFactory.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>());
messagingFactory.PrefetchCount = container.Resolve<ConcurrentHandlerLimitSetting>();
return messagingFactory;
});
if (configuration.Debugging.RemoveAllExistingNamespaceElements)
{
var namespaceCleanser = container.Resolve<NamespaceCleanser>();
namespaceCleanser.RemoveAllExistingNamespaceElements().Wait();
}
logger.Debug("Creating message receivers...");
var messageReceiverManager = new MessageRecevierManager(
container.Resolve<CommandMessageReceiverFactory>().CreateAll(),
container.Resolve<MulticastEventMessageReceiverFactory>().CreateAll(),
container.Resolve<CompetingEventMessageReceiverFactory>().CreateAll());
logger.Debug("Message receivers are all created.");
var bus = new Bus(container.Resolve<IZombusLogger>(),
container.Resolve<ICommandSender>(),
container.Resolve<IEventSender>(),
messageReceiverManager,
container.Resolve<DeadLetterQueues>(),
container.Resolve<IHeartbeat>());
bus.Starting += delegate
{
container.Resolve<AzureQueueManager>().WarmUp();
container.Resolve<PropertyInjector>().Bus = bus;
};
bus.Disposing += delegate { container.Dispose(); };
logger.Info("Bus built. Job done!");
return bus;
}
开发者ID:Royal-Jay,项目名称:Zombus,代码行数:60,代码来源:BusBuilder.cs
示例3: Main
public static void Main()
{
BusG.Init ();
Application.Init ();
Button btn = new Button ("Click me");
btn.Clicked += OnClick;
VBox vb = new VBox (false, 2);
vb.PackStart (btn, false, true, 0);
Window win = new Window ("D-Bus#");
win.SetDefaultSize (640, 480);
win.Add (vb);
win.Destroyed += delegate {Application.Quit ();};
win.ShowAll ();
bus = Bus.Session;
string bus_name = "org.ndesk.gtest";
ObjectPath path = new ObjectPath ("/org/ndesk/test");
if (bus.RequestName (bus_name) == RequestNameReply.PrimaryOwner) {
//create a new instance of the object to be exported
demo = new DemoObject ();
bus.Register (path, demo);
} else {
//import a remote to a local proxy
demo = bus.GetObject<DemoObject> (bus_name, path);
}
//run the main loop
Application.Run ();
}
开发者ID:bl8,项目名称:dbus-sharp-glib,代码行数:34,代码来源:TestExport.cs
示例4: Interpolate
public static Point Interpolate(Bus bus, List<Point> path, double timeNow)
{
int lastTime = bus.lastStop.stopMinuteTime;
int nextTime = bus.nextStop.stopMinuteTime;
double fractionComplete = (timeNow - lastTime) / (nextTime - lastTime);
double distanceRequired = bus.lengthOfLeg * fractionComplete;
double finalLineFraction = 0;
bool atThePoint = false;
int i = bus.lastStopIndex;
while (!atThePoint)
{
double lineLength = Distance(path[i], path[i + 1]);
if (lineLength > distanceRequired)
{
atThePoint = true;
finalLineFraction = distanceRequired / lineLength;
}
else
{
distanceRequired -= lineLength;
i++;
}
}
int x = (int)(path[i].X + finalLineFraction * (path[i + 1].X - path[i].X));
int y = (int)(path[i].Y + finalLineFraction * (path[i + 1].Y - path[i].Y));
return new Point((int)x, (int)y);
}
开发者ID:JoelRussell,项目名称:OmniBusWight,代码行数:28,代码来源:Geometry.cs
示例5: Init
public static void Init()
{
var bus = new Bus();
var cashier = new Cashier(bus);
var barista = new Barista(Guid.NewGuid(), bus);
var repository = new SagaRepository<OrderFufillment>(bus);
bus.RouteToSaga(repository, (DrinkOrdered e) => e.OrderId);
bus.RouteToSaga(repository, (DrinkPrepared e) => e.OrderId);
bus.RouteToSaga(repository, (PaymentReceived e) => e.OrderId);
bus.Register<OrderDrink>(c => cashier.Order(c.OrderId, c.Drink));
bus.RegisterOnThreadPool<Pay>(c => cashier.Pay(c.OrderId, PaymentMethod.CreditCard, c.Amount));
bus.RegisterOnThreadPool<PrepareDrink>(c => barista.PrepareDrink(c.OrderId, c.Drink));
bus.Register<NotifyCustomer>(c =>
{
Console.WriteLine("{0} is ready", c.OrderId);
ThreadPool.QueueUserWorkItem(_ => bus.Send(new Pay
{
OrderId =
c.OrderId,
Amount = 12m
}));
});
ServiceLocator.RegisterDispatcher<Command>(bus.Send);
WindowsCommunicationFoundation.RegisterServiceLayer<Sales>();
}
开发者ID:thefringeninja,项目名称:CopyAndPasteMe,代码行数:30,代码来源:Startup.cs
示例6: StartConsumingShouldConsumeAllMessageTypes
public void StartConsumingShouldConsumeAllMessageTypes()
{
// Arrange
var bus = new Bus(_mockConfiguration.Object);
_mockConsumer.Setup(x => x.ConsumeMessageType(It.IsAny<string>()));
var handlerReferences = new List<HandlerReference>
{
new HandlerReference
{
HandlerType = typeof (FakeHandler1),
MessageType = typeof (FakeMessage1)
},
new HandlerReference
{
HandlerType = typeof (FakeHandler2),
MessageType = typeof (FakeMessage2)
}
};
_mockContainer.Setup(x => x.GetHandlerTypes()).Returns(handlerReferences);
_mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.Is<IList<string>>(m => m.Contains(typeof(FakeMessage1).FullName.Replace(".", string.Empty)) && m.Contains(typeof(FakeMessage2).FullName.Replace(".", string.Empty))), It.IsAny<ConsumerEventHandler>(), It.IsAny<IConfiguration>()));
// Act
bus.StartConsuming();
// Assert
_mockContainer.VerifyAll();
_mockConsumerPool.Verify(x => x.AddConsumer(It.IsAny<string>(), It.Is<IList<string>>(m => m.Contains(typeof(FakeMessage1).FullName.Replace(".", string.Empty)) && m.Contains(typeof(FakeMessage2).FullName.Replace(".", string.Empty))), It.IsAny<ConsumerEventHandler>(), It.IsAny<IConfiguration>()), Times.Once);
}
开发者ID:geffzhang,项目名称:ServiceConnect-CSharp,代码行数:31,代码来源:BusTests.cs
示例7: lnkBtnSave_Click
protected void lnkBtnSave_Click(object sender, EventArgs e)
{
string busPlate = BusPlate.Text;
string busName = BusName.Text;
string seat = Seat.Text;
string busTypeId = ddlBusType.SelectedValue.ToString();
string categoryID = ddlCategory.SelectedValue.ToString();
if (BLLBus.checkBusPlateExist(busPlate) != 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "Notify", "alert('!!!Bus Plate existed. Please try again');", true);
}
else
{
Bus bus = new Bus();
bus.BusPlate = busPlate;
bus.BusName = busName;
bus.Seat = Int32.Parse(seat);
bus.BusTypeID = Int32.Parse(busTypeId);
bus.CategoryID = Int32.Parse(categoryID);
bus.Status = true;
BLLBus.InsertBus(bus);
Response.Redirect("BusList.aspx");
}
}
开发者ID:rizkioa,项目名称:ceurape1,代码行数:25,代码来源:BusAdd.aspx.cs
示例8: Given
public virtual async Task Given(ITestHarnessBusFactory busFactory)
{
Bus = (Bus) busFactory.Create();
Console.WriteLine();
Console.WriteLine();
}
开发者ID:shingi,项目名称:Nimbus,代码行数:7,代码来源:TestForAllBuses.cs
示例9: Main
public static void Main()
{
BusG.Init ();
Application.Init ();
Window win = new Window ("D-Bus#");
win.SetDefaultSize (640, 480);
win.Destroyed += delegate {Application.Quit ();};
win.ShowAll ();
bus = Bus.Session;
sysBus = Bus.System.GetObject<IBus> ("org.freedesktop.DBus", new ObjectPath ("/org/freedesktop/DBus"));
string bus_name = "org.ndesk.gtest";
ObjectPath path = new ObjectPath ("/org/ndesk/test");
if (bus.RequestName (bus_name) == RequestNameReply.PrimaryOwner) {
//create a new instance of the object to be exported
demo = new DemoObject ();
sysBus.NameOwnerChanged += demo.FireChange;
bus.Register (path, demo);
} else {
//import a remote to a local proxy
demo = bus.GetObject<DemoObject> (bus_name, path);
}
//run the main loop
Application.Run ();
}
开发者ID:bl8,项目名称:dbus-sharp-glib,代码行数:29,代码来源:TestSystemBus.cs
示例10: CanPublish
public void CanPublish()
{
var mockRepository = new MockRepository();
var config = mockRepository.DynamicMock<IBrokerConfiguration>();
var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
var conn = mockRepository.DynamicMock<IBrokerConnection>();
var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();
var message = new TestMessage();
using (mockRepository.Record())
{
SetupResult.For(consumer.MessageType).Return(typeof(TestMessage));
SetupResult.For(connFactory.CreateConnection()).Return(conn);
SetupResult.For(config.Exchange).Return("ex");
SetupResult.For(config.ConnectionFactory).Return(connFactory);
SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } }); ;
SetupResult.For(conn.IsOpen).Return(true);
Expect.Call(() => conn.Publish<TestMessage>(null))
.IgnoreArguments()
.WhenCalled(mi =>
{
var envelope = mi.Arguments[0];
Assert.IsAssignableFrom(typeof(IMessageEnvelope<TestMessage>), envelope);
Assert.Same(message, ((IMessageEnvelope<TestMessage>)envelope).Message);
});
}
using (mockRepository.Playback())
{
var bus = new Bus(config);
bus.Publish(message);
}
}
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:35,代码来源:BusTests.cs
示例11: ClosesOpenConnectionOnDispose
public void ClosesOpenConnectionOnDispose()
{
var mockRepository = new MockRepository();
var config = mockRepository.DynamicMock<IBrokerConfiguration>();
var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
var conn = mockRepository.DynamicMock<IBrokerConnection>();
var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();
using (mockRepository.Record())
{
SetupResult.For(consumer.MessageType).Return(typeof (TestMessage));
SetupResult.For(connFactory.CreateConnection()).Return(conn);
SetupResult.For(config.ConnectionFactory).Return(connFactory);
SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } });
SetupResult.For(conn.IsOpen).Return(true);
Expect.Call(conn.Close);
}
using (mockRepository.Playback())
{
var bus = new Bus(config);
bus.GetLiveConnection();
bus.Dispose();
}
}
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:26,代码来源:BusTests.cs
示例12: Awake
void Awake()
{
bus = GetComponent<Bus>();
bus.PropertyChanged += OnPropertyChanged;
audio = gameObject.AddComponent<AudioSource>();
}
开发者ID:jabza,项目名称:BusSimulator,代码行数:7,代码来源:AudibleBus.cs
示例13: Connect
public static IBus Connect(DepotSettings settings)
{
if (settings == null)
{
throw new ArgumentNullException("settings");
}
settings.Validate();
var connectionString = settings.ConnectionString;
var connectionFactory = settings.ConnectionFactoryBuilder();
var consumerFactory = settings.ConsumerFactoryBuilder();
var modelFactory = connectionFactory.Create(new Uri(connectionString));
var messageSerializers = settings.MessageSerializers;
var bus = new Bus(
modelFactory,
consumerFactory,
new RequesterFactory(),
new PublisherFactory(messageSerializers),
new SubscriptionFactory(modelFactory, messageSerializers));
foreach (var concern in settings.StartupConcerns)
{
concern.Run(bus);
}
return bus;
}
开发者ID:jamescrowley,项目名称:chinchilla,代码行数:30,代码来源:Depot.cs
示例14: StartMessageShouldCreateANewMessageBusReadStream
public void StartMessageShouldCreateANewMessageBusReadStream()
{
// Arrange
var bus = new Bus(_mockConfiguration.Object);
var mockStream = new Mock<IMessageBusReadStream>();
mockStream.Setup(x => x.HandlerCount).Returns(1);
_mockConsumerPool.Setup(x => x.AddConsumer(It.IsAny<string>(), It.IsAny<IList<string>>(), It.Is<ConsumerEventHandler>(y => AssignEventHandler(y)), It.IsAny<IConfiguration>()));
var mockProcessor = new Mock<IStreamProcessor>();
_mockContainer.Setup(x => x.GetInstance<IStreamProcessor>(It.Is<Dictionary<string, object>>(y => y["container"] == _mockContainer.Object))).Returns(mockProcessor.Object);
mockProcessor.Setup(x => x.ProcessMessage(It.IsAny<FakeMessage1>(), mockStream.Object));
_mockConfiguration.Setup(x => x.GetMessageBusReadStream()).Returns(mockStream.Object);
var message = new FakeMessage1(Guid.NewGuid())
{
Username = "Tim"
};
bus.StartConsuming();
// Act
_fakeEventHandler(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)), typeof(FakeMessage1).AssemblyQualifiedName, new Dictionary<string, object>
{
{ "Start", "" },
{ "SequenceId", Encoding.UTF8.GetBytes("TestSequence") },
{ "SourceAddress", Encoding.UTF8.GetBytes("Source") },
{ "RequestMessageId", Encoding.UTF8.GetBytes("MessageId") },
{ "MessageType", Encoding.UTF8.GetBytes("ByteStream")}
});
// Assert
mockProcessor.Verify(x => x.ProcessMessage(It.IsAny<FakeMessage1>(), It.IsAny<IMessageBusReadStream>()), Times.Once);
}
开发者ID:geffzhang,项目名称:ServiceConnect-CSharp,代码行数:32,代码来源:ProcessStreamMessageTests.cs
示例15: Main
static void Main(string[] args)
{
IBusLog log = new BusLog();
try
{
using (IBus bus = new Bus(@".\private$\testreq", @".\private$\", @".\private$\testack", null, null, log))
{
bus.BusLoggingLevel = BusLoggingLevel.Diagnostic;
bus.RegisterHandler<ARequest, AResponse, AHandler>();
bus.RegisterHandler<BRequest, BResponse, BHandler>();
bus.RegisterHandler<CRequest, CResponse, CHandler>();
bus.RegisterHandler<DRequest, DResponse, DHandler>();
bus.StartListening();
log.Info("Server ready. Press Enter to quit.");
Console.ReadLine();
bus.StopListening();
Console.WriteLine("Total sent: " + bus.TotalSent);
Console.WriteLine("Total received: " + bus.TotalReceived);
Thread.Sleep(5000);
}
}
catch (Exception ex)
{
log.Error(ex);
Thread.Sleep(5000);
}
}
开发者ID:simongoldstone,项目名称:ReallyEasyBus,代码行数:34,代码来源:Program.cs
示例16: Test
public void Test()
{
var bus = new Bus<Int32>();
bus.SendLocal(34);
/* bus.Where(i => i > 100).Subscribe(i =>
{
Console.WriteLine("New Message Arrived {0}", i);
});
var dis = bus.Subscribe(i =>
{
Console.WriteLine("||| New Message Arrived {0}", i);
});*/
bus.SendLocal(346);
bus.Run();
bus.SendLocal(777);
// dis.Dispose();
bus.SendLocal(888);
}
开发者ID:paralect,项目名称:Paralect.ServiceBus,代码行数:28,代码来源:BusTest.cs
示例17: Main
public static void Main()
{
BusG.Init ();
Application.Init ();
btn = new Button ("Click me");
btn.Clicked += OnClick;
VBox vb = new VBox (false, 2);
vb.PackStart (btn, false, true, 0);
Window win = new Window ("D-Bus#");
win.SetDefaultSize (640, 480);
win.Add (vb);
win.Destroyed += delegate {Application.Quit ();};
win.ShowAll ();
bus = Bus.Session;
string bus_name = "org.ndesk.gtest";
ObjectPath path = new ObjectPath ("/org/ndesk/btn");
if (bus.RequestName (bus_name) == RequestNameReply.PrimaryOwner) {
bus.Register (path, btn);
rbtn = btn;
} else {
rbtn = bus.GetObject<Button> (bus_name, path);
}
//run the main loop
Application.Run ();
}
开发者ID:bl8,项目名称:dbus-sharp-glib,代码行数:32,代码来源:TestUI.cs
示例18: RegisterHandlersInAssembly
private static void RegisterHandlersInAssembly(IEnumerable<Assembly> assemblies, Type messageType, Bus.Bus bus, Type[] ctorArgTypes, object[] ctorArgs)
{
//among classes in handlers assemblies select any which handle specified message type
var handlerTypesWithMessages = assemblies
.SelectMany(a => a.GetTypes())
.Where(t => !t.IsInterface && t.GetInterfaces()
.Any(i => i.IsGenericType
&& i.GetGenericTypeDefinition() == typeof(IHandle<>)
&& messageType.IsAssignableFrom(i.GetGenericArguments().First())))
.Select(t => new
{
Type = t,
MessageTypes = t.GetInterfaces().Select(i => i.GetGenericArguments().First())
});
foreach (var handler in handlerTypesWithMessages)
{
var ctor = handler.Type.GetConstructor(ctorArgTypes);
var handlerInstance = ctor.Invoke(ctorArgs);
foreach (Type msgType in handler.MessageTypes)
{
MethodInfo handleMethod = handler.Type
.GetMethods()
.Where(m => m.Name.Equals("Handle", StringComparison.OrdinalIgnoreCase))
.First(m => msgType.IsAssignableFrom(m.GetParameters().First().ParameterType));
Type actionType = typeof(Action<>).MakeGenericType(msgType);
Delegate handlerDelegate = Delegate.CreateDelegate(actionType, handlerInstance, handleMethod);
MethodInfo genericRegister = bus.GetType().GetMethod("RegisterHandler").MakeGenericMethod(new[] { msgType });
genericRegister.Invoke(bus, new[] { handlerDelegate });
}
}
}
开发者ID:MaximShishov,项目名称:EComWithCQRS,代码行数:35,代码来源:MessageHandlersRegister.cs
示例19: CreateStreamShouldCreateAMessageBusWriteStream
public void CreateStreamShouldCreateAMessageBusWriteStream()
{
// Arrange
var mockConfiguration = new Mock<IConfiguration>();
var mockProducer = new Mock<IProducer>();
var mockContainer = new Mock<IBusContainer>();
var mockRequestConfiguration = new Mock<IRequestConfiguration>();
var mockStream = new Mock<IMessageBusWriteStream>();
mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object);
mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);
mockConfiguration.SetupGet(x => x.TransportSettings).Returns(new TransportSettings ());
mockConfiguration.Setup(x => x.GetRequestConfiguration(It.IsAny<Guid>())).Returns(mockRequestConfiguration.Object);
mockConfiguration.Setup(x=> x.GetMessageBusWriteStream(It.IsAny<IProducer>(), "TestEndpoint", It.IsAny<string>(), It.IsAny<IConfiguration>())).Returns(mockStream.Object);
var task = new Task(() => { });
mockRequestConfiguration.Setup(x => x.SetHandler(It.IsAny<Action<object>>())).Returns(task);
var message = new FakeMessage1(Guid.NewGuid())
{
Username = "Tim Watson"
};
mockProducer.Setup(x => x.Send(It.IsAny<string>(), It.IsAny<Type>(), It.IsAny<byte[]>(), It.IsAny<Dictionary<string, string>>())).Callback(task.Start);
// Act
var bus = new Bus(mockConfiguration.Object);
// Act
var stream = bus.CreateStream("TestEndpoint", message);
// Assert
Assert.NotNull(stream);
Assert.Equal(mockStream.Object, stream);
}
开发者ID:geffzhang,项目名称:ServiceConnect-CSharp,代码行数:34,代码来源:CreateStreamTests.cs
示例20: Painter_should_paint_bus_with_given_color
public void Painter_should_paint_bus_with_given_color()
{
var painter = new Painter();
var bus = new Bus("REG");
painter.Paint(bus, Color.HotPink);
Assert.AreEqual(Color.HotPink, bus.Color);
}
开发者ID:JAkerblom,项目名称:FFCG.JAkerblom.Movies,代码行数:8,代码来源:PainterTests.cs
注:本文中的Bus类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论