コード例 #1
0
        protected void CreateSingleTrigger( string modelName, WorkflowTriggerType triggerType, string qualifierColumn, string qualifierValue, string workflowTypeGuid, string description )
        {
            var insertQuery = string.Format( @"
                INSERT INTO [dbo].[WorkflowTrigger]
                   ([IsSystem]
                   ,[EntityTypeId]
                   ,[EntityTypeQualifierColumn]
                   ,[EntityTypeQualifierValue]
                   ,[WorkflowTypeId]
                   ,[WorkflowTriggerType]
                   ,[WorkflowName]
                   ,[Guid]
                   ,[IsActive])
                VALUES
                   (0
                   ,(SELECT Id FROM EntityType WHERE NAME = 'Rock.Model.{0}')
                   ,'{1}'
                   ,{2}
                   ,(SELECT Id FROM WorkflowType WHERE Guid = '{3}')
                   ,{4}
                   ,'{5} API Sync'
                   ,NEWID()
                   ,1)", modelName, qualifierColumn, qualifierValue, workflowTypeGuid, (int)triggerType, description );

            Sql( insertQuery );
        }
コード例 #2
0
 /// <summary>
 /// Returns a queryable collection of  the <see cref="Rock.Model.WorkflowTrigger"/> by <see cref="Rock.Model.EntityType"/> name
 /// and <see cref="Rock.Model.WorkflowTriggerType"/>
 /// </summary>
 /// <param name="entityTypeName">A <see cref="System.String"/> representing the name of the <see cref="Rock.Model.EntityType"/> to filter by.</param>
 /// <param name="triggerType">The <see cref="Rock.Model.WorkflowTriggerType"/> to filter by.</param>
 /// <returns>A queryable collection of <see cref="Rock.Model.WorkflowTrigger"/> entities that meet the specified criteria.</returns>
 public IQueryable<WorkflowTrigger> Get( string entityTypeName, WorkflowTriggerType triggerType )
 {
     return Repository.AsQueryable()
         .Where( t =>
             t.EntityType.Name == entityTypeName &&
             t.WorkflowTriggerType == triggerType );
 }
コード例 #3
0
 /// <summary>
 /// Returns a queryable collection of  the <see cref="Rock.Model.WorkflowTrigger"/> by <see cref="Rock.Model.EntityType"/> name
 /// and <see cref="Rock.Model.WorkflowTriggerType"/>
 /// </summary>
 /// <param name="entityTypeName">A <see cref="System.String"/> representing the name of the <see cref="Rock.Model.EntityType"/> to filter by.</param>
 /// <param name="triggerType">The <see cref="Rock.Model.WorkflowTriggerType"/> to filter by.</param>
 /// <returns>A queryable collection of <see cref="Rock.Model.WorkflowTrigger"/> entities that meet the specified criteria.</returns>
 public IQueryable <WorkflowTrigger> Get(string entityTypeName, WorkflowTriggerType triggerType)
 {
     return(Repository.AsQueryable()
            .Where(t =>
                   t.EntityType.Name == entityTypeName &&
                   t.WorkflowTriggerType == triggerType));
 }
コード例 #4
0
        protected void CreateSingleTrigger(string modelName, WorkflowTriggerType triggerType, string qualifierColumn, string qualifierValue, string workflowTypeGuid, string description)
        {
            var insertQuery = string.Format(@"
                INSERT INTO [dbo].[WorkflowTrigger]
                   ([IsSystem]
                   ,[EntityTypeId]
                   ,[EntityTypeQualifierColumn]
                   ,[EntityTypeQualifierValue]
                   ,[WorkflowTypeId]
                   ,[WorkflowTriggerType]
                   ,[WorkflowName]
                   ,[Guid]
                   ,[IsActive])
                VALUES
                   (0
                   ,(SELECT Id FROM EntityType WHERE NAME = 'Rock.Model.{0}')
                   ,'{1}'
                   ,{2}
                   ,(SELECT Id FROM WorkflowType WHERE Guid = '{3}')
                   ,{4}
                   ,'{5} API Sync'
                   ,NEWID()
                   ,1)", modelName, qualifierColumn, qualifierValue, workflowTypeGuid, (int)triggerType, description);

            Sql(insertQuery);
        }
コード例 #5
0
        /// <summary>
        /// Triggerses the specified entity type name.
        /// </summary>
        /// <param name="entityTypeName">Name of the entity type.</param>
        /// <param name="triggerType">Type of the trigger.</param>
        /// <returns></returns>
        public List <WorkflowTriggerDto> Triggers(string entityTypeName, WorkflowTriggerType triggerType)
        {
            var triggers = new List <WorkflowTriggerDto>();

            if (EntityTriggers != null && EntityTriggers.ContainsKey(entityTypeName))
            {
                foreach (var trigger in EntityTriggers[entityTypeName])
                {
                    if (trigger.WorkflowTriggerType == triggerType)
                    {
                        triggers.Add(trigger);
                    }
                }
            }

            return(triggers);
        }
コード例 #6
0
        /// <summary>
        /// Gets a collection of Workflow Triggers for the specified criteria.
        /// </summary>
        /// <param name="entityTypeName">Name of the entity type.</param>
        /// <param name="triggerType">Type of the trigger.</param>
        /// <returns></returns>
        public static List <WorkflowTrigger> Triggers(string entityTypeName, WorkflowTriggerType triggerType)
        {
            var triggers = Get();

            if (triggers == null)
            {
                return(new List <WorkflowTrigger>());
            }

            if (triggers.EntityTriggers != null && triggers.EntityTriggers.ContainsKey(entityTypeName))
            {
                return(triggers.EntityTriggers[entityTypeName]
                       .Where(t => t.WorkflowTriggerType == triggerType)
                       .ToList());
            }

            return(new List <WorkflowTrigger>());
        }
コード例 #7
0
ファイル: TriggerCache.cs プロジェクト: pkdevbox/Rock
        /// <summary>
        /// Triggerses the specified entity type name.
        /// </summary>
        /// <param name="entityTypeName">Name of the entity type.</param>
        /// <param name="triggerType">Type of the trigger.</param>
        /// <returns></returns>
        public static List<WorkflowTrigger> Triggers( string entityTypeName, WorkflowTriggerType triggerType )
        {
            var triggers = new List<WorkflowTrigger>();

            lock ( obj )
            {
                if ( EntityTriggers != null && EntityTriggers.ContainsKey( entityTypeName ) )
                {
                    foreach ( var trigger in EntityTriggers[entityTypeName] )
                    {
                        if ( trigger.WorkflowTriggerType == triggerType )
                        {
                            triggers.Add( trigger );
                        }
                    }
                }
            }

            return triggers;
        }
コード例 #8
0
ファイル: Service.cs プロジェクト: jh2mhs8/Rock-ChMS
        /// <summary>
        /// Triggers the workflows.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="triggerType">Type of the trigger.</param>
        /// <param name="personId">The person id.</param>
        /// <returns></returns>
        private bool TriggerWorkflows(IEntity entity, WorkflowTriggerType triggerType, int?personId)
        {
            foreach (var trigger in TriggerCache.Instance.Triggers(entity.TypeName, triggerType))
            {
                if (triggerType == WorkflowTriggerType.PreSave || triggerType == WorkflowTriggerType.PreDelete)
                {
                    var workflowTypeService = new WorkflowTypeService();
                    var workflowType        = workflowTypeService.Get(trigger.WorkflowTypeId);

                    if (workflowType != null)
                    {
                        var workflow = Rock.Model.Workflow.Activate(workflowType, trigger.WorkflowName);

                        List <string> workflowErrors;
                        if (!workflow.Process(entity.Dto, out workflowErrors))
                        {
                            ErrorMessages.AddRange(workflowErrors);
                            return(false);
                        }
                        else
                        {
                            if (workflowType.IsPersisted)
                            {
                                var workflowService = new Rock.Model.WorkflowService();
                                workflowService.Add(workflow, personId);
                                workflowService.Save(workflow, personId);
                            }
                        }
                    }
                }
                else
                {
                    var transaction = new Rock.Transactions.WorkflowTriggerTransaction();
                    transaction.Trigger  = trigger;
                    transaction.Dto      = entity.Dto;
                    transaction.PersonId = personId;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                }
            }
            return(true);
        }
コード例 #9
0
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance.
 /// </summary>
 /// <returns>
 /// A <see cref="System.String" /> that represents this instance.
 /// </returns>
 public override string ToString()
 {
     // TODO ask David if we can EntityType.ToStringSafe() instead of EntityType.Name below
     return(this.WorkflowName ?? EntityType.Name + " " + WorkflowTriggerType.ConvertToString());
 }
コード例 #10
0
ファイル: DbContext.cs プロジェクト: garyholeman/Rock
        /// <summary>
        /// Triggers all the workflows of the given triggerType for the given entity item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="triggerType">Type of the trigger.</param>
        /// <param name="personAlias">The person alias.</param>
        /// <returns></returns>
        private bool TriggerWorkflows(ContextItem item, WorkflowTriggerType triggerType, PersonAlias personAlias)
        {
            IEntity entity = item.Entity;
            Dictionary <string, PropertyInfo> properties = null;

            // Look at each trigger for this entity and for the given trigger type
            // and see if it's a match.
            foreach (var trigger in WorkflowTriggersCache.Triggers(entity.TypeName, triggerType).Where(t => t.IsActive == true))
            {
                bool match = true;

                // If a qualifier column was given, then we need to check the previous or current qualifier value
                // otherwise it's just an automatic match.
                if (!string.IsNullOrWhiteSpace(trigger.EntityTypeQualifierColumn))
                {
                    // Get and cache the properties https://lotsacode.wordpress.com/2010/04/13/reflection-type-getproperties-and-performance/
                    // (Note: its possible that none of the triggers need them, so future TODO could be to
                    // bypass all this in that case.
                    if (properties == null)
                    {
                        properties = new Dictionary <string, PropertyInfo>();
                        foreach (PropertyInfo propertyInfo in entity.GetType().GetProperties())
                        {
                            properties.Add(propertyInfo.Name.ToLower(), propertyInfo);
                        }
                    }

                    match = IsQualifierMatch(item, properties, trigger);
                }

                // If we found a matching trigger, then fire it; otherwise do nothing.
                if (match)
                {
                    // If it's one of the pre or immediate triggers, fire it immediately; otherwise queue it.
                    if (triggerType == WorkflowTriggerType.PreSave || triggerType == WorkflowTriggerType.PreDelete || triggerType == WorkflowTriggerType.ImmediatePostSave)
                    {
                        var workflowType = WorkflowTypeCache.Get(trigger.WorkflowTypeId);
                        if (workflowType != null && (workflowType.IsActive ?? true))
                        {
                            var workflow = Rock.Model.Workflow.Activate(workflowType, trigger.WorkflowName);

                            List <string> workflowErrors;

                            using (var rockContext = new RockContext())
                            {
                                var workflowService = new WorkflowService(rockContext);
                                if (!workflowService.Process(workflow, entity, out workflowErrors))
                                {
                                    SaveErrorMessages.AddRange(workflowErrors);
                                    return(false);
                                }
                            }
                        }
                    }
                    else
                    {
                        var transaction = new Rock.Transactions.WorkflowTriggerTransaction();
                        transaction.Trigger     = trigger;
                        transaction.Entity      = entity.Clone();
                        transaction.PersonAlias = personAlias;
                        Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                    }
                }
            }


            return(true);
        }
コード例 #11
0
ファイル: TriggerCache.cs プロジェクト: waldo2590/Rock
 public static List <WorkflowTrigger> Triggers(string entityTypeName, WorkflowTriggerType triggerType)
 {
     return(WorkflowTriggersCache.Triggers(entityTypeName, triggerType));
 }
コード例 #12
0
ファイル: DbContext.cs プロジェクト: azturner/Rock
        /// <summary>
        /// Triggers all the workflows of the given triggerType for the given entity item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="triggerType">Type of the trigger.</param>
        /// <param name="personAlias">The person alias.</param>
        /// <returns></returns>
        private bool TriggerWorkflows( ContextItem item, WorkflowTriggerType triggerType, PersonAlias personAlias )
        {
            IEntity entity = item.Entity;
            Dictionary<string, PropertyInfo> properties = null;

            using ( var rockContext = new RockContext() )
            {
                var workflowTypeService = new WorkflowTypeService( rockContext );
                var workflowService = new WorkflowService( rockContext );

                // Look at each trigger for this entity and for the given trigger type
                // and see if it's a match.
                foreach ( var trigger in TriggerCache.Triggers( entity.TypeName, triggerType ).Where( t => t.IsActive == true ) )
                {
                    bool match = true;

                    // If a qualifier column was given, then we need to check the previous or current qualifier value
                    // otherwise it's just an automatic match.
                    if ( !string.IsNullOrWhiteSpace( trigger.EntityTypeQualifierColumn ) )
                    {
                        // Get and cache the properties https://lotsacode.wordpress.com/2010/04/13/reflection-type-getproperties-and-performance/
                        // (Note: its possible that none of the triggers need them, so future TODO could be to
                        // bypass all this in that case.
                        if ( properties == null )
                        {
                            properties = new Dictionary<string, PropertyInfo>();
                            foreach ( PropertyInfo propertyInfo in entity.GetType().GetProperties() )
                            {
                                properties.Add( propertyInfo.Name.ToLower(), propertyInfo );
                            }
                        }

                        match = IsQualifierMatch( item, properties, trigger );
                    }

                    // If we found a matching trigger, then fire it; otherwise do nothing.
                    if ( match )
                    {
                        // If it's one of the pre or immediate triggers, fire it immediately; otherwise queue it.
                        if ( triggerType == WorkflowTriggerType.PreSave || triggerType == WorkflowTriggerType.PreDelete || triggerType == WorkflowTriggerType.ImmediatePostSave )
                        {
                            var workflowType = workflowTypeService.Get( trigger.WorkflowTypeId );

                            if ( workflowType != null )
                            {
                                var workflow = Rock.Model.Workflow.Activate( workflowType, trigger.WorkflowName );

                                List<string> workflowErrors;
                                if ( !workflowService.Process( workflow, entity, out workflowErrors ) )
                                {
                                    SaveErrorMessages.AddRange( workflowErrors );
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            var transaction = new Rock.Transactions.WorkflowTriggerTransaction();
                            transaction.Trigger = trigger;
                            transaction.Entity = entity.Clone();
                            transaction.PersonAlias = personAlias;
                            Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
                        }
                    }
                }
            }

            return true;
        }
コード例 #13
0
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance.
 /// </summary>
 /// <returns>
 /// A <see cref="System.String" /> that represents this instance.
 /// </returns>
 public override string ToString()
 {
     return(this.WorkflowName ?? EntityType.Name + " " + WorkflowTriggerType.ConvertToString());
 }
コード例 #14
0
        private bool TriggerWorkflows(IEntity entity, WorkflowTriggerType triggerType, PersonAlias personAlias)
        {
            Dictionary <string, PropertyInfo> properties = null;

            using (var rockContext = new RockContext())
            {
                var workflowTypeService = new WorkflowTypeService(rockContext);
                var workflowService     = new WorkflowService(rockContext);

                foreach (var trigger in TriggerCache.Triggers(entity.TypeName, triggerType).Where(t => t.IsActive == true))
                {
                    bool match = true;

                    if (!string.IsNullOrWhiteSpace(trigger.EntityTypeQualifierColumn))
                    {
                        if (properties == null)
                        {
                            properties = new Dictionary <string, PropertyInfo>();
                            foreach (PropertyInfo propertyInfo in entity.GetType().GetProperties())
                            {
                                properties.Add(propertyInfo.Name.ToLower(), propertyInfo);
                            }
                        }

                        match = (properties.ContainsKey(trigger.EntityTypeQualifierColumn.ToLower()) &&
                                 properties[trigger.EntityTypeQualifierColumn.ToLower()].GetValue(entity, null).ToString()
                                 == trigger.EntityTypeQualifierValue);
                    }

                    if (match)
                    {
                        if (triggerType == WorkflowTriggerType.PreSave || triggerType == WorkflowTriggerType.PreDelete)
                        {
                            var workflowType = workflowTypeService.Get(trigger.WorkflowTypeId);

                            if (workflowType != null)
                            {
                                var workflow = Rock.Model.Workflow.Activate(workflowType, trigger.WorkflowName);

                                List <string> workflowErrors;
                                if (!workflow.Process(rockContext, entity, out workflowErrors))
                                {
                                    SaveErrorMessages.AddRange(workflowErrors);
                                    return(false);
                                }
                                else
                                {
                                    if (workflow.IsPersisted || workflowType.IsPersisted)
                                    {
                                        workflowService.Add(workflow);
                                        rockContext.SaveChanges();
                                    }
                                }
                            }
                        }
                        else
                        {
                            var transaction = new Rock.Transactions.WorkflowTriggerTransaction();
                            transaction.Trigger     = trigger;
                            transaction.Entity      = entity.Clone();
                            transaction.PersonAlias = personAlias;
                            Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #15
0
ファイル: DbContext.cs プロジェクト: Ganon11/Rock
        private bool TriggerWorkflows( IEntity entity, WorkflowTriggerType triggerType, PersonAlias personAlias )
        {
            Dictionary<string, PropertyInfo> properties = null;

            var rockContext = new RockContext();
            var workflowTypeService = new WorkflowTypeService( rockContext );
            var workflowService = new WorkflowService( rockContext );

            foreach ( var trigger in TriggerCache.Triggers( entity.TypeName, triggerType ).Where( t => t.IsActive == true ) )
            {
                bool match = true;

                if ( !string.IsNullOrWhiteSpace( trigger.EntityTypeQualifierColumn ) )
                {
                    if ( properties == null )
                    {
                        properties = new Dictionary<string, PropertyInfo>();
                        foreach ( PropertyInfo propertyInfo in entity.GetType().GetProperties() )
                        {
                            properties.Add( propertyInfo.Name.ToLower(), propertyInfo );
                        }
                    }

                    match = ( properties.ContainsKey( trigger.EntityTypeQualifierColumn.ToLower() ) &&
                        properties[trigger.EntityTypeQualifierColumn.ToLower()].GetValue( entity, null ).ToString()
                            == trigger.EntityTypeQualifierValue );
                }

                if ( match )
                {
                    if ( triggerType == WorkflowTriggerType.PreSave || triggerType == WorkflowTriggerType.PreDelete )
                    {
                        var workflowType = workflowTypeService.Get( trigger.WorkflowTypeId );

                        if ( workflowType != null )
                        {
                            var workflow = Rock.Model.Workflow.Activate( workflowType, trigger.WorkflowName );

                            List<string> workflowErrors;
                            if ( !workflow.Process( rockContext, entity, out workflowErrors ) )
                            {
                                SaveErrorMessages.AddRange( workflowErrors );
                                return false;
                            }
                            else
                            {
                                if ( workflow.IsPersisted || workflowType.IsPersisted )
                                {
                                    workflowService.Add( workflow );
                                    rockContext.SaveChanges();
                                }
                            }
                        }
                    }
                    else
                    {
                        var transaction = new Rock.Transactions.WorkflowTriggerTransaction();
                        transaction.Trigger = trigger;
                        transaction.Entity = entity.Clone();
                        transaction.PersonAlias = personAlias;
                        Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
                    }
                }
            }
            return true;
        }
コード例 #16
0
        /// <summary>
        /// Creates the workflow trigger.
        /// </summary>
        /// <param name="entityTypeName">Name of the entity type.</param>
        /// <param name="triggerType">Type of the trigger.</param>
        /// <param name="qualifierColumn">The qualifier column.</param>
        /// <param name="qualifierValue">The qualifier value.</param>
        /// <param name="workflowTypeGuid">The workflow type unique identifier.</param>
        /// <param name="description">The description.</param>
        /// <param name="guid">The unique identifier.</param>
        public void CreateWorkflowTrigger( string entityTypeName, WorkflowTriggerType triggerType, string qualifierColumn, string qualifierValue, string workflowTypeGuid, string description, string guid = null )
        {
            guid = guid != null ? string.Format( "'{0}'", guid ) : "NEWID()";

            Migration.Sql( string.Format( @"
                INSERT INTO [dbo].[WorkflowTrigger]
                   ([IsSystem]
                   ,[EntityTypeId]
                   ,[EntityTypeQualifierColumn]
                   ,[EntityTypeQualifierValue]
                   ,[WorkflowTypeId]
                   ,[WorkflowTriggerType]
                   ,[WorkflowName]
                   ,[Guid]
                   ,[IsActive])
                VALUES
                   (0
                   ,(SELECT Id FROM EntityType WHERE NAME = 'Rock.Model.{0}')
                   ,'{1}'
                   ,'{2}'
                   ,(SELECT Id FROM WorkflowType WHERE Guid = '{3}')
                   ,{4}
                   ,'{5}'
                   ,{6}
                   ,1)", entityTypeName, qualifierColumn, qualifierValue, workflowTypeGuid, (int)triggerType, description, guid ) );
        }