Esempio n. 1
0
        ///// <summary>
        ///// 验证锁定。如果打开即需要锁定,那么尝试锁定,并返回尝试结果;否则,检查是否有被其他工作项锁定,如果有则返回false,否则返回true。
        ///// </summary>
        ///// <param name="Enviroment"></param>
        ///// <param name="Message"></param>
        ///// <returns></returns>
        //public static bool ValidateLockLevel(SheetEnviroment Enviroment, ref string Message)
        //{
        //    return ValidateLockLevel(Enviroment.Engine,
        //        Enviroment.UserValidator,
        //        Enviroment.WorkflowActivity,
        //        Enviroment.WorkItem,
        //        ref Message);
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="Engine"></param>
        /// <param name="UserValidator"></param>
        /// <param name="WorkflowActivity"></param>
        /// <param name="WorkItem"></param>
        /// <param name="Message"></param>
        /// <returns></returns>
        public static bool ValidateLockLevel(IEngine Engine, UserValidator UserValidator,
                                             Activity WorkflowActivity, WorkItem.WorkItem WorkItem, ref string Message)
        {
            WorkflowTemplate.ParticipativeActivity task = WorkflowActivity as WorkflowTemplate.ParticipativeActivity;
            if (task != null && task.LockPolicy == OThinker.H3.WorkflowTemplate.LockPolicy.Open)
            {
                return(TryLock(Engine, UserValidator, WorkflowActivity, WorkItem, ref Message));
            }
            else if (!WorkItem.IsLocked)
            {
                // 没有被其他任何人锁定
                return(true);
            }
            else
            {
                string locker         = Engine.WorkItemManager.GetLocker(WorkItem.InstanceId, WorkItem.TokenId);
                string lockerFullName = Engine.Organization.GetName(locker);
                Message = string.Format(
                    Configs.Global.ResourceManager.GetString("SheetUtility_LockedBy"),
                    lockerFullName);
                if (task.LockLevel == WorkflowTemplate.LockLevel.Mono) // 禁止多人编辑表单
                {
                    return(false);
                }
                else // 当多人编辑表单时,只是给出提示
                {
                    return(true);
                }
            }
        }
Esempio n. 2
0
        ///// <summary>
        ///// 验证锁定级别
        ///// </summary>
        ///// <param name="Enviroment"></param>
        ///// <param name="Message"></param>
        ///// <returns></returns>
        //public static bool TryLock(SheetEnviroment Enviroment, ref string Message)
        //{
        //    return TryLock(Enviroment.Engine, Enviroment.UserValidator, Enviroment.WorkflowActivity, Enviroment.WorkItem, ref Message);
        //}

        /// <summary>
        /// 尝试锁定表单
        /// </summary>
        /// <param name="Engine"></param>
        /// <param name="UserValidator"></param>
        /// <param name="WorkflowActivity"></param>
        /// <param name="WorkItem"></param>
        /// <param name="Message"></param>
        /// <returns></returns>
        public static bool TryLock(IEngine Engine,
                                   UserValidator UserValidator,
                                   Activity WorkflowActivity,
                                   WorkItem.WorkItem WorkItem,
                                   ref string Message)
        {
            WorkItem.LockResult result = OThinker.H3.WorkItem.LockResult.Success;

            // 解析锁定的策略
            bool cancelOther = false;
            bool onlyWarning = false;

            WorkflowTemplate.ParticipativeActivity task = (WorkflowTemplate.ParticipativeActivity)WorkflowActivity;
            if (task != null)
            {
                switch (task.LockLevel)
                {
                case WorkflowTemplate.LockLevel.Warning:
                    onlyWarning = true;
                    cancelOther = false;
                    break;

                case WorkflowTemplate.LockLevel.Mono:
                    onlyWarning = false;
                    cancelOther = false;
                    break;

                case OThinker.H3.WorkflowTemplate.LockLevel.CancelOthers:
                    // 需要单独锁定
                    onlyWarning = false;
                    cancelOther = true;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            if (WorkItem.IsLocking)
            {
                //  已经执行过了锁定
                result = H3.WorkItem.LockResult.LockedAlready;
            }
            else if (WorkItem.IsLocked)
            {
                // 已经被锁定了
                result = H3.WorkItem.LockResult.LockedByOther;
            }
            else
            {
                // 需要单独锁定
                result = Engine.WorkItemManager.LockActivity(WorkItem.WorkItemID, UserValidator.UserID, cancelOther);
            }

            switch (result)
            {
            case OThinker.H3.WorkItem.LockResult.NoNeed:
            case OThinker.H3.WorkItem.LockResult.LockedAlready:
                return(true);

            case OThinker.H3.WorkItem.LockResult.Success:
                WorkItem.IsLocking = true;
                Message            = Configs.Global.ResourceManager.GetString("SheetUtility_LockSucceed");
                return(true);

            case OThinker.H3.WorkItem.LockResult.LockedByOther:
                // 找到当前的所有正在进行操作的用户
                string locker = Engine.WorkItemManager.GetLocker(WorkItem.InstanceId, WorkItem.TokenId);
                // 生成提示
                Message = string.Format(
                    Configs.Global.ResourceManager.GetString("SheetUtility_LockedBy"),
                    Engine.Organization.GetName(locker)
                    //Engine.Organization.GetFullName(locker)
                    );

                // 如果锁定级别是提示,那么仍然返回true,表示验证成功;否则返回false,表示验证失败
                if (onlyWarning)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                throw new NotImplementedException();
            }
        }