public object LockOwner(int project, LockTypes lockType) { object res = driver.fetchSingle("SELECT ", dbe.Col("id_owner"), " FROM ", dbe.Table("locks"), " WHERE ", dbe.Col("id_project"), " = ", project, " AND ", dbe.Col("lock_type"), " = ", lockNumbers[lockType]); return(res); }
private void Lock(LockTypes type) { switch (type) { case LockTypes.Ready: btnLoad.Enabled = true; btnRun.Visible = true; btnRun.Enabled = listView.Items.Count > 0; btnStop.Visible = false; btnProfile.Enabled = true; statusBarLabel3.Text = "就绪"; timer.Enabled = false; break; case LockTypes.Loading: btnLoad.Enabled = false; btnRun.Visible = false; btnStop.Visible = true; btnProfile.Enabled = false; statusBarLabel3.Text = "正在加载配置..."; timer.Enabled = true; break; case LockTypes.Running: btnLoad.Enabled = false; btnRun.Visible = false; btnStop.Visible = true; btnProfile.Enabled = false; statusBarLabel3.Text = "正在迁移数据..."; timer.Enabled = true; break; } }
public bool TryGetLock(object userId, int project, LockTypes lockType) { Dictionary <string, object> insVals = new Dictionary <string, object> { { "id_project", project }, { "id_owner", userId.ToString() }, { "lock_type", lockNumbers[lockType] } }; object owner = LockOwner(project, lockType); if (owner == null) { try { driver.query("INSERT INTO", dbe.Table("locks"), dbe.InsVals(insVals)); } catch { return(false); } return(true); } else if (owner.ToString() == userId.ToString()) { return(true); } return(false); }
protected virtual IDisposable LockChildren(LockTypes lockType) { var result = new CompositeDisposable(); lock (ChildLocksSync) { foreach (var child in ChildLocks) { if (lockType == LockTypes.Read) { result.AddIfNotNull(child.AcquireReadLockIfNotHeld()); } else if (lockType == LockTypes.UpgradeableRead) { result.AddIfNotNull(child.AcquireUpgradeableReadLock()); } else if (lockType == LockTypes.Write) { result.AddIfNotNull(child.AcquireWriteLockIfNotHeld()); } else { throw new NotSupportedException(lockType.ToString()); } } } return result; }
public void DowngradeToRead() { if (enteredLockType != LockTypes.Upgradeable) throw new InvalidOperationException("Upgradeable read lock is not held."); readerWriterLock.EnterReadLock(); readerWriterLock.ExitUpgradeableReadLock(); enteredLockType = LockTypes.Read; }
/// <summary> /// Call EnterWriteLock on the managed lock /// </summary> public void EnterWriteLock() { if (_readerWriterLock == null) throw new ObjectDisposedException(GetType().FullName); if (_enteredLockType != LockTypes.None) throw new InvalidOperationException("Create a new ReaderWriterLockMgr for each state you wish to enter"); // Allow exceptions by the Enter* call to propogate // and prevent updating of _enteredLockType _readerWriterLock.EnterWriteLock(); _enteredLockType = LockTypes.Write; }
public void DowngradeToRead() { if (enteredLockType != LockTypes.Upgradeable) { throw new InvalidOperationException("Upgradeable read lock is not held."); } readerWriterLock.EnterReadLock(); readerWriterLock.ExitUpgradeableReadLock(); enteredLockType = LockTypes.Read; }
internal HeightArrayLock(LockTypes lockType, ReaderWriterLockSlim lockSlim) { if (lockSlim == null) { throw new ArgumentNullException(nameof(lockSlim)); } readerWriterLockSlim = lockSlim; switch (lockType) { case LockTypes.Read: readerWriterLockSlim.EnterReadLock(); break; case LockTypes.ReadWrite: readerWriterLockSlim.EnterWriteLock(); break; default: throw new ArgumentException($"{ nameof(lockType) } is invalid type"); } }
public bool TryGetLock(object userId, int project, LockTypes lockType) { Dictionary<string, object> insVals = new Dictionary<string,object>{ {"id_project", project}, {"id_owner", userId.ToString()}, {"lock_type", lockNumbers[lockType]} }; object owner = LockOwner(project, lockType); if (owner == null) { try { driver.query("INSERT INTO", dbe.Table("locks"), dbe.InsVals(insVals)); } catch { return false; } return true; } else if (owner.ToString() == userId.ToString()) return true; return false; }
public void ReleaseLock(object userId, int project, LockTypes lockType) { driver.query("DELETE FROM ", dbe.Table("locks"), "WHERE", dbe.Col("id_owner"), " = ", dbe.InObj(userId.ToString()), "AND ", dbe.Col("id_project"), " = ", project, "AND ", dbe.Col("lock_type"), " = ", lockNumbers[lockType]); }
public object LockOwner(int project, LockTypes lockType) { object res = driver.fetchSingle("SELECT ", dbe.Col("id_owner"), " FROM ", dbe.Table("locks"), " WHERE ", dbe.Col("id_project"), " = ", project, " AND ", dbe.Col("lock_type"), " = ", lockNumbers[lockType]); return res; }
public void EnterUpgradeableReadLock() { readerWriterLock.EnterUpgradeableReadLock(); enteredLockType = LockTypes.Upgradeable; }
public void EnterWriteLock() { readerWriterLock.EnterWriteLock(); enteredLockType = LockTypes.Write; }
public static bool IsLicensed(out string message, out int daysRemaining, out bool errorOccurred, out bool demo, out LockTypes lockType) { lockType = LockTypes.None; message = ""; errorOccurred = false; daysRemaining = 0; demo = true; try { #if DEBUG daysRemaining = 12; demo = true; return false; #endif errorOccurred = false; //daysRemaining = License.Status.Evaluation_Time - License.Status.Evaluation_Time_Current; daysRemaining = EvaluationMonitor.CurrentLicense.ExpirationDays - EvaluationMonitor.CurrentLicense.ExpirationDays_Current; demo = false; // Are we in demo mode? //if (License.Status.Evaluation_Lock_Enabled) if (EvaluationMonitor.CurrentLicense.ExpirationDays_Enabled) { demo = true; //daysRemaining = License.Status.Evaluation_Time - License.Status.Evaluation_Time_Current; daysRemaining = EvaluationMonitor.CurrentLicense.ExpirationDays - EvaluationMonitor.CurrentLicense.ExpirationDays_Current; lockType = LockTypes.Days; } //else if (License.Status.Expiration_Date_Lock_Enable) else if (EvaluationMonitor.CurrentLicense.ExpirationDate_Enabled) { demo = true; //daysRemaining = License.Status.Expiration_Date.Subtract(DateTime.Now).Days; daysRemaining = EvaluationMonitor.CurrentLicense.ExpirationDate.Subtract(DateTime.Now).Days; lockType = LockTypes.Date; } //return License.Status.Licensed; return EvaluationMonitor.CurrentLicense.LicenseStatus == LicenseStatus.Licensed; } catch (Exception ex) { message = ex.Message; return false; } }
public virtual bool TryLockChildren(LockTypes lockType, TimeSpan timeout, out IDisposable childDisposables) { var all_child_disposables = new CompositeDisposable(); childDisposables = all_child_disposables; bool all_good = true; foreach(var child in ChildLocks) { if (!all_good) break; if (lockType == LockTypes.Read) { var acqusition = (IReadLockAcquisition)null; if (child.TryAcquireReadLock(timeout, out acqusition)) { all_child_disposables.AddIfNotNull(acqusition); } else { all_good = false; } } else if (lockType == LockTypes.UpgradeableRead) { var acqusition = (IUpgradeableReadLockAcquisition)null; if (child.TryAcquireUpgradeableReadLock(timeout, out acqusition)) { all_child_disposables.AddIfNotNull(acqusition); } else { all_good = false; } } else if (lockType == LockTypes.Write) { var acqusition = (IWriteLockAcquisition)null; if (child.TryAcquireWriteLock(timeout, out acqusition)) { all_child_disposables.AddIfNotNull(acqusition); } else { all_good = false; } } else { throw new NotSupportedException(lockType.ToString()); } } if(all_good) { return true; } else { all_child_disposables.Clear(); return false; } }
public static bool IsLicensed(string licenseFilename, out string message, out int daysRemaining, out bool errorOccurred, out bool demo, out LockTypes lockType, out LicenseStates status) { status = LicenseStates.NotChecked; lockType = LockTypes.None; message = ""; errorOccurred = false; daysRemaining = 0; demo = true; // TODO: add licensing back in for the real launch (not beta) demo = false; //return true; try { LicenseMonitor.LicenseFilename = licenseFilename; errorOccurred = false; daysRemaining = LicenseMonitor.CurrentLicense.ExpirationDays - LicenseMonitor.CurrentLicense.ExpirationDays_Current; switch (LicenseMonitor.CurrentLicense.LicenseStatus.ToString()) { case "EvaluationExpired": status = LicenseStates.EvaluationExpired; break; case "EvaluationMode": status = LicenseStates.EvaluationMode; break; case "HardwareNotMatched": status = LicenseStates.HardwareNotMatched; break; case "InvalidSignature": status = LicenseStates.InvalidSignature; break; case "Licensed": status = LicenseStates.Licensed; break; case "LicenseFileNotFound": status = LicenseStates.LicenseFileNotFound; break; case "NotChecked": status = LicenseStates.NotChecked; break; case "ServerValidationFailed": status = LicenseStates.ServerValidationFailed; break; case "Revoked": status = LicenseStates.Revoked; break; } demo = false; // Are we in demo mode? if (LicenseMonitor.CurrentLicense.ExpirationDays_Enabled) { demo = true; daysRemaining = LicenseMonitor.CurrentLicense.ExpirationDays - LicenseMonitor.CurrentLicense.ExpirationDays_Current; lockType = LockTypes.Days; } else if (LicenseMonitor.CurrentLicense.ExpirationDate_Enabled) { demo = true; daysRemaining = LicenseMonitor.CurrentLicense.ExpirationDate.Subtract(DateTime.Now).Days; lockType = LockTypes.Date; } return LicenseMonitor.CurrentLicense.LicenseStatus == LicenseMonitor.LicenseStates.Licensed; } catch (Exception ex) { errorOccurred = true; message = ex.Message; return false; } }
/// <summary> /// Exit the lock, allowing re-entry later on whilst this manager is in scope /// </summary> /// <returns>Whether the lock was previously held</returns> public bool ExitLock() { switch (_enteredLockType) { case LockTypes.Read: _readerWriterLock.ExitReadLock(); _enteredLockType = LockTypes.None; return true; case LockTypes.Write: _readerWriterLock.ExitWriteLock(); _enteredLockType = LockTypes.None; return true; case LockTypes.Upgradeable: _readerWriterLock.ExitUpgradeableReadLock(); _enteredLockType = LockTypes.None; return true; } return false; }
/// <summary> /// Enters the write lock. /// </summary> public void EnterWriteLock() { _readerWriterLock.EnterWriteLock(); _enteredLockType = LockTypes.Write; }
/// <summary> /// Enters the read lock. /// </summary> public void EnterReadLock() { _readerWriterLock.EnterReadLock(); _enteredLockType = LockTypes.Read; }
public static bool IsLicensed(string licenseFilename, out string message, out int daysRemaining, out bool errorOccurred, out bool demo, out LockTypes lockType, out LicenseStates status) { status = LicenseStates.NotChecked; lockType = LockTypes.None; message = ""; errorOccurred = false; daysRemaining = 0; demo = true; // TODO: add licensing back in for the real launch (not beta) demo = false; //return true; try { LicenseMonitor.LicenseFilename = licenseFilename; errorOccurred = false; daysRemaining = LicenseMonitor.CurrentLicense.ExpirationDays - LicenseMonitor.CurrentLicense.ExpirationDays_Current; switch (LicenseMonitor.CurrentLicense.LicenseStatus.ToString()) { case "EvaluationExpired": status = LicenseStates.EvaluationExpired; break; case "EvaluationMode": status = LicenseStates.EvaluationMode; break; case "HardwareNotMatched": status = LicenseStates.HardwareNotMatched; break; case "InvalidSignature": status = LicenseStates.InvalidSignature; break; case "Licensed": status = LicenseStates.Licensed; break; case "LicenseFileNotFound": status = LicenseStates.LicenseFileNotFound; break; case "NotChecked": status = LicenseStates.NotChecked; break; case "ServerValidationFailed": status = LicenseStates.ServerValidationFailed; break; case "Revoked": status = LicenseStates.Revoked; break; } demo = false; // Are we in demo mode? if (LicenseMonitor.CurrentLicense.ExpirationDays_Enabled) { demo = true; daysRemaining = LicenseMonitor.CurrentLicense.ExpirationDays - LicenseMonitor.CurrentLicense.ExpirationDays_Current; lockType = LockTypes.Days; } else if (LicenseMonitor.CurrentLicense.ExpirationDate_Enabled) { demo = true; daysRemaining = LicenseMonitor.CurrentLicense.ExpirationDate.Subtract(DateTime.Now).Days; lockType = LockTypes.Date; } return(LicenseMonitor.CurrentLicense.LicenseStatus == LicenseMonitor.LicenseStates.Licensed); } catch (Exception ex) { errorOccurred = true; message = ex.Message; return(false); } }
public static bool IsLicensed(out string message, out int daysRemaining, out bool errorOccurred, out bool demo, out LockTypes lockType) { lockType = LockTypes.None; message = ""; errorOccurred = false; daysRemaining = 0; demo = true; try { #if DEBUG daysRemaining = 12; demo = true; return(false); #endif errorOccurred = false; //daysRemaining = License.Status.Evaluation_Time - License.Status.Evaluation_Time_Current; daysRemaining = EvaluationMonitor.CurrentLicense.ExpirationDays - EvaluationMonitor.CurrentLicense.ExpirationDays_Current; demo = false; // Are we in demo mode? //if (License.Status.Evaluation_Lock_Enabled) if (EvaluationMonitor.CurrentLicense.ExpirationDays_Enabled) { demo = true; //daysRemaining = License.Status.Evaluation_Time - License.Status.Evaluation_Time_Current; daysRemaining = EvaluationMonitor.CurrentLicense.ExpirationDays - EvaluationMonitor.CurrentLicense.ExpirationDays_Current; lockType = LockTypes.Days; } //else if (License.Status.Expiration_Date_Lock_Enable) else if (EvaluationMonitor.CurrentLicense.ExpirationDate_Enabled) { demo = true; //daysRemaining = License.Status.Expiration_Date.Subtract(DateTime.Now).Days; daysRemaining = EvaluationMonitor.CurrentLicense.ExpirationDate.Subtract(DateTime.Now).Days; lockType = LockTypes.Date; } //return License.Status.Licensed; return(EvaluationMonitor.CurrentLicense.LicenseStatus == LicenseStatus.Licensed); } catch (Exception ex) { message = ex.Message; return(false); } }
public void EnterReadLock() { readerWriterLock.EnterReadLock(); enteredLockType = LockTypes.Read; }