Ejemplo n.º 1
0
        public void LockSettingsUnLockTest()
        {
            string lockId = "LockID2";
            IUser  user   = (IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object;

            MCS.Library.SOA.DataObjects.Lock _lock = GetInstanceOfLock(lockId, user);

            LockAdapter.SetLock(_lock);
            CheckLockResult result = LockAdapter.CheckLock(lockId, user.ID);

            Assert.IsNotNull(result.CurrentLock);

            LockAdapter.Unlock(lockId, user.ID);

            CheckLockResult checkResult = LockAdapter.CheckLock(lockId, user.ID);

            Assert.IsNull(checkResult.CurrentLock);

            IUser user2 = (IUser)OguObjectSettings.GetConfig().Objects["ceo"].Object;

            result.CurrentLock.PersonID = user2.ID;
            LockAdapter.SetLock(result.CurrentLock);

            CheckLockResult reResult = LockAdapter.CheckLock(lockId, user2.ID);

            Assert.IsNotNull(reResult.CurrentLock);

            LockAdapter.Unlock(lockId, user2.ID);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 检查锁是否有效,只需一个无效,则抛异常
        /// </summary>
        public void CheckLocksAvailable()
        {
            foreach (Lock lockInfo in this._Locks)
            {
                CheckLockResult result = LockAdapter.CheckLock(lockInfo);

                ExceptionHelper.FalseThrow(
                    result.CurrentLockStatus == LockStatus.LockedByRight || result.CurrentLockStatus == LockStatus.LockedByRightAndExpire,
                    result.GetCheckLockStatusText());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查锁
        /// </summary>
        private static void CheckLock(string lockID, string personID)
        {
            if (!string.IsNullOrEmpty(lockID) && !string.IsNullOrEmpty(personID))
            {
                CheckLockResult result = LockAdapter.CheckLock(lockID, personID);

                //如果不是本人加锁 则不允许上传
                ExceptionHelper.FalseThrow(
                    (result.CurrentLockStatus == LockStatus.LockedByRight ||
                     result.CurrentLockStatus == LockStatus.LockedByRightAndExpire),
                    CheckLockOperation.GetCheckLockStatusText(result));
            }
        }
Ejemplo n.º 4
0
        public void LockSettingsSaveTest()
        {
            string lockId = "LockID1";
            IUser  user   = (IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object;

            MCS.Library.SOA.DataObjects.Lock _lock = GetInstanceOfLock(lockId, user);

            LockAdapter.SetLock(_lock);

            CheckLockResult result = LockAdapter.CheckLock(lockId, user.ID);

            Assert.AreEqual(user.ID, result.PersonID);
            Assert.AreEqual(lockId, result.CurrentLock.LockID);

            LockAdapter.Unlock(lockId, user.ID);
        }
Ejemplo n.º 5
0
        public void LockSettingsFoceLockTest()
        {
            string lockId = "LockID3";
            IUser  user   = (IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object;

            MCS.Library.SOA.DataObjects.Lock _lock = GetInstanceOfLock(lockId, user);
            _lock.LockType = LockType.AdminLock;
            LockAdapter.SetLock(_lock);

            CheckLockResult result = LockAdapter.CheckLock(_lock.LockID, user.ID);

            IUser user2 = (IUser)OguObjectSettings.GetConfig().Objects["ceo"].Object;

            result.CurrentLock.LockType = LockType.ActivityLock;
            result.CurrentLock.PersonID = user2.ID;
            LockAdapter.SetLock(result.CurrentLock, true);

            LockAdapter.Unlock(result.CurrentLock.LockID, user.ID);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 根据checkLock的结果显示不同的信息
        /// </summary>
        /// <param name="CheckLockResult">操作返回的对象</param>
        /// <returns></returns>
        public static string GetCheckLockStatusText(CheckLockResult chkResult)
        {
            string result;

            string displayName = string.Empty;

            if (chkResult.CurrentLock != null)
            {
                displayName = GetDisplayName(chkResult.CurrentLock.PersonID);
            }

            switch (chkResult.CurrentLockStatus)
            {
            case LockStatus.LockedByAnother:
                result = string.Format(Resources.LockedByAnother, displayName);
                break;

            case LockStatus.NotLocked:
                result = Resources.NotLocked;
                break;

            case LockStatus.LockByAnotherAndExpire:
                result = string.Format(Resources.LockByAnotherAndExpire, displayName);
                break;

            case LockStatus.LockedByRight:
                result = Resources.LockedByRight;
                break;

            case LockStatus.LockedByRightAndExpire:
                result = Resources.LockedByRightAndExpire;
                break;

            default:
                result = string.Empty;
                break;
            }

            return(result);
        }