예제 #1
0
        private IStartableMessageBus Build() {
            var messageTypes = MessageTypeConventions.ScanAssembliesForMessageTypes(assembliesToScan);
            var messageMapper = new MessageMapper();
            messageMapper.SetMessageTypeConventions(this.MessageTypeConventions);
            messageMapper.Initialize(messageTypes);
            var allMessageTypes = messageTypes.Concat(messageMapper.DynamicTypes);

            MessageSerializer = new XmlMessageSerializer(messageMapper);
            (MessageSerializer as XmlMessageSerializer).Initialize(messageTypes);

            this.MessageHandlers.AddAssembliesToScan(assembliesToScan);
            this.MessageHandlers.Init();
            if (executeTheseHandlersFirst.Any())
                this.MessageHandlers.ExecuteTheseHandlersFirst(executeTheseHandlersFirst);
            if (executeTheseHandlersLast.Any())
                this.MessageHandlers.ExecuteTheseHandlersLast(executeTheseHandlersLast);

            // Get endpoint mapping
            foreach (MessageEndpointMapping mapping in this.MessageEndpointMappingCollection) {
                try {
                    var messageType = Type.GetType(mapping.Messages, false);
                    if (messageType != null && MessageTypeConventions.IsMessageType(messageType))
                    {
                        typesToEndpoints[messageType] = mapping.Endpoint.Trim();
                        continue;
                    }
                } catch (Exception ex) {
                    Logger.Error("Problem loading message type: " + mapping.Messages, ex);
                }

                try {
                    var a = Assembly.Load(mapping.Messages);
                    foreach (var t in a.GetTypes().Where(t => MessageTypeConventions.IsMessageType(t)))
                        typesToEndpoints[t] = mapping.Endpoint.Trim();
                } catch (Exception ex) {
                    throw new ArgumentException("Problem loading message assembly: " + mapping.Messages, ex);
                }

            }

            var transport = TransportBuilder.Build();

            var messageDispatcher = new MessageDispatcher(ServiceLocator, this.MessageHandlers);
            var messageBus = new UnicastMessageBus(messageMapper, transport, messageDispatcher);
            messageBus.MapMessageTypesToAddress(typesToEndpoints);

            var performanceCounters = new PerformanceCounters();
            messageBus.MessageReceived += performanceCounters.OnMessageReceived;
            messageBus.MessageSent += performanceCounters.OnMessageSent;
            messageBus.MessageFailed += performanceCounters.OnMessageFailure;
            messageBus.MessageHandled += performanceCounters.OnMessageHandled;

            return messageBus;
        }
예제 #2
0
        public static void Main(string[] args)
        {
            var showHelp  = false;
            var install   = false;
            var uninstall = false;
            var test      = false;
            var p         = new OptionSet();

            p.Add("h|help|?", "Displays This", v => showHelp = true);
            p.Add("i|install", "Installs the Perf Counters", v => install           = true);
            p.Add("u|uninstall", "Installs the Perf Counters", v => uninstall       = true);
            p.Add("t|test", "Tests That The Perf Counters Are Installed", v => test = true);
            p.Parse(args);

            if (showHelp)
            {
                p.WriteOptionDescriptions(Console.Out);
                return;
            }

            if (install)
            {
                PerformanceCounters.InstallCounters();
                return;
            }

            if (uninstall)
            {
                PerformanceCounters.UninstallCounters();
                return;
            }

            if (test)
            {
                Debug.Assert(PerformanceCounterCategory.Exists(PerformanceCounters.CategoryName), "Performance Counter Category Is NOT Installed");
                Debug.Assert(PerformanceCounterCategory.CounterExists(PerformanceCounters.TotalMessagesReceived, PerformanceCounters.CategoryName), "Performance Counter Is NOT Installed");
                return;
            }
        }