Exemple #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);
        }
Exemple #2
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);
            }
        }
        /// <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);
        }
        /// <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);
            }
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
        /// <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);
            }
        }