Esempio n. 1
0
 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;
 }
Esempio n. 2
0
        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");
                }
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 /// <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));
 }
Esempio n. 6
0
        public TransactionInterceptorAttribute(ScopeOption scopeOption,TimeSpan timeOut)
        {
            this.options = new TransactionOptions { transactionScopeOption = scopeOption, TimeOut = timeOut } ;

        }
Esempio n. 7
0
 public TransactionInterceptorAttribute(ScopeOption scopeOption)
 {
     this.options = new TransactionOptions { transactionScopeOption = scopeOption, TimeOut = new TimeSpan(0, 30, 0) }; 
     
 }
Esempio n. 8
0
 static internal extern uint EstablishContext(ScopeOption scope, IntPtr reserved1,
                                              IntPtr reserved2, ref SmartcardContextSafeHandle context);
 public SessionScopeAttribute(ScopeOption option = ScopeOption.Required)
 {
     Option = option;
 }