/// <summary>
        /// 启动流程
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <param name="result">结果对象</param>
        /// <returns>运行时实例对象</returns>
        public static WfRuntimeManager CreateRuntimeInstanceStartup(WfAppRunner runner,
                                                                    ref WfExecutedResult result)
        {
            //检查流程是否可以被启动
            var rmins = new WfRuntimeManagerStartup();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            //正常流程启动
            var pim = new ProcessInstanceManager();
            ProcessInstanceEntity processInstance = pim.GetProcessInstanceCurrent(runner.AppInstanceID,
                                                                                  runner.ProcessGUID);

            //不能同时启动多个主流程
            if (processInstance != null &&
                processInstance.ParentProcessInstanceID == null &&
                processInstance.ProcessState == (short)ProcessStateEnum.Running)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Started_IsRunningAlready;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceStartup.error");
                return(rmins);
            }

            rmins.AppRunner = runner;

            //获取流程第一个可办理节点
            rmins.ProcessModel = ProcessModelFactory.Create(runner.ProcessGUID, runner.Version);
            var startActivity = rmins.ProcessModel.GetStartActivity();
            var firstActivity = rmins.ProcessModel.GetFirstActivity();

            //var firstActivityList = rmins.ProcessModel.GetFirstActivityList(startActivity, runner.Conditions);

            if (startActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.None)
            {
                rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(firstActivity.ActivityGUID,
                                                                                                       runner.UserID,
                                                                                                       runner.UserName);
            }
            else if (startActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.Timer ||
                     startActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.Message)
            {
                if (!string.IsNullOrEmpty(runner.UserID))
                {
                    rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(firstActivity.ActivityGUID,
                                                                                                           runner.UserID,
                                                                                                           runner.UserName);
                }
                else
                {
                    rmins.AppRunner.NextActivityPerformers = rmins.ProcessModel.GetActivityPerformers(firstActivity.ActivityGUID);
                }
            }
            rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);

            return(rmins);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 启动流程
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <param name="result">结果对象</param>
        /// <returns>运行时实例对象</returns>
        public static WfRuntimeManager CreateRuntimeInstanceStartup(WfAppRunner runner,
                                                                    ref WfExecutedResult result)
        {
            //检查流程是否可以被启动
            var rmins = new WfRuntimeManagerStartup();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            //正常流程启动
            var pim = new ProcessInstanceManager();
            ProcessInstanceEntity processInstance = pim.GetProcessInstanceCurrent(runner.AppInstanceID,
                                                                                  runner.ProcessGUID);

            //不能同时启动多个主流程
            if (processInstance != null &&
                processInstance.ParentProcessInstanceID == null &&
                processInstance.ProcessState == (short)ProcessStateEnum.Running)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Started_IsRunningAlready;
                result.Message       = "流程已经处于运行状态,如果要重新启动,请先终止当前流程实例!";
                return(rmins);
            }

            rmins.AppRunner = runner;

            //获取流程第一个可办理节点
            rmins.ProcessModel = ProcessModelFactory.Create(runner.ProcessGUID, runner.Version);
            var startActivity = rmins.ProcessModel.GetStartActivity();
            var firstActivity = rmins.ProcessModel.GetFirstActivity();

            if (startActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.None)
            {
                rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(firstActivity.ActivityGUID,
                                                                                                       runner.UserID,
                                                                                                       runner.UserName);
            }
            else if (startActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.Timer)
            {
                var roleList = rmins.ProcessModel.GetActivityRoles(firstActivity.ActivityGUID);
                rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(firstActivity.ActivityGUID, roleList);
            }
            rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);

            return(rmins);
        }