/// <summary>
        /// Starts the wizard by adding the required information to the
        /// session and invoking <see cref="IWizardController.OnWizardStart"/>
        /// and detecting the first step.
        /// </summary>
        /// <param name="engineContext">The engine context.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="redirect">if set to <c>true</c>, a redirect
        /// will be issued to the first step.</param>
        protected void StartWizard(IEngineContext engineContext, IController controller, IControllerContext controllerContext, bool redirect)
        {
            ResetSteps(engineContext, controller);

            var wizardController = (IWizardController)controller;

            var stepList = (IList)engineContext.Items["wizard.step.list"];

            var firstStep = (String)stepList[0];

            var wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);

            engineContext.Session[wizardName + "currentstepindex"] = 0;
            engineContext.Session[wizardName + "currentstep"]      = firstStep;

            wizardController.OnWizardStart();

            if (redirect)
            {
                if (wizardController.UseCurrentRouteForRedirects)
                {
                    engineContext.Response.RedirectUsingRoute(controllerContext.Name, firstStep, true);
                }
                else
                {
                    engineContext.Response.Redirect(controllerContext.AreaName, controllerContext.Name, firstStep);
                }
            }
        }
        /// <summary>
        /// Determines whether all wizard specific information is on the user session.
        /// </summary>
        /// <param name="engineContext">The engine context.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="controllerContext">The controller context.</param>
        /// <returns>
        ///     <c>true</c> if has session data; otherwise, <c>false</c>.
        /// </returns>
        protected bool HasRequiredSessionData(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
        {
            var wizardName = WizardUtils.ConstructWizardNamespace(controllerContext);

            return(engineContext.Session.Contains(wizardName + "currentstepindex") &&
                   engineContext.Session.Contains(wizardName + "currentstep"));
        }
Exemplo n.º 3
0
        protected bool HasRequiredSessionData(Controller controller)
        {
            String wizardName = WizardUtils.ConstructWizardNamespace(controller);

            IRailsEngineContext context = controller.Context;

            return(context.Session.Contains(wizardName + "currentstepindex") &&
                   context.Session.Contains(wizardName + "currentstep"));
        }
        /// <summary>
        /// Invoked when a step is accessed on the url,
        /// i.e. http://host/mywizard/firststep.rails and
        /// when an inner action is invoked like http://host/mywizard/firststep-save.rails
        /// </summary>
        /// <param name="engineContext">The engine context.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="controllerContext">The controller context.</param>
        private object OnStepActionRequested(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
        {
            if (currentStepInstance != null && !HasRequiredSessionData(engineContext, controller, controllerContext))
            {
                StartWizard(engineContext, controller, controllerContext, false);
            }

            controllerContext.SelectedViewName = null;

            var wizController = (IWizardController)controller;

            var wizardName  = WizardUtils.ConstructWizardNamespace(controllerContext);
            var currentStep = (String)engineContext.Session[wizardName + "currentstep"];

            // If OnBeforeStep returns false we stop
            if (!wizController.OnBeforeStep(wizardName, currentStep, currentStepInstance))
            {
                return(null);
            }

            var stepMetaDescriptor =
                engineContext.Services.ControllerDescriptorProvider.BuildDescriptor(currentStepInstance);

            // Record the step we're working with
            WizardUtils.RegisterCurrentStepInfo(engineContext, controller, controllerContext, currentStepInstance.ActionName);

            try
            {
                var stepContext =
                    engineContext.Services.ControllerContextFactory.Create(
                        controllerContext.AreaName, controllerContext.Name, innerAction,
                        stepMetaDescriptor, controllerContext.RouteMatch);
                stepContext.PropertyBag = controllerContext.PropertyBag;

                SetUpWizardHelper(engineContext, wizController, currentStepInstance, stepContext);

                // IsPreConditionSatisfied might need the controller's context
                if (currentStepInstance is Controller)
                {
                    ((Controller)currentStepInstance).Contextualize(engineContext, stepContext);
                }

                // The step cannot be accessed in the current state of matters
                if (!currentStepInstance.IsPreConditionSatisfied(engineContext))
                {
                    return(null);
                }

                currentStepInstance.Process(engineContext, stepContext);

                return(null);
            }
            finally
            {
                wizController.OnAfterStep(wizardName, currentStep, currentStepInstance);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sends a redirect to the previous wizard step
        /// </summary>
        /// <exception cref="MonoRailException">
        /// if no previous step exists (ie. already in the first one)</exception>
        protected virtual void RedirectToPreviousStep(IDictionary queryStringParameters)
        {
            var wizardName = WizardUtils.ConstructWizardNamespace(wizardcontrollerContext);

            var currentIndex = (int)Context.Session[wizardName + "currentstepindex"];

            var stepList = (IList)Context.Items["wizard.step.list"];

            if ((currentIndex - 1) >= 0)
            {
                var prevStepIndex = currentIndex - 1;

                var prevStep = (String)stepList[prevStepIndex];

                InternalRedirectToStep(Context, prevStepIndex, prevStep, queryStringParameters);
            }
            else
            {
                throw new MonoRailException("There is no previous step available");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sends a redirect to the previous wizard step
        /// </summary>
        /// <exception cref="RailsException">
        /// if no previous step exists (ie. already in the first one)</exception>
        protected void RedirectToPreviousStep()
        {
            String wizardName = WizardUtils.ConstructWizardNamespace(_wizardcontroller);

            int currentIndex = (int)Context.Session[wizardName + "currentstepindex"];

            IList stepList = (IList)Context.UnderlyingContext.Items["wizard.step.list"];

            if ((currentIndex - 1) >= 0)
            {
                int prevStepIndex = currentIndex - 1;

                String prevStep = (String)stepList[prevStepIndex];

                InternalRedirectToStep(prevStepIndex, prevStep);
            }
            else
            {
                throw new RailsException("No previous step available");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Invoked when a step is accessed on the url,
        /// i.e. http://host/mywizard/firststep.rails and
        /// when an inner action is invoked like http://host/mywizard/firststep-save.rails
        /// </summary>
        /// <param name="controller"></param>
        private void OnStepActionRequested(Controller controller)
        {
            controller.CancelView();

            IRailsEngineContext context = controller.Context;

            IWizardController wizController = (IWizardController)controller;

            String wizardName = WizardUtils.ConstructWizardNamespace(controller);

            String currentStep = (String)context.Session[wizardName + "currentstep"];

            // The step will inherit the controller property bag,
            // this way filters can pass values to the step property without having to know it
            currentStepInstance.PropertyBag = controller.PropertyBag;

            if (!wizController.OnBeforeStep(wizardName, currentStep, currentStepInstance))
            {
                return;
            }

            WizardUtils.RegisterCurrentStepInfo(controller, currentStepInstance.ActionName);

            if (innerAction == null || innerAction == String.Empty)
            {
                currentStepInstance.Process(
                    controller.Context, controller.ServiceProvider,
                    urlInfo.Area, urlInfo.Controller, "RenderWizardView");
            }
            else
            {
                currentStepInstance.Process(
                    controller.Context, controller.ServiceProvider,
                    urlInfo.Area, urlInfo.Controller, innerAction);
            }

            wizController.OnAfterStep(wizardName, currentStep, currentStepInstance);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sends a redirect to the next wizard step (if it exists)
        /// </summary>
        /// <exception cref="MonoRailException">if no further step exists</exception>
        protected virtual void RedirectToNextStep(IDictionary queryStringParameters)
        {
            var wizardName = WizardUtils.ConstructWizardNamespace(ControllerContext);

            var currentIndex = (int)Context.Session[wizardName + "currentstepindex"];

            var stepList = (IList)Context.Items["wizard.step.list"];

            if ((currentIndex + 1) < stepList.Count)
            {
                var nextStepIndex = currentIndex + 1;

                var nextStep = (String)stepList[nextStepIndex];

                WizardUtils.RegisterCurrentStepInfo(Context, wizardParentController, ControllerContext, nextStepIndex, nextStep);

                InternalRedirectToStep(Context, nextStepIndex, nextStep, queryStringParameters);
            }
            else
            {
                throw new MonoRailException("There is no next step available");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Sends a redirect to the next wizard step (if it exists)
        /// </summary>
        /// <exception cref="RailsException">if no further step exists</exception>
        protected void RedirectToNextStep()
        {
            String wizardName = WizardUtils.ConstructWizardNamespace(_wizardcontroller);

            int currentIndex = (int)Context.Session[wizardName + "currentstepindex"];

            IList stepList = (IList)Context.UnderlyingContext.Items["wizard.step.list"];

            if ((currentIndex + 1) < stepList.Count)
            {
                int nextStepIndex = currentIndex + 1;

                String nextStep = (String)stepList[nextStepIndex];

                WizardUtils.RegisterCurrentStepInfo(_wizardcontroller, nextStepIndex, nextStep);

                InternalRedirectToStep(nextStepIndex, nextStep);
            }
            else
            {
                throw new RailsException("No next step available");
            }
        }
Exemplo n.º 10
0
        protected void StartWizard(Controller controller, bool redirect)
        {
            ResetSteps(controller);

            IWizardController wizardController = controller as IWizardController;

            IRailsEngineContext context = controller.Context;

            IList stepList = (IList)context.UnderlyingContext.Items["wizard.step.list"];

            String firstStep = (String)stepList[0];

            String wizardName = WizardUtils.ConstructWizardNamespace(controller);

            context.Session[wizardName + "currentstepindex"] = 0;
            context.Session[wizardName + "currentstep"]      = firstStep;

            wizardController.OnWizardStart();

            if (redirect)
            {
                context.Response.Redirect(controller.Name, firstStep);
            }
        }