/// <summary> /// The set lock. /// </summary> /// <param name="LockKey"> /// The lock key. /// </param> /// <param name="userName"> /// The user name. /// </param> /// <returns> /// The set lock. /// </returns> /// <exception cref="DataServiceNotFoundException"> /// </exception> public string SetLock(string LockKey, string userName) { if (dataService == null) { throw new DataServiceNotFoundException(); } var ld = new LockData(); ld.LockKey = LockKey; ld.UserName = userName + (UseMachineNameInKey ? " @ " + Environment.MachineName : string.Empty); try { dataService.LoadObject(ld, false, true); return(ld.UserName); } catch { DataObject dobj = ld; dataService.UpdateObject(ref dobj); if (!AllLocks.ContainsKey(ld.CombinedKey())) { AllLocks.Add(ld.CombinedKey(), ld); } return(string.Empty); } }
/// <summary> /// Очистить блокировку /// </summary> /// <param name="LockKey"> /// </param> /// <param name="userName"> /// </param> public void ClearLock(string LockKey, string userName) { if (dataService == null) { throw new DataServiceNotFoundException(); } var ld = new LockData(); ld.LockKey = LockKey; ld.UserName = userName + (UseMachineNameInKey ? " @ " + Environment.MachineName : string.Empty); if (AllLocks.Contains(ld.CombinedKey())) { ld.SetStatus(ObjectStatus.Deleted); DataObject dobj = ld; dataService.UpdateObject(ref dobj); AllLocks.Remove(ld.CombinedKey()); } }