/// <summary> /// 延长锁的时间 /// </summary> /// <param name="lockData"></param> /// <returns></returns> public SCCheckLockResult ExtendLockTime(SCLock lockData) { SCCheckLockResult result = null; lockData.LockTime = DateTime.MinValue; using (TransactionScope scope = TransactionScopeFactory.Create()) { bool updated = false; SCLock lockInDB = lockInDB = Update(lockData, true, out updated); if (updated == false) { result = BuildNotAvailableResult(lockData); } else { result = BuildAvailableResult(lockInDB, true); } scope.Complete(); } return(result); }
private static SCCheckLockResult BuildNotAvailableResult(SCLock lockData) { SCCheckLockResult result = new SCCheckLockResult(); result.Lock = lockData; result.LockStatus = SCCheckLockStatus.Locked; return(result); }
/// <summary> /// 延长锁的时间 /// </summary> public void ExtendLock() { SCLock lockData = this._Lock; if (lockData == null) { lockData = SCLock.CreateDefaultDataOperationLock(); } SCCheckLockResult checkResult = SCLockAdapter.Instance.ExtendLockTime(lockData); this._Lock = checkResult.Lock; }
public void AddLock(TimeSpan effectiveTime, string description) { SCLock lockData = SCLock.CreateDefaultDataOperationLock(); lockData.EffectiveTime = effectiveTime; lockData.Description = description; SCCheckLockResult checkResult = SCLockAdapter.Instance.AddLock(lockData); if (checkResult.Available == false) { throw new SCCheckLockException(SCCheckLockException.CheckLockResultToMessage(checkResult)); } this._Lock = checkResult.Lock; }
private static SCCheckLockResult BuildAvailableResult(SCLock lockData, bool overrideLock) { SCCheckLockResult result = new SCCheckLockResult(); result.Lock = lockData; if (overrideLock) { result.LockStatus = SCCheckLockStatus.LockExpired; } else { result.LockStatus = SCCheckLockStatus.NotLocked; } return(result); }
public static string CheckLockResultToMessage(SCCheckLockResult checkResult) { checkResult.NullCheck("checkResult"); StringBuilder strB = new StringBuilder(); strB.AppendFormat("申请{0}失败。", EnumItemDescriptionAttribute.GetDescription(checkResult.Lock.LockType)); if (OguBase.IsNotNullOrEmpty(checkResult.Lock.LockPerson)) strB.AppendFormat("正在由\"{0}\"执行\"{1}\"。", checkResult.Lock.LockPerson.DisplayName, checkResult.Lock.Description); else strB.AppendFormat("正在执行\"{0}\"", checkResult.Lock.Description); strB.Append("请稍后再尝试。"); return strB.ToString(); }
public static string CheckLockResultToMessage(SCCheckLockResult checkResult) { checkResult.NullCheck("checkResult"); StringBuilder strB = new StringBuilder(); strB.AppendFormat("申请{0}失败。", EnumItemDescriptionAttribute.GetDescription(checkResult.Lock.LockType)); if (OguBase.IsNotNullOrEmpty(checkResult.Lock.LockPerson)) { strB.AppendFormat("正在由\"{0}\"执行\"{1}\"。", checkResult.Lock.LockPerson.DisplayName, checkResult.Lock.Description); } else { strB.AppendFormat("正在执行\"{0}\"", checkResult.Lock.Description); } strB.Append("请稍后再尝试。"); return(strB.ToString()); }
/// <summary> /// 加锁。返回新加的锁,或者原来锁的状态。成功与否,检查SCCheckLockResult的Available属性 /// </summary> /// <param name="lockData"></param> /// <returns></returns> public SCCheckLockResult AddLock(SCLock lockData) { SCCheckLockResult result = null; lockData.LockTime = DateTime.MinValue; using (TransactionScope scope = TransactionScopeFactory.Create()) { //插入是否成功,判断锁是否已经存在 SCLock lockInDB = Insert(lockData); if (lockInDB == null) { //更新是否成功,如果不成功,表示锁被占用。 bool updated = false; lockInDB = Update(lockData, false, out updated); if (updated == false) { result = BuildNotAvailableResult(lockInDB); } else { result = BuildAvailableResult(lockInDB, true); } } else { result = BuildAvailableResult(lockInDB, false); } scope.Complete(); } return(result); }
private static SCCheckLockResult BuildAvailableResult(SCLock lockData, bool overrideLock) { SCCheckLockResult result = new SCCheckLockResult(); result.Lock = lockData; if (overrideLock) result.LockStatus = SCCheckLockStatus.LockExpired; else result.LockStatus = SCCheckLockStatus.NotLocked; return result; }
private static SCCheckLockResult BuildNotAvailableResult(SCLock lockData) { SCCheckLockResult result = new SCCheckLockResult(); result.Lock = lockData; result.LockStatus = SCCheckLockStatus.Locked; return result; }