static void Main() { //IContainer c = BootstrapContainer(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); NodeContext nc = null; NodeRecord rec = new NodeRecord(); string host = "localhost"; bool tryConnect = false; var connectForm = new ConnectForm(); connectForm.FormClosing += (s, ea) => { try { rec.NodeId = connectForm.NodeId; rec.OrgNodeId = -1; rec.QueueBaseName = connectForm.AppName; rec.QueueTransportSettings = TransportSettings.UseRabbitMq(connectForm.Host); host = connectForm.Host; tryConnect = true; } catch (Exception ex) { ea.Cancel = true; MessageBox.Show(connectForm, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }; Application.Run(connectForm); if (connectForm.DialogResult != DialogResult.Cancel && tryConnect) { connectForm = null; var bus = ServiceBusFactory.New(sbc => { sbc.ReceiveFrom(rec.QueueUri); sbc.UseControlBus(); rec.QueueTransportSettings.ApplyGlobalConfig(sbc); }); // We got a node context, yay. // Launch a service which takes care of traffix, and provide some // means for the ClientForm to xommunixate with that service: var clientForm = new ClientForm(rec, bus); //LaunchMessageService(nc, svc => //{ Application.Run(clientForm); nc.Dispose(); //}); } }
public static NodeContext ConnectNode(string host, NodeRecord node, Func<object, object> transportSpecificQueueNameTranslator, Action<ServiceBusConfigurator> customBusConfiguration = null) { transportSpecificQueueNameTranslator = transportSpecificQueueNameTranslator ?? MsmqTransportTranslator; dynamic queueSpecs = transportSpecificQueueNameTranslator(new { Format = "uri", Host = host, NodeRecord = node }); Uri receiveFromUri = new Uri(queueSpecs.Uri); Action<ServiceBusConfigurator> sbcOps = queueSpecs.SBCAdjustments; TransportSettings ts = new TransportSettings { PrimaryHost = host, ProtocolUriPrefix = queueSpecs.Prefix }; var serviceBus = ServiceBusFactory.New(sbc => { sbc.ReceiveFrom(receiveFromUri); sbcOps(sbc); sbc.UseControlBus(); //sbc.EnableRemoteIntrospection(); if (customBusConfiguration != null) customBusConfiguration(sbc); }); return new NodeContext { Record = node, Bus = serviceBus, QueueName = queueSpecs.QueueName, Settings = ts }; }