コード例 #1
0
        public void Execute(PipelineContext <TContext> pipelineEvent, TContext context, TransactionScopeOption transactionScope)
        {
            Contract.Requires(pipelineEvent != null);
            Contract.Requires(context != null);

            Definition.Pipeline pipeline = GetPipelineDefinition();

            System.Transactions.TransactionScopeOption scopeOption =
                GetTransactionScopeOption(transactionScope);

            if (pipelineEvent != null)
            {
                using (TransactionScope eventScope = new TransactionScope(scopeOption))
                {
                    PipelineEventFiringEventArgs args =
                        new PipelineEventFiringEventArgs(pipeline.Name);
                    OnPipelineEventFiring(args);

                    if (!args.Cancel)
                    {
                        if (pipeline.InvokeAll)
                        {
                            if (pipelineEvent != null)
                            {
                                pipelineEvent(context);
                            }
                        }
                        else
                        {
                            Delegate[] list = pipelineEvent.GetInvocationList();

                            foreach (PipelineContext <TContext> item in list)
                            {
                                item(context);
                                if (context.Cancel)
                                {
                                    break;
                                }
                            }
                        }

                        OnPipelineEventFired(new PipelineEventFiredEventArgs(pipeline.Name));
                    }

                    eventScope.Complete();
                }
            }
        }
コード例 #2
0
        protected Definition.Pipeline GetPipelineDefinition(string pipelineName)
        {
            PipelineElement pipelineElement = GetPipelineConfigurationElement(pipelineName);

            Definition.Pipeline pipeline = new Definition.Pipeline(pipelineElement.Name)
            {
                InvokeAll = pipelineElement.InvokeAll
            };

            foreach (ProviderSettings item in pipelineElement.Modules)
            {
                pipeline.Modules.Add(item.Name, item.Type, item.Parameters);
            }

            return(pipeline);
        }
コード例 #3
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);
        }
コード例 #4
0
        protected Backbone(Definition.Pipeline pipeline)
        {
            Contract.Requires(pipeline != null);

            _Pipeline = pipeline;
        }
コード例 #5
0
 public static TEvents InitializePipeline(Definition.Pipeline pipeline)
 {
     return(new Backbone <TEvents>(pipeline).Initialize());
 }
コード例 #6
0
 public Backbone(Definition.Pipeline pipeline)
     : base(pipeline)
 {
 }
コード例 #7
0
 public static void ExecutePipeline(Definition.Pipeline pipeline, TEvents pipelineEvents, TContext context)
 {
     new Backbone <TEvents, TContext>(pipeline).Execute(pipelineEvents, context);
 }
コード例 #8
0
 public static void ExecutePipelineEvent(Definition.Pipeline pipeline, PipelineContext <TContext> pipelineEvent, TContext context, TransactionScopeOption transactionScope)
 {
     new Backbone <TEvents, TContext>(pipeline).Execute(pipelineEvent, context, transactionScope);
 }
コード例 #9
0
        public void Execute(TEvents pipelineEvents, TContext context)
        {
            Contract.Requires(pipelineEvents != null);
            Contract.Requires(context != null);

            Definition.Pipeline pipeline = GetPipelineDefinition();

            PropertyInfo[] properties = pipelineEvents.GetType().GetProperties();

            List <PropertyInfo> sortedProperties = properties.ToList <PropertyInfo>();

            sortedProperties.Sort(new PropertyComparer());

            System.Transactions.TransactionScopeOption pipelineScopeOption = TransactionRequirement(sortedProperties);

            using (TransactionScope pipelineScope = new TransactionScope(pipelineScopeOption))
            {
                sortedProperties.ForEach(property =>
                {
                    object[] attributes =
                        property.GetCustomAttributes(typeof(PipelineEventAttribute), true);

                    if (attributes.Length > 0)
                    {
                        PipelineEventAttribute attr = (PipelineEventAttribute)attributes[0];

                        System.Transactions.TransactionScopeOption scopeOption =
                            GetTransactionScopeOption(attr.TransactionScopeOption);

                        object value = property.GetValue(pipelineEvents, null);
                        PipelineContext <TContext> eventProp = (PipelineContext <TContext>)value;

                        if (eventProp != null)
                        {
                            using (TransactionScope eventScope = new TransactionScope(scopeOption))
                            {
                                PipelineEventFiringEventArgs args = new PipelineEventFiringEventArgs(pipeline.Name, property.Name);
                                OnPipelineEventFiring(args);

                                if (!args.Cancel)
                                {
                                    if (pipeline.InvokeAll)
                                    {
                                        if (eventProp != null)
                                        {
                                            eventProp(context);
                                        }
                                    }
                                    else
                                    {
                                        Delegate[] list = eventProp.GetInvocationList();

                                        foreach (PipelineContext <TContext> item in list)
                                        {
                                            item(context);
                                            if (context.Cancel)
                                            {
                                                break;
                                            }
                                        }
                                    }

                                    OnPipelineEventFired(new PipelineEventFiredEventArgs(pipeline.Name, property.Name));
                                }

                                eventScope.Complete();
                            }
                        }
                    }
                });

                pipelineScope.Complete();
            }
        }