private static void OnFinish(FlowToken flowToken, Dictionary <string, object> bindings, FlowControllerServicesContainer serviceContainer)
        {
            WorkflowFlowToken workflowFlowToken = (WorkflowFlowToken)flowToken;

            using (TaskContainer taskContainer = TaskManagerFacade.RuntTasks(flowToken, new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId)
            {
                EventName = "Finish"
            }))
            {
                TaskManagerFlowControllerService taskManagerFlowControllerService = new TaskManagerFlowControllerService(taskContainer);
                serviceContainer.AddService(taskManagerFlowControllerService);

                WorkflowFacade.FireFinishEvent(workflowFlowToken.WorkflowInstanceId, bindings);
                WorkflowFacade.SetFlowControllerServicesContainer(workflowFlowToken.WorkflowInstanceId, serviceContainer);
                WorkflowFacade.RunWorkflow(workflowFlowToken.WorkflowInstanceId);
                taskContainer.SetOnIdleTaskManagerEvent(new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId));
            }


            IFormFlowRenderingService formServices = serviceContainer.GetService <IFormFlowRenderingService>();

            if (!formServices.HasFieldMessages)
            {
                serviceContainer.GetService <IFormFlowRenderingService>().RerenderView();
            }
        }
Exemplo n.º 2
0
        private static void OnCancel(FlowToken flowToken, Dictionary <string, object> bindings, FlowControllerServicesContainer serviceContainer)
        {
            WorkflowFlowToken workflowFlowToken = (WorkflowFlowToken)flowToken;

            if (WorkflowFacade.WorkflowExists(workflowFlowToken.WorkflowInstanceId))
            {
                using (TaskManagerFacade.RuntTasks(flowToken, new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId)
                {
                    EventName = "Cancel"
                }))
                {
                    WorkflowFacade.FireCancelEvent(workflowFlowToken.WorkflowInstanceId, bindings);
                    WorkflowFacade.SetFlowControllerServicesContainer(workflowFlowToken.WorkflowInstanceId, serviceContainer);
                    WorkflowFacade.RunWorkflow(workflowFlowToken.WorkflowInstanceId);
                }
            }
            else
            {
                Log.LogVerbose(LogTitle, "Cancel event suppressed because the workflow was terminated ({0})", workflowFlowToken.WorkflowInstanceId);
            }

            if (serviceContainer != null)
            {
                serviceContainer.GetService <IFormFlowRenderingService>().RerenderView();
            }
        }
        private void OnWorkflowInstanceTerminatedCleanup(Guid instanceId)
        {
            AbortedWorkflows.Remove(instanceId);

            WorkflowFlowToken flowToken = new WorkflowFlowToken(instanceId);

            TaskManagerFacade.CompleteTasks(flowToken);

            ReleaseAllLocks(instanceId);

            SetWorkflowInstanceStatus(instanceId, WorkflowInstanceStatus.Terminated, false);

            RemoveFlowControllerServicesContainer(instanceId);

            RemoveIfExistFormData(instanceId);

            RemovePersistingType(instanceId);

            DeletePersistedWorkflow(instanceId);

            DeletePersistedFormData(instanceId);

            using (ThreadDataManager.EnsureInitialize())
            {
                FlowControllerFacade.FlowComplete(new WorkflowFlowToken(instanceId));
            }
        }
        private static void OnPreview(FlowToken flowToken, Dictionary <string, object> bindings, FlowControllerServicesContainer serviceContainer)
        {
            WorkflowFlowToken workflowFlowToken = (WorkflowFlowToken)flowToken;

            using (TaskContainer taskContainer = TaskManagerFacade.RuntTasks(flowToken, new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId)
            {
                EventName = "Preview"
            }))
            {
                WorkflowFacade.FirePreviewEvent(workflowFlowToken.WorkflowInstanceId, bindings);
                WorkflowFacade.SetFlowControllerServicesContainer(workflowFlowToken.WorkflowInstanceId, serviceContainer);
                WorkflowFacade.RunWorkflow(workflowFlowToken.WorkflowInstanceId);
                taskContainer.SetOnIdleTaskManagerEvent(new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId));
            }
        }
        private static void OnCustomEvent(int customEventNumber, FlowToken flowToken, Dictionary <string, object> bindings, FlowControllerServicesContainer serviceContainer)
        {
            if (customEventNumber < 1 || customEventNumber > 5)
            {
                throw new ArgumentException("Number must be between 1 and 5", nameof(customEventNumber));
            }

            WorkflowFlowToken workflowFlowToken = (WorkflowFlowToken)flowToken;

            using (TaskContainer taskContainer = TaskManagerFacade.RuntTasks(flowToken, new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId)
            {
                EventName = "CustomEvent0" + customEventNumber
            }))
            {
                WorkflowFacade.FireCustomEvent(customEventNumber, workflowFlowToken.WorkflowInstanceId, bindings);
                WorkflowFacade.SetFlowControllerServicesContainer(workflowFlowToken.WorkflowInstanceId, serviceContainer);
                WorkflowFacade.RunWorkflow(workflowFlowToken.WorkflowInstanceId);
                taskContainer.SetOnIdleTaskManagerEvent(new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId));
            }
        }
        private static void OnSaveAndPublish(FlowToken flowToken, Dictionary <string, object> bindings, FlowControllerServicesContainer serviceContainer)
        {
            WorkflowFlowToken workflowFlowToken = (WorkflowFlowToken)flowToken;

            using (TaskContainer taskContainer = TaskManagerFacade.RuntTasks(flowToken, new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId)
            {
                EventName = "Save"
            }))
            {
                TaskManagerFlowControllerService taskManagerFlowControllerService = new TaskManagerFlowControllerService(taskContainer);
                serviceContainer.AddService(taskManagerFlowControllerService);

                WorkflowFacade.FireSaveAndPublishEvent(workflowFlowToken.WorkflowInstanceId, bindings);
                WorkflowFacade.SetFlowControllerServicesContainer(workflowFlowToken.WorkflowInstanceId, serviceContainer);
                WorkflowFacade.RunWorkflow(workflowFlowToken.WorkflowInstanceId);
                taskContainer.SetOnIdleTaskManagerEvent(new WorkflowTaskManagerEvent(flowToken, workflowFlowToken.WorkflowInstanceId));

                serviceContainer.RemoveService(taskManagerFlowControllerService);
            }
        }
        /// <exclude />
        public static FlowToken Execute(EntityToken entityToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer, TaskManagerEvent taskManagerEvent)
        {
            if (entityToken == null)
            {
                throw new ArgumentNullException("entityToken");
            }
            if (actionToken == null)
            {
                throw new ArgumentNullException("actionToken");
            }


            string username = UserValidationFacade.GetUsername();

#if NO_SECURITY
#else
            HookingFacade.EnsureInitialization();

            IEnumerable <UserPermissionDefinition>      userPermissionDefinitions      = PermissionTypeFacade.GetUserPermissionDefinitions(username);
            IEnumerable <UserGroupPermissionDefinition> userGroupPermissionDefinitions = PermissionTypeFacade.GetUserGroupPermissionDefinitions(username);
            SecurityResult securityResult = SecurityResolver.Resolve(UserValidationFacade.GetUserToken(), actionToken, entityToken, userPermissionDefinitions, userGroupPermissionDefinitions);
            if (securityResult != SecurityResult.Allowed && !(entityToken is SecurityViolationWorkflowEntityToken))
            {
                return(ExecuteSecurityViolation(actionToken, entityToken, flowControllerServicesContainer));
            }
#endif

            bool ignoreLocking = actionToken.IsIgnoreEntityTokenLocking();

            if (!ignoreLocking && ActionLockingFacade.IsLocked(entityToken))
            {
                return(ExecuteEntityTokenLocked(actionToken, entityToken, flowControllerServicesContainer));
            }

            IActionExecutor actionExecutor = ActionExecutorCache.GetActionExecutor(actionToken);

            ActionEventSystemFacade.FireOnBeforeActionExecution(entityToken, actionToken);

            FlowToken flowToken;
            using (TaskContainer taskContainer = TaskManagerFacade.CreateNewTasks(entityToken, actionToken, taskManagerEvent))
            {
                ITaskManagerFlowControllerService taskManagerService = null;
                if (flowControllerServicesContainer.GetService(typeof(ITaskManagerFlowControllerService)) == null)
                {
                    taskManagerService = new TaskManagerFlowControllerService(taskContainer);
                    flowControllerServicesContainer.AddService(taskManagerService);
                }

                try
                {
                    if (actionExecutor is IActionExecutorSerializedParameters)
                    {
                        string serializedEntityToken = EntityTokenSerializer.Serialize(entityToken);
                        string serializedActionToken = ActionTokenSerializer.Serialize(actionToken);

                        flowToken = Execute(actionExecutor as IActionExecutorSerializedParameters,
                                            serializedEntityToken, serializedActionToken, actionToken,
                                            flowControllerServicesContainer);
                    }
                    else
                    {
                        flowToken = Execute(actionExecutor, entityToken, actionToken,
                                            flowControllerServicesContainer);
                    }
                }
                finally
                {
                    if (taskManagerService != null)
                    {
                        flowControllerServicesContainer.RemoveService(taskManagerService);
                    }
                }

                taskContainer.SetOnIdleTaskManagerEvent(new FlowTaskManagerEvent(flowToken));
                taskContainer.UpdateTasksWithFlowToken(flowToken);

                taskContainer.SaveTasks();
            }

            ActionEventSystemFacade.FireOnAfterActionExecution(entityToken, actionToken, flowToken);

            IManagementConsoleMessageService managementConsoleMessageService = flowControllerServicesContainer
                                                                               .GetService <IManagementConsoleMessageService>();
            if (managementConsoleMessageService != null)
            {
                FlowControllerFacade.RegisterNewFlowInformation(flowToken, entityToken, actionToken,
                                                                managementConsoleMessageService.CurrentConsoleId);
            }
            else
            {
                Log.LogWarning(nameof(ActionExecutorFacade), "Missing ManagementConsoleMessageService, can not register the flow");
            }

            return(flowToken);
        }