コード例 #1
0
ファイル: Program.cs プロジェクト: barbatron/converge
        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();
                //});
            }
        }
コード例 #2
0
        public static void Main()
        {
            Log4NetLogger.Use(@"D:\code\net\Converge\log4net.xml");

            var transportSettings = TransportSettings.UseRabbitMq("localhost");
            var container         = BootstrapContainer(transportSettings, "converge_centralmon");

            var appSubscribers = new CompositeSubscriber();

            //appSubscribers.RegisterSubscribers(container.GetAllInstances<IDisposableSubscriber>());

            // Roll out a service actnig as the primary app grunks
            HostFactory.Run(c =>
            {
                c.SetServiceName("ConvergeCMon");
                c.SetDisplayName("Converge Central monitor");
                c.SetDescription("Converge node activity monitor.");

                c.RunAsLocalSystem();

                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

                c.Service <MonitorService>(s =>
                {
                    s.ConstructUsing(builder => container.GetInstance <MonitorService>());
                    s.WhenStarted(o => o.Start());
                    s.WhenStopped(o => o.Stop());
                });
            });
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: barbatron/converge
        static void Main(string[] args)
        {
            try
            {
                TransportSettings ts = TransportSettings.UseRabbitMq("localhost");
                int    saltNumber    = new Random().Next(1000, 10000);
                string appName       = string.Format("cclient_{0}", saltNumber);

                var bus = ServiceBusFactory.New(sbc =>
                {
                    sbc.ReceiveFrom(ts.GetQueueUri(appName));
                    sbc.UseControlBus();

                    ts.ApplyGlobalConfig(sbc);
                });

                bus.PublishRequest(new NodeSetupRequest
                {
                    NodeId                   = appName,
                    CorrelationId            = CombGuid.Generate(),
                    NqApplicationId          = 1000,
                    NqInstanceNumber         = 0,
                    NqApplicationVersionInfo = "1.0.0.0"
                }, x =>
                {
                    x.HandleTimeout(TimeSpan.FromSeconds(10d), () =>
                    {
                        Console.WriteLine("Node setup request timed out - please ensure server connectivity and try again.");
                        throw new TimeoutException();
                    });
                    x.HandleFault(fault =>
                    {
                        Console.WriteLine("Node setup request total error.");
                        throw new IOException();
                    });
                    x.Handle <NodeSetupResponse>(msg =>
                    {
                        Console.WriteLine("Got NodeSetupResponse: " + msg.ToString());
                        x.SetTimeout(TimeSpan.FromSeconds(30));
                    });
                });

                using (var ms = new MessageSubscriber(bus))
                {
                    ms.Subscribe();
                    Console.WriteLine("Waiting for messages. Press Escape to exit.");

                    while (Console.ReadKey().Key != ConsoleKey.Escape)
                    {
                        Thread.Sleep(10);
                    }
                }

                bus.Dispose();
            }
            catch (TimeoutException)
            { }
            catch (IOException) { }
        }