Exemple #1
0
        /// <summary>
        /// 派单
        /// </summary>
        /// <param name="entity"></param>
        public WfAppResult Dispatch(ProductOrderEntity entity)
        {
            //启动流程
            var appResult = WfAppResult.Default();
            var wfas      = new WfAppInteropService();

            try
            {
                //判断流程有没有已经启动
                var isRunning = wfas.CheckProcessInstanceRunning(WfAppRunner);
                if (isRunning == false)
                {
                    var startedResult = wfas.StartProcess(WfAppRunner);
                    if (startedResult.Status != WfExecutedStatus.Success)
                    {
                        appResult = WfAppResult.Error(startedResult.Message);
                        return(appResult);
                    }
                }
            }
            catch (System.Exception ex)
            {
                appResult = WfAppResult.Error(ex.Message);
                return(appResult);
            }

            //运行流程部分
            //继续下一步运行
            var session = SessionFactory.CreateSession();

            try
            {
                session.BeginTrans();

                //运行流程
                var runResult = wfas.RunProcess(session, WfAppRunner, WfAppRunner.Conditions);
                if (runResult.Status == WfExecutedStatus.Success)
                {
                    //写步骤记录表
                    Write(session, WfAppRunner, "派单", entity.ID.ToString(), entity.OrderCode, "完成派单");

                    //业务数据处理部分,此处是简单示例...
                    short status = GetProductOrderStatusByActivityCode(WfAppRunner.ProcessGUID, WfAppRunner.Version,
                                                                       WfAppRunner.NextActivityPerformers.Keys.ElementAt <string>(0));
                    UpdateStatus(entity.ID, status, session);
                    session.Commit();
                    appResult = WfAppResult.Success();
                }
                else
                {
                    session.Rollback();
                    appResult = WfAppResult.Error(runResult.Message);
                }
            }
            catch (System.Exception ex)
            {
                session.Rollback();
                appResult = WfAppResult.Error(ex.Message);
            }
            finally
            {
                session.Dispose();
            }
            return(appResult);
        }
        /// <summary>
        /// 派单
        /// </summary>
        /// <param name="entity"></param>
        public WfAppResult Dispatch(ProductOrderEntity entity)
        {
            //启动流程
            var appResult = WfAppResult.Default();
            var wfas = new WfAppInteropService();

            try
            {
                //判断流程有没有已经启动
                var isRunning = wfas.CheckProcessInstanceRunning(WfAppRunner);
                if (isRunning == false)
                {
                    var startedResult = wfas.StartProcess(WfAppRunner);
                    if (startedResult.Status != WfExecutedStatus.Success)
                    {
                        appResult = WfAppResult.Error(startedResult.Message);
                        return appResult;
                    }
                }
            }
            catch (System.Exception ex)
            {
                appResult = WfAppResult.Error(ex.Message);
                return appResult;
            }

            //运行流程部分
            //继续下一步运行
            var session = SessionFactory.CreateSession();
            try
            {
                session.BeginTrans();

                //运行流程
                var runResult = wfas.RunProcess(session, WfAppRunner, WfAppRunner.Conditions);
                if (runResult.Status == WfExecutedStatus.Success)
                {

                    //写步骤记录表
                    Write(session, WfAppRunner, "派单", entity.ID.ToString(), entity.OrderCode, "完成派单");

                    //业务数据处理部分,此处是简单示例...
                    short status = GetProductOrderStatusByActivityCode(WfAppRunner.ProcessGUID, WfAppRunner.Version,
                        WfAppRunner.NextActivityPerformers.Keys.ElementAt<string>(0));
                    UpdateStatus(entity.ID, status, session);
                    session.Commit();
                    appResult = WfAppResult.Success();
                }
                else
                {
                    session.Rollback();
                    appResult = WfAppResult.Error(runResult.Message);
                }
            }
            catch (System.Exception ex)
            {
                session.Rollback();
                appResult = WfAppResult.Error(ex.Message);
            }
            finally
            {
                session.Dispose();
            }
            return appResult;
        }