/// <summary> /// Clone the specified ApplicationContext and create a new DependentApplicationContext />. /// </summary> /// <param name="context">The DependentApplicationContext to be cloned.</param> /// <returns>The DependentApplicationContext</returns>. public static DependentApplicationContext DepedentClone(this ApplicationContext context) { Guard.ArgumentNotNull(context, "context"); ContextItemCollection currentContext = context.ContextLocator.GetCurrentContext(); ContextItemCollection contextItemCollection = new ContextItemCollection(); foreach (ContextItem current in currentContext) { object obj = current.Value; ICloneable cloneable = obj as ICloneable; if (cloneable != null) { obj = cloneable.Clone(); } ContextItem contextItem = new ContextItem(current.Key, obj, current.IsLocal); if (current.ReadOnly) { contextItem.ReadOnly = true; } contextItemCollection.Add(contextItem); } return new DependentApplicationContext(contextItemCollection); }
private void EnsureCanWrite(ContextItem contextItem) { Guard.ArgumentNotNull(contextItem, "contextItem"); ContextItem contextItem2 = this.GetContextItem(contextItem.Key); if (contextItem2 != null && contextItem2.ReadOnly) { throw new InvalidOperationException(ResourceUtility.Format(Resources.ExceptionCannotChangeReadonlyContextItem, new object[0])); } }
/// <summary> /// Set context item inernally. /// </summary> /// <param name="contextItem">The context item.</param> protected abstract void SetContextItemCore(ContextItem contextItem);
/// <summary> /// Add a new context item or use the new context item to override the exiting one. /// </summary> /// <param name="contextItem">The new <see cref="T:Smartac.SR.Core.ApplicationContexts.ContextItem" /> to set.</param> public void SetContextItem(ContextItem contextItem) { this.EnsureCanWrite(contextItem); this.SetContextItemCore(contextItem); }
/// <summary> /// Add a new context item or use the new context item to override the exiting one. /// </summary> /// <param name="contextItem">The new <see cref="T:Smartac.SR.Core.ApplicationContexts.ContextItem" /> to set.</param> protected override void SetContextItemCore(ContextItem contextItem) { Guard.ArgumentNotNull(contextItem, "contextItem"); CallContext.FreeNamedDataSlot(contextItem.Key); CallContext.SetData(contextItem.Key, contextItem); if (!CallContextLocator.Keys.Contains(contextItem.Key)) { CallContextLocator.Keys.Add(contextItem.Key); } }
/// <summary> /// Add a new context item or use the new context item to override the exiting one. /// </summary> /// <param name="contextItem">The new <see cref="T:Smartac.SR.Core.ApplicationContexts.ContextItem" /> to set.</param> protected override void SetContextItemCore(ContextItem contextItem) { Guard.ArgumentNotNull(contextItem, "contextItem"); if (this.SessionStateAvailabe) { HttpContext.Current.Session[contextItem.Key] = contextItem; if (!this.ContextItemKeys.Contains(contextItem.Key)) { this.ContextItemKeys.Add(contextItem.Key); return; } } else { this.CallContextLocator.SetContextItem(contextItem); } }