public Scope(ScopeOption scopeOption, params ScopeContext[] contexts) { _ScopeOption = scopeOption; if (IsNewScopeRequired(scopeOption)) { _ScopeContexts = new Dictionary <Type, ScopeContext>(); foreach (var newScopeElement in contexts) { var scopeElementType = newScopeElement.GetType(); if (_ScopeContexts.ContainsKey(scopeElementType)) { var currentScopeElement = _ScopeContexts[scopeElementType]; currentScopeElement.NewScopeContextIsCompatible(newScopeElement); } _ScopeContexts.Add(scopeElementType, newScopeElement); } ConfigCurrentScope(); } else { // Supress destructor if this instance will not be used GC.SuppressFinalize(true); InstanceCount = InstanceCount + 1; } // At end of ctor the current static instance, is the scope used to equality _CurrentScopeToThisInstance = Current; }
public SessionScope( bool readOnly, IsolationLevel?isolationLevel, ISessionConnectionFactory factory, ScopeOption option = ScopeOption.Required, ISessionExceptionHandler exceptionHandler = null) : base(new SessionConnectionCollection(readOnly, isolationLevel, factory, exceptionHandler), option) { _completed = false; _readOnly = readOnly; _exceptionHandler = exceptionHandler; if (isolationLevel != null && option == ScopeOption.Required) { throw new ArgumentException( "Can't join an ambient session if an explicit database transaction is required"); } if (Nested && option == ScopeOption.Required) { var parentScope = ParentScope; if (parentScope._readOnly && !_readOnly) { throw new InvalidOperationException( "Cannot nest a read/write session scope within a read-only scope"); } } }
private bool IsNewScopeRequired(ScopeOption scopeOption) { bool existsActiveScope = _Current != null; if (!existsActiveScope || scopeOption == ScopeOption.RequireNew) { return(true); } // Verify if any scope element vote for a new scope bool anyElementVoteForNewScope = new List <ScopeContext>(ScopeContexts.Values).Exists(se => se.RequireNewScope); if (anyElementVoteForNewScope) { bool anyElementsRefuseNewScope = new List <ScopeContext>(ScopeContexts.Values).Exists(se => se.RefuseNewScope); if (anyElementsRefuseNewScope) { throw new InvalidOperationException( "Some elements are in a state that they refuse the creation of a new scope"); } return(true); } return(false); }
/// <summary>Initializes a new instance of the <see cref="LoggingProviderScope"/> class.</summary> /// <param name="option">The scope option.</param> public LoggingProviderScope(ScopeOption option) : this() { this.option = option; }
public ISessionScope Create(bool readOnly = false, ScopeOption joiningOption = ScopeOption.Required, IsolationLevel?isolationLevel = null) { return(new SessionScope(readOnly, isolationLevel, _factory, joiningOption, _exceptionHandler)); }
public TransactionInterceptorAttribute(ScopeOption scopeOption,TimeSpan timeOut) { this.options = new TransactionOptions { transactionScopeOption = scopeOption, TimeOut = timeOut } ; }
public TransactionInterceptorAttribute(ScopeOption scopeOption) { this.options = new TransactionOptions { transactionScopeOption = scopeOption, TimeOut = new TimeSpan(0, 30, 0) }; }
static internal extern uint EstablishContext(ScopeOption scope, IntPtr reserved1, IntPtr reserved2, ref SmartcardContextSafeHandle context);
public SessionScopeAttribute(ScopeOption option = ScopeOption.Required) { Option = option; }