/// <summary>
        /// Initializes the WCF service manager with all configured services.
        /// </summary>
        /// <param name="dbSet">The set of active Mosaic databases.</param>
        /// <param name="packConveyorManager">The currently active pack conveyor manager.</param>
        /// <param name="orchestrationManager">The currently active orchestration manager.</param>
        /// <param name="boxSystem">The currently active box system implementation.</param>
        /// <returns>
        ///   <c>true</c> if initialization was successful;<c>false</c> otherwise.
        /// </returns>
        public bool Initialize(DatabaseSet dbSet, PackConveyorManager packConveyorManager, OrchestrationManager orchestrationManager, IBoxSystem boxSystem)
        {
            if (dbSet == null)
            {
                throw new ArgumentException("Invalid dbSet specified.");
            }

            if (packConveyorManager == null)
            {
                throw new ArgumentException("Invalid packConveyorManager specified.");
            }

            if (orchestrationManager == null)
            {
                throw new ArgumentException("Invalid orchestrationManager specified.");
            }

            _serviceList.Clear();

            this.Trace("Initializing WCF service manager...");

            try
            {
                List <Component> componentList = dbSet.Productive.Query <Component>(new CommandFilter("Type", ComponentType.WcfService.ToString()));

                foreach (Component component in componentList)
                {
                    if (component.IsActive == false)
                    {
                        continue;
                    }

                    this.Info("Initializing WCF service '{0}' with ID '{1}'.", component.Description, component.ID);
                    IWcfService service = ComponentLoader.LoadInterface <IWcfService>(component.Assembly, component.ClassName);

                    if (service == null)
                    {
                        this.Fatal("WCF service '{0}' with ID '{1}' in assembly '{2}' and class '{3}' could not be found.",
                                   component.Description, component.ID, component.Assembly, component.ClassName);
                        return(false);
                    }

                    ServiceHost svcHost = service.Initialize(component.ID,
                                                             dbSet.Productive.Query <ConfigurationValue>(new CommandFilter("ComponentID", component.ID)),
                                                             dbSet,
                                                             packConveyorManager.PackConveyors,
                                                             orchestrationManager.Orchestrations,
                                                             boxSystem);

                    if (svcHost == null)
                    {
                        this.Error("Initializing WCF service '{0}' with ID '{1}' failed.", component.Description, component.ID);
                        return(false);
                    }

                    try
                    {
                        svcHost.Open();
                        _serviceList.Add(svcHost);
                    }
                    catch (Exception ex)
                    {
                        this.Error("Starting WCF service '{0}' failed.", ex, component.Description);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                this.Error("Initializing WCF services failed.", ex);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the connector manager with all configured connectors.
        /// </summary>
        /// <param name="dbSet">The set of active Mosaic databases.</param>
        /// <param name="orchestrationManager">The active orchestration manager to notify about new converter streams.</param>
        /// <param name="taskScheduler">The active task scheduler to notify about converter streams.</param>
        /// <returns><c>true</c> if initialization was successful;<c>false</c> otherwise.</returns>
        public bool Initialize(DatabaseSet dbSet,
                               OrchestrationManager orchestrationManager,
                               TaskScheduler taskScheduler)
        {
            if (dbSet == null)
            {
                throw new ArgumentException("Invalid dbSet specified.");
            }

            if (orchestrationManager == null)
            {
                throw new ArgumentException("Invalid orchestrationManager specified.");
            }

            if (taskScheduler == null)
            {
                throw new ArgumentException("Invalid taskScheduler specified.");
            }

            this.Trace("Initializing converter manager...");

            _converterList.Clear();
            _taskAssignments.Clear();
            _orchestrationManager = orchestrationManager;
            _taskScheduler        = taskScheduler;

            try
            {
                List <Component> componentList = dbSet.Productive.Query <Component>(new CommandFilter("Type", ComponentType.Converter.ToString()));

                foreach (Component component in componentList)
                {
                    if (component.IsActive == false)
                    {
                        continue;
                    }

                    this.Info("Initializing converter '{0}' with ID '{1}'.", component.Description, component.ID);
                    IConverter converter = ComponentLoader.LoadInterface <IConverter>(component.Assembly, component.ClassName);

                    if (converter == null)
                    {
                        this.Fatal("Converter '{0}' with ID '{1}' in assembly '{2}' and class '{3}' could not be found.",
                                   component.Description, component.ID, component.Assembly, component.ClassName);
                        return(false);
                    }

                    if (converter.Initialize(component.ID,
                                             dbSet.Productive.Query <ConfigurationValue>(new CommandFilter("ComponentID", component.ID))) == false)
                    {
                        this.Error("Initializing converter '{0}' with ID '{1}' failed.", component.Description, component.ID);
                        return(false);
                    }

                    _converterList.Add(converter);

                    if (component.ConnectedComponentID != 0)
                    {
                        _taskAssignments.Add(converter.ID, component.ConnectedComponentID);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                this.Error("Initializing converters failed.", ex);
            }

            return(false);
        }