Example #1
0
        /// <summary>
        /// Makes the context having the given id the current one.
        /// If it doesn't exist, it is created.
        /// </summary>
        /// <param name="pNewContextId">The new context id.</param>
        /// <returns>The new current context.</returns>
        public IUserCommandContext SwitchContext(string pNewContextId)
        {
            if (this.CurrentContext != null && this.CurrentContext.Id == pNewContextId)
            {
                return(this.CurrentContext);
            }

            IUserCommandContext lOldContext = this.CurrentContext;
            IUserCommandContext lNewContext = this.GetContextById(pNewContextId);

            if (lNewContext == null)
            {
                lNewContext = this.CreateContext(pNewContextId);
            }

            if (lNewContext == null)
            {
                // Do not change for a null context.
                return(this.CurrentContext);
            }
            else
            {
                // Notifying the modification and updating the current context.
                this.CurrentContext = lNewContext;

                if (this.ContextChanged != null)
                {
                    this.ContextChanged(this, new ContextChangedEventArgs(this, lOldContext, lNewContext));
                }

                return(this.CurrentContext);
            }
        }
Example #2
0
        /// <summary>
        /// Creates a context with the given id.
        /// </summary>
        /// <param name="pId">The id of the new context.</param>
        /// <returns>The new context if a context having the same id does not have the same id, null otherwise.</returns>
        private IUserCommandContext CreateContext(string pId)
        {
            if (this.mContextes.ContainsKey(pId) == false)
            {
                IUserCommandContext lContext = this.CustomCreateContext(pId);
                if (lContext != null)
                {
                    this.mContextes[pId] = lContext;
                    return(lContext);
                }
            }

            return(null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ContextChangedEventArgs"/> class.
 /// </summary>
 /// <param name="pSession">The parent session.</param>
 /// <param name="pOldContext">The old context.</param>
 /// <param name="pNewContext">The new context.</param>
 public ContextChangedEventArgs(IUserCommandSession pSession, IUserCommandContext pOldContext, IUserCommandContext pNewContext)
 {
     this.Session    = pSession;
     this.OldContext = pOldContext;
     this.NewContext = pNewContext;
 }