示例#1
0
		public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
		{
			Lock lockObj = new Lock();

			lockObj.LockID = DictionaryHelper.GetValue(dictionary, "lockID", string.Empty);

			lockObj.LockTime = DateTime.Parse((string)dictionary["lockTime"]);
			lockObj.PersonID = DictionaryHelper.GetValue(dictionary, "personID", string.Empty);
			lockObj.ResourceID = DictionaryHelper.GetValue(dictionary, "resourceID", string.Empty);
			lockObj.LockType = DictionaryHelper.GetValue(dictionary, "lockType", LockType.FormLock);
			lockObj.EffectiveTime = TimeSpan.FromSeconds(DictionaryHelper.GetValue(dictionary, "effectiveTime", 0));

			return lockObj;
		}
示例#2
0
		public static SetLockResult SetLock(Lock lockInfo, bool forceLock)
		{
			ExceptionHelper.TrueThrow<ArgumentNullException>(lockInfo == null, "lockInfo");

			using (TransactionScope ts = TransactionScopeFactory.Create(TransactionScopeOption.Required))
			{
				DataTable table = DbHelper.RunSPReturnDS("WF.SetLock",
											  lockInfo.LockID,
											  lockInfo.ResourceID,
											  lockInfo.PersonID,
											  lockInfo.EffectiveTime.TotalSeconds,
											  lockInfo.LockType,
                                              TenantContext.Current.TenantCode,
											  forceLock ? "y" : "n").Tables[0];
				ts.Complete();

				return new SetLockResult(lockInfo.PersonID, table);
			}
		}
示例#3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="lockInfo"></param>
		/// <returns></returns>
		public static CheckLockResult CheckLock(Lock lockInfo)
		{
			ExceptionHelper.TrueThrow<ArgumentNullException>(lockInfo == null, "lockInfo");

			return CheckLock(lockInfo.LockID, lockInfo.PersonID);
		}
示例#4
0
		public static SetLockResult SetLock(Lock lockEntity)
		{
			return SetLock(lockEntity, false);
		}
		/// <summary>
		/// 解锁
		/// </summary>
		public void UnlockAll()
		{
			Lock[] lockArray = new Lock[this._Locks.Count];

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

			this._Locks.Clear();
		}
		/// <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;
			}
		}
		/// <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;
			}
		}
		/// <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;
		}
示例#9
0
		private LockStatus CalculateLockStatus(Lock nLock, Lock oLock)
		{
			LockStatus result = LockStatus.NotLocked;

			if (oLock == null)
				result = LockStatus.NotLocked;
			else
			{
				if (nLock == null)
					result = LockStatus.LockedByAnother;
				else
				{
					if (string.Compare(nLock.PersonID, oLock.PersonID, true) == 0)
					{
						if (oLock.LockTime.Add(oLock.EffectiveTime) < nLock.LockTime)
							result = LockStatus.LockedByRightAndExpire;
						else
							result = LockStatus.LockedByRight;
					}
					else
					{
						if (oLock.LockTime.Add(oLock.EffectiveTime) < nLock.LockTime)
							result = LockStatus.LockByAnotherAndExpire;
					}
				}
			}

			return result;
		}
示例#10
0
		internal SetLockResult(string personID, DataTable table)
			: base(personID)
		{
			ExceptionHelper.FalseThrow(table.Rows.Count == 2,
				"加锁后返回的结果集的行数必须为2,现在是{1}", table.Rows.Count);

			if (table.Rows[0]["LOCK_ID"] != DBNull.Value)
			{
				this.newLock = new Lock();

				ORMapping.DataRowToObject(table.Rows[0], this.newLock);
			}

			if (table.Rows[1]["LOCK_ID"] != DBNull.Value)
			{
				this.originalLock = new Lock();

				ORMapping.DataRowToObject(table.Rows[1], this.originalLock);
			}

			this.originalLockStatus = CalculateLockStatus(this.newLock, this.originalLock);
		}
示例#11
0
		private LockStatus CalculateLockStatus(string personID, DateTime currentTime, Lock currentLock)
		{
			LockStatus status = LockStatus.NotLocked;

			if (currentLock != null)
			{
				if (string.Compare(personID, currentLock.PersonID, true) == 0)
				{
					if (currentLock.LockTime.Add(currentLock.EffectiveTime) < currentTime)
						status = LockStatus.LockedByRightAndExpire;
					else
						status = LockStatus.LockedByRight;
				}
				else
				{
					if (currentLock.LockTime.Add(currentLock.EffectiveTime) < currentTime)
						status = LockStatus.LockByAnotherAndExpire;
					else
						status = LockStatus.LockedByAnother;
				}
			}

			return status;
		}
示例#12
0
		internal CheckLockResult(string personID, DataTable table)
			: base(personID)
		{
			if (table.Rows.Count > 0)
			{
				this.currentLock = new Lock();

				ORMapping.DataRowToObject(table.Rows[0], this.currentLock);

				this.currentLockStatus = CalculateLockStatus(personID, (DateTime)table.Rows[0]["CURRENT_TIME"], this.currentLock);
			}
		}