private static void RegisterMessageQueueListeners()
        {
            var messageQueue = IocContainer.Resolve <IMessageQueue>();

            RegisterMessageQueueListeners <UpdateVariableMessage>(messageQueue);
            RegisterMessageQueueListeners <CommandMessage>(messageQueue);
            RegisterMessageQueueListeners <NotifyUserMessage>(messageQueue);
            RegisterMessageQueueListeners <ExecuteScriptMessage>(messageQueue);
            RegisterMessageQueueListeners <NetworkDeviceFoundMessage>(messageQueue);
        }
        public static IDisposable Run()
        {
            DbMigrator.Run();
            IocContainer.Build();
            RegisterMessageQueueListeners();

            var gateways          = IocContainer.Resolve <IList <IGateway> >();
            var networkScanners   = IocContainer.Resolve <IList <INetworkDeviceScanner> >();
            var cancellationToken = new CancellationTokenSource();

            foreach (var gateway in gateways)
            {
                Task.Factory.StartNew(() => gateway.StartAsync(cancellationToken.Token), TaskCreationOptions.LongRunning);
            }

            foreach (var networkDeviceScanner in networkScanners)
            {
                Task.Factory.StartNew(() => networkDeviceScanner.StartAsync(cancellationToken.Token), TaskCreationOptions.LongRunning);
            }

            return(new Disposer(cancellationToken));
        }
        private static void RegisterMessageQueueListeners <T>(IMessageQueue messageQueue) where T : IMessageQueueMessage
        {
            var listener = IocContainer.Resolve <IList <IMessageQueueListener <T> > >().ToList();

            listener.ForEach(l => messageQueue.Subscribe <T>(l.Notify));
        }