Exemplo 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 解锁
        /// </summary>
        public void UnlockAll()
        {
            Lock[] lockArray = new Lock[this._Locks.Count];

            //this._Locks.CopyTo(lockArray, 0);
            LockAdapter.Unlock(lockArray);

            this._Locks.Clear();
        }
Exemplo n.º 3
0
        protected override void OnInit(EventArgs e)
        {
            if (WebUtility.GetRequestQueryString("_op", string.Empty) == "lockCallBack")
            {
                if (string.Compare(Page.Request.HttpMethod, "POST", true) == 0)
                {
                    string cmd = WebUtility.GetRequestQueryString("cmd", string.Empty);

                    string requestData = string.Empty;
                    string result      = string.Empty;

                    try
                    {
                        using (StreamReader sr = new StreamReader(Page.Request.InputStream))
                        {
                            requestData = sr.ReadToEnd();

                            Lock[]      locks    = (Lock[])JSONSerializerExecute.DeserializeObject(requestData, typeof(Lock[]));
                            List <Lock> addLocks = new List <Lock>();

                            switch (cmd)
                            {
                            case "checkLock":
                                Array.ForEach(locks, l => addLocks.Add(LockAdapter.SetLock(l).NewLock));
                                break;

                            case "unlock":
                                LockAdapter.Unlock(locks);
                                break;

                            default:
                                throw new ApplicationException(string.Format("Invalid command {0}", cmd));
                            }

                            result = JSONSerializerExecute.Serialize(addLocks.ToArray());
                        }
                    }
                    catch (System.Exception ex)
                    {
                        var err = new { type = "$ErrorType", message = ex.Message };

                        result = JSONSerializerExecute.Serialize(err);
                    }
                    finally
                    {
                        Page.Response.Write(result);
                        Page.Response.End();
                    }
                }
            }
            else
            {
                base.OnInit(e);
            }
        }
Exemplo n.º 4
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());
            }
        }
Exemplo n.º 5
0
        protected override void OnSaveApplicationData(WfExecutorDataContext dataContext)
        {
            base.OnSaveApplicationData(dataContext);

            if (this.Locks != null)
            {
                foreach (Lock wfLock in this.Locks)
                {
                    LockAdapter.Unlock(wfLock);
                }
            }
        }
Exemplo n.º 6
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));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 添加表单锁
        /// </summary>
        /// <param name="formID">表单ID</param>
        /// <returns>加锁的结果</returns>
        public SetLockResult AddFormLock(string formID)
        {
            Lock formLockInfo = new Lock(formID, DeluxeIdentity.CurrentUser.ID);

            SetLockResult lockResult = LockAdapter.SetLock(formLockInfo);

            if (lockResult.Succeed)
            {
                this._Locks.Add(lockResult.NewLock);
            }

            return(lockResult);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 添加表单锁
        /// </summary>
        /// <param name="formID">表单ID</param>
        /// <param name="activityID">工作流节点ID</param>
        /// <returns>加锁的结果</returns>
        public SetLockResult AddFormLock(string formID, string activityID)
        {
            Lock formLockInfo = new Lock(formID, DeluxeIdentity.CurrentUser.ID);

            SetLockResult finalResult = null;

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                SetLockResult formLockResult = LockAdapter.SetLock(formLockInfo);

                if (formLockResult.Succeed == false && formLockResult.OriginalLock.LockType == LockType.AdminLock)
                {
                    scope.Complete();

                    return(formLockResult);
                }

                if (formLockResult.Succeed)
                {
                    this._Locks.Add(formLockResult.NewLock);
                }

                Lock activityLockInfo = new Lock(activityID, formID, DeluxeIdentity.CurrentUser.ID);

                activityLockInfo.LockType = LockType.ActivityLock;

                SetLockResult activityLockResult = LockAdapter.SetLock(activityLockInfo);

                if (activityLockResult.Succeed)
                {
                    this._Locks.Add(activityLockResult.NewLock);
                }

                if (formLockResult.Succeed)
                {
                    finalResult = formLockResult;
                }
                else
                {
                    finalResult = activityLockResult;
                }

                scope.Complete();

                this._LockResult = finalResult;

                return(finalResult);
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 添加管理员锁
        /// </summary>
        /// <param name="formID">表单锁</param>
        /// <param name="forceLock">是否强制加锁</param>
        /// <returns>加锁的结果</returns>
        public SetLockResult AddAdminLock(string formID, bool forceLock)
        {
            Lock adminLockInfo = new Lock(formID, DeluxeIdentity.CurrentUser.ID);

            adminLockInfo.LockType = LockType.AdminLock;
            SetLockResult adminLockResult = null;

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                adminLockResult = LockAdapter.SetLock(adminLockInfo, forceLock);

                if (adminLockResult.Succeed)
                {
                    this._Locks.Add(adminLockResult.NewLock);
                }

                scope.Complete();

                return(adminLockResult);
            }
        }