Ejemplo n.º 1
0
        public LearningApi AddModule(IPipelineModule module, string name = null)
        {
            // TODO: Need few checks here. Dbl key name, module == null,..
            if (name == null)
            {
                name = module.GetType().Name;
            }

            this.Modules.Add(name, module);

            return(this);
        }
Ejemplo n.º 2
0
        public TEvents Initialize()
        {
            TEvents pipelineEvents = new TEvents();

            Definition.Pipeline pipeline = null;

            if (_Pipeline == null)
            {
                pipeline = GetPipelineDefinition();
            }
            else
            {
                pipeline = _Pipeline;
            }

            foreach (Definition.Module moduleItem in pipeline.Modules)
            {
                PipelineModuleInitializingEventArgs beforeArgs = new PipelineModuleInitializingEventArgs(pipeline.Name, moduleItem.Name);
                OnPipelineModuleInitializing(beforeArgs);

                if (!beforeArgs.Cancel)
                {
                    object          obj    = Activator.CreateInstance(Type.GetType(moduleItem.Type));
                    IPipelineModule module = (IPipelineModule)obj;

                    if (module is IPipelineModuleBehavior)
                    {
                        IPipelineModuleBehavior behavior = module as IPipelineModuleBehavior;
                        behavior.ModuleInitializing(beforeArgs);
                    }

                    if (!beforeArgs.Cancel)
                    {
                        object[] attributes = module.GetType().GetCustomAttributes(false);
                        if (attributes != null)
                        {
                            foreach (object attribute in attributes)
                            {
                                if (attribute is IPipelineModuleBehavior)
                                {
                                    if (!beforeArgs.Cancel)
                                    {
                                        IPipelineModuleBehavior behavior = attribute as IPipelineModuleBehavior;
                                        behavior.ModuleInitializing(beforeArgs);
                                    }
                                }
                            }
                        }

                        module.Initialize(pipelineEvents, moduleItem.Parameters);

                        PipelineModuleInitializedEventArgs afterArgs =
                            new PipelineModuleInitializedEventArgs(pipeline.Name, moduleItem.Name);
                        OnPipelineModuleInitialized(afterArgs);

                        if (module is IPipelineModuleBehavior)
                        {
                            IPipelineModuleBehavior behavior = module as IPipelineModuleBehavior;
                            behavior.ModuleInitialized(afterArgs);
                        }

                        if (attributes != null)
                        {
                            foreach (object attribute in attributes)
                            {
                                if (attribute is IPipelineModuleBehavior)
                                {
                                    IPipelineModuleBehavior behavior = attribute as IPipelineModuleBehavior;
                                    behavior.ModuleInitialized(afterArgs);
                                }
                            }
                        }
                    }
                }
            }

            return(pipelineEvents);
        }