int IComparer <PropertyInfo> .Compare(PropertyInfo x, PropertyInfo y)
        {
            int ret = 0;

            int orderX = 0;
            int orderY = 0;

            object[] attrX = x.GetCustomAttributes(typeof(PipelineEventAttribute), true);
            object[] attrY = y.GetCustomAttributes(typeof(PipelineEventAttribute), true);

            if (attrX.Length > 0)
            {
                PipelineEventAttribute attr = (PipelineEventAttribute)attrX[0];
                orderX = attr.Order;
            }

            if (attrY.Length > 0)
            {
                PipelineEventAttribute attr = (PipelineEventAttribute)attrY[0];
                orderY = attr.Order;
            }

            if (orderX < orderY)
            {
                ret = -1;
            }
            else if (orderX > orderY)
            {
                ret = 1;
            }

            return(ret);
        }
Beispiel #2
0
        private System.Transactions.TransactionScopeOption TransactionRequirement(List <PropertyInfo> sortedProperties)
        {
            System.Transactions.TransactionScopeOption pipelineScopeOption = System.Transactions.TransactionScopeOption.Suppress;

            foreach (PropertyInfo property in sortedProperties)
            {
                object[] attributes = property.GetCustomAttributes(typeof(PipelineEventAttribute), true);
                if (attributes.Length > 0)
                {
                    PipelineEventAttribute attr = (PipelineEventAttribute)attributes[0];
                    if (attr.TransactionScopeOption != TransactionScopeOption.Suppress)
                    {
                        pipelineScopeOption = System.Transactions.TransactionScopeOption.Required;
                        break;
                    }
                }
            }

            return(pipelineScopeOption);
        }
Beispiel #3
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();
            }
        }