public ScopeItem(T value, ScopeItem outer = null) { Id = Guid.NewGuid().ToString(); Value = value; Outer = outer; }
public ScopeItem(T value, ScopeItem outer = null) { this.Id = Guid.NewGuid().ToString(); this.Value = value; this.Outer = outer; }
/// <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); })); }
//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); })); }
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); })); }
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); })); }
protected virtual void OnScopeItemAdded(ScopeItem obj) { ScopeItemAdded?.Invoke(obj); }
/// <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); } }