コード例 #1
0
        /// <summary>
        /// Activates the specified WorkflowActivity
        /// </summary>
        /// <param name="activityTypeCache">The activity type cache.</param>
        /// <param name="workflow">The persisted <see cref="Rock.Model.Workflow" /> instance that this Workflow activity belongs to.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns>
        /// The activated <see cref="Rock.Model.WorkflowActivity" />.
        /// </returns>
        public static WorkflowActivity Activate(WorkflowActivityTypeCache activityTypeCache, Workflow workflow, RockContext rockContext)
        {
            if (!workflow.IsActive)
            {
                return(null);
            }

            var activity = new WorkflowActivity();

            activity.Workflow          = workflow;
            activity.ActivityTypeId    = activityTypeCache.Id;
            activity.ActivatedDateTime = RockDateTime.Now;
            activity.LoadAttributes(rockContext);

            activity.AddLogEntry("Activated");

            foreach (var actionType in activityTypeCache.ActionTypes)
            {
                activity.Actions.Add(WorkflowAction.Activate(actionType, activity, rockContext));
            }

            workflow.Activities.Add(activity);

            return(activity);
        }
コード例 #2
0
        private void CopyAttributes(Rock.Model.Workflow newWorkflow, Rock.Model.WorkflowActivity currentActivity, RockContext rockContext)
        {
            if (currentActivity.Attributes == null)
            {
                currentActivity.LoadAttributes(rockContext);
            }

            if (currentActivity.Workflow.Attributes == null)
            {
                currentActivity.Workflow.LoadAttributes(rockContext);
            }

            // Pass attributes from current Workflow to new Workflow.
            foreach (string key in currentActivity.Workflow.AttributeValues.Keys)
            {
                newWorkflow.SetAttributeValue(key, currentActivity.Workflow.GetAttributeValue(key));
            }

            // Pass attributes from current Activity to new Workflow.
            foreach (string key in currentActivity.AttributeValues.Keys)
            {
                newWorkflow.SetAttributeValue(key, currentActivity.GetAttributeValue(key));
            }
        }