コード例 #1
0
            public ScopeItem(T value, ScopeItem outer = null)
            {
                Id = Guid.NewGuid().ToString();

                Value = value;
                Outer = outer;
            }
コード例 #2
0
            public ScopeItem(T value, ScopeItem outer = null)
            {
                this.Id = Guid.NewGuid().ToString();

                this.Value = value;
                this.Outer = outer;
            }
コード例 #3
0
        /// <summary>
        /// 设置值
        /// </summary>
        /// <param name="contextKey">上下文键</param>
        /// <param name="value">值</param>
        /// <returns></returns>
        public IDisposable BeginScope(string contextKey, T value)
        {
            var item = new ScopeItem(value, GetCurrentItem(contextKey));

            if (!ScopeDictionary.TryAdd(item.Id, item))
            {
                throw new Warning("Can not add item! ScopeDictionary.TryAdd returns false!");
            }

            _dataContext.SetData(contextKey, item.Id);

            return(new DisposeAction(() =>
            {
                ScopeDictionary.TryRemove(item.Id, out item);

                if (item.Outer == null)
                {
                    _dataContext.SetData(contextKey, null);
                    return;
                }
                _dataContext.SetData(contextKey, item.Outer.Id);
            }));
        }
コード例 #4
0
        //public void Dispose()
        //{
        //    GC.SuppressFinalize(this);
        //}


        public IDisposable Use(int?tenantId)
        {
            var item = new ScopeItem(tenantId, GetCurrentItem(DataContextKey));

            string key = item.Id;

            if (!ConcurrentItems.TryAdd(key, item))
            {
                throw new AbpException("Can not add item! ConcurrentItems.TryAdd returns false!");
            }

            _dataContext.SetData(DataContextKey, key);

            return(new DisposeAction(() =>
            {
                ConcurrentItems.TryRemove(key, out item);
                if (item == null)
                {
                    _dataContext.SetData(DataContextKey, null);
                    return;
                }
                _dataContext.SetData(DataContextKey, item.Outer?.Id);
            }));
        }
コード例 #5
0
        public IDisposable BeginScope(string contextKey, T value)
        {
            var item = new ScopeItem(value, GetCurrentItem(contextKey));

            if (!ScopeDictionary.TryAdd(item.Id, item))
            {
                throw new SharePlatformException("无法添加项目!scopedictionary.tryadd返回false!");
            }

            _dataContext.SetData(contextKey, item.Id);

            return(new DisposeAction(() =>
            {
                ScopeDictionary.TryRemove(item.Id, out item);

                if (item.Outer == null)
                {
                    _dataContext.SetData(contextKey, null);
                    return;
                }

                _dataContext.SetData(contextKey, item.Outer.Id);
            }));
        }
コード例 #6
0
        public IDisposable BeginScope(string contextKey, T value)
        {
            var item = new ScopeItem(value, this.GetCurrentItem(contextKey));

            if (!ScopeDictionary.TryAdd(item.Id, item))
            {
                throw new AbpException("Can not set unit of work! ScopeDictionary.TryAdd returns false!");
            }

            this._dataContext.SetData(contextKey, item.Id);

            return(new DisposeAction(() =>
            {
                ScopeDictionary.TryRemove(item.Id, out item);

                if (item.Outer == null)
                {
                    this._dataContext.SetData(contextKey, null);
                    return;
                }

                this._dataContext.SetData(contextKey, item.Outer.Id);
            }));
        }
コード例 #7
0
 protected virtual void OnScopeItemAdded(ScopeItem obj)
 {
     ScopeItemAdded?.Invoke(obj);
 }
コード例 #8
0
 /// <summary>
 /// Adds a variable onto the scope stack with some data
 /// </summary>
 /// <param name="variable">Variable name</param>
 /// <param name="data">Data to assign to the variable</param>
 internal void SetVariable(String variable, object data)
 {
     if (scopesItemMap.ContainsKey(variable))
     {
         scopesItemMap[variable].Data = data;
     }
     else
     {
         ScopeItem newScope = new ScopeItem(variable, data);
         scopesItemMap[variable] = newScope;
         scopes.Add(newScope);
     }
 }