Launches a workflow and optionally sets the name and attribute values
상속: ITransaction
        /// <summary>
        /// Launches the workflow.
        /// </summary>
        /// <param name="workflowTypeId">The workflow type identifier.</param>
        private void LaunchWorkflow(int workflowTypeId)
        {
            var          attempt = GetStreakAchievementAttempt();
            ITransaction transaction;

            if (attempt != null)
            {
                transaction = new LaunchWorkflowTransaction <StreakAchievementAttempt>(workflowTypeId, attempt.Id);
            }
            else
            {
                transaction = new LaunchWorkflowTransaction(workflowTypeId);
            }

            transaction.Enqueue();
        }
예제 #2
0
        /// <summary>
        /// Launches the workflow if configured
        /// </summary>
        private void LaunchWorkflow()
        {
            // Check to see if a workflow should be launched when viewed
            WorkflowTypeCache workflowType = null;
            Guid?workflowTypeGuid          = GetAttributeValue("WorkflowType").AsGuidOrNull();

            if (!workflowTypeGuid.HasValue)
            {
                return;
            }

            workflowType = WorkflowTypeCache.Get(workflowTypeGuid.Value);

            if (workflowType == null || (workflowType.IsActive != true))
            {
                return;
            }

            bool launchWorkflowOnlyIfIndividualLoggedIn = this.GetAttributeValue("LaunchWorkflowOnlyIfIndividualLoggedIn").AsBoolean();

            if (launchWorkflowOnlyIfIndividualLoggedIn && this.CurrentPerson == null)
            {
                // don't launch a workflow if LaunchWorkflowOnlyIfIndividualLoggedIn = true and nobody is logged in
                return;
            }

            var launchWorkflowCondition = this.GetAttributeValue("LaunchWorkflowCondition").ConvertToEnum <LaunchWorkflowCondition>();

            if (launchWorkflowCondition != LaunchWorkflowCondition.Always && this.CurrentPerson == null)
            {
                // don't launch a workflow if LaunchWorkflowOnlyIfIndividualLoggedIn = true and nobody is logged in
                return;
            }

            var contentChannelItem = GetContentChannelItem(this.GetContentChannelItemParameterValue());

            // use BlockUserPreference to store whether the Workflow was already launched depending on LaunchWorkflowCondition
            string alreadyLaunchedKey = null;

            if (launchWorkflowCondition == LaunchWorkflowCondition.OncePerPersonPerContentChannelItem)
            {
                alreadyLaunchedKey = string.Format("WorkflowLaunched_{0}_{1}", workflowType.Id, contentChannelItem.Id);
            }
            else if (launchWorkflowCondition == LaunchWorkflowCondition.OncePerPerson)
            {
                alreadyLaunchedKey = string.Format("WorkflowLaunched_{0}", workflowType.Id);
            }

            if (alreadyLaunchedKey != null)
            {
                var alreadyLaunched = this.GetBlockUserPreference(alreadyLaunchedKey).AsBooleanOrNull();
                if (alreadyLaunched == true)
                {
                    return;
                }
                else
                {
                    this.SetBlockUserPreference(alreadyLaunchedKey, true.ToString(), true);
                }
            }

            var workflowAttributeValues = new Dictionary <string, string>();

            workflowAttributeValues.Add("ContentChannelItem", contentChannelItem.Guid.ToString());

            LaunchWorkflowTransaction launchWorkflowTransaction;

            if (this.CurrentPersonId.HasValue)
            {
                workflowAttributeValues.Add("Person", this.CurrentPerson.Guid.ToString());
                launchWorkflowTransaction = new Rock.Transactions.LaunchWorkflowTransaction <Person>(workflowType.Id, null, this.CurrentPersonId.Value);
            }
            else
            {
                launchWorkflowTransaction = new Rock.Transactions.LaunchWorkflowTransaction(workflowType.Id, null);
            }

            if (workflowAttributeValues != null)
            {
                launchWorkflowTransaction.WorkflowAttributeValues = workflowAttributeValues;
            }

            launchWorkflowTransaction.InitiatorPersonAliasId = this.CurrentPersonAliasId;
            launchWorkflowTransaction.Enqueue();
        }
예제 #3
0
        /// <summary>
        /// Launches the workflow.
        /// </summary>
        /// <param name="workflowTypeId">The workflow type identifier.</param>
        private static void LaunchWorkflow(int workflowTypeId)
        {
            var transaction = new LaunchWorkflowTransaction(workflowTypeId);

            transaction.Enqueue();
        }