Esempio n. 1
0
        public void AddNewLockTest()
        {
            SCLock lockData = new SCLock();

            lockData.LockID = UuidHelper.NewUuidString();

            SCCheckLockResult result = SCLockAdapter.Instance.AddLock(lockData);

            Assert.IsTrue(result.Available);
            Assert.IsTrue(result.Lock.LockTime > DateTime.MinValue);
        }
Esempio n. 2
0
        public void AddExistedNewLockTest()
        {
            SCLock lockData = new SCLock();

            lockData.LockID = UuidHelper.NewUuidString();

            SCCheckLockResult result = SCLockAdapter.Instance.AddLock(lockData);

            //重复加锁
            result = SCLockAdapter.Instance.AddLock(lockData);

            Assert.IsFalse(result.Available);
            Assert.AreEqual(SCCheckLockStatus.Locked, result.LockStatus);
        }
Esempio n. 3
0
        public void ExtendExistedLockTest()
        {
            SCLock lockData = new SCLock();

            lockData.LockID = UuidHelper.NewUuidString();

            SCCheckLockResult result = SCLockAdapter.Instance.AddLock(lockData);

            Thread.Sleep(500);

            //延长
            SCCheckLockResult extendedResult = SCLockAdapter.Instance.ExtendLockTime(lockData);

            Assert.IsTrue(extendedResult.Lock.LockTime > result.Lock.LockTime);

            Console.WriteLine("Original time: {0:yyyy-MM-dd HH:mm:ss.ffff}, extended time: {1:yyyy-MM-dd HH:mm:ss.ffff}",
                              result.Lock.LockTime, extendedResult.Lock.LockTime);
        }
Esempio n. 4
0
        public void AddExistedExpiredNewLockTest()
        {
            SCLock lockData = new SCLock();

            lockData.EffectiveTime = TimeSpan.FromSeconds(1);
            lockData.LockID        = UuidHelper.NewUuidString();

            SCCheckLockResult result = SCLockAdapter.Instance.AddLock(lockData);

            Thread.Sleep(1100);

            //重复加锁
            result = SCLockAdapter.Instance.AddLock(lockData);

            Assert.IsTrue(result.Available);
            Assert.AreEqual(SCCheckLockStatus.LockExpired, result.LockStatus);
            Assert.IsTrue(result.Lock.LockTime > DateTime.MinValue);
        }
Esempio n. 5
0
        private void Lock()
        {
            SCLock syncLock = new SCLock()
            {
                LockID = SynchronizationLockID, LockType = SCLockType.DataOperation
            };

            syncLock.EffectiveTime = SynchronizationEffectiveTime;
            syncLock.Description   = "AD反向同步到权限中心";

            SCCheckLockResult checkResult = SCLockAdapter.Instance.AddLock(syncLock);

            if (checkResult.Available == false)
            {
                throw new SCCheckLockException(SCCheckLockException.CheckLockResultToMessage(checkResult));
            }

            this.synchronizeLock    = syncLock;
            this.lastExtendLockTime = DateTime.Now;
        }
        public void AddLock()
        {
            SCLock syncLock = new SCLock()
            {
                LockID = SCLock.DefaultDataOperationLockID, LockType = SCLockType.DataOperation
            };

            syncLock.EffectiveTime = SynchronizationEffectiveTime;
            syncLock.Description   = "权限中心同步到AD";

            SCCheckLockResult checkResult = SCLockAdapter.Instance.AddLock(syncLock);

            if (checkResult.Available == false)
            {
                throw new SCCheckLockException(SCCheckLockException.CheckLockResultToMessage(checkResult));
            }

            this._SynchronizeLock    = syncLock;
            this._LastExtendLockTime = SNTPClient.AdjustedTime;
        }