Exemple #1
0
        /// <summary>
        /// Launch the workflow
        /// </summary>
        protected void LaunchTheWorkflow(string workflowName)
        {
            Guid workflowTypeGuid = Guid.NewGuid();

            if (Guid.TryParse(workflowName, out workflowTypeGuid))
            {
                var workflowTypeService = new WorkflowTypeService();
                var workflowType        = workflowTypeService.Get(workflowTypeGuid);
                if (workflowType != null)
                {
                    var workflow = Rock.Model.Workflow.Activate(workflowType, workflowName);

                    List <string> workflowErrors;
                    if (workflow.Process(out workflowErrors))
                    {
                        if (workflowType.IsPersisted)
                        {
                            var workflowService = new Rock.Model.WorkflowService();
                            workflowService.Add(workflow, CurrentPersonId);
                            workflowService.Save(workflow, CurrentPersonId);
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Handles the FileUploaded event of the fsFile control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void fsFile_FileUploaded(object sender, EventArgs e)
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                var        binaryFileService = new BinaryFileService();
                BinaryFile binaryFile        = null;
                if (fsFile.BinaryFileId.HasValue)
                {
                    binaryFile = binaryFileService.Get(fsFile.BinaryFileId.Value);
                }

                if (binaryFile != null)
                {
                    if (!string.IsNullOrWhiteSpace(tbName.Text))
                    {
                        binaryFile.FileName = tbName.Text;
                    }

                    // set binaryFile.Id to original id since the UploadedFile is a temporary binaryFile with a different id
                    binaryFile.Id               = hfBinaryFileId.ValueAsInt();
                    binaryFile.Description      = tbDescription.Text;
                    binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
                    if (binaryFile.BinaryFileTypeId.HasValue)
                    {
                        binaryFile.BinaryFileType = new BinaryFileTypeService().Get(binaryFile.BinaryFileTypeId.Value);
                    }

                    binaryFile.LoadAttributes();
                    Rock.Attribute.Helper.GetEditValues(phAttributes, binaryFile);

                    // Process uploaded file using an optional workflow
                    Guid workflowTypeGuid = Guid.NewGuid();
                    if (Guid.TryParse(GetAttributeValue("Workflow"), out workflowTypeGuid))
                    {
                        var workflowTypeService = new WorkflowTypeService();
                        var workflowType        = workflowTypeService.Get(workflowTypeGuid);
                        if (workflowType != null)
                        {
                            var workflow = Workflow.Activate(workflowType, binaryFile.FileName);

                            List <string> workflowErrors;
                            if (workflow.Process(binaryFile, out workflowErrors))
                            {
                                binaryFile = binaryFileService.Get(binaryFile.Id);

                                if (workflowType.IsPersisted)
                                {
                                    var workflowService = new Rock.Model.WorkflowService();
                                    workflowService.Add(workflow, CurrentPersonId);
                                    workflowService.Save(workflow, CurrentPersonId);
                                }
                            }
                        }
                    }

                    ShowBinaryFileDetail(binaryFile);
                }
            }
        }
Exemple #3
0
        /// <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);
        }
        /// <summary>
        /// Execute method to write transaction to the database.
        /// </summary>
        public void Execute()
        {
            if ( Trigger != null )
            {
                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, out workflowErrors ) )
                    {
                        if ( workflowType.IsPersisted )
                        {
                            var workflowService = new Rock.Model.WorkflowService();
                            workflowService.Add( workflow, PersonId );
                            workflowService.Save( workflow, PersonId );
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Execute method to write transaction to the database.
        /// </summary>
        public void Execute()
        {
            if (Trigger != null)
            {
                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(Dto, out workflowErrors))
                    {
                        if (workflowType.IsPersisted)
                        {
                            var workflowService = new Rock.Model.WorkflowService();
                            workflowService.Add(workflow, PersonId);
                            workflowService.Save(workflow, PersonId);
                        }
                    }
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Launch the workflow
        /// </summary>
        protected void LaunchTheWorkflow(string workflowName)
        {
            Guid workflowTypeGuid = Guid.NewGuid();
            if ( Guid.TryParse( workflowName, out workflowTypeGuid ) )
            {
                var workflowTypeService = new WorkflowTypeService();
                var workflowType = workflowTypeService.Get( workflowTypeGuid );
                if ( workflowType != null )
                {
                    var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName );

                    List<string> workflowErrors;
                    if ( workflow.Process( out workflowErrors ) )
                    {
                        if ( workflowType.IsPersisted )
                        {
                            var workflowService = new Rock.Model.WorkflowService();
                            workflowService.Add( workflow, CurrentPersonId );
                            workflowService.Save( workflow, CurrentPersonId );
                        }
                    }
                }
            }     
        }
Exemple #7
0
        /// <summary>
        /// Handles the Delete event of the gWorkflows control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gWorkflows_Delete( object sender, RowEventArgs e )
        {
            RockTransactionScope.WrapTransaction( () =>
            {
                WorkflowService workflowService = new WorkflowService();
                Workflow workflow = workflowService.Get( (int)e.RowKeyValue );
                if ( workflow != null )
                {
                    string errorMessage;
                    if ( !workflowService.CanDelete( workflow, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    workflowService.Delete( workflow, CurrentPersonId );
                    workflowService.Save( workflow, CurrentPersonId );
                }
            } );

            BindGrid();
        }
        /// <summary>
        /// Handles the FileUploaded event of the fsFile control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void fsFile_FileUploaded( object sender, EventArgs e )
        {
            using ( new Rock.Data.UnitOfWorkScope() )
            {
                var binaryFileService = new BinaryFileService();
                BinaryFile binaryFile = null;
                if ( fsFile.BinaryFileId.HasValue )
                {
                    binaryFile = binaryFileService.Get( fsFile.BinaryFileId.Value );
                }

                if ( binaryFile != null )
                {
                    if ( !string.IsNullOrWhiteSpace( tbName.Text ) )
                    {
                        binaryFile.FileName = tbName.Text;
                    }

                    // set binaryFile.Id to original id since the UploadedFile is a temporary binaryFile with a different id
                    binaryFile.Id = hfBinaryFileId.ValueAsInt();
                    binaryFile.Description = tbDescription.Text;
                    binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
                    if ( binaryFile.BinaryFileTypeId.HasValue )
                    {
                        binaryFile.BinaryFileType = new BinaryFileTypeService().Get( binaryFile.BinaryFileTypeId.Value );
                    }

                    binaryFile.LoadAttributes();
                    Rock.Attribute.Helper.GetEditValues( phAttributes, binaryFile );

                    // Process uploaded file using an optional workflow
                    Guid workflowTypeGuid = Guid.NewGuid();
                    if ( Guid.TryParse( GetAttributeValue( "Workflow" ), out workflowTypeGuid ) )
                    {
                        var workflowTypeService = new WorkflowTypeService();
                        var workflowType = workflowTypeService.Get( workflowTypeGuid );
                        if ( workflowType != null )
                        {
                            var workflow = Workflow.Activate( workflowType, binaryFile.FileName );

                            List<string> workflowErrors;
                            if ( workflow.Process( binaryFile, out workflowErrors ) )
                            {
                                binaryFile = binaryFileService.Get( binaryFile.Id );

                                if ( workflowType.IsPersisted )
                                {
                                    var workflowService = new Rock.Model.WorkflowService();
                                    workflowService.Add( workflow, CurrentPersonId );
                                    workflowService.Save( workflow, CurrentPersonId );
                                }
                            }
                        }
                    }
                    
                    ShowBinaryFileDetail( binaryFile );
                }
            }
        }
Exemple #9
0
        /// <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)
        {
            Dictionary <string, PropertyInfo> properties = null;

            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 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, 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.Entity   = entity.Clone();
                        transaction.PersonId = personId;
                        Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                    }
                }
            }
            return(true);
        }