예제 #1
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 UserCommandContext CreateContext(string pId)
        {
            // Validating the id.
            pId = pId.Trim();
            if (string.IsNullOrEmpty(pId))
            {
                return(null);
            }

            if (this.mContextes.ContainsKey(pId) == false)
            {
                UserCommandContext lContext = this.CustomCreateContext(this.mParentManager, pId);
                if (lContext != null)
                {
                    this.mContextes[pId] = lContext;
                    return(lContext);
                }
            }

            return(null);
        }
예제 #2
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 UserCommandContext SwitchContext(string pNewContextId)
        {
            if (this.CurrentContext != null && this.CurrentContext.Id == pNewContextId)
            {
                return(this.CurrentContext);
            }

            UserCommandContext lOldContext = this.CurrentContext;
            UserCommandContext 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;

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

                // Manager notification.
                this.mParentManager.NotifyContextChanged(lEventArgs);

                return(this.CurrentContext);
            }
        }