public void Setup()
        {
            var servicesAdmin = ServiceManager.Create();
            var services      = servicesAdmin.Manager;

            IService service;
            var      loggerService = new MainLogger(out service);

            services.Register(service);
            var queueService = new HostApplicationActionQueue(out service);

            services.Register(service);

            TaskContextDummy taskContext = new TaskContextDummy();

            servicesAdmin.StartServices(taskContext);

            queue = services.Get <IHostApplicationActionQueue>();
        }
Пример #2
0
        public static void Initialize(IEnumerable <IService> hostServices = null)
        {
            IService service;

            m_mainLogger = new MainLogger(out service);
            m_rootLogger = m_mainLogger.Logger.RootLogger;
            m_serviceManagerAdmin.Manager.Register(service);

            m_loadedFilesManager = new LoadedFilesManager(out service);
            m_serviceManagerAdmin.Manager.Register(service);

            m_addonManager = new AddonManager(
                (IAddonManager m) =>
            {
                // **** LOAD THE ADDON MODULES ****

                m.AddAssembly(typeof(DateTime).Assembly, false);
                m.AddAssembly(typeof(Enumerable).Assembly, false);
                m.AddAssembly(typeof(Math).Assembly, false);
                m.AddAssembly(AddonManager.StepBroCoreAssembly, true);

                var modulesFolder = Path.Combine(Path.GetDirectoryName(typeof(AddonManager).Assembly.Location), "Modules");
                foreach (var f in Directory.GetFiles(modulesFolder, "*.dll"))
                {
                    m.LoadAssembly(f, false);
                }
            },
                out service);
            m_serviceManagerAdmin.Manager.Register(service);

            m_logSinkManager = new LogSinkManager(out service);
            m_serviceManagerAdmin.Manager.Register(service);

            m_taskManager = new TaskManager(out service);
            m_serviceManagerAdmin.Manager.Register(service);

            m_hostActions = new HostApplicationActionQueue(out service);
            m_serviceManagerAdmin.Manager.Register(service);

            m_scriptExecutionManager = new ScriptExecutionManager(out service);
            m_serviceManagerAdmin.Manager.Register(service);

            m_dynamicObjectManager = new DynamicObjectManager(out service);
            m_serviceManagerAdmin.Manager.Register(service);

            m_uiCalculator = new UICalculator(out service);
            m_serviceManagerAdmin.Manager.Register(service);

            if (hostServices != null)
            {
                foreach (var hs in hostServices)
                {
                    m_serviceManagerAdmin.Manager.Register(hs);
                }
            }

            TaskContextDummy taskContext = new TaskContextDummy();

            try
            {
                m_serviceManagerAdmin.StartServices(taskContext);
            }
            catch (Exception ex)
            {
                // Roll back (stop) the services that actually did start.
                try
                {
                    m_serviceManagerAdmin.StopServices(taskContext);
                }
                catch { /* Ignore exceptions during stop */ }
                throw new Exception("Failed to start all services. " + ex.GetType().Name + ", " + ex.ToString());
            }

            m_initialized = true;
            m_initIndex++;
        }