protected virtual void Using(ContentMapLockType lockType, Action <ContentMap> action, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { var map = _map.Value; map.Using(lockType, () => action(map), memberName, sourceFilePath, sourceLineNumber); }
protected virtual T Using <T>(ContentMapLockType lockType, Func <ContentMap, T> action, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { var map = _map.Value; return(map.Using(lockType, () => action(map), memberName, sourceFilePath, sourceLineNumber)); }
public void Using(ContentMapLockType lockType, Action action, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { var timer = Stopwatch.StartNew(); var contentMapCallId = Guid.NewGuid(); CmsEventSource.Log.ContentMapLockStatus(lockType, "Requested", timer.ElapsedMilliseconds); ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("ContentMap[{0}]: LockType - {1}, Requested - {2}", contentMapCallId, lockType, timer.ElapsedMilliseconds), memberName, sourceFilePath, sourceLineNumber); if (lockType == ContentMapLockType.Read && !_lock.TryEnterReadLock(LockTimeout)) { TraceLock("Using", _lock); CmsEventSource.Log.ContentMapLockTimeout(lockType, _lock); ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("ContentMap[{0}]: Failed to acquire read lock on content map. LockType - {1}", contentMapCallId, lockType), memberName, sourceFilePath, sourceLineNumber); throw new TimeoutException("Failed to acquire read lock on content map."); } if (lockType == ContentMapLockType.Write && !_lock.TryEnterWriteLock(LockTimeout)) { TraceLock("Using", _lock); CmsEventSource.Log.ContentMapLockTimeout(lockType, _lock); ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("ContentMap[{0}]: A write lock couldn't be acquired on the content map. LockType - {1}", contentMapCallId, lockType), memberName, sourceFilePath, sourceLineNumber); throw new TimeoutException("A write lock couldn't be acquired on the content map."); } try { CmsEventSource.Log.ContentMapLockStatus(lockType, "Acquired", timer.ElapsedMilliseconds); ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("ContentMap[{0}]: LockType - {1}, Acquired - {2}", contentMapCallId, lockType, timer.ElapsedMilliseconds), memberName, sourceFilePath, sourceLineNumber); action(); } finally { if (lockType == ContentMapLockType.Read) { _lock.ExitReadLock(); } if (lockType == ContentMapLockType.Write) { _lock.ExitWriteLock(); } timer.Stop(); CmsEventSource.Log.ContentMapLockStatus(lockType, "Released", timer.ElapsedMilliseconds); ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("ContentMap[{0}]: LockType - {1}, Released - {2}", contentMapCallId, lockType, timer.ElapsedMilliseconds), memberName, sourceFilePath, sourceLineNumber); } }
public T Using <T>(ContentMapLockType lockType, Func <T> action, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { var result = default(T); Using(lockType, () => { result = action(); }, memberName, sourceFilePath, sourceLineNumber); return(result); }
public void ContentMapLockStatus(ContentMapLockType lockType, string status, long duration) { ContentMapLockStatus( lockType.ToString(), status, duration, this.PortalUrl, this.PortalVersion, this.ProductionOrTrial, this.SessionId, this.ElapsedTime()); }
public void ContentMapLockTimeout(ContentMapLockType lockType, ReaderWriterLockSlim contentMapLock) { ContentMapLockTimeout( lockType.ToString(), contentMapLock.IsReadLockHeld, contentMapLock.IsUpgradeableReadLockHeld, contentMapLock.IsWriteLockHeld, contentMapLock.CurrentReadCount, contentMapLock.RecursiveReadCount, contentMapLock.RecursiveUpgradeCount, contentMapLock.RecursiveWriteCount, contentMapLock.WaitingReadCount, contentMapLock.WaitingUpgradeCount, contentMapLock.WaitingWriteCount, this.PortalUrl, this.PortalVersion, this.ProductionOrTrial, this.SessionId, this.ElapsedTime()); }