本文整理汇总了C#中Bus类的典型用法代码示例。如果您正苦于以下问题:C# Bus类的具体用法?C# Bus怎么用?C# Bus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bus类属于命名空间,在下文中一共展示了Bus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Coordinator
public Coordinator(Bus.Attachment.IFactory attachmentFactory, Bus.Object.IFactory objectFactory)
{
_attachmentFactory = attachmentFactory;
_objectFactory = objectFactory;
_objects = new Dictionary<string, Object.Instance>();
}
示例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;
}
示例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 ();
}
示例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);
}
示例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>();
}
示例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);
}
示例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");
}
}
示例8: Given
public virtual async Task Given(ITestHarnessBusFactory busFactory)
{
Bus = (Bus) busFactory.Create();
Console.WriteLine();
Console.WriteLine();
}
示例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 ();
}
示例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);
}
}
示例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();
}
}
示例12: Awake
void Awake()
{
bus = GetComponent<Bus>();
bus.PropertyChanged += OnPropertyChanged;
audio = gameObject.AddComponent<AudioSource>();
}
示例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;
}
示例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);
}
示例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);
}
}