Пример #1
0
        /// <summary>
        /// Processes the specified <see cref="Rock.Model.Workflow" />
        /// </summary>
        /// <param name="workflow">The <see cref="Rock.Model.Workflow" /> instance to process.</param>
        /// <param name="errorMessages">A <see cref="System.Collections.Generic.List{String}" /> that contains any error messages that were returned while processing the <see cref="Rock.Model.Workflow" />.</param>
        public void Process(Workflow workflow, out List <string> errorMessages)
        {
            workflow.IsProcessing = true;
            this.Context.SaveChanges();

            var rockContext = (RockContext)this.Context;

            workflow.LoadAttributes(rockContext);

            workflow.Process(rockContext, out errorMessages);

            if (workflow.IsPersisted)
            {
                this.Context.WrapTransaction(() =>
                {
                    this.Context.SaveChanges();
                    workflow.SaveAttributeValues(rockContext);
                    foreach (var activity in workflow.Activities)
                    {
                        activity.SaveAttributeValues(rockContext);
                    }
                });

                workflow.IsProcessing = false;
                this.Context.SaveChanges();
            }
        }
Пример #2
0
        /// <summary>
        /// Activates the specified workflow type cache.
        /// </summary>
        /// <param name="workflowTypeCache">The workflow type cache.</param>
        /// <param name="name">The name.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        public static Workflow Activate(WorkflowTypeCache workflowTypeCache, string name, RockContext rockContext)
        {
            var workflow = new Workflow();

            workflow.WorkflowTypeId = workflowTypeCache.Id;

            if (!string.IsNullOrWhiteSpace(name))
            {
                workflow.Name = name;
            }
            else
            {
                workflow.Name = workflowTypeCache.Name;
            }

            workflow.Status            = "Active";
            workflow.IsProcessing      = false;
            workflow.ActivatedDateTime = RockDateTime.Now;
            workflow.LoadAttributes(rockContext);

            workflow.AddLogEntry("Activated");

            foreach (var activityType in workflowTypeCache.ActivityTypes.OrderBy(a => a.Order))
            {
                if (activityType.IsActivatedWithWorkflow)
                {
                    WorkflowActivity.Activate(activityType, workflow, rockContext);
                }
            }

            return(workflow);
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        private void ShowDetail( int workflowId )
        {
            var rockContext = new RockContext();

            Workflow = new WorkflowService( rockContext )
                    .Queryable( "WorkflowType, Activities")
                    .Where( w => w.Id == workflowId )
                    .FirstOrDefault();

            if ( Workflow == null )
            {
                pnlContent.Visible = false;
                return;
            }

            Workflow.LoadAttributes( rockContext );
            foreach ( var activity in Workflow.Activities )
            {
                activity.LoadAttributes();
            }

            lReadOnlyTitle.Text = Workflow.Name.FormatAsHtmlTitle();
            if ( Workflow.CompletedDateTime.HasValue )
            {
                hlState.LabelType = LabelType.Default;
                hlState.Text = "Complete";
            }
            else
            {
                hlState.LabelType = LabelType.Success;
                hlState.Text = "Active";
            }
            hlType.Text = Workflow.WorkflowType.Name;

            ShowReadonlyDetails();
        }
Пример #4
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        private void ShowDetail( int workflowId )
        {
            var rockContext = new RockContext();

            Workflow = new WorkflowService( rockContext )
                    .Queryable( "WorkflowType, Activities")
                    .Where( w => w.Id == workflowId )
                    .FirstOrDefault();

            if ( Workflow == null )
            {
                pnlContent.Visible = false;
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
                return;
            }

            pdAuditDetails.SetEntity( Workflow, ResolveRockUrl( "~" ) );

            _canEdit = UserCanEdit || Workflow.IsAuthorized( Rock.Security.Authorization.EDIT, CurrentPerson );

            Workflow.LoadAttributes( rockContext );
            foreach ( var activity in Workflow.Activities )
            {
                activity.LoadAttributes();
            }

            lReadOnlyTitle.Text = Workflow.Name.FormatAsHtmlTitle();
            if ( Workflow.CompletedDateTime.HasValue )
            {
                hlState.LabelType = LabelType.Default;
                hlState.Text = "Complete";
            }
            else
            {
                hlState.LabelType = LabelType.Success;
                hlState.Text = "Active";
            }
            hlType.Text = Workflow.WorkflowType.Name;
            hlblWorkflowId.Text = Workflow.WorkflowId;

            ShowReadonlyDetails();
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (_rockContext == null)
            {
                _rockContext = new RockContext();
            }

            if (_workflowService == null)
            {
                _workflowService = new WorkflowService(_rockContext);
            }
            var paramWorkflowId = PageParameter("WorkflowId");

            WorkflowId = paramWorkflowId.AsIntegerOrNull();
            if (!WorkflowId.HasValue)
            {
                Guid guid = PageParameter("WorkflowGuid").AsGuid();
                if (!guid.IsEmpty())
                {
                    _workflow = _workflowService.Queryable()
                                .Where(w => w.Guid.Equals(guid))
                                .FirstOrDefault();
                    if (_workflow != null)
                    {
                        WorkflowId = _workflow.Id;
                    }
                }
            }

            if (WorkflowId.HasValue)
            {
                if (_workflow == null)
                {
                    _workflow = _workflowService.Queryable()
                                .Where(w => w.Id == WorkflowId.Value)
                                .FirstOrDefault();
                }
                //-------------------------------
                if (_workflow != null)
                {
                    _workflow.LoadAttributes();
                }
            }

            if (_workflow != null)
            {
                if (_workflow.IsActive)
                {
                    int personId = CurrentPerson != null ? CurrentPerson.Id : 0;
                    foreach (var activity in _workflow.Activities
                             .Where(a =>
                                    a.IsActive &&
                                    (
                                        (!a.AssignedGroupId.HasValue && !a.AssignedPersonAliasId.HasValue) ||
                                        (a.AssignedPersonAlias != null && a.AssignedPersonAlias.PersonId == personId) ||
                                        (a.AssignedGroup != null && a.AssignedGroup.Members.Any(m => m.PersonId == personId))
                                    )
                                    )
                             .OrderBy(a => a.ActivityType.Order))
                    {
                        if ((activity.ActivityType.IsAuthorized(Authorization.VIEW, CurrentPerson)))
                        {
                            foreach (var action in activity.ActiveActions)
                            {
                                if (action.ActionType.WorkflowForm != null && action.IsCriteriaValid)
                                {
                                    _activity = activity;
                                    _activity.LoadAttributes(_rockContext);
                                }
                            }
                        }
                    }

                    if (_activity != null)
                    {
                        var entryPage = _workflow.GetAttributeValue("EntryFormPage");

                        if (!String.IsNullOrEmpty(entryPage))
                        {
                            var queryParams = new Dictionary <string, string>();
                            queryParams.Add("WorkflowTypeId", _activity.Workflow.WorkflowTypeId.ToString());
                            queryParams.Add("WorkflowId", _activity.WorkflowId.ToString());

                            var attrsToSend = GetAttributeValue("WorkflowAttributes");

                            if (!String.IsNullOrWhiteSpace(attrsToSend))
                            {
                                foreach (var attr in attrsToSend.Split(','))
                                {
                                    var attrName = attr.Trim();
                                    if (!String.IsNullOrEmpty(_activity.GetAttributeValue(attrName)))
                                    {
                                        queryParams.Add(attrName, _activity.GetAttributeValue(attrName));
                                    }
                                    else if (!String.IsNullOrEmpty(_activity.Workflow.GetAttributeValue(attrName)))
                                    {
                                        queryParams.Add(attrName, _activity.Workflow.GetAttributeValue(attrName));
                                    }
                                }
                            }

                            var pageReference = new Rock.Web.PageReference(entryPage, queryParams);

                            bool paramsDiffer = false;

                            foreach (var pair in queryParams)
                            {
                                if (pair.Value != PageParameter(pair.Key))
                                {
                                    paramsDiffer = true;
                                    break;
                                }
                            }

                            if (paramsDiffer || (pageReference.PageId != CurrentPageReference.PageId))
                            {
                                Response.Redirect(pageReference.BuildUrl(), true);
                            }
                        }
                    }
                }
            }
        }