Ejemplo n.º 1
0
        /// <summary>
        /// 读取任务,设置任务为已读状态
        /// </summary>
        /// <param name="taskID"></param>
        /// <param name="userID"></param>
        /// <param name="userName"></param>
        internal void Read(long taskID,
                           int userID,
                           string userName)
        {
            ISession session = SessionFactory.CreateSession();

            try
            {
                //置任务为处理状态
                var task      = GetTask(taskID);
                var logonUser = new WfLogonUser(userID, userName);
                SetTaskState(task, logonUser, TaskStateEnum.Handling, session);

                //置活动为运行状态
                (new ActivityInstanceManager()).Read(task.ActivityInstanceGUID, logonUser, session);

                session.Commit();
            }
            catch (System.Exception e)
            {
                session.Rollback();
                throw new WorkflowException(string.Format("阅读待办任务时出错!,详细错误:{0}", e.Message), e);
            }
            finally
            {
                session.Dispose();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建活动实例的对象
        /// </summary>
        /// <param name="activity"></param>
        /// <param name="processInstance"></param>
        /// <returns></returns>
        internal ActivityInstanceEntity CreateActivityInstanceObject(string appName,
                                                                     int appInstanceID,
                                                                     Guid processInstanceGUID,
                                                                     ActivityEntity activity,
                                                                     WfLogonUser logonUser)
        {
            ActivityInstanceEntity instance = new ActivityInstanceEntity();

            instance.ActivityGUID           = activity.ActivityGUID;
            instance.ActivityName           = activity.ActivityName;
            instance.ActivityType           = (short)activity.NodeType;
            instance.GatewayDirectionTypeID = (short)activity.GatewayDirectionType;
            instance.ProcessGUID            = activity.ProcessGUID;
            instance.AppName              = appName;
            instance.AppInstanceID        = appInstanceID;
            instance.ProcessInstanceGUID  = processInstanceGUID;
            instance.ActivityInstanceGUID = Guid.NewGuid();
            instance.TokensRequired       = 1;
            instance.TokensHad            = 1;
            instance.CreatedByUserID      = logonUser.UserID;
            instance.CreatedByUserName    = logonUser.UserName;
            instance.CreatedDateTime      = System.DateTime.Now;
            instance.State            = (short)NodeStateEnum.Ready;
            instance.CanRenewInstance = 0;

            return(instance);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 插入任务数据
 /// </summary>
 /// <param name="activityInstance"></param>
 /// <param name="performers"></param>
 /// <param name="wfLinqDataContext"></param>
 internal void Insert(ActivityInstanceEntity activityInstance,
                      PerformerList performers,
                      WfLogonUser logonUser,
                      ISession session)
 {
     foreach (Performer performer in performers)
     {
         TaskEntity entity = new TaskEntity();
         entity.AppName              = activityInstance.AppName;
         entity.AppInstanceID        = activityInstance.AppInstanceID;
         entity.ActivityInstanceGUID = activityInstance.ActivityInstanceGUID;
         entity.ProcessInstanceGUID  = activityInstance.ProcessInstanceGUID;
         entity.ActivityGUID         = activityInstance.ActivityGUID;
         entity.ActivityName         = activityInstance.ActivityName;
         entity.ProcessGUID          = activityInstance.ProcessGUID;
         entity.TaskType             = (short)TaskTypeEnum.Manual;
         entity.AssignedToUserID     = performer.UserID;
         entity.AssignedToUserName   = performer.UserName;
         entity.TaskState            = 1; //1-待办状态
         entity.CreatedByUserID      = logonUser.UserID;
         entity.CreatedByUserName    = logonUser.UserName;
         entity.CreatedDateTime      = System.DateTime.Now;
         entity.RecordStatusInvalid  = 0;
         Insert(entity, session);
     }
 }
Ejemplo n.º 4
0
        internal TransitionInstanceEntity CreateTransitionInstanceObject(ProcessInstanceEntity processInstance,
                                                                         TransitionEntity transition,
                                                                         ActivityInstanceEntity fromActivityInstance,
                                                                         ActivityInstanceEntity toActivityInstance,
                                                                         TransitionTypeEnum transitionType,
                                                                         WfLogonUser logonUser,
                                                                         byte conditionParseResult)
        {
            var entity = new TransitionInstanceEntity();

            entity.AppName                  = processInstance.AppName;
            entity.AppInstanceID            = processInstance.AppInstanceID;
            entity.TransitionInstanceGUID   = Guid.NewGuid();
            entity.ProcessGUID              = processInstance.ProcessGUID;
            entity.ProcessInstanceGUID      = processInstance.ProcessInstanceGUID;
            entity.TransitionGUID           = transition.TransitionGUID;
            entity.TransitionType           = (byte)transitionType;
            entity.FromActivityGUID         = transition.FromActivityGUID;
            entity.FromActivityInstanceGUID = fromActivityInstance.ActivityInstanceGUID;
            entity.FromActivityType         = fromActivityInstance.ActivityType;
            entity.FromActivityName         = fromActivityInstance.ActivityName;
            entity.ToActivityGUID           = transition.ToActivityGUID;
            entity.ToActivityInstanceGUID   = toActivityInstance.ActivityInstanceGUID;
            entity.ToActivityType           = toActivityInstance.ActivityType;
            entity.ToActivityName           = toActivityInstance.ActivityName;
            entity.ConditionParseResult     = conditionParseResult;
            entity.CreatedByUserID          = logonUser.UserID;
            entity.CreatedByUserName        = logonUser.UserName;
            entity.CreatedDateTime          = System.DateTime.Now;

            return(entity);
        }
Ejemplo n.º 5
0
 internal ActivityResource(int userID,
                           string userName,
                           IDictionary <Guid, PerformerList> nextActivityPerformers,
                           IDictionary <string, string> conditionKeyValuePair = null)
 {
     LogonUser = new WfLogonUser(userID, userName);
     NextActivityPerformers = nextActivityPerformers;
     ConditionKeyValuePair  = conditionKeyValuePair;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 更新活动节点的Token数目
        /// </summary>
        /// <param name="activityInstanceGUID"></param>
        /// <param name="logonUser"></param>
        /// <param name="wfLinqDataContext"></param>
        internal void IncreaseTokensHad(Guid activityInstanceGUID,
                                        WfLogonUser logonUser,
                                        ISession session)
        {
            ActivityInstanceEntity activityInstance = GetById(activityInstanceGUID);

            activityInstance.TokensHad += 1;
            Update(activityInstance, session);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 设置任务状态
 /// </summary>
 /// <param name="task"></param>
 /// <param name="logonUser"></param>
 /// <param name="taskState"></param>
 /// <param name="session"></param>
 private void SetTaskState(TaskEntity task,
                           WfLogonUser logonUser,
                           TaskStateEnum taskState,
                           ISession session)
 {
     task.TaskState             = (short)taskState;
     task.LastUpdatedByUserID   = logonUser.UserID;
     task.LastUpdatedByUserName = logonUser.UserName;
     task.LastUpdatedDateTime   = System.DateTime.Now;
     Update(task, session);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 设置任务完成
        /// </summary>
        /// <param name="taskID">任务ID</param>
        /// <param name="currentLogonUser"></param>
        /// <param name="wfLinqDataContext"></param>
        internal void Complete(long taskID,
                               WfLogonUser currentLogonUser,
                               ISession session)
        {
            TaskEntity task = TaskRepository.GetById <TaskEntity>(taskID);

            task.TaskState       = (byte)TaskStateEnum.Completed;
            task.EndedDateTime   = DateTime.Now;
            task.EndedByUserID   = currentLogonUser.UserID;
            task.EndedByUserName = currentLogonUser.UserName;

            Update(task, session);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 设置活动实例状态
        /// </summary>
        /// <param name="activityInstanceGUID"></param>
        /// <param name="nodeState"></param>
        /// <param name="logonUser"></param>
        /// <param name="session"></param>
        private void SetActivityState(Guid activityInstanceGUID,
                                      NodeStateEnum nodeState,
                                      WfLogonUser logonUser,
                                      ISession session)
        {
            var activityInstance = GetById(activityInstanceGUID);

            activityInstance.State = (short)nodeState;
            activityInstance.LastUpdatedByUserID   = logonUser.UserID;
            activityInstance.LastUpdatedByUserName = logonUser.UserName;
            activityInstance.LastUpdatedDateTime   = System.DateTime.Now;
            Update(activityInstance, session);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 创建节点对象
        /// </summary>
        /// <param name="processInstance">流程实例</param>
        internal ActivityInstanceEntity CreateActivityInstanceObject(ProcessInstanceEntity processInstance,
                                                                     WfLogonUser logonUser)
        {
            ActivityInstanceManager aim = new ActivityInstanceManager();

            this.ActivityInstance = aim.CreateActivityInstanceObject(processInstance.AppName,
                                                                     processInstance.AppInstanceID,
                                                                     processInstance.ProcessInstanceGUID,
                                                                     Activity,
                                                                     logonUser);

            AfterActivityInstanceObjectCreated();
            return(this.ActivityInstance);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 活动实例完成
        /// </summary>
        /// <param name="activityInstanceGUID"></param>
        /// <param name="logonUser"></param>
        /// <param name="session"></param>
        internal void Complete(Guid activityInstanceGUID,
                               WfLogonUser logonUser,
                               ISession session)
        {
            var activityInstance = GetById(activityInstanceGUID, session);

            activityInstance.State = (short)NodeStateEnum.Completed;
            activityInstance.IsActivityCompleted   = 1;
            activityInstance.LastUpdatedByUserID   = logonUser.UserID;
            activityInstance.LastUpdatedByUserName = logonUser.UserName;
            activityInstance.LastUpdatedDateTime   = System.DateTime.Now;
            activityInstance.EndedByUserID         = logonUser.UserID;
            activityInstance.EndedByUserName       = logonUser.UserName;
            activityInstance.EndedDateTime         = System.DateTime.Now;

            Update(activityInstance, session);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 流程完成,设置流程的状态为完成
        /// </summary>
        /// <returns>是否成功</returns>
        internal void Complete(Guid processInstanceGUID, WfLogonUser currentUser, ISession session)
        {
            var bEntity      = GetById(processInstanceGUID);
            var processState = (ProcessStateEnum)Enum.Parse(typeof(ProcessStateEnum), bEntity.ProcessState.ToString());

            if ((processState | ProcessStateEnum.Running) == ProcessStateEnum.Running)
            {
                bEntity.ProcessState       = (short)ProcessStateEnum.Completed;
                bEntity.IsProcessCompleted = 1;
                bEntity.EndedDateTime      = System.DateTime.Now;
                bEntity.EndedByUserID      = currentUser.UserID;
                bEntity.EndedByUserName    = currentUser.UserName;

                Update(bEntity, session);
            }
            else
            {
                throw new ProcessInstanceException("流程不在运行状态,不能被完成!");
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 插入连线实例的方法
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="fromToTransition"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="toActivityInstance"></param>
        /// <param name="conditionParseResult"></param>
        /// <param name="wfLinqDataContext"></param>
        /// <returns></returns>
        internal virtual void InsertTransitionInstance(ProcessInstanceEntity processInstance,
                                                       TransitionEntity fromToTransition,
                                                       ActivityInstanceEntity fromActivityInstance,
                                                       ActivityInstanceEntity toActivityInstance,
                                                       TransitionTypeEnum transitionType,
                                                       WfLogonUser logonUser,
                                                       ISession session)
        {
            var tim = new TransitionInstanceManager();
            var transitionInstanceObject = tim.CreateTransitionInstanceObject(processInstance,
                                                                              fromToTransition,
                                                                              fromActivityInstance,
                                                                              toActivityInstance,
                                                                              transitionType,
                                                                              logonUser,
                                                                              (byte)ConditionParseResultEnum.Passed);

            tim.Insert(transitionInstanceObject,
                       session);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 返签流程,将流程状态置为返签,并修改流程未完成标志
        /// </summary>
        /// <param name="processInstanceGUID"></param>
        /// <param name="currentUser"></param>
        /// <param name="session"></param>
        internal void Reverse(Guid processInstanceGUID,
                              WfLogonUser currentUser,
                              ISession session)
        {
            var bEntity = GetById(processInstanceGUID);

            if (bEntity.ProcessState == (short)ProcessStateEnum.Completed)
            {
                bEntity.ProcessState          = (short)ProcessStateEnum.Running;
                bEntity.IsProcessCompleted    = 0;
                bEntity.LastUpdatedByUserID   = currentUser.UserID;
                bEntity.LastUpdatedByUserName = currentUser.UserName;
                bEntity.LastUpdatedDateTime   = System.DateTime.Now;

                Update(bEntity, session);
            }
            else
            {
                throw new ProcessInstanceException("流程不在运行状态,不能被完成!");
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// 退回活动实例
 /// </summary>
 /// <param name="activityInstanceGUID"></param>
 /// <param name="logonUser"></param>
 /// <param name="session"></param>
 internal void Reject(Guid activityInstanceGUID,
                      WfLogonUser logonUser,
                      ISession session)
 {
     SetActivityState(activityInstanceGUID, NodeStateEnum.Rejected, logonUser, session);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 撤销活动实例
 /// </summary>
 /// <param name="activityInstanceGUID"></param>
 /// <param name="logonUser"></param>
 /// <param name="session"></param>
 internal void Withdraw(Guid activityInstanceGUID,
                        WfLogonUser logonUser,
                        ISession session)
 {
     SetActivityState(activityInstanceGUID, NodeStateEnum.Withdrawed, logonUser, session);
 }