コード例 #1
0
        public void SetAmbient(IScopeInternal scope, ScopeContext context = null)
        {
            // clear all
            SetHttpContextObject(ScopeItemKey, null, false);
            SetHttpContextObject(ScopeRefItemKey, null, false);
            SetCallContextObject(ScopeItemKey, null);
            SetHttpContextObject(ContextItemKey, null, false);
            SetCallContextObject(ContextItemKey, null);
            if (scope == null)
            {
                if (context != null)
                {
                    throw new ArgumentException("Must be null if scope is null.", "context");
                }
                return;
            }

            if (scope.CallContext == false && SetHttpContextObject(ScopeItemKey, scope, false))
            {
                SetHttpContextObject(ScopeRefItemKey, StaticScopeReference);
                SetHttpContextObject(ContextItemKey, context);
            }
            else
            {
                SetCallContextObject(ScopeItemKey, scope);
                SetCallContextObject(ContextItemKey, context);
            }
        }
コード例 #2
0
 // initializes a new scope
 public Scope(ScopeProvider scopeProvider,
     ILogger logger, FileSystems fileSystems, bool detachable, ScopeContext scopeContext,
     IsolationLevel isolationLevel = IsolationLevel.Unspecified,
     RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified,
     IEventDispatcher eventDispatcher = null,
     bool? scopeFileSystems = null,
     bool callContext = false,
     bool autoComplete = false)
     : this(scopeProvider, logger, fileSystems, null, scopeContext, detachable, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete)
 { }
コード例 #3
0
        // initializes a new scope, replacing a NoScope instance
        public Scope(ScopeProvider scopeProvider, NoScope noScope,
                     ScopeContext scopeContext,
                     IsolationLevel isolationLevel           = IsolationLevel.Unspecified,
                     RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified,
                     IEventDispatcher eventDispatcher        = null,
                     bool?scopeFileSystems = null,
                     bool callContext      = false)
            : this(scopeProvider, null, scopeContext, false, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext)
        {
            // steal everything from NoScope
            _database = noScope.DatabaseOrNull;
            _messages = noScope.MessagesOrNull;

            // make sure the NoScope can be replaced ie not in a transaction
            if (_database != null && _database.InTransaction)
            {
                throw new Exception("NoScope instance is not free.");
            }
        }
コード例 #4
0
        // initializes a new scope
        private Scope(ScopeProvider scopeProvider,
                      ILogger logger, FileSystems fileSystems, Scope parent, ScopeContext scopeContext, bool detachable,
                      IsolationLevel isolationLevel           = IsolationLevel.Unspecified,
                      RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified,
                      IEventDispatcher eventDispatcher        = null,
                      bool?scopeFileSystems = null,
                      bool callContext      = false,
                      bool autoComplete     = false)
        {
            _scopeProvider = scopeProvider;
            _logger        = logger;

            Context = scopeContext;

            _isolationLevel      = isolationLevel;
            _repositoryCacheMode = repositoryCacheMode;
            _eventDispatcher     = eventDispatcher;
            _scopeFileSystem     = scopeFileSystems;
            _callContext         = callContext;
            _autoComplete        = autoComplete;

            Detachable = detachable;

#if DEBUG_SCOPES
            _scopeProvider.RegisterScope(this);
            Console.WriteLine("create " + InstanceId.ToString("N").Substring(0, 8));
#endif

            if (detachable)
            {
                if (parent != null)
                {
                    throw new ArgumentException("Cannot set parent on detachable scope.", nameof(parent));
                }
                if (scopeContext != null)
                {
                    throw new ArgumentException("Cannot set context on detachable scope.", nameof(scopeContext));
                }
                if (autoComplete)
                {
                    throw new ArgumentException("Cannot auto-complete a detachable scope.", nameof(autoComplete));
                }

                // detachable creates its own scope context
                Context = new ScopeContext();

                // see note below
                if (scopeFileSystems == true)
                {
                    _fscope = fileSystems.Shadow();
                }

                return;
            }

            if (parent != null)
            {
                ParentScope = parent;

                // cannot specify a different mode!
                // TODO: means that it's OK to go from L2 to None for reading purposes, but writing would be BAD!
                // this is for XmlStore that wants to bypass caches when rebuilding XML (same for NuCache)
                if (repositoryCacheMode != RepositoryCacheMode.Unspecified && parent.RepositoryCacheMode > repositoryCacheMode)
                {
                    throw new ArgumentException($"Value '{repositoryCacheMode}' cannot be lower than parent value '{parent.RepositoryCacheMode}'.", nameof(repositoryCacheMode));
                }

                // cannot specify a dispatcher!
                if (_eventDispatcher != null)
                {
                    throw new ArgumentException("Value cannot be specified on nested scope.", nameof(eventDispatcher));
                }

                // cannot specify a different fs scope!
                // can be 'true' only on outer scope (and false does not make much sense)
                if (scopeFileSystems != null && parent._scopeFileSystem != scopeFileSystems)
                {
                    throw new ArgumentException($"Value '{scopeFileSystems.Value}' be different from parent value '{parent._scopeFileSystem}'.", nameof(scopeFileSystems));
                }
            }
            else
            {
                // the FS scope cannot be "on demand" like the rest, because we would need to hook into
                // every scoped FS to trigger the creation of shadow FS "on demand", and that would be
                // pretty pointless since if scopeFileSystems is true, we *know* we want to shadow
                if (scopeFileSystems == true)
                {
                    _fscope = fileSystems.Shadow();
                }
            }
        }
コード例 #5
0
        // initializes a new scope
        private Scope(ScopeProvider scopeProvider,
                      Scope parent, ScopeContext scopeContext, bool detachable,
                      IsolationLevel isolationLevel           = IsolationLevel.Unspecified,
                      RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified,
                      IEventDispatcher eventDispatcher        = null,
                      bool?scopeFileSystems = null,
                      bool callContext      = false)
        {
            _scopeProvider       = scopeProvider;
            _scopeContext        = scopeContext;
            _isolationLevel      = isolationLevel;
            _repositoryCacheMode = repositoryCacheMode;
            _eventDispatcher     = eventDispatcher;
            _scopeFileSystem     = scopeFileSystems;
            _callContext         = callContext;
            Detachable           = detachable;

#if DEBUG_SCOPES
            _scopeProvider.RegisterScope(this);
            Console.WriteLine("create " + _instanceId.ToString("N").Substring(0, 8));
#endif

            if (detachable)
            {
                if (parent != null)
                {
                    throw new ArgumentException("Cannot set parent on detachable scope.", "parent");
                }
                if (scopeContext != null)
                {
                    throw new ArgumentException("Cannot set context on detachable scope.", "scopeContext");
                }

                // detachable creates its own scope context
                _scopeContext = new ScopeContext();

                // see note below
                if (scopeFileSystems == true)
                {
                    _fscope = FileSystemProviderManager.Current.Shadow(Guid.NewGuid());
                }

                return;
            }

            if (parent != null)
            {
                ParentScope = parent;

                // cannot specify a different mode!
                if (repositoryCacheMode != RepositoryCacheMode.Unspecified && parent.RepositoryCacheMode != repositoryCacheMode)
                {
                    throw new ArgumentException("Cannot be different from parent.", "repositoryCacheMode");
                }

                // cannot specify a dispatcher!
                if (_eventDispatcher != null)
                {
                    throw new ArgumentException("Cannot be specified on nested scope.", "eventDispatcher");
                }

                // cannot specify a different fs scope!
                if (scopeFileSystems != null && parent._scopeFileSystem != scopeFileSystems)
                {
                    throw new ArgumentException("Cannot be different from parent.", "scopeFileSystems");
                }
            }
            else
            {
                // the FS scope cannot be "on demand" like the rest, because we would need to hook into
                // every scoped FS to trigger the creation of shadow FS "on demand", and that would be
                // pretty pointless since if scopeFileSystems is true, we *know* we want to shadow
                if (scopeFileSystems == true)
                {
                    _fscope = FileSystemProviderManager.Current.Shadow(Guid.NewGuid());
                }
            }
        }